net.sourceforge.squirrel_sql.plugins.derby.types
Class DerbyClobDataTypeComponent

java.lang.Object
  extended by net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent
      extended by net.sourceforge.squirrel_sql.plugins.derby.types.DerbyClobDataTypeComponent
All Implemented Interfaces:
IDataTypeComponent

public class DerbyClobDataTypeComponent
extends BaseDataTypeComponent
implements IDataTypeComponent

Author:
manningr This class provides the display components for handling Derby Clob data types, specifically SQL type CLOB. This is a necessary override of the default implementation provided in SQuirreL's fw module since newer versions of Derby disallow access to a CLOB Locator once the transaction has been committed. This implementation therefore doesn't support partial reading the clob contents or placeholders to allow the user to later fetch the remaining data from the saved CLOB. There is no point to saving the CLOB so all of the data is fetched, always. This should probably be re-implemented somehow (perhaps using the primary key to fetch the data when placeholders are clicked). The display components are for: The class also contains

The components returned from this class extend RestorableJTextField and RestorableJTextArea for use in editing table cells that contain values of this data type. It provides the special behavior for null handling and resetting the cell to the original value.


Field Summary
 
Fields inherited from class net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent
_beepHelper, _colDef, _table, _textArea, _textField, NULL_VALUE_PATTERN
 
Constructor Summary
DerbyClobDataTypeComponent()
          Default Constructor
 
Method Summary
 boolean areEqual(Object obj1, Object obj2)
          Determine if two objects of this data type contain the same value.
 boolean canDoFileIO()
          Can always do File I/O with Derby clobs.
 void exportObject(FileOutputStream outStream, String text)
          Construct an appropriate external representation of the object and write it to a file.
 String getClassName()
          Return the name of the java class used to hold this data type.
 Object getDefaultValue(String dbDefaultValue)
          Get a default value for the table used to input data for a new row to be inserted into the DB.
 JTextArea getJTextArea(Object value)
           
 JTextField getJTextField()
          Return a JTextField usable in a CellEditor.
protected  KeyListener getKeyListener(IRestorableTextComponent component)
          If any custom key handling behavior is required, this can be set by sub-class implementations
static boolean getReadCompleteClob()
          Used to provide manual override in cases where we are exporting data.
 IWhereClausePart getWhereClauseValue(Object value, ISQLDatabaseMetaData md)
          When updating the database, generate a string form of this object value that can be used in the WHERE clause to match the value in the database.
 String importObject(FileInputStream inStream)
          Read a file and construct a valid object from its contents.
 boolean isEditableInCell(Object originalValue)
          This Data Type can be edited in a table cell.
 boolean isEditableInPopup(Object originalValue)
          Returns true if data type may be edited in the popup, false if not.
 boolean needToReRead(Object originalValue)
          Derby doesn't support using a Clob descriptor after the transaction that read it is closed.
 Object readResultSet(ResultSet rs, int index, boolean limitDataRead)
          On input from the DB, read the data from the ResultSet into the appropriate type of object to be stored in the table cell.
 String renderObject(Object value)
          Render a value into text for this DataType.
 void setColumnDisplayDefinition(ColumnDisplayDefinition def)
           
 void setPreparedStatementValue(PreparedStatement pstmt, Object value, int position)
          When updating the database, insert the appropriate datatype into the prepared statment at the given variable position.
static void setReadCompleteClob(boolean val)
          Used to provide manual override in cases where we are exporting data.
static Object staticReadResultSet(ResultSet rs, int index)
          Derby does not allow to read a Clob, end the transaction, then attempt to get it's contents later.
 boolean useBinaryEditingPanel()
          If true, this tells the PopupEditableIOPanel to use the binary editing panel rather than a pure text panel.
 Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer)
          Implement the interface for validating and converting to internal object.
 Object validateAndConvertInPopup(String value, Object originalValue, StringBuffer messageBuffer)
           
 
Methods inherited from class net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent
setBeepHelper, setTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IDataTypeComponent
setBeepHelper, setTable
 

Constructor Detail

DerbyClobDataTypeComponent

public DerbyClobDataTypeComponent()
Default Constructor

