Author: steve.ebersole(a)jboss.com
Date: 2006-11-07 16:35:24 -0500 (Tue, 07 Nov 2006)
New Revision: 10756
Modified:
trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
Log:
javadocs
Modified: trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:12:32 UTC (rev
10755)
+++ trunk/Hibernate3/src/org/hibernate/type/TypeFactory.java 2006-11-07 21:35:24 UTC (rev
10756)
@@ -34,7 +34,7 @@
/**
* Used internally to obtain instances of <tt>Type</tt>. Applications should
use static methods
* and constants on <tt>org.hibernate.Hibernate</tt>.
- *
+ *
* @see org.hibernate.Hibernate
* @author Gavin King
*/
@@ -114,7 +114,7 @@
Type type = new AdaptedImmutableType(Hibernate.DATE);
basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.TIME);
- basics.put( type.getName(), type );
+ basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.TIMESTAMP);
basics.put( type.getName(), type );
type = new AdaptedImmutableType( new DbTimestampType() );
@@ -127,7 +127,7 @@
basics.put( type.getName(), type );
type = new AdaptedImmutableType(Hibernate.BINARY);
basics.put( type.getName(), type );
-
+
BASIC_TYPES = Collections.unmodifiableMap( basics );
}
@@ -139,13 +139,13 @@
* A one-to-one association type for the given class
*/
public static EntityType oneToOne(
- String persistentClass,
+ String persistentClass,
ForeignKeyDirection foreignKeyType,
- String uniqueKeyPropertyName,
- boolean lazy,
+ String uniqueKeyPropertyName,
+ boolean lazy,
boolean unwrapProxy,
- boolean isEmbeddedInXML,
- String entityName,
+ boolean isEmbeddedInXML,
+ String entityName,
String propertyName
) {
return new OneToOneType(
@@ -156,7 +156,7 @@
unwrapProxy,
isEmbeddedInXML,
entityName,
- propertyName
+ propertyName
);
}
@@ -178,18 +178,18 @@
* A many-to-one association type for the given class
*/
public static EntityType manyToOne(
- String persistentClass,
+ String persistentClass,
String uniqueKeyPropertyName,
- boolean lazy,
- boolean unwrapProxy,
+ boolean lazy,
+ boolean unwrapProxy,
boolean isEmbeddedInXML,
boolean ignoreNotFound
) {
- return new ManyToOneType(
- persistentClass,
- uniqueKeyPropertyName,
+ return new ManyToOneType(
+ persistentClass,
+ uniqueKeyPropertyName,
lazy,
- unwrapProxy,
+ unwrapProxy,
isEmbeddedInXML,
ignoreNotFound
);
@@ -232,9 +232,9 @@
type = (Type) typeClass.newInstance();
}
catch (Exception e) {
- throw new MappingException(
+ throw new MappingException(
"Could not instantiate Type: " + typeClass.getName(),
- e
+ e
);
}
injectParameters(type, parameters);
@@ -314,11 +314,36 @@
return new SortedSetType( role, propertyRef, comparator, embedded );
}
+ public static void injectParameters(Object type, Properties parameters) {
+ if (type instanceof ParameterizedType) {
+ ( (ParameterizedType) type ).setParameterValues(parameters);
+ }
+ else if ( parameters!=null && !parameters.isEmpty() ) {
+ throw new MappingException(
+ "type is not parameterized: " +
+ type.getClass().getName()
+ );
+ }
+ }
+
+
+ // convenience methods relating to operations across arrays of types...
+
/**
- * Deep copy values in the first array into the second
+ * Deep copy a series of values from one array to another...
+ *
+ * @param values The values to copy (the source)
+ * @param types The value types
+ * @param copy an array indicating which values to include in the copy
+ * @param target The array into which to copy the values
+ * @param session The orginating session
*/
- public static void deepCopy(Object[] values, Type[] types, boolean[] copy, Object[]
target,
- SessionImplementor session) throws HibernateException {
+ public static void deepCopy(
+ final Object[] values,
+ final Type[] types,
+ final boolean[] copy,
+ final Object[] target,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
if ( copy[i] ) {
if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -334,57 +359,17 @@
}
/**
- * Determine if any of the given field values are dirty, returning an array containing
indexes
- * of the dirty fields or <tt>null</tt> if no fields are dirty.
+ * Apply the {@link Type#beforeAssemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
*/
- /*public static int[] findDirty(Type[] types, Object[] x, Object[] y, boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
+ public static void beforeAssemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session) {
for ( int i = 0; i < types.length; i++ ) {
- if ( check[i] && types[i].isDirty( x[i], y[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- /**
- * Determine if any of the given field values are modified, returning an array
containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- */
- /*public static int[] findModified(Type[] types, Object[] old, Object[] current,
boolean[] check,
- SessionImplementor session) throws HibernateException {
- int[] results = null;
- int count = 0;
- for ( int i = 0; i < types.length; i++ ) {
- if ( check[i]
- && types[i].isModified( old[i], current[i], session ) ) {
- if ( results == null ) results = new int[types.length];
- results[count++] = i;
- }
- }
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
- }*/
-
- public static void beforeAssemble(Serializable[] row, Type[] types, SessionImplementor
session)
- throws HibernateException {
- for ( int i = 0; i < types.length; i++ ) {
if ( row[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
&& row[i] != BackrefPropertyAccessor.UNKNOWN ) {
types[i].beforeAssemble( row[i], session );
@@ -392,12 +377,23 @@
}
}
- public static Object[] assemble(Serializable[] row, Type[] types, SessionImplementor
session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#assemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The assembled state
+ */
+ public static Object[] assemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner) {
Object[] assembled = new Object[row.length];
for ( int i = 0; i < types.length; i++ ) {
- if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] ==
BackrefPropertyAccessor.UNKNOWN ) {
assembled[i] = row[i];
}
else {
@@ -407,15 +403,28 @@
return assembled;
}
- public static Serializable[] disassemble(Object[] row, Type[] types, boolean[]
nonCacheable, SessionImplementor session,
- Object owner) throws HibernateException {
+ /**
+ * Apply the {@link Type#disassemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param nonCacheable An array indicating which values to include in the disassemled
state
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @return The disassembled state
+ */
+ public static Serializable[] disassemble(
+ final Object[] row,
+ final Type[] types,
+ final boolean[] nonCacheable,
+ final SessionImplementor session,
+ final Object owner) {
Serializable[] disassembled = new Serializable[row.length];
for ( int i = 0; i < row.length; i++ ) {
if ( nonCacheable!=null && nonCacheable[i] ) {
disassembled[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
}
- else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] ==
BackrefPropertyAccessor.UNKNOWN ) {
disassembled[i] = (Serializable) row[i];
}
else {
@@ -425,8 +434,24 @@
return disassembled;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -440,9 +465,26 @@
return copied;
}
- public static Object[] replace(Object[] original, Object[] target, Type[] types,
- SessionImplementor session, Object owner, Map copyCache,
- ForeignKeyDirection foreignKeyDirection) throws HibernateException {
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The orginating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @param foreignKeyDirection FK directionality to be applied to the replacement
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache,
+ final ForeignKeyDirection foreignKeyDirection) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
@@ -459,37 +501,40 @@
/**
- * Determine if any of the given field values are dirty, returning an array containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state from the time the object was loaded
+ * Determine if any of the given field values are dirty, returning an array containing
+ * indices of the dirty fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the dirty checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized
property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the dirty properties, or null if no properties
considered dirty.
*/
public static int[] findDirty(
- final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final StandardProperty[] properties,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean dirty = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the
"current" state
- && properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isDirty( y[i], x[i], includeColumns[i], session
);
-
+ final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && properties[i].isDirtyCheckable( anyUninitializedProperties )
+ && properties[i].getType().isDirty( previousState[i], currentState[i],
includeColumns[i], session );
if ( dirty ) {
if ( results == null ) {
results = new int[span];
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -504,28 +549,33 @@
/**
* Determine if any of the given field values are modified, returning an array
containing
- * indexes of the dirty fields or <tt>null</tt> if no fields are dirty.
- * @param x the current state of the entity
- * @param y the snapshot state just retrieved from the database
+ * indices of the modified fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the mod checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized
property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the modified properties, or null if no properties
considered modified.
*/
public static int[] findModified(
final StandardProperty[] properties,
- final Object[] x,
- final Object[] y,
+ final Object[] currentState,
+ final Object[] previousState,
final boolean[][] includeColumns,
- final boolean anyUninitializedProperties,
- final SessionImplementor session)
- throws HibernateException {
-
+ final boolean anyUninitializedProperties,
+ final SessionImplementor session) {
int[] results = null;
int count = 0;
int span = properties.length;
for ( int i = 0; i < span; i++ ) {
-
- final boolean modified = x[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY //x is the
"current" state
+ final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
&& properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isModified( y[i], x[i], includeColumns[i],
session );
+ && properties[i].getType().isModified( previousState[i], currentState[i],
includeColumns[i], session );
if ( modified ) {
if ( results == null ) {
@@ -533,7 +583,6 @@
}
results[count++] = i;
}
-
}
if ( count == 0 ) {
@@ -546,16 +595,4 @@
}
}
- public static void injectParameters(Object type, Properties parameters) {
- if (type instanceof ParameterizedType) {
- ( (ParameterizedType) type ).setParameterValues(parameters);
- }
- else if ( parameters!=null && !parameters.isEmpty() ) {
- throw new MappingException(
- "type is not parameterized: " +
- type.getClass().getName()
- );
- }
- }
-
}