Author: steve.ebersole(a)jboss.com
Date: 2006-10-26 09:39:23 -0400 (Thu, 26 Oct 2006)
New Revision: 10654
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Classification.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ClassificationType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Zoo.java
Log:
use ordinal value for db value
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Classification.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Classification.java 2006-10-26
13:38:50 UTC (rev 10653)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Classification.java 2006-10-26
13:39:23 UTC (rev 10654)
@@ -64,4 +64,15 @@
public static Classification valueOf(String name) {
return ( Classification ) INSTANCES.get( name );
}
+
+ public static Classification valueOf(Integer ordinal) {
+ if ( ordinal == null ) {
+ return null;
+ }
+ switch ( ordinal.intValue() ) {
+ case 0: return COOL;
+ case 1: return LAME;
+ default: throw new IllegalArgumentException( "unknown classification ordinal
[" + ordinal + "]" );
+ }
+ }
}
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ClassificationType.java
===================================================================
---
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ClassificationType.java 2006-10-26
13:38:50 UTC (rev 10653)
+++
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ClassificationType.java 2006-10-26
13:39:23 UTC (rev 10654)
@@ -1,6 +1,5 @@
package org.hibernate.test.hql;
-import org.hibernate.usertype.UserType;
import org.hibernate.usertype.EnhancedUserType;
import org.hibernate.HibernateException;
import org.hibernate.Hibernate;
@@ -12,7 +11,11 @@
import java.io.Serializable;
/**
- * todo: describe ClassificationType
+ * A custom type for mapping {@link org.hibernate.test.hql.Classification} instances
+ * to the respective db column.
+ * </p>
+ * THis is largely intended to mimic JDK5 enum support in JPA. Here we are
+ * using the approach of storing the ordinal values, rather than the names.
*
* @author Steve Ebersole
*/
@@ -43,13 +46,13 @@
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
HibernateException, SQLException {
- String name = ( String ) Hibernate.STRING.nullSafeGet( rs, names[0] );
- return name == null ? null : Classification.valueOf( name );
+ Integer ordinal = ( Integer ) Hibernate.INTEGER.nullSafeGet( rs, names[0] );
+ return Classification.valueOf( ordinal );
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws
HibernateException, SQLException {
- String name = value == null ? null : ( ( Classification ) value ).name();
- Hibernate.STRING.nullSafeSet( st, name, index );
+ Integer ordinal = value == null ? null : new Integer( ( ( Classification ) value
).ordinal() );
+ Hibernate.INTEGER.nullSafeSet( st, ordinal, index );
}
public Object deepCopy(Object value) throws HibernateException {
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Zoo.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Zoo.java 2006-10-26
13:38:50 UTC (rev 10653)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/Zoo.java 2006-10-26
13:39:23 UTC (rev 10654)
@@ -53,4 +53,13 @@
public void setAddress(Address address) {
this.address = address;
}
+
+
+ public Classification getClassification() {
+ return classification;
+ }
+
+ public void setClassification(Classification classification) {
+ this.classification = classification;
+ }
}
Show replies by date