Hibernate SVN: r19650 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validator/test/engine/messageinterpolation and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-02 05:30:55 -0400 (Wed, 02 Jun 2010)
New Revision: 19650
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
Log:
HV-330
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java 2010-06-02 05:15:54 UTC (rev 19649)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/messageinterpolation/ResourceBundleMessageInterpolator.java 2010-06-02 09:30:55 UTC (rev 19650)
@@ -74,6 +74,11 @@
*/
private final Map<LocalisedMessage, String> resolvedMessages = new WeakHashMap<LocalisedMessage, String>();
+ /**
+ * Flag indicating whether this interpolator should chance some of the interpolation steps.
+ */
+ private final boolean cacheMessages;
+
public ResourceBundleMessageInterpolator() {
this( ( ResourceBundleLocator ) null );
}
@@ -95,7 +100,11 @@
}
public ResourceBundleMessageInterpolator(ResourceBundleLocator userResourceBundleLocator) {
+ this( userResourceBundleLocator, true );
+ }
+ public ResourceBundleMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, boolean cacheMessages) {
+
defaultLocale = Locale.getDefault();
if ( userResourceBundleLocator == null ) {
@@ -113,6 +122,8 @@
new CachingResourceBundleLocator(
new PlatformResourceBundleLocator( DEFAULT_VALIDATION_MESSAGES )
);
+
+ this.cacheMessages = cacheMessages;
}
public String interpolate(String message, Context context) {
@@ -134,14 +145,18 @@
*
* @param message the message to interpolate
* @param annotationParameters the parameters of the annotation for which to interpolate this message
- * @param locale the <code>Locale</code> to use for the resource bundle.
+ * @param locale the {@code Locale} to use for the resource bundle.
*
* @return the interpolated message.
*/
private String interpolateMessage(String message, Map<String, Object> annotationParameters, Locale locale) {
LocalisedMessage localisedMessage = new LocalisedMessage( message, locale );
- String resolvedMessage = resolvedMessages.get( localisedMessage );
+ String resolvedMessage = null;
+ if ( cacheMessages ) {
+ resolvedMessage = resolvedMessages.get( localisedMessage );
+ }
+
// if the message is not already in the cache we have to run step 1-3 of the message resolution
if ( resolvedMessage == null ) {
ResourceBundle userResourceBundle = userResourceBundleLocator
@@ -168,7 +183,9 @@
// search the default bundle non recursive (step2)
resolvedMessage = replaceVariables( userBundleResolvedMessage, defaultResourceBundle, locale, false );
evaluatedDefaultBundleOnce = true;
- resolvedMessages.put( localisedMessage, resolvedMessage );
+ if ( cacheMessages ) {
+ resolvedMessages.put( localisedMessage, resolvedMessage );
+ }
} while ( true );
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java 2010-06-02 05:15:54 UTC (rev 19649)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/test/engine/messageinterpolation/ResourceBundleMessageInterpolatorTest.java 2010-06-02 09:30:55 UTC (rev 19650)
@@ -34,10 +34,10 @@
import org.hibernate.validator.engine.MessageInterpolatorContext;
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+import org.hibernate.validator.metadata.ConstraintDescriptorImpl;
import org.hibernate.validator.metadata.ConstraintHelper;
+import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.resourceloading.ResourceBundleLocator;
-import org.hibernate.validator.metadata.ConstraintDescriptorImpl;
-import org.hibernate.validator.metadata.ConstraintOrigin;
import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
@@ -264,12 +264,67 @@
}
/**
+ * HV-330
+ */
+ @Test
+ public void testMessageCaching() {
+
+ // do the whole tests first with caching enabled
+ TestResourceBundle testBundle = new TestResourceBundle();
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator( testBundle )
+ );
+ MessageInterpolator.Context context = new MessageInterpolatorContext( notNullDescriptor, null );
+
+ String expected = "{hv-330}";
+ String actual = interpolator.interpolate( "{hv-330}", context );
+ assertEquals( actual, expected, "The key should not not exist in the bundle." );
+
+ testBundle.addOrUpdateMessage( "hv-330", "success" );
+ expected = "{hv-330}";
+ actual = interpolator.interpolate( "{hv-330}", context );
+ assertEquals(
+ actual,
+ expected,
+ "The message has not changed since per default the ResourceBundleMessageInterpolator caches the messages"
+ );
+
+ // now without caching
+ testBundle = new TestResourceBundle();
+ interpolator = new ResourceBundleMessageInterpolator(
+ new TestResourceBundleLocator( testBundle ), false
+ );
+ context = new MessageInterpolatorContext( notNullDescriptor, null );
+
+ expected = "{hv-330}";
+ actual = interpolator.interpolate( "{hv-330}", context );
+ assertEquals( actual, expected, "The key should not not exist in the bundle." );
+
+ testBundle.addOrUpdateMessage( "hv-330", "success" );
+ expected = "success";
+ actual = interpolator.interpolate( "{hv-330}", context );
+ assertEquals(
+ actual,
+ expected,
+ "The message should change since ResourceBundleMessageInterpolator does not cache"
+ );
+ }
+
+ /**
* A dummy locator always returning a {@link TestResourceBundle}.
*/
private static class TestResourceBundleLocator implements ResourceBundleLocator {
- private TestResourceBundle resourceBundle = new TestResourceBundle();
+ private final ResourceBundle resourceBundle;
+ public TestResourceBundleLocator() {
+ this( new TestResourceBundle() );
+ }
+
+ public TestResourceBundleLocator(ResourceBundle bundle) {
+ resourceBundle = bundle;
+ }
+
public ResourceBundle getResourceBundle(Locale locale) {
return resourceBundle;
}
@@ -315,5 +370,10 @@
throw new NoSuchElementException();
}
}
+
+ public void addOrUpdateMessage(String key, String message) {
+ testResources.put( key, message );
+ iter = testResources.keySet().iterator();
+ }
}
}
14 years, 9 months
Hibernate SVN: r19649 - in core/trunk/core/src: main/java/org/hibernate/type and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-02 01:15:54 -0400 (Wed, 02 Jun 2010)
New Revision: 19649
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
core/trunk/core/src/main/java/org/hibernate/type/CustomType.java
core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java
core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java
Log:
HHH-5262 - Allow UserType and CompositeUserType to be registered with BasicTypeRegistry
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -58,6 +58,7 @@
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import org.hibernate.DuplicateMappingException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
@@ -66,9 +67,6 @@
import org.hibernate.MappingNotFoundException;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
-import org.hibernate.DuplicateMappingException;
-import org.hibernate.id.IdentifierGeneratorAggregator;
-import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.SQLFunction;
@@ -107,36 +105,39 @@
import org.hibernate.event.ReplicateEventListener;
import org.hibernate.event.SaveOrUpdateEventListener;
import org.hibernate.id.IdentifierGenerator;
+import org.hibernate.id.IdentifierGeneratorAggregator;
import org.hibernate.id.PersistentIdentifierGenerator;
+import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
-import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory;
import org.hibernate.impl.SessionFactoryImpl;
import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.DenormalizedTable;
+import org.hibernate.mapping.FetchProfile;
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.IdentifierCollection;
import org.hibernate.mapping.Index;
+import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
+import org.hibernate.mapping.TypeDef;
import org.hibernate.mapping.UniqueKey;
-import org.hibernate.mapping.FetchProfile;
-import org.hibernate.mapping.DenormalizedTable;
-import org.hibernate.mapping.TypeDef;
-import org.hibernate.mapping.Column;
-import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.secure.JACCConfiguration;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
+import org.hibernate.tool.hbm2ddl.IndexMetadata;
import org.hibernate.tool.hbm2ddl.TableMetadata;
-import org.hibernate.tool.hbm2ddl.IndexMetadata;
+import org.hibernate.tuple.entity.EntityTuplizerFactory;
import org.hibernate.type.BasicType;
-import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.SerializationException;
import org.hibernate.type.Type;
import org.hibernate.type.TypeResolver;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.usertype.UserType;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.ConfigHelper;
@@ -2287,10 +2288,25 @@
return typeResolver;
}
+ /**
+ * Allows registration of a type into the type regsitry. The phrase 'override' in the method name simply
+ * reminds that registration *potentially* replaces a previously registered type .
+ *
+ * @param type The type to register.
+ */
public void registerTypeOverride(BasicType type) {
getTypeResolver().registerTypeOverride( type );
}
+
+ public void registerTypeOverride(UserType type, String[] keys) {
+ getTypeResolver().registerTypeOverride( type, keys );
+ }
+
+ public void registerTypeOverride(CompositeUserType type, String[] keys) {
+ getTypeResolver().registerTypeOverride( type, keys );
+ }
+
public SessionFactoryObserver getSessionFactoryObserver() {
return sessionFactoryObserver;
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -31,6 +31,8 @@
import org.slf4j.LoggerFactory;
import org.hibernate.HibernateException;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.usertype.UserType;
/**
* A registry of {@link BasicType} instances
@@ -146,6 +148,14 @@
}
}
+ public void register(UserType type, String[] keys) {
+ register( new CustomType( type, keys ) );
+ }
+
+ public void register(CompositeUserType type, String[] keys) {
+ register( new CompositeCustomType( type, keys ) );
+ }
+
public BasicType getRegisteredType(String key) {
return registry.get( key );
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -29,10 +29,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
-import java.util.Properties;
import org.dom4j.Element;
import org.dom4j.Node;
+
import org.hibernate.EntityMode;
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
@@ -42,20 +42,40 @@
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.usertype.LoggableUserType;
+import org.hibernate.util.ArrayHelper;
/**
- * Adapts <tt>CompositeUserType</tt> to <tt>Type</tt> interface
+ * Adapts {@link CompositeUserType} to the {@link Type} interface
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CompositeCustomType extends AbstractType implements CompositeType {
+public class CompositeCustomType extends AbstractType implements CompositeType, BasicType {
private final CompositeUserType userType;
+ private final String[] registrationKeys;
private final String name;
+ private final boolean customLogging;
public CompositeCustomType(CompositeUserType userType) {
+ this( userType, ArrayHelper.EMPTY_STRING_ARRAY );
+ }
+
+ public CompositeCustomType(CompositeUserType userType, String[] registrationKeys) {
this.userType = userType;
this.name = userType.getClass().getName();
+ this.customLogging = LoggableUserType.class.isInstance( userType );
+ this.registrationKeys = registrationKeys;
}
-
+
+ public String[] getRegistrationKeys() {
+ return registrationKeys;
+ }
+
+ public CompositeUserType getUserType() {
+ return userType;
+ }
+
public boolean isMethodOf(Method method) {
return false;
}
@@ -155,8 +175,8 @@
public int getColumnSpan(Mapping mapping) throws MappingException {
Type[] types = userType.getPropertyTypes();
int n=0;
- for (int i=0; i<types.length; i++) {
- n+=types[i].getColumnSpan(mapping);
+ for ( Type type : types ) {
+ n += type.getColumnSpan( mapping );
}
return n;
}
@@ -217,20 +237,26 @@
}
public int[] sqlTypes(Mapping mapping) throws MappingException {
- Type[] types = userType.getPropertyTypes();
int[] result = new int[ getColumnSpan(mapping) ];
int n=0;
- for (int i=0; i<types.length; i++) {
- int[] sqlTypes = types[i].sqlTypes(mapping);
- for ( int k=0; k<sqlTypes.length; k++ ) result[n++] = sqlTypes[k];
+ for ( Type type : userType.getPropertyTypes() ) {
+ for ( int sqlType : type.sqlTypes( mapping ) ) {
+ result[n++] = sqlType;
+ }
}
return result;
}
- public String toLoggableString(Object value, SessionFactoryImplementor factory)
- throws HibernateException {
-
- return value==null ? "null" : value.toString();
+ public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
+ if ( value == null ) {
+ return "null";
+ }
+ else if ( customLogging ) {
+ return ( (LoggableUserType) userType ).toLoggableString( value, factory );
+ }
+ else {
+ return value.toString();
+ }
}
public boolean[] getPropertyNullability() {
Modified: core/trunk/core/src/main/java/org/hibernate/type/CustomType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CustomType.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/main/java/org/hibernate/type/CustomType.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -44,32 +44,42 @@
import org.hibernate.usertype.LoggableUserType;
import org.hibernate.usertype.UserType;
import org.hibernate.usertype.UserVersionType;
+import org.hibernate.util.ArrayHelper;
/**
* Adapts {@link UserType} to the generic {@link Type} interface, in order
* to isolate user code from changes in the internal Type contracts.
*
- * @see org.hibernate.usertype.UserType
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CustomType extends AbstractType implements IdentifierType, DiscriminatorType, VersionType {
-
+public class CustomType extends AbstractType implements IdentifierType, DiscriminatorType, VersionType, BasicType {
private final UserType userType;
private final String name;
private final int[] types;
private final boolean customLogging;
+ private final String[] registrationKeys;
public CustomType(UserType userType) throws MappingException {
+ this( userType, ArrayHelper.EMPTY_STRING_ARRAY );
+ }
+
+ public CustomType(UserType userType, String[] registrationKeys) throws MappingException {
this.userType = userType;
this.name = userType.getClass().getName();
this.types = userType.sqlTypes();
this.customLogging = LoggableUserType.class.isInstance( userType );
+ this.registrationKeys = registrationKeys;
}
public UserType getUserType() {
return userType;
}
+ public String[] getRegistrationKeys() {
+ return registrationKeys;
+ }
+
public int[] sqlTypes(Mapping pi) {
return types;
}
@@ -86,8 +96,7 @@
return userType.equals(x, y);
}
- public boolean isEqual(Object x, Object y, EntityMode entityMode)
- throws HibernateException {
+ public boolean isEqual(Object x, Object y, EntityMode entityMode) throws HibernateException {
return isEqual(x, y);
}
@@ -95,33 +104,24 @@
return userType.hashCode(x);
}
- public Object nullSafeGet(
- ResultSet rs,
- String[] names,
- SessionImplementor session,
- Object owner
- ) throws HibernateException, SQLException {
-
+ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
+ throws HibernateException, SQLException {
return userType.nullSafeGet(rs, names, owner);
}
- public Object nullSafeGet(
- ResultSet rs,
- String columnName,
- SessionImplementor session,
- Object owner
- ) throws HibernateException, SQLException {
+ public Object nullSafeGet(ResultSet rs, String columnName, SessionImplementor session, Object owner)
+ throws HibernateException, SQLException {
return nullSafeGet(rs, new String[] { columnName }, session, owner);
}
public Object assemble(Serializable cached, SessionImplementor session, Object owner)
- throws HibernateException {
+ throws HibernateException {
return userType.assemble(cached, owner);
}
public Serializable disassemble(Object value, SessionImplementor session, Object owner)
- throws HibernateException {
+ throws HibernateException {
return userType.disassemble(value);
}
@@ -130,42 +130,36 @@
Object target,
SessionImplementor session,
Object owner,
- Map copyCache)
- throws HibernateException {
+ Map copyCache) throws HibernateException {
return userType.replace(original, target, owner);
}
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- boolean[] settable,
- SessionImplementor session
- ) throws HibernateException, SQLException {
-
- if ( settable[0] ) userType.nullSafeSet(st, value, index);
+ public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session)
+ throws HibernateException, SQLException {
+ if ( settable[0] ) {
+ userType.nullSafeSet( st, value, index );
+ }
}
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- SessionImplementor session
- ) throws HibernateException, SQLException {
-
- userType.nullSafeSet(st, value, index);
+ public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
+ throws HibernateException, SQLException {
+ userType.nullSafeSet( st, value, index );
}
+ @SuppressWarnings({ "UnusedDeclaration" })
public String toXMLString(Object value, SessionFactoryImplementor factory) {
- if (value==null) return null;
- if (userType instanceof EnhancedUserType) {
- return ( (EnhancedUserType) userType ).toXMLString(value);
+ if ( value == null ) {
+ return null;
}
+ if ( userType instanceof EnhancedUserType ) {
+ return ( (EnhancedUserType) userType ).toXMLString( value );
+ }
else {
return value.toString();
}
}
+ @SuppressWarnings({ "UnusedDeclaration" })
public Object fromXMLString(String xml, Mapping factory) {
return ( (EnhancedUserType) userType ).fromXMLString(xml);
}
@@ -175,7 +169,7 @@
}
public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory)
- throws HibernateException {
+ throws HibernateException {
return userType.deepCopy(value);
}
@@ -208,12 +202,12 @@
}
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
- throws HibernateException {
+ throws HibernateException {
node.setText( toXMLString(value, factory) );
}
public String toLoggableString(Object value, SessionFactoryImplementor factory)
- throws HibernateException {
+ throws HibernateException {
if ( value == null ) {
return "null";
}
@@ -227,12 +221,14 @@
public boolean[] toColumnNullness(Object value, Mapping mapping) {
boolean[] result = new boolean[ getColumnSpan(mapping) ];
- if (value!=null) Arrays.fill(result, true);
+ if ( value != null ) {
+ Arrays.fill(result, true);
+ }
return result;
}
- public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session) throws HibernateException {
+ public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
+ throws HibernateException {
return checkable[0] && isDirty(old, current, session);
}
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -60,6 +60,14 @@
basicTypeRegistry.register( type );
}
+ public void registerTypeOverride(UserType type, String[] keys) {
+ basicTypeRegistry.register( type, keys );
+ }
+
+ public void registerTypeOverride(CompositeUserType type, String[] keys) {
+ basicTypeRegistry.register( type, keys );
+ }
+
public TypeFactory getTypeFactory() {
return typeFactory;
}
Modified: core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java 2010-06-01 23:23:40 UTC (rev 19648)
+++ core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java 2010-06-02 05:15:54 UTC (rev 19649)
@@ -23,13 +23,21 @@
*/
package org.hibernate.type;
+import java.io.Serializable;
import java.net.URL;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.UUID;
import junit.framework.TestCase;
+import org.hibernate.HibernateException;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.descriptor.java.UrlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.usertype.UserType;
/**
* TODO : javadoc
@@ -67,6 +75,27 @@
assertSame( UrlType.INSTANCE, type );
}
+ public void testRegisteringUserTypes() {
+ registry.register( new TotallyIrrelevantUserType(), new String[] { "key" } );
+ BasicType type = registry.getRegisteredType( "key" );
+ assertNotNull( type );
+ assertEquals( CustomType.class, type.getClass() );
+ assertEquals( TotallyIrrelevantUserType.class, ( (CustomType) type ).getUserType().getClass() );
+
+ registry.register( new TotallyIrrelevantCompositeUserType(), new String[] { "key" } );
+ type = registry.getRegisteredType( "key" );
+ assertNotNull( type );
+ assertEquals( CompositeCustomType.class, type.getClass() );
+ assertEquals( TotallyIrrelevantCompositeUserType.class, ( (CompositeCustomType) type ).getUserType().getClass() );
+
+ type = registry.getRegisteredType( UUID.class.getName() );
+ assertSame( UUIDBinaryType.INSTANCE, type );
+ registry.register( new TotallyIrrelevantUserType(), new String[] { UUID.class.getName() } );
+ type = registry.getRegisteredType( UUID.class.getName() );
+ assertNotSame( UUIDBinaryType.INSTANCE, type );
+ assertEquals( CustomType.class, type.getClass() );
+ }
+
public static class UrlType extends AbstractSingleColumnStandardBasicType<URL> {
public static final UrlType INSTANCE = new UrlType();
@@ -83,4 +112,111 @@
return true;
}
}
+
+ public static class TotallyIrrelevantUserType implements UserType {
+
+ public int[] sqlTypes() {
+ return new int[0];
+ }
+
+ public Class returnedClass() {
+ return null;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException {
+ return false;
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return 0;
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
+ return null;
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
+ }
+
+ public Object deepCopy(Object value) throws HibernateException {
+ return null;
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return null;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException {
+ return null;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws HibernateException {
+ return null;
+ }
+ }
+
+ public static class TotallyIrrelevantCompositeUserType implements CompositeUserType {
+
+ public String[] getPropertyNames() {
+ return new String[0];
+ }
+
+ public Type[] getPropertyTypes() {
+ return new Type[0];
+ }
+
+ public Object getPropertyValue(Object component, int property) throws HibernateException {
+ return null;
+ }
+
+ public void setPropertyValue(Object component, int property, Object value) throws HibernateException {
+ }
+
+ public Class returnedClass() {
+ return null;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException {
+ return false;
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return 0;
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
+ throws HibernateException, SQLException {
+ return null;
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
+ throws HibernateException, SQLException {
+ }
+
+ public Object deepCopy(Object value) throws HibernateException {
+ return null;
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException {
+ return null;
+ }
+
+ public Object assemble(Serializable cached, SessionImplementor session, Object owner)
+ throws HibernateException {
+ return null;
+ }
+
+ public Object replace(Object original, Object target, SessionImplementor session, Object owner)
+ throws HibernateException {
+ return null;
+ }
+ }
}
14 years, 9 months
Hibernate SVN: r19648 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-06-01 19:23:40 -0400 (Tue, 01 Jun 2010)
New Revision: 19648
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5268 Add documentation for uuid and uuid2 identifier generators
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-06-01 19:16:50 UTC (rev 19647)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-06-01 23:23:40 UTC (rev 19648)
@@ -1877,14 +1877,81 @@
<term><literal>uuid</literal></term>
<listitem>
- <para>uses a 128-bit UUID algorithm to generate identifiers
- of type string that are unique within a network (the IP
- address is used). The UUID is encoded as a string of 32
- hexadecimal digits in length.</para>
+ <para>Generates a 128-bit UUID based on a custom algorithm.
+ The value generated is represented as a string of 32
+ hexidecimal digits. Users can also configure it to use a
+ separator (config parameter "separator") which separates the
+ hexidecimal digits into 8{sep}8{sep}4{sep}8{sep}4. Note
+ specifically that this is different than the IETF RFC 4122
+ representation of 8-4-4-4-12. If you need RFC 4122 compliant
+ UUIDs, consider using "uuid2" generator discussed
+ below.</para>
</listitem>
</varlistentry>
<varlistentry>
+ <term><literal>uuid2</literal></term>
+
+ <listitem>
+ <para>Generates a IETF RFC 4122 compliant (variant 2)
+ 128-bit UUID. The exact "version" (the RFC term) generated
+ depends on the pluggable "generation strategy" used (see
+ below). Capable of generating values as
+ <classname>java.util.UUID</classname>,
+ <classname>java.lang.String</classname> or as a byte array
+ of length 16 (<literal>byte[16]</literal>). The "generation
+ strategy" is defined by the interface
+ <interfacename>org.hibernate.id.UUIDGenerationStrategy</interfacename>.
+ The generator defines 2 configuration parameters for
+ defining which generation strategy to use: <variablelist>
+ <varlistentry>
+ <term><literal>uuid_gen_strategy_class</literal></term>
+
+ <listitem>
+ <para>Names the UUIDGenerationStrategy class to
+ use</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><literal>uuid_gen_strategy</literal></term>
+
+ <listitem>
+ <para>Names the UUIDGenerationStrategy instance to
+ use</para>
+ </listitem>
+ </varlistentry>
+ </variablelist></para>
+
+ <para>Out of the box, comes with the following strategies:
+ <itemizedlist>
+ <listitem>
+ <para><classname>org.hibernate.id.uuid.StandardRandomStrategy</classname>
+ (the default) - generates "version 3" (aka, "random")
+ UUID values via the
+ <methodname>randomUUID</methodname> method of
+ <classname>java.util.UUID</classname></para>
+ </listitem>
+
+ <listitem>
+ <para><classname>org.hibernate.id.uuid.CustomVersionOneStrategy</classname>
+ - generates "version 1" UUID values, using IP address
+ since mac address not available. If you need mac
+ address to be used, consider leveraging one of the
+ existing third party UUID generators which sniff out
+ mac address and integrating it via the
+ <interfacename>org.hibernate.id.UUIDGenerationStrategy</interfacename>
+ contract. Two such libraries known at time of this
+ writing include <ulink
+ url="http://johannburkard.de/software/uuid/">http://johannburkard.de/software/uuid/</ulink>
+ and <ulink
+ url="http://commons.apache.org/sandbox/id/uuid.html">http://commons.apache.org/sandbox/id/uuid.html</ulink></para>
+ </listitem>
+ </itemizedlist></para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>guid</literal></term>
<listitem>
14 years, 9 months
Hibernate SVN: r19647 - in core/trunk: core/src/main/java/org/hibernate/type and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-01 15:16:50 -0400 (Tue, 01 Jun 2010)
New Revision: 19647
Added:
core/trunk/core/src/main/java/org/hibernate/type/PostgresUUIDType.java
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
Log:
HHH-3579 - Support for PostgreSQL UUID data type
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java 2010-06-01 18:34:12 UTC (rev 19646)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java 2010-06-01 19:16:50 UTC (rev 19647)
@@ -45,7 +45,7 @@
/**
* An SQL dialect for Postgres
* <p/>
- * For discussion of BLOB "support" in postrges, as of 8.4, have a peek at
+ * For discussion of BLOB support in Postgres, as of 8.4, have a peek at
* <a href="http://jdbc.postgresql.org/documentation/84/binary-data.html">http://jdbc.postgresql.org/documentation/84/binary-data.html</a>.
* For the effects in regards to Hibernate see <a href="http://in.relation.to/15492.lace">http://in.relation.to/15492.lace</a>
*
@@ -73,6 +73,7 @@
registerColumnType( Types.CLOB, "text" );
registerColumnType( Types.BLOB, "oid" );
registerColumnType( Types.NUMERIC, "numeric($p, $s)" );
+ registerColumnType( Types.OTHER, "uuid" );
registerFunction( "abs", new StandardSQLFunction("abs") );
registerFunction( "sign", new StandardSQLFunction("sign", Hibernate.INTEGER) );
Modified: core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-01 18:34:12 UTC (rev 19646)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-01 19:16:50 UTC (rev 19647)
@@ -75,6 +75,7 @@
register( ClassType.INSTANCE );
register( UUIDBinaryType.INSTANCE );
register( UUIDCharType.INSTANCE );
+ register( PostgresUUIDType.INSTANCE );
register( BinaryType.INSTANCE );
register( WrapperBinaryType.INSTANCE );
Added: core/trunk/core/src/main/java/org/hibernate/type/PostgresUUIDType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/PostgresUUIDType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/PostgresUUIDType.java 2010-06-01 19:16:50 UTC (rev 19647)
@@ -0,0 +1,85 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.UUID;
+
+import org.hibernate.type.descriptor.ValueBinder;
+import org.hibernate.type.descriptor.ValueExtractor;
+import org.hibernate.type.descriptor.WrapperOptions;
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BasicBinder;
+import org.hibernate.type.descriptor.sql.BasicExtractor;
+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
+
+/**
+ * Specialized type mapping for {@link UUID} and the Postgres UUID data type (which is mapped as OTHER in its
+ * JDBC driver).
+ *
+ * @author Steve Ebersole
+ * @author David Driscoll
+ */
+public class PostgresUUIDType extends AbstractSingleColumnStandardBasicType<UUID> {
+ public static final PostgresUUIDType INSTANCE = new PostgresUUIDType();
+
+ public PostgresUUIDType() {
+ super( PostgresUUIDSqlTypeDescriptor.INSTANCE, UUIDTypeDescriptor.INSTANCE );
+ }
+
+ public String getName() {
+ return "pg-uuid";
+ }
+
+ public static class PostgresUUIDSqlTypeDescriptor implements SqlTypeDescriptor {
+ public static final PostgresUUIDSqlTypeDescriptor INSTANCE = new PostgresUUIDSqlTypeDescriptor();
+
+ public int getSqlType() {
+ // ugh
+ return Types.OTHER;
+ }
+
+ public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
+ return new BasicBinder<X>( javaTypeDescriptor, this ) {
+ @Override
+ protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
+ st.setObject( index, javaTypeDescriptor.unwrap( value, UUID.class, options ) );
+ }
+ };
+ }
+
+ public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
+ return new BasicExtractor<X>( javaTypeDescriptor, this ) {
+ @Override
+ protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
+ return javaTypeDescriptor.wrap( rs.getObject( name ), options );
+ }
+ };
+ }
+ }
+}
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-06-01 18:34:12 UTC (rev 19646)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-06-01 19:16:50 UTC (rev 19647)
@@ -610,6 +610,19 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><classname>org.hibernate.type.PostgresUUIDType</classname></term>
+ <listitem>
+ <para>
+ Maps a java.util.UUID to the PostgreSQL UUID data type (through
+ <literal>Types#OTHER</literal> which is how the PostgreSQL JDBC driver defines it).
+ </para>
+ <para>
+ Registered under <literal>pg-uuid</literal> in the type registry (see
+ <xref linkend="types.registry"/>).
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</section>
<section id="types.basic.value.serializable">
@@ -698,29 +711,17 @@
The main categorization was between entity types and value types. To review we said that entities, by
nature of their unique identifier, exist independently of other objects whereas values do not. An
application cannot "delete" a Product sku; instead, the sku is removed when the Product itself is
- deleted (obviously you can <emphasis>update</emphasis> the sku of that Product to null to maker it
+ deleted (obviously you can <emphasis>update</emphasis> the sku of that Product to null to make it
"go away", but even there the access is done through the Product).
</para>
<para>
Nor can you define an association <emphasis>to</emphasis> that Product sku. You <emphasis>can</emphasis>
- define an association to Product <emphasis>based on</emphasis> its sku, assuming sku is unique but that
+ define an association to Product <emphasis>based on</emphasis> its sku, assuming sku is unique, but that
is totally different.
-
-
- entity types define
- data that maintains its own lifecycle, while value types define data that only exists dependently. Essentially it defines it own unique identifier. In turn that means
- that it can be used to share references to that data from other entities (or components or collections).
- This dependence/independence has a few important ramifications:
- <itemizedlist>
- <listitem>
- <para>
- First, entities can be looked up and referenced (as in foreign keys). The same is not true of
- a value type. For example, a <classname>Product</classname> entity can be looked up by its
- unique identifier. The sku of that Product
- </para>
- </listitem>
- </itemizedlist>
</para>
+ <para>
+ TBC...
+ </para>
</section>
<section id="types.custom">
14 years, 9 months
Hibernate SVN: r19646 - in core/trunk: core/src/main/java/org/hibernate/id/factory and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-06-01 14:34:12 -0400 (Tue, 01 Jun 2010)
New Revision: 19646
Added:
core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerationStrategy.java
core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/uuid/
core/trunk/core/src/main/java/org/hibernate/id/uuid/CustomVersionOneStrategy.java
core/trunk/core/src/main/java/org/hibernate/id/uuid/Helper.java
core/trunk/core/src/main/java/org/hibernate/id/uuid/StandardRandomStrategy.java
core/trunk/core/src/main/java/org/hibernate/type/UUIDBinaryType.java
core/trunk/core/src/main/java/org/hibernate/type/UUIDCharType.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UUIDTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java
core/trunk/core/src/test/java/org/hibernate/id/uuid/
core/trunk/core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java
core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.java
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlbinary/
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlchar/
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlchar/UUIDCharTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/CustomStrategyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.java
Modified:
core/trunk/core/src/main/java/org/hibernate/id/GUIDGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/UUIDHexGenerator.java
core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java
core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/util/BytesHelper.java
core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
Log:
HHH-5268 - Support for java.util.UUID properties/generators
Modified: core/trunk/core/src/main/java/org/hibernate/id/GUIDGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/GUIDGenerator.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/id/GUIDGenerator.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id;
@@ -41,10 +40,21 @@
* @author Joseph Fifield
*/
public class GUIDGenerator implements IdentifierGenerator {
-
private static final Logger log = LoggerFactory.getLogger(GUIDGenerator.class);
+ private static boolean warned = false;
- public Serializable generate(SessionImplementor session, Object obj)
+ public GUIDGenerator() {
+ if ( ! warned ) {
+ warned = true;
+ log.warn(
+ "DEPRECATED : use {} instead with custom {} implementation",
+ UUIDGenerator.class.getName(),
+ UUIDGenerationStrategy.class.getName()
+ );
+ }
+ }
+
+ public Serializable generate(SessionImplementor session, Object obj)
throws HibernateException {
final String sql = session.getFactory().getDialect().getSelectGUIDString();
Added: core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerationStrategy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerationStrategy.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerationStrategy.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,64 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * A strategy for generating a variant 2 {@link UUID} value.
+ *
+ * @author Steve Ebersole
+ */
+public interface UUIDGenerationStrategy extends Serializable {
+ /**
+ * Which variant, according to IETF RFC 4122, of UUID does this strategy generate? RFC 4122 defines
+ * 5 variants (though it only describes algorithms to generate 4):<ul>
+ * <li>1 = time based</li>
+ * <li>2 = DCE based using POSIX UIDs</li>
+ * <li>3 = name based (md5 hash)</li>
+ * <li>4 = random numbers based</li>
+ * <li>5 = name based (sha-1 hash)</li>
+ * </ul>
+ * Returning the values above should be reserved to those generators creating variants compliant with the
+ * corresponding RFC definition; others can feel free to return other values as they see fit.
+ * <p/>
+ * Informational only, and not used at this time.
+ *
+ * @return The supported generation version
+ */
+ public int getGeneratedVersion();
+
+ /**
+ * Generate the UUID.
+ *
+ * @param session The session asking for the generation
+ *
+ * @return The generated UUID.
+ */
+ public UUID generateUUID(SessionImplementor session);
+
+}
Added: core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerator.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/id/UUIDGenerator.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,112 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id;
+
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.id.uuid.StandardRandomStrategy;
+import org.hibernate.type.Type;
+import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * An {@link IdentifierGenerator} which generates {@link UUID} values using a pluggable
+ * {@link UUIDGenerationStrategy generation strategy}. The values this generator can return
+ * include {@link UUID}, {@link String} and byte[16]
+ * <p/>
+ * Supports 2 config parameters:<ul>
+ * <li>{@link #UUID_GEN_STRATEGY} - names the {@link UUIDGenerationStrategy} instance to use</li>
+ * <li>{@link #UUID_GEN_STRATEGY_CLASS} - names the {@link UUIDGenerationStrategy} class to use</li>
+ * </ul>
+ * <p/>
+ * Currently there are 2 standard implementations of {@link UUIDGenerationStrategy}:<ul>
+ * <li>{@link StandardRandomStrategy} (the default, if none specified)</li>
+ * <li>{@link org.hibernate.id.uuid.CustomVersionOneStrategy}</li>
+ * </ul>
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDGenerator implements IdentifierGenerator, Configurable {
+ public static final String UUID_GEN_STRATEGY = "uuid_gen_strategy";
+ public static final String UUID_GEN_STRATEGY_CLASS = "uuid_gen_strategy_class";
+
+ private static final Logger log = LoggerFactory.getLogger( UUIDGenerator.class );
+
+ private UUIDGenerationStrategy strategy;
+ private UUIDTypeDescriptor.ValueTransformer valueTransformer;
+
+ public void configure(Type type, Properties params, Dialect d) throws MappingException {
+ // check first for the strategy instance
+ strategy = (UUIDGenerationStrategy) params.get( UUID_GEN_STRATEGY );
+ if ( strategy == null ) {
+ // next check for the strategy class
+ final String strategyClassName = params.getProperty( UUID_GEN_STRATEGY_CLASS );
+ if ( strategyClassName != null ) {
+ try {
+ final Class strategyClass = ReflectHelper.classForName( strategyClassName );
+ try {
+ strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
+ }
+ catch ( Exception ignore ) {
+ log.warn( "Unable to instantiate UUID generation strategy class : {}", ignore );
+ }
+ }
+ catch ( ClassNotFoundException ignore ) {
+ log.warn( "Unable to locate requested UUID generation strategy class : {}", strategyClassName );
+ }
+ }
+ }
+ if ( strategy == null ) {
+ // lastly use the standard random generator
+ strategy = StandardRandomStrategy.INSTANCE;
+ }
+
+ if ( UUID.class.isAssignableFrom( type.getReturnedClass() ) ) {
+ valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
+ }
+ else if ( String.class.isAssignableFrom( type.getReturnedClass() ) ) {
+ valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
+ }
+ else if ( byte[].class.isAssignableFrom( type.getReturnedClass() ) ) {
+ valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
+ }
+ else {
+ throw new HibernateException( "Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion" );
+ }
+ }
+
+ public Serializable generate(SessionImplementor session, Object object) throws HibernateException {
+ return valueTransformer.transform( strategy.generateUUID( session ) );
+ }
+
+}
Modified: core/trunk/core/src/main/java/org/hibernate/id/UUIDHexGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/UUIDHexGenerator.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/id/UUIDHexGenerator.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,14 +20,15 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.id;
import java.io.Serializable;
import java.util.Properties;
-import org.hibernate.Hibernate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.Type;
@@ -45,54 +46,54 @@
*
* @author Gavin King
*/
-
public class UUIDHexGenerator extends AbstractUUIDGenerator implements Configurable {
+ private static final Logger log = LoggerFactory.getLogger( UUIDHexGenerator.class );
+ private static boolean warned = false;
private String sep = "";
- protected String format(int intval) {
- String formatted = Integer.toHexString(intval);
- StringBuffer buf = new StringBuffer("00000000");
- buf.replace( 8-formatted.length(), 8, formatted );
- return buf.toString();
+ public UUIDHexGenerator() {
+ if ( ! warned ) {
+ warned = true;
+ log.warn(
+ "Using {} which does not generate IETF RFC 4122 compliant UUID values; consider using {} instead",
+ this.getClass().getName(),
+ UUIDGenerator.class.getName()
+ );
+ }
}
- protected String format(short shortval) {
- String formatted = Integer.toHexString(shortval);
- StringBuffer buf = new StringBuffer("0000");
- buf.replace( 4-formatted.length(), 4, formatted );
- return buf.toString();
+ /**
+ * {@inheritDoc}
+ */
+ public void configure(Type type, Properties params, Dialect d) {
+ sep = PropertiesHelper.getString( "separator", params, "" );
}
+ /**
+ * {@inheritDoc}
+ */
public Serializable generate(SessionImplementor session, Object obj) {
- return new StringBuffer(36)
- .append( format( getIP() ) ).append(sep)
- .append( format( getJVM() ) ).append(sep)
- .append( format( getHiTime() ) ).append(sep)
- .append( format( getLoTime() ) ).append(sep)
- .append( format( getCount() ) )
- .toString();
+ return new StringBuffer( 36 )
+ .append( format( getIP() ) ).append( sep )
+ .append( format( getJVM() ) ).append( sep )
+ .append( format( getHiTime() ) ).append( sep )
+ .append( format( getLoTime() ) ).append( sep )
+ .append( format( getCount() ) )
+ .toString();
}
- public void configure(Type type, Properties params, Dialect d) {
- sep = PropertiesHelper.getString("separator", params, "");
+ protected String format(int intValue) {
+ String formatted = Integer.toHexString( intValue );
+ StringBuffer buf = new StringBuffer( "00000000" );
+ buf.replace( 8 - formatted.length(), 8, formatted );
+ return buf.toString();
}
- public static void main( String[] args ) throws Exception {
- Properties props = new Properties();
- props.setProperty("separator", "/");
- IdentifierGenerator gen = new UUIDHexGenerator();
- ( (Configurable) gen ).configure(Hibernate.STRING, props, null);
- IdentifierGenerator gen2 = new UUIDHexGenerator();
- ( (Configurable) gen2 ).configure(Hibernate.STRING, props, null);
-
- for ( int i=0; i<10; i++) {
- String id = (String) gen.generate(null, null);
- System.out.println(id);
- String id2 = (String) gen2.generate(null, null);
- System.out.println(id2);
- }
-
+ protected String format(short shortValue) {
+ String formatted = Integer.toHexString( shortValue );
+ StringBuffer buf = new StringBuffer( "0000" );
+ buf.replace( 4 - formatted.length(), 4, formatted );
+ return buf.toString();
}
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -31,6 +31,7 @@
import org.slf4j.LoggerFactory;
import org.hibernate.id.IdentifierGenerator;
+import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.UUIDHexGenerator;
import org.hibernate.id.TableHiLoGenerator;
import org.hibernate.id.Assigned;
@@ -65,7 +66,10 @@
* Constructs a new DefaultIdentifierGeneratorFactory.
*/
public DefaultIdentifierGeneratorFactory() {
- register( "uuid", UUIDHexGenerator.class );
+ register( "uuid2", UUIDGenerator.class );
+ register( "guid", GUIDGenerator.class ); // can be done with UUIDGenerator + strategy
+ register( "uuid", UUIDHexGenerator.class ); // "deprecated" for new use
+ register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
register( "hilo", TableHiLoGenerator.class );
register( "assigned", Assigned.class );
register( "identity", IdentityGenerator.class );
@@ -74,8 +78,6 @@
register( "seqhilo", SequenceHiLoGenerator.class );
register( "increment", IncrementGenerator.class );
register( "foreign", ForeignGenerator.class );
- register( "guid", GUIDGenerator.class );
- register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
register( "sequence-identity", SequenceIdentityGenerator.class );
register( "enhanced-sequence", SequenceStyleGenerator.class );
register( "enhanced-table", TableGenerator.class );
Added: core/trunk/core/src/main/java/org/hibernate/id/uuid/CustomVersionOneStrategy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/uuid/CustomVersionOneStrategy.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/id/uuid/CustomVersionOneStrategy.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,125 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id.uuid;
+
+import java.util.UUID;
+
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.id.UUIDGenerationStrategy;
+import org.hibernate.util.BytesHelper;
+
+/**
+ * Applies a version 1 (time-based) generation strategy (using ip address rather than mac address) but applies them in a
+ * different layout. The strategy is very similar to the legacy {@link org.hibernate.id.UUIDHexGenerator} id generator
+ * but uses a RFC 4122 compliant layout (variant 2).
+ * <p/>
+ * NOTE : Can be a bottle neck due to the need to synchronize in order to increment an
+ * internal count as part of the algorithm.
+ *
+ * @author Steve Ebersole
+ */
+public class CustomVersionOneStrategy implements UUIDGenerationStrategy {
+ public int getGeneratedVersion() {
+ return 1;
+ }
+
+ private final long mostSignificantBits;
+
+ public CustomVersionOneStrategy() {
+ // generate the "most significant bits" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ byte[] hiBits = new byte[8];
+ // use address as first 32 bits (8 * 4 bytes)
+ System.arraycopy( Helper.getAddressBytes(), 0, hiBits, 0, 4 );
+ // use the "jvm identifier" as the next 32 bits
+ System.arraycopy( Helper.getJvmIdentifierBytes(), 0, hiBits, 4, 4 );
+ // set the version (rfc term) appropriately
+ hiBits[6] &= 0x0f;
+ hiBits[6] |= 0x10;
+
+ mostSignificantBits = BytesHelper.asLong( hiBits );
+ }
+
+ public UUID generateUUID(SessionImplementor session) {
+ long leastSignificantBits = generateLeastSignificantBits( System.currentTimeMillis() );
+ return new UUID( mostSignificantBits, leastSignificantBits );
+ }
+
+ public long getMostSignificantBits() {
+ return mostSignificantBits;
+ }
+
+ public static long generateLeastSignificantBits(long seed) {
+ byte[] loBits = new byte[8];
+
+ short hiTime = (short) ( seed >>> 32 );
+ int loTime = (int) seed;
+ System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 );
+ System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 );
+ System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 );
+ loBits[0] &= 0x3f;
+ loBits[0] |= ((byte)2 << (byte)6);
+
+ return BytesHelper.asLong( loBits );
+ }
+
+ public static void main(String[] args) {
+ CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();
+
+ for ( int i = 0; i < 1000; i++ ) {
+ System.out.println( "Generation # " + i + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+ byte[] loBits = new byte[8];
+
+ long sysTime = System.currentTimeMillis();
+ short hiTime = (short) ( System.currentTimeMillis() >>> 32 );
+ int loTime = (int) sysTime;
+ System.arraycopy( BytesHelper.fromShort( hiTime ), 0, loBits, 0, 2 );
+ System.arraycopy( BytesHelper.fromInt( loTime ), 0, loBits, 2, 4 );
+ System.arraycopy( Helper.getCountBytes(), 0, loBits, 6, 2 );
+
+ System.out.println( " before bit setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+ System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) );
+ System.out.println( " lsb : " + BytesHelper.toBinaryString( BytesHelper.asLong( loBits ) ) );
+ System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+
+ loBits[0] &= 0x3f;
+ loBits[0] |= ((byte)2 << (byte)6);
+
+ System.out.println( " after bit setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+ System.out.println( " loBits[0] : " + BytesHelper.toBinaryString( loBits[0] ) );
+ long leastSignificantBits = BytesHelper.asLong( loBits );
+ System.out.println( " lsb : " + BytesHelper.toBinaryString( leastSignificantBits ) );
+ System.out.println( " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+
+
+ UUID uuid = new UUID( strategy.mostSignificantBits, leastSignificantBits );
+ System.out.println( " uuid : " + uuid.toString() );
+ System.out.println( " variant : " + uuid.variant() );
+ System.out.println( " version : " + uuid.version() );
+ if ( uuid.variant() != 2 ) {
+ throw new RuntimeException( "bad variant" );
+ }
+ System.out.println( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
+ }
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/id/uuid/Helper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/uuid/Helper.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/id/uuid/Helper.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,147 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id.uuid;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.hibernate.util.BytesHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Helper {
+
+ // IP ADDRESS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ private static final byte[] ADDRESS_BYTES;
+ private static final int ADDRESS_INT;
+ private static final String ADDRESS_HEX_STRING;
+
+ static {
+ byte[] address;
+ try {
+ address = InetAddress.getLocalHost().getAddress();
+ }
+ catch ( Exception e ) {
+ address = new byte[4];
+ }
+ ADDRESS_BYTES = address;
+ ADDRESS_INT = BytesHelper.toInt( ADDRESS_BYTES );
+ ADDRESS_HEX_STRING = format( ADDRESS_INT );
+ }
+
+ public static byte[] getAddressBytes() {
+ return ADDRESS_BYTES;
+ }
+
+ public static int getAddressInt() {
+ return ADDRESS_INT;
+ }
+
+ public static String getAddressHexString() {
+ return ADDRESS_HEX_STRING;
+ }
+
+
+ // JVM identifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ private static final byte[] JVM_IDENTIFIER_BYTES;
+ private static final int JVM_IDENTIFIER_INT;
+ private static final String JVM_IDENTIFIER_HEX_STRING;
+
+ static {
+ JVM_IDENTIFIER_INT = (int) ( System.currentTimeMillis() >>> 8 );
+ JVM_IDENTIFIER_BYTES = BytesHelper.fromInt( JVM_IDENTIFIER_INT );
+ JVM_IDENTIFIER_HEX_STRING = format( JVM_IDENTIFIER_INT );
+ }
+
+ public static byte[] getJvmIdentifierBytes() {
+ return JVM_IDENTIFIER_BYTES;
+ }
+
+ public static int getJvmIdentifierInt() {
+ return JVM_IDENTIFIER_INT;
+ }
+
+ public static String getJvmIdentifierHexString() {
+ return JVM_IDENTIFIER_HEX_STRING;
+ }
+
+
+ // counter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ private static short counter = (short) 0;
+
+ /**
+ * Unique in a millisecond for this JVM instance (unless there are > Short.MAX_VALUE instances created in a
+ * millisecond)
+ */
+ public static short getCountShort() {
+ synchronized ( Helper.class ) {
+ if ( counter < 0 ) {
+ counter = 0;
+ }
+ return counter++;
+ }
+ }
+
+ public static byte[] getCountBytes() {
+ return BytesHelper.fromShort( getCountShort() );
+ }
+
+
+ // Helper methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public static String format(int value) {
+ final String formatted = Integer.toHexString( value );
+ StringBuffer buf = new StringBuffer( "00000000".intern() );
+ buf.replace( 8 - formatted.length(), 8, formatted );
+ return buf.toString();
+ }
+
+ public static String format(short value) {
+ String formatted = Integer.toHexString( value );
+ StringBuffer buf = new StringBuffer( "0000" );
+ buf.replace( 4 - formatted.length(), 4, formatted );
+ return buf.toString();
+ }
+
+
+ public static void main(String[] args) throws UnknownHostException {
+ byte[] addressBytes = InetAddress.getLocalHost().getAddress();
+ System.out.println( "Raw ip address bytes : " + addressBytes.toString() );
+
+ int addressInt = BytesHelper.toInt( addressBytes );
+ System.out.println( "ip address int : " + addressInt );
+
+ String formatted = Integer.toHexString( addressInt );
+ StringBuffer buf = new StringBuffer( "00000000" );
+ buf.replace( 8 - formatted.length(), 8, formatted );
+ String addressHex = buf.toString();
+ System.out.println( "ip address hex : " + addressHex );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/id/uuid/StandardRandomStrategy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/uuid/StandardRandomStrategy.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/id/uuid/StandardRandomStrategy.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,53 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id.uuid;
+
+import java.util.UUID;
+
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.id.UUIDGenerationStrategy;
+
+/**
+ * Implements a "random" UUID generation strategy as defined by the {@link UUID#randomUUID()} method.
+ *
+ * @author Steve Ebersole
+ */
+public class StandardRandomStrategy implements UUIDGenerationStrategy {
+ public static final StandardRandomStrategy INSTANCE = new StandardRandomStrategy();
+
+ /**
+ * A variant 4 (random) strategy
+ */
+ public int getGeneratedVersion() {
+ // a "random" strategy
+ return 4;
+ }
+
+ /**
+ * Delegates to {@link UUID#randomUUID()}
+ */
+ public UUID generateUUID(SessionImplementor session) {
+ return UUID.randomUUID();
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -73,6 +73,8 @@
register( CurrencyType.INSTANCE );
register( TimeZoneType.INSTANCE );
register( ClassType.INSTANCE );
+ register( UUIDBinaryType.INSTANCE );
+ register( UUIDCharType.INSTANCE );
register( BinaryType.INSTANCE );
register( WrapperBinaryType.INSTANCE );
Added: core/trunk/core/src/main/java/org/hibernate/type/UUIDBinaryType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/UUIDBinaryType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/UUIDBinaryType.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.util.UUID;
+
+import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BinaryTypeDescriptor;
+
+/**
+ * A type mapping {@link java.sql.Types#BINARY} and {@link UUID}
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDBinaryType extends AbstractSingleColumnStandardBasicType<UUID> {
+ public static final UUIDBinaryType INSTANCE = new UUIDBinaryType();
+
+ public UUIDBinaryType() {
+ super( BinaryTypeDescriptor.INSTANCE, UUIDTypeDescriptor.INSTANCE );
+ }
+
+ public String getName() {
+ return "uuid-binary";
+ }
+
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/UUIDCharType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/UUIDCharType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/UUIDCharType.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.util.UUID;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
+import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
+
+/**
+ * A type mapping {@link java.sql.Types#CHAR} (or {@link java.sql.Types#VARCHAR}) and {@link java.util.UUID}
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDCharType extends AbstractSingleColumnStandardBasicType<UUID> implements LiteralType<UUID> {
+ public static final UUIDCharType INSTANCE = new UUIDCharType();
+
+ public UUIDCharType() {
+ super( CharTypeDescriptor.INSTANCE, UUIDTypeDescriptor.INSTANCE );
+ }
+
+ public String getName() {
+ return "uuid-char";
+ }
+
+ public String objectToSQLString(UUID value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( value.toString(), dialect );
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -29,7 +29,7 @@
import org.hibernate.type.descriptor.WrapperOptions;
/**
- * TODO : javadoc
+ * Descriptor for {@link TimeZone} handling.
*
* @author Steve Ebersole
*/
@@ -79,6 +79,6 @@
if ( String.class.isInstance( value ) ) {
return fromString( (String) value );
}
- throw unknownUnwrap( value.getClass() );
+ throw unknownWrap( value.getClass() );
}
}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UUIDTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UUIDTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UUIDTypeDescriptor.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,132 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type.descriptor.java;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.hibernate.type.descriptor.WrapperOptions;
+import org.hibernate.util.BytesHelper;
+
+/**
+ * Descriptor for {@link UUID} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDTypeDescriptor extends AbstractTypeDescriptor<UUID> {
+ public static final UUIDTypeDescriptor INSTANCE = new UUIDTypeDescriptor();
+
+ public UUIDTypeDescriptor() {
+ super( UUID.class );
+ }
+
+ public String toString(UUID value) {
+ return ToStringTransformer.INSTANCE.transform( value );
+ }
+
+ public UUID fromString(String string) {
+ return ToStringTransformer.INSTANCE.parse( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(UUID value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( UUID.class.isAssignableFrom( type ) ) {
+ return (X) PassThroughTransformer.INSTANCE.transform( value );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) ToStringTransformer.INSTANCE.transform( value );
+ }
+ if ( byte[].class.isAssignableFrom( type ) ) {
+ return (X) ToBytesTransformer.INSTANCE.transform( value );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> UUID wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( UUID.class.isInstance( value ) ) {
+ return PassThroughTransformer.INSTANCE.parse( value );
+ }
+ if ( String.class.isInstance( value ) ) {
+ return ToStringTransformer.INSTANCE.parse( value );
+ }
+ if ( byte[].class.isInstance( value ) ) {
+ return ToBytesTransformer.INSTANCE.parse( value );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+
+ public static interface ValueTransformer {
+ public Serializable transform(UUID uuid);
+ public UUID parse(Object value);
+ }
+
+ public static class PassThroughTransformer implements ValueTransformer {
+ public static final PassThroughTransformer INSTANCE = new PassThroughTransformer();
+
+ public UUID transform(UUID uuid) {
+ return uuid;
+ }
+
+ public UUID parse(Object value) {
+ return (UUID)value;
+ }
+ }
+
+ public static class ToStringTransformer implements ValueTransformer {
+ public static final ToStringTransformer INSTANCE = new ToStringTransformer();
+
+ public String transform(UUID uuid) {
+ return uuid.toString();
+ }
+
+ public UUID parse(Object value) {
+ return UUID.fromString( (String) value );
+ }
+ }
+
+ public static class ToBytesTransformer implements ValueTransformer {
+ public static final ToBytesTransformer INSTANCE = new ToBytesTransformer();
+
+ public byte[] transform(UUID uuid) {
+ byte[] bytes = new byte[16];
+ System.arraycopy( BytesHelper.fromLong( uuid.getMostSignificantBits() ), 0, bytes, 0, 8 );
+ System.arraycopy( BytesHelper.fromLong( uuid.getLeastSignificantBits() ), 0, bytes, 8, 8 );
+ return bytes;
+ }
+
+ public UUID parse(Object value) {
+ byte[] msb = new byte[8];
+ byte[] lsb = new byte[8];
+ System.arraycopy( value, 0, msb, 0, 8 );
+ System.arraycopy( value, 8, lsb, 0, 8 );
+ return new UUID( BytesHelper.asLong( msb ), BytesHelper.asLong( lsb ) );
+ }
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/UrlTypeDescriptor.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,77 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type.descriptor.java;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.hibernate.HibernateException;
+import org.hibernate.type.descriptor.WrapperOptions;
+
+/**
+ * Descriptor for {@link URL} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class UrlTypeDescriptor extends AbstractTypeDescriptor<URL> {
+ public static final UrlTypeDescriptor INSTANCE = new UrlTypeDescriptor();
+
+ public UrlTypeDescriptor() {
+ super( URL.class );
+ }
+
+ public String toString(URL value) {
+ return value.toExternalForm();
+ }
+
+ public URL fromString(String string) {
+ try {
+ return new URL( string );
+ }
+ catch ( MalformedURLException e ) {
+ throw new HibernateException( "Unable to convert string [" + string + "] to URL : " + e );
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(URL value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) toString( value );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> URL wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return fromString( (String) value );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/util/BytesHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/BytesHelper.java 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/core/src/main/java/org/hibernate/util/BytesHelper.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
+ * distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@@ -20,26 +20,123 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.util;
public final class BytesHelper {
- private BytesHelper() {}
+ private BytesHelper() {
+ }
- public static int toInt( byte[] bytes ) {
+ /**
+ * Custom algorithm used to generate an int from a series of bytes.
+ * <p/>
+ * NOTE : this is different than interpreting the incoming bytes as an int value!
+ *
+ * @param bytes The bytes to use in generating the int.
+ *
+ * @return The generated int.
+ */
+ public static int toInt(byte[] bytes) {
int result = 0;
- for (int i=0; i<4; i++) {
+ for ( int i = 0; i < 4; i++ ) {
result = ( result << 8 ) - Byte.MIN_VALUE + (int) bytes[i];
}
return result;
}
-
-}
+ /**
+ * Interpret a short as its binary form
+ *
+ * @param shortValue The short to interpret to binary
+ *
+ * @return The binary
+ */
+ public static byte[] fromShort(int shortValue) {
+ byte[] bytes = new byte[2];
+ bytes[0] = (byte) ( shortValue >> 8 );
+ bytes[1] = (byte) ( ( shortValue << 8 ) >> 8 );
+ return bytes;
+ }
+ /**
+ * Interpret an int as its binary form
+ *
+ * @param intValue The int to interpret to binary
+ *
+ * @return The binary
+ */
+ public static byte[] fromInt(int intValue) {
+ byte[] bytes = new byte[4];
+ bytes[0] = (byte) ( intValue >> 24 );
+ bytes[1] = (byte) ( ( intValue << 8 ) >> 24 );
+ bytes[2] = (byte) ( ( intValue << 16 ) >> 24 );
+ bytes[3] = (byte) ( ( intValue << 24 ) >> 24 );
+ return bytes;
+ }
+ /**
+ * Interpret a long as its binary form
+ *
+ * @param longValue The long to interpret to binary
+ *
+ * @return The binary
+ */
+ public static byte[] fromLong(long longValue) {
+ byte[] bytes = new byte[8];
+ bytes[0] = (byte) ( longValue >> 56 );
+ bytes[1] = (byte) ( ( longValue << 8 ) >> 56 );
+ bytes[2] = (byte) ( ( longValue << 16 ) >> 56 );
+ bytes[3] = (byte) ( ( longValue << 24 ) >> 56 );
+ bytes[4] = (byte) ( ( longValue << 32 ) >> 56 );
+ bytes[5] = (byte) ( ( longValue << 40 ) >> 56 );
+ bytes[6] = (byte) ( ( longValue << 48 ) >> 56 );
+ bytes[7] = (byte) ( ( longValue << 56 ) >> 56 );
+ return bytes;
+ }
+ /**
+ * Interpret the binary representation of a long.
+ *
+ * @param bytes The bytes to interpret.
+ *
+ * @return The long
+ */
+ public static long asLong(byte[] bytes) {
+ if ( bytes == null ) {
+ return 0;
+ }
+ if ( bytes.length != 8 ) {
+ throw new IllegalArgumentException( "Expecting 8 byte values to construct a long" );
+ }
+ long value = 0;
+ for (int i=0; i<8; i++) {
+ value = (value << 8) | (bytes[i] & 0xff);
+ }
+ return value;
+ }
+ public static String toBinaryString(byte value) {
+ String formatted = Integer.toBinaryString( value );
+ if ( formatted.length() > 8 ) {
+ formatted = formatted.substring( formatted.length() - 8 );
+ }
+ StringBuffer buf = new StringBuffer( "00000000" );
+ buf.replace( 8 - formatted.length(), 8, formatted );
+ return buf.toString();
+ }
+ public static String toBinaryString(int value) {
+ String formatted = Long.toBinaryString( value );
+ StringBuffer buf = new StringBuffer( StringHelper.repeat( '0', 32 ) );
+ buf.replace( 64 - formatted.length(), 64, formatted );
+ return buf.toString();
+ }
+
+ public static String toBinaryString(long value) {
+ String formatted = Long.toBinaryString( value );
+ StringBuffer buf = new StringBuffer( StringHelper.repeat( '0', 64 ) );
+ buf.replace( 64 - formatted.length(), 64, formatted );
+ return buf.toString();
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/id/uuid/CustomVersionOneStrategyTest.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,79 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.id.uuid;
+
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CustomVersionOneStrategyTest extends TestCase {
+ public static void main(String[] args) {
+ System.out.println( System.currentTimeMillis() );
+ System.out.println( Long.MAX_VALUE );
+ }
+ public void testUniqueCounter() {
+ CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();
+ long now = System.currentTimeMillis();
+ UUID uuid1 = new UUID(
+ strategy.getMostSignificantBits(),
+ CustomVersionOneStrategy.generateLeastSignificantBits( now )
+ );
+ assertEquals( 2, uuid1.variant() );
+ assertEquals( 1, uuid1.version() );
+
+ for ( int i = 0; i < 100; i++ ) {
+ UUID uuidX = new UUID(
+ strategy.getMostSignificantBits(),
+ CustomVersionOneStrategy.generateLeastSignificantBits( now )
+ );
+ assertEquals( 2, uuidX.variant() );
+ assertEquals( 1, uuidX.version() );
+ assertFalse( uuid1.equals( uuidX ) );
+ assertEquals( uuid1.getMostSignificantBits(), uuidX.getMostSignificantBits() );
+ }
+ }
+
+ public void testRangeOfValues() {
+ CustomVersionOneStrategy strategy = new CustomVersionOneStrategy();
+
+ UUID uuid = new UUID(
+ strategy.getMostSignificantBits(),
+ CustomVersionOneStrategy.generateLeastSignificantBits( 0 )
+ );
+ assertEquals( 2, uuid.variant() );
+ assertEquals( 1, uuid.version() );
+
+ uuid = new UUID(
+ strategy.getMostSignificantBits(),
+ CustomVersionOneStrategy.generateLeastSignificantBits( Long.MAX_VALUE )
+ );
+ assertEquals( 2, uuid.variant() );
+ assertEquals( 1, uuid.version() );
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/BasicTypeRegistryTest.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,86 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.type;
+
+import java.net.URL;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.hibernate.type.descriptor.java.UrlTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BasicTypeRegistryTest extends TestCase {
+ private final BasicTypeRegistry registry = new BasicTypeRegistry();
+
+ public void testOverriding() {
+ BasicType type = registry.getRegisteredType( "uuid-binary" );
+ assertSame( UUIDBinaryType.INSTANCE, type );
+ type = registry.getRegisteredType( UUID.class.getName() );
+ assertSame( UUIDBinaryType.INSTANCE, type );
+
+ BasicType override = new UUIDCharType() {
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
+ }
+ };
+ registry.register( override );
+ type = registry.getRegisteredType( UUID.class.getName() );
+ assertNotSame( UUIDBinaryType.INSTANCE, type );
+ assertSame( override, type );
+ }
+
+ public void testExpanding() {
+ BasicType type = registry.getRegisteredType( URL.class.getName() );
+ assertNull( type );
+
+ registry.register( UrlType.INSTANCE );
+ type = registry.getRegisteredType( URL.class.getName() );
+ assertNotNull( type );
+ assertSame( UrlType.INSTANCE, type );
+ }
+
+ public static class UrlType extends AbstractSingleColumnStandardBasicType<URL> {
+ public static final UrlType INSTANCE = new UrlType();
+
+ public UrlType() {
+ super( VarcharTypeDescriptor.INSTANCE, UrlTypeDescriptor.INSTANCE );
+ }
+
+ public String getName() {
+ return "url";
+ }
+
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
+ }
+ }
+}
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-06-01 16:14:56 UTC (rev 19645)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/type.xml 2010-06-01 18:34:12 UTC (rev 19646)
@@ -583,8 +583,37 @@
</varlistentry>
</variablelist>
</section>
+ <section id="types.basic.value.uuid">
+ <title><classname>java.util.UUID</classname></title>
+ <variablelist>
+ <varlistentry>
+ <term><classname>org.hibernate.type.UUIDBinaryType</classname></term>
+ <listitem>
+ <para>
+ Maps a java.util.UUID to a JDBC BINARY
+ </para>
+ <para>
+ Registered under <literal>uuid-binary</literal> and <literal>java.util.UUID</literal>
+ in the type registry (see <xref linkend="types.registry"/>).
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><classname>org.hibernate.type.UUIDCharType</classname></term>
+ <listitem>
+ <para>
+ Maps a java.util.UUID to a JDBC CHAR (though VARCHAR is fine too for existing schemas)
+ </para>
+ <para>
+ Registered under <literal>uuid-char</literal> in the type registry (see
+ <xref linkend="types.registry"/>).
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </section>
<section id="types.basic.value.serializable">
- <title>java.io.Serializable</title>
+ <title><classname>java.io.Serializable</classname></title>
<variablelist>
<varlistentry>
<term><classname>org.hibernate.type.SerializableType</classname></term>
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.hbm.xml (from rev 19581, core/trunk/testsuite/src/test/java/org/hibernate/test/id/Car.hbm.xml)
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.hbm.xml 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.id.uuid.sqlrep">
+
+ <class name="Node">
+
+ <id name="id">
+ <generator class="uuid2"/>
+ </id>
+ <property name="name"/>
+ <many-to-one name="parent"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/Node.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,73 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.uuid.sqlrep;
+
+import java.util.UUID;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Node {
+ private UUID id;
+ private String name;
+ private Node parent;
+
+ public Node() {
+ }
+
+ public Node(String name) {
+ this.name = name;
+ }
+
+ public Node(String name, Node parent) {
+ this.name = name;
+ this.parent = parent;
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Node getParent() {
+ return parent;
+ }
+
+ public void setParent(Node parent) {
+ this.parent = parent;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,81 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.uuid.sqlrep.sqlbinary;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.test.id.uuid.sqlrep.Node;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDBinaryTest extends FunctionalTestCase {
+ public UUIDBinaryTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "id/uuid/sqlrep/Node.hbm.xml" };
+ }
+
+ public void testUsage() {
+ Session session = openSession();
+ session.beginTransaction();
+ Node root = new Node( "root" );
+ session.save( root );
+ assertNotNull( root.getId() );
+ Node child = new Node( "child", root );
+ session.save( child );
+ assertNotNull( child.getId() );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ Node node = (Node) session.get( Node.class, root.getId() );
+ assertNotNull( node );
+ node = (Node) session.get( Node.class, child.getId() );
+ assertNotNull( node );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ // test joining
+ node = (Node) session.createQuery( "from Node n join fetch n.parent where n.parent is not null" ).uniqueResult();
+ assertNotNull( node );
+ assertNotNull( node.getParent() );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ session.delete( child );
+ session.delete( root );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlchar/UUIDCharTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlchar/UUIDCharTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/sqlrep/sqlchar/UUIDCharTest.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,51 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.uuid.sqlrep.sqlchar;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.test.id.uuid.sqlrep.sqlbinary.UUIDBinaryTest;
+import org.hibernate.type.UUIDCharType;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class UUIDCharTest extends UUIDBinaryTest {
+ public UUIDCharTest(String string) {
+ super( string );
+ }
+
+ @Override
+ public void configure(Configuration cfg) {
+ cfg.registerTypeOverride(
+ new UUIDCharType() {
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
+ }
+ }
+ );
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/CustomStrategyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/CustomStrategyTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/CustomStrategyTest.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,60 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.uuid.strategy;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CustomStrategyTest extends FunctionalTestCase {
+ public CustomStrategyTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "id/uuid/strategy/Node.hbm.xml" };
+ }
+
+ public void testUsage() {
+ Session session = openSession();
+ session.beginTransaction();
+ Node node = new Node();
+ session.save( node );
+ assertNotNull( node.getId() );
+ assertEquals( 2, node.getId().variant() );
+ assertEquals( 1, node.getId().version() );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ session.delete( node );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.hbm.xml 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.id.uuid.strategy">
+
+ <class name="Node">
+
+ <id name="id">
+ <generator class="uuid2">
+ <!-- the "standard random" strategy gets tested in the other id.uuid tests -->
+ <param name="uuid_gen_strategy_class">org.hibernate.id.uuid.CustomVersionOneStrategy</param>
+ </generator>
+ </id>
+ <property name="name"/>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/id/uuid/strategy/Node.java 2010-06-01 18:34:12 UTC (rev 19646)
@@ -0,0 +1,59 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.id.uuid.strategy;
+
+import java.util.UUID;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Node {
+ private UUID id;
+ private String name;
+
+ public Node() {
+ }
+
+ public Node(String name) {
+ this.name = name;
+ }
+
+ public UUID getId() {
+ return id;
+ }
+
+ public void setId(UUID id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
14 years, 9 months
Hibernate SVN: r19645 - validator/trunk/hibernate-validator.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-01 12:14:56 -0400 (Tue, 01 Jun 2010)
New Revision: 19645
Modified:
validator/trunk/hibernate-validator/pom.xml
Log:
changed the release plugin config
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2010-06-01 15:54:38 UTC (rev 19644)
+++ validator/trunk/hibernate-validator/pom.xml 2010-06-01 16:14:56 UTC (rev 19645)
@@ -297,7 +297,7 @@
<executions>
<execution>
<id>make-doc</id>
- <phase>site</phase>
+ <phase>deploy</phase>
<goals>
<goal>resources</goal>
<goal>generate</goal>
@@ -319,7 +319,7 @@
<executions>
<execution>
<id>make-assembly</id>
- <phase>site</phase>
+ <phase>deploy</phase>
<goals>
<goal>assembly</goal>
</goals>
@@ -329,11 +329,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
- <configuration>
- <goals>deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources
- org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly
- </goals>
- </configuration>
</plugin>
<plugin>
<groupId>org.twdata.maven</groupId>
14 years, 9 months
Hibernate SVN: r19644 - in validator/trunk: hibernate-validator and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-01 11:54:38 -0400 (Tue, 01 Jun 2010)
New Revision: 19644
Modified:
validator/trunk/hibernate-validator/pom.xml
validator/trunk/pom.xml
Log:
changed the release plugin config
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2010-06-01 15:38:01 UTC (rev 19643)
+++ validator/trunk/hibernate-validator/pom.xml 2010-06-01 15:54:38 UTC (rev 19644)
@@ -330,8 +330,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
- <goals>javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources
- org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly deploy
+ <goals>deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:resources
+ org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.0:generate assembly:assembly
</goals>
</configuration>
</plugin>
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2010-06-01 15:38:01 UTC (rev 19643)
+++ validator/trunk/pom.xml 2010-06-01 15:54:38 UTC (rev 19644)
@@ -244,9 +244,8 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
- <version>2.0-beta-9</version>
+ <version>2.0</version>
<configuration>
- <preparationGoals>clean install</preparationGoals>
<autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<remoteTagging>true</remoteTagging>
14 years, 9 months
Hibernate SVN: r19643 - validator/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-01 11:38:01 -0400 (Tue, 01 Jun 2010)
New Revision: 19643
Modified:
validator/trunk/pom.xml
Log:
changed the release plugin config
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2010-06-01 12:53:13 UTC (rev 19642)
+++ validator/trunk/pom.xml 2010-06-01 15:38:01 UTC (rev 19643)
@@ -250,7 +250,6 @@
<autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<remoteTagging>true</remoteTagging>
- <goal>deploy</goal>
</configuration>
</plugin>
<plugin>
14 years, 9 months
Hibernate SVN: r19642 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-01 08:53:13 -0400 (Tue, 01 Jun 2010)
New Revision: 19642
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConfigurationImpl.java
Log:
HV-328 Fixed typo
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConfigurationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConfigurationImpl.java 2010-06-01 12:46:16 UTC (rev 19641)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/engine/ConfigurationImpl.java 2010-06-01 12:53:13 UTC (rev 19642)
@@ -116,7 +116,7 @@
}
public HibernateValidatorConfiguration addMapping(InputStream stream) {
- if ( mapping == null ) {
+ if ( stream == null ) {
throw new IllegalArgumentException( "The stream cannot be null." );
}
validationBootstrapParameters.mappings.add( stream );
14 years, 9 months