| Method from org.hibernate.type.EnumType Detail: |
public Object assemble(Serializable cached,
Object owner) throws HibernateException {
return cached;
}
|
public Object deepCopy(Object value) throws HibernateException {
return value;
}
|
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}
|
public boolean equals(Object x,
Object y) throws HibernateException {
return x == y;
}
|
public Object fromXMLString(String xmlValue) {
try {
int ordinal = Integer.parseInt( xmlValue );
Object[] values = enumValues.get( enumClass );
if ( values == null ) throw new AssertionFailure( "enumValues not preprocessed: " + enumClass );
if ( ordinal < 0 || ordinal >= values.length ) {
throw new IllegalArgumentException( "Unknown ordinal value for enum " + enumClass + ": " + ordinal );
}
return values[ordinal];
}
catch(NumberFormatException e) {
try {
return Enum.valueOf( enumClass, xmlValue );
}
catch (IllegalArgumentException iae) {
throw new IllegalArgumentException( "Unknown name value for enum " + enumClass + ": " + xmlValue, iae );
}
}
}
|
public int hashCode(Object x) throws HibernateException {
return x == null ? 0 : x.hashCode();
}
|
public boolean isMutable() {
return false;
}
|
public Object nullSafeGet(ResultSet rs,
String[] names,
Object owner) throws HibernateException, SQLException {
Object object = rs.getObject( names[0] );
if ( rs.wasNull() ) {
if ( IS_TRACE_ENABLED ) {
log.debug( "Returning null as column " + names[0] );
}
return null;
}
if ( object instanceof Number ) {
Object[] values = enumValues.get( enumClass );
if ( values == null ) throw new AssertionFailure( "enumValues not preprocessed: " + enumClass );
int ordinal = ( (Number) object ).intValue();
if ( ordinal < 0 || ordinal >= values.length ) {
throw new IllegalArgumentException( "Unknown ordinal value for enum " + enumClass + ": " + ordinal );
}
if ( IS_TRACE_ENABLED ) {
log.debug( "Returning '" + ordinal + "' as column " + names[0] );
}
return values[ordinal];
}
else {
String name = (String) object;
if ( IS_TRACE_ENABLED ) {
log.debug( "Returning '" + name + "' as column " + names[0] );
}
try {
return Enum.valueOf( enumClass, name );
}
catch (IllegalArgumentException iae) {
throw new IllegalArgumentException( "Unknown name value for enum " + enumClass + ": " + name, iae );
}
}
}
|
public void nullSafeSet(PreparedStatement st,
Object value,
int index) throws HibernateException, SQLException {
//if (!guessed) guessType( st, index );
if ( value == null ) {
if ( IS_TRACE_ENABLED ) log.debug( "Binding null to parameter: " + index );
st.setNull( index, sqlType );
}
else {
boolean isOrdinal = isOrdinal( sqlType );
if ( isOrdinal ) {
int ordinal = ( (Enum) value ).ordinal();
if ( IS_TRACE_ENABLED ) {
log.debug( "Binding '" + ordinal + "' to parameter: " + index );
}
st.setObject( index, Integer.valueOf( ordinal ), sqlType );
}
else {
String enumString = ( (Enum) value ).name();
if ( IS_TRACE_ENABLED ) {
log.debug( "Binding '" + enumString + "' to parameter: " + index );
}
st.setObject( index, enumString, sqlType );
}
}
}
|
public String objectToSQLString(Object value) {
boolean isOrdinal = isOrdinal( sqlType );
if ( isOrdinal ) {
int ordinal = ( (Enum) value ).ordinal();
return Integer.toString( ordinal );
}
else {
return '\'" + ( (Enum) value ).name() + '\'";
}
}
|
public Object replace(Object original,
Object target,
Object owner) throws HibernateException {
return original;
}
|
public Class returnedClass() {
return enumClass;
}
|
public void setParameterValues(Properties parameters) {
String enumClassName = parameters.getProperty( ENUM );
try {
enumClass = ReflectHelper.classForName( enumClassName, this.getClass() ).asSubclass( Enum.class );
}
catch (ClassNotFoundException exception) {
throw new HibernateException( "Enum class not found", exception );
}
//this is threadsafe to do it here, setParameterValues() is called sequencially
initEnumValue();
//nullify unnullified properties yuck!
schema = parameters.getProperty( SCHEMA );
if ( "".equals( schema ) ) schema = null;
catalog = parameters.getProperty( CATALOG );
if ( "".equals( catalog ) ) catalog = null;
table = parameters.getProperty( TABLE );
column = parameters.getProperty( COLUMN );
String type = parameters.getProperty( TYPE );
if ( type != null ) {
sqlType = Integer.decode( type ).intValue();
guessed = true;
}
}
|
public int[] sqlTypes() {
//before any guessing
return new int[]{sqlType};
}
|
public String toXMLString(Object value) {
boolean isOrdinal = isOrdinal( sqlType );
if ( isOrdinal ) {
int ordinal = ( (Enum) value ).ordinal();
return Integer.toString( ordinal );
}
else {
return ( (Enum) value ).name();
}
}
|