org.apache.cayenne.access.types
Class CharType

java.lang.Object
  extended by org.apache.cayenne.access.types.AbstractType
      extended by org.apache.cayenne.access.types.CharType
All Implemented Interfaces:
ExtendedType

public class CharType
extends AbstractType

Handles java.lang.String, mapping it as either of JDBC types - CLOB or (VAR)CHAR. Can be configured to trim trailing spaces.

Author:
Andrus Adamchik

Field Summary
protected  boolean trimmingChars
           
protected  boolean usingClobs
           
 
Constructor Summary
CharType(boolean trimingChars, boolean usingClobs)
           
 
Method Summary
 java.lang.String getClassName()
          Returns "java.lang.String".
 boolean isTrimmingChars()
          Returns true if 'materializeObject' method should trim trailing spaces from the CHAR columns.
 boolean isUsingClobs()
           
 java.lang.Object materializeObject(java.sql.CallableStatement cs, int index, int type)
          Return trimmed string.
 java.lang.Object materializeObject(java.sql.ResultSet rs, int index, int type)
          Return trimmed string.
protected  java.lang.String readCharStream(java.sql.ResultSet rs, int index)
           
protected  java.lang.String readClob(java.sql.Clob clob)
           
protected  java.lang.String readValueStream(java.io.Reader in, int streamSize, int bufSize)
           
 void setJdbcObject(java.sql.PreparedStatement st, java.lang.Object val, int pos, int type, int precision)
          Calls "PreparedStatement.setObject(..)".
 void setTrimmingChars(boolean trimingChars)
           
 void setUsingClobs(boolean usingClobs)
           
 boolean validateProperty(java.lang.Object source, java.lang.String property, java.lang.Object value, DbAttribute dbAttribute, ValidationResult validationResult)
          Validates string property.
 
Methods inherited from class org.apache.cayenne.access.types.AbstractType
toString, validateNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trimmingChars

protected boolean trimmingChars

usingClobs

protected boolean usingClobs
Constructor Detail

CharType

public CharType(boolean trimingChars,
                boolean usingClobs)
Method Detail

getClassName

public java.lang.String getClassName()
Returns "java.lang.String".

Specified by:
getClassName in interface ExtendedType
Specified by:
getClassName in class AbstractType

validateProperty

public boolean validateProperty(java.lang.Object source,
                                java.lang.String property,
                                java.lang.Object value,
                                DbAttribute dbAttribute,
                                ValidationResult validationResult)
Validates string property.

Specified by:
validateProperty in interface ExtendedType
Overrides:
validateProperty in class AbstractType
Since:
1.1

materializeObject

public java.lang.Object materializeObject(java.sql.ResultSet rs,
                                          int index,
                                          int type)
                                   throws java.lang.Exception
Return trimmed string.

Specified by:
materializeObject in interface ExtendedType
Specified by:
materializeObject in class AbstractType
Throws:
java.lang.Exception - if read error ocurred, or an object can't be converted to a target Java class.

materializeObject

public java.lang.Object materializeObject(java.sql.CallableStatement cs,
                                          int index,
                                          int type)
                                   throws java.lang.Exception
Return trimmed string.

Specified by:
materializeObject in interface ExtendedType
Specified by:
materializeObject in class AbstractType
Throws:
java.lang.Exception - if read error ocurred, or an object can't be converted to a target Java class.

setJdbcObject

public void setJdbcObject(java.sql.PreparedStatement st,
                          java.lang.Object val,
                          int pos,
                          int type,
                          int precision)
                   throws java.lang.Exception
Description copied from class: AbstractType
Calls "PreparedStatement.setObject(..)". Some DbAdapters may need to override this behavior for at least some of the object types, as it doesn't work consistently across all JDBC drivers.

Specified by:
setJdbcObject in interface ExtendedType
Overrides:
setJdbcObject in class AbstractType
Throws:
java.lang.Exception

readClob

protected java.lang.String readClob(java.sql.Clob clob)
                             throws java.io.IOException,
                                    java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

readCharStream

protected java.lang.String readCharStream(java.sql.ResultSet rs,
                                          int index)
                                   throws java.io.IOException,
                                          java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

readValueStream

protected java.lang.String readValueStream(java.io.Reader in,
                                           int streamSize,
                                           int bufSize)
                                    throws java.io.IOException
Throws:
java.io.IOException

isTrimmingChars

public boolean isTrimmingChars()
Returns true if 'materializeObject' method should trim trailing spaces from the CHAR columns. This addresses an issue with some JDBC drivers (e.g. Oracle), that return Strings for CHAR columsn padded with spaces.


setTrimmingChars

public void setTrimmingChars(boolean trimingChars)

isUsingClobs

public boolean isUsingClobs()

setUsingClobs

public void setUsingClobs(boolean usingClobs)


Copyright © 2001-2006 Apache.org All Rights Reserved.