Method Detail

getClassName

public String getClassName()
Return the name of the java class used to hold this data type.

Specified by:
getClassName in interface IDataTypeComponent
Overrides:
getClassName in class BaseDataTypeComponent

getReadCompleteClob

public static boolean getReadCompleteClob()
Used to provide manual override in cases where we are exporting data.

Returns:
the current value of _readCompleteClob

setReadCompleteClob

public static void setReadCompleteClob(boolean val)
Used to provide manual override in cases where we are exporting data.

Parameters:
val - the new value of _readCompleteClob

areEqual

public boolean areEqual(Object obj1,
                        Object obj2)
Determine if two objects of this data type contain the same value. Neither of the objects is null

Specified by:
areEqual in interface IDataTypeComponent
Overrides:
areEqual in class BaseDataTypeComponent

renderObject

public String renderObject(Object value)
Render a value into text for this DataType.

Specified by:
renderObject in interface IDataTypeComponent
Overrides:
renderObject in class BaseDataTypeComponent

isEditableInCell

public boolean isEditableInCell(Object originalValue)
This Data Type can be edited in a table cell. This function is not called during the initial table load, or during normal table operations. It is called only when the user enters the cell, either to examine or to edit the data. The user may have set the DataType properties to minimize the data read during the initial table load (to speed it up), but when they enter this cell we would like to show them the entire contents of the CLOB. Therefore we use a call to this function as a trigger to make sure that we have all of the CLOB data, if that is possible.

If the data includes newlines, the user must not be allowed to edit it in the cell because the CellEditor uses a JTextField which filters out newlines. If we try to use anything other than a JTextField, or use a JTextField with no newline filtering, the text is not visible in the cell, so the user cannot even read the text, much less edit it. The simplest solution is to allow editing of multi-line text only in the Popup window.

Specified by:
isEditableInCell in interface IDataTypeComponent

needToReRead

public boolean needToReRead(Object originalValue)
Derby doesn't support using a Clob descriptor after the transaction that read it is closed. So we never have to re-read.

Specified by:
needToReRead in interface IDataTypeComponent

setColumnDisplayDefinition

public void setColumnDisplayDefinition(ColumnDisplayDefinition def)
Specified by:
setColumnDisplayDefinition in interface IDataTypeComponent
Overrides:
setColumnDisplayDefinition in class BaseDataTypeComponent
See Also:
BaseDataTypeComponent.setColumnDisplayDefinition(net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition)

validateAndConvert

public Object validateAndConvert(String value,
                                 Object originalValue,
                                 StringBuffer messageBuffer)
Implement the interface for validating and converting to internal object. Null is a valid successful return, so errors are indicated only by existance or not of a message in the messageBuffer. If originalValue is null, then we are just checking that the data is in a valid format (for file import/export) and not actually converting the data.

Specified by:
validateAndConvert in interface IDataTypeComponent
Overrides:
validateAndConvert in class BaseDataTypeComponent

useBinaryEditingPanel

public boolean useBinaryEditingPanel()
If true, this tells the PopupEditableIOPanel to use the binary editing panel rather than a pure text panel. The binary editing panel assumes the data is an array of bytes, converts it into text form, allows the user to change how that data is displayed (e.g. Hex, Decimal, etc.), and converts the data back from text to bytes when the user editing is completed. If this returns false, this DataType class must convert the internal data into a text string that can be displayed (and edited, if allowed) in a TextField or TextArea, and must handle all user key strokes related to editing of that data.

Specified by:
useBinaryEditingPanel in interface IDataTypeComponent

isEditableInPopup

public boolean isEditableInPopup(Object originalValue)
Returns true if data type may be edited in the popup, false if not.

Specified by:
isEditableInPopup in interface IDataTypeComponent

validateAndConvertInPopup

public Object validateAndConvertInPopup(String value,
                                        Object originalValue,
                                        StringBuffer messageBuffer)
Specified by:
validateAndConvertInPopup in interface IDataTypeComponent
Overrides:
validateAndConvertInPopup in class BaseDataTypeComponent
See Also:
BaseDataTypeComponent.validateAndConvertInPopup(java.lang.String, java.lang.Object, java.lang.StringBuffer)

getKeyListener

protected KeyListener getKeyListener(IRestorableTextComponent component)
If any custom key handling behavior is required, this can be set by sub-class implementations

Overrides:
getKeyListener in class BaseDataTypeComponent

getJTextField

public JTextField getJTextField()
Return a JTextField usable in a CellEditor.

Specified by:
getJTextField in interface IDataTypeComponent
Overrides:
getJTextField in class BaseDataTypeComponent

getJTextArea

public JTextArea getJTextArea(Object value)
Specified by:
getJTextArea in interface IDataTypeComponent
Overrides:
getJTextArea in class BaseDataTypeComponent

readResultSet

public Object readResultSet(ResultSet rs,
                            int index,
                            boolean limitDataRead)
                     throws SQLException
On input from the DB, read the data from the ResultSet into the appropriate type of object to be stored in the table cell.

Specified by:
readResultSet in interface IDataTypeComponent
Throws:
SQLException

staticReadResultSet

public static Object staticReadResultSet(ResultSet rs,
                                         int index)
                                  throws SQLException
Derby does not allow to read a Clob, end the transaction, then attempt to get it's contents later. So we simply read the entire thing.

Parameters:
rs -
index -
Returns:
Throws:
SQLException

getWhereClauseValue

public IWhereClausePart getWhereClauseValue(Object value,
                                            ISQLDatabaseMetaData md)
When updating the database, generate a string form of this object value that can be used in the WHERE clause to match the value in the database. A return value of null means that this column cannot be used in the WHERE clause, while a return of "null" (or "is null", etc) means that the column can be used in the WHERE clause and the value is actually a null value. This function must also include the column label so that its output is of the form: "columnName = value" or "columnName is null" or whatever is appropriate for this column in the database.

Specified by:
getWhereClauseValue in interface IDataTypeComponent
Overrides:
getWhereClauseValue in class BaseDataTypeComponent

setPreparedStatementValue

public void setPreparedStatementValue(PreparedStatement pstmt,
                                      Object value,
                                      int position)
                               throws SQLException
When updating the database, insert the appropriate datatype into the prepared statment at the given variable position.

Specified by:
setPreparedStatementValue in interface IDataTypeComponent
Throws:
SQLException

getDefaultValue

public Object getDefaultValue(String dbDefaultValue)
Get a default value for the table used to input data for a new row to be inserted into the DB.

Specified by:
getDefaultValue in interface IDataTypeComponent

canDoFileIO

public boolean canDoFileIO()
Can always do File I/O with Derby clobs.

Specified by:
canDoFileIO in interface IDataTypeComponent
See Also:
IDataTypeComponent.canDoFileIO()

importObject

public String importObject(FileInputStream inStream)
                    throws IOException
Read a file and construct a valid object from its contents. Errors are returned by throwing an IOException containing the cause of the problem as its message.

DataType is responsible for validating that the imported data can be converted to an object, and then must return a text string that can be used in the Popup window text area. This object-to-text conversion is the same as is done by the DataType object internally in the getJTextArea() method.

File is assumed to be and ASCII string of digits representing a value of this data type.

Specified by:
importObject in interface IDataTypeComponent
Overrides:
importObject in class BaseDataTypeComponent
Throws:
IOException

exportObject

public void exportObject(FileOutputStream outStream,
                         String text)
                  throws IOException
Construct an appropriate external representation of the object and write it to a file. Errors are returned by throwing an IOException containing the cause of the problem as its message.

DataType is responsible for validating that the given text text from a Popup JTextArea can be converted to an object. This text-to-object conversion is the same as validateAndConvertInPopup, which may be used internally by the object to do the validation.

The DataType object must flush and close the output stream before returning. Typically it will create another object (e.g. an OutputWriter), and that is the object that must be flushed and closed.

File is assumed to be and ASCII string of digits representing a value of this data type.

Specified by:
exportObject in interface IDataTypeComponent
Overrides:
exportObject in class BaseDataTypeComponent
Throws:
IOException


Copyright © 2001-2011. All Rights Reserved.