Hibernate SVN: r19335 - in core/trunk: annotations/src/main/java/org/hibernate/cfg/annotations and 38 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-01 14:20:26 -0400 (Sat, 01 May 2010)
New Revision: 19335
Added:
core/trunk/core/src/main/java/org/hibernate/type/AbstractSingleColumnStandardBasicType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java
core/trunk/core/src/main/java/org/hibernate/type/BasicType.java
core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
core/trunk/core/src/main/java/org/hibernate/type/ObjectType.java
core/trunk/core/src/main/java/org/hibernate/type/SingleColumnType.java
core/trunk/core/src/main/java/org/hibernate/type/StringRepresentableType.java
core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java
core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java
core/trunk/core/src/main/java/org/hibernate/type/XmlRepresentableType.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/AbstractTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ArrayMutabilityPlan.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BlobTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClassTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DateTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ImmutableMutabilityPlan.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IncomparableComparator.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IntegerTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutabilityPlan.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutableMutabilityPlan.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/WrapperOptions.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BigIntTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BinaryTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BitTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/CharTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/ClobTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DecimalTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DoubleTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/FloatTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/IntegerTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarbinaryTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarcharTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/NumericTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/RealTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SmallIntTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SqlTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TinyIntTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarbinaryTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarcharTypeDescriptor.java
core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/package.html
core/trunk/core/src/test/java/org/hibernate/type/
core/trunk/core/src/test/java/org/hibernate/type/TypeTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/
core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java
core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java
Removed:
core/trunk/testsuite/src/test/java/org/hibernate/test/where/NumericTrueFalseType.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java
core/trunk/core/src/main/java/org/hibernate/Hibernate.java
core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
core/trunk/core/src/main/java/org/hibernate/cfg/ResultSetMappingBinder.java
core/trunk/core/src/main/java/org/hibernate/collection/PersistentIndexedElementHolder.java
core/trunk/core/src/main/java/org/hibernate/collection/PersistentListElementHolder.java
core/trunk/core/src/main/java/org/hibernate/collection/PersistentMapElementHolder.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java
core/trunk/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java
core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java
core/trunk/core/src/main/java/org/hibernate/event/def/DefaultFlushEntityEventListener.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/BooleanLiteralNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/JavaConstantNode.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java
core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
core/trunk/core/src/main/java/org/hibernate/hql/classic/WhereParser.java
core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
core/trunk/core/src/main/java/org/hibernate/mapping/Any.java
core/trunk/core/src/main/java/org/hibernate/mapping/Component.java
core/trunk/core/src/main/java/org/hibernate/mapping/DependantValue.java
core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java
core/trunk/core/src/main/java/org/hibernate/mapping/OneToOne.java
core/trunk/core/src/main/java/org/hibernate/mapping/SimpleValue.java
core/trunk/core/src/main/java/org/hibernate/mapping/ToOne.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractBynaryType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractCharArrayType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractLongBinaryType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractLongStringType.java
core/trunk/core/src/main/java/org/hibernate/type/AbstractType.java
core/trunk/core/src/main/java/org/hibernate/type/AdaptedImmutableType.java
core/trunk/core/src/main/java/org/hibernate/type/AnyType.java
core/trunk/core/src/main/java/org/hibernate/type/ArrayType.java
core/trunk/core/src/main/java/org/hibernate/type/AssociationType.java
core/trunk/core/src/main/java/org/hibernate/type/BagType.java
core/trunk/core/src/main/java/org/hibernate/type/BigDecimalType.java
core/trunk/core/src/main/java/org/hibernate/type/BigIntegerType.java
core/trunk/core/src/main/java/org/hibernate/type/BinaryType.java
core/trunk/core/src/main/java/org/hibernate/type/BlobType.java
core/trunk/core/src/main/java/org/hibernate/type/BooleanType.java
core/trunk/core/src/main/java/org/hibernate/type/ByteType.java
core/trunk/core/src/main/java/org/hibernate/type/CalendarDateType.java
core/trunk/core/src/main/java/org/hibernate/type/CalendarType.java
core/trunk/core/src/main/java/org/hibernate/type/CharArrayType.java
core/trunk/core/src/main/java/org/hibernate/type/CharBooleanType.java
core/trunk/core/src/main/java/org/hibernate/type/CharacterArrayType.java
core/trunk/core/src/main/java/org/hibernate/type/CharacterType.java
core/trunk/core/src/main/java/org/hibernate/type/ClassType.java
core/trunk/core/src/main/java/org/hibernate/type/ClobType.java
core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java
core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java
core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
core/trunk/core/src/main/java/org/hibernate/type/CurrencyType.java
core/trunk/core/src/main/java/org/hibernate/type/CustomCollectionType.java
core/trunk/core/src/main/java/org/hibernate/type/CustomType.java
core/trunk/core/src/main/java/org/hibernate/type/DateType.java
core/trunk/core/src/main/java/org/hibernate/type/DbTimestampType.java
core/trunk/core/src/main/java/org/hibernate/type/DiscriminatorType.java
core/trunk/core/src/main/java/org/hibernate/type/DoubleType.java
core/trunk/core/src/main/java/org/hibernate/type/EmbeddedComponentType.java
core/trunk/core/src/main/java/org/hibernate/type/EntityType.java
core/trunk/core/src/main/java/org/hibernate/type/FloatType.java
core/trunk/core/src/main/java/org/hibernate/type/ForeignKeyDirection.java
core/trunk/core/src/main/java/org/hibernate/type/IdentifierBagType.java
core/trunk/core/src/main/java/org/hibernate/type/IdentifierType.java
core/trunk/core/src/main/java/org/hibernate/type/ImageType.java
core/trunk/core/src/main/java/org/hibernate/type/ImmutableType.java
core/trunk/core/src/main/java/org/hibernate/type/IntegerType.java
core/trunk/core/src/main/java/org/hibernate/type/ListType.java
core/trunk/core/src/main/java/org/hibernate/type/LiteralType.java
core/trunk/core/src/main/java/org/hibernate/type/LocaleType.java
core/trunk/core/src/main/java/org/hibernate/type/LongType.java
core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java
core/trunk/core/src/main/java/org/hibernate/type/MapType.java
core/trunk/core/src/main/java/org/hibernate/type/MaterializedBlobType.java
core/trunk/core/src/main/java/org/hibernate/type/MaterializedClobType.java
core/trunk/core/src/main/java/org/hibernate/type/MetaType.java
core/trunk/core/src/main/java/org/hibernate/type/MutableType.java
core/trunk/core/src/main/java/org/hibernate/type/NullableType.java
core/trunk/core/src/main/java/org/hibernate/type/NumericBooleanType.java
core/trunk/core/src/main/java/org/hibernate/type/OneToOneType.java
core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java
core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java
core/trunk/core/src/main/java/org/hibernate/type/PrimitiveType.java
core/trunk/core/src/main/java/org/hibernate/type/SerializableType.java
core/trunk/core/src/main/java/org/hibernate/type/SerializationException.java
core/trunk/core/src/main/java/org/hibernate/type/SetType.java
core/trunk/core/src/main/java/org/hibernate/type/ShortType.java
core/trunk/core/src/main/java/org/hibernate/type/SortedMapType.java
core/trunk/core/src/main/java/org/hibernate/type/SortedSetType.java
core/trunk/core/src/main/java/org/hibernate/type/SpecialOneToOneType.java
core/trunk/core/src/main/java/org/hibernate/type/StringType.java
core/trunk/core/src/main/java/org/hibernate/type/TextType.java
core/trunk/core/src/main/java/org/hibernate/type/TimeType.java
core/trunk/core/src/main/java/org/hibernate/type/TimeZoneType.java
core/trunk/core/src/main/java/org/hibernate/type/TimestampType.java
core/trunk/core/src/main/java/org/hibernate/type/TrueFalseType.java
core/trunk/core/src/main/java/org/hibernate/type/Type.java
core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
core/trunk/core/src/main/java/org/hibernate/type/VersionType.java
core/trunk/core/src/main/java/org/hibernate/type/WrapperBinaryType.java
core/trunk/core/src/main/java/org/hibernate/type/YesNoType.java
core/trunk/core/src/main/java/org/hibernate/type/package.html
core/trunk/core/src/main/java/org/hibernate/util/CalendarComparator.java
core/trunk/core/src/main/java/org/hibernate/util/ComparableComparator.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/entitymode/dom4j/accessors/Dom4jAccessorTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ClassificationType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/QueryTranslatorTestCase.java
core/trunk/testsuite/src/test/java/org/hibernate/test/instrument/domain/CustomBlobType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/DoubleStringType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiplicityType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/where/File.hbm.xml
Log:
HHH-5138 - Redesign types + introduce TypeRegistry & TypeResolver
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -655,7 +655,7 @@
if ( persistentClass.getEntityPersisterClass() == null ) {
persistentClass.getRootClass().setEntityPersisterClass( JoinedSubclassEntityPersister.class );
}
- SimpleValue key = new DependantValue( jsc.getTable(), jsc.getIdentifier() );
+ SimpleValue key = new DependantValue( mappings, jsc.getTable(), jsc.getIdentifier() );
jsc.setKey( key );
ForeignKey fk = clazzToProcess.getAnnotation( ForeignKey.class );
if ( fk != null && !BinderHelper.isDefault( fk.name() ) ) {
@@ -686,7 +686,8 @@
( RootClass ) persistentClass,
discriminatorColumn,
entityBinder.getSecondaryTables(),
- propertyHolder
+ propertyHolder,
+ mappings
);
entityBinder.bindDiscriminatorValue();//bind it again since the type might have changed
}
@@ -1229,7 +1230,7 @@
private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) {
Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>();
for ( ParamDef param : defAnn.parameters() ) {
- params.put( param.name(), TypeFactory.heuristicType( param.type() ) );
+ params.put( param.name(), mappings.getTypeResolver().heuristicType( param.type() ) );
}
FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params );
log.info( "Binding filter definition: {}", def.getFilterName() );
@@ -1301,16 +1302,17 @@
private static void bindDiscriminatorToPersistentClass(
RootClass rootClass,
- Ejb3DiscriminatorColumn discriminatorColumn, Map<String, Join> secondaryTables,
- PropertyHolder propertyHolder
- ) {
+ Ejb3DiscriminatorColumn discriminatorColumn,
+ Map<String, Join> secondaryTables,
+ PropertyHolder propertyHolder,
+ ExtendedMappings mappings) {
if ( rootClass.getDiscriminator() == null ) {
if ( discriminatorColumn == null ) {
throw new AssertionFailure( "discriminator column should have been built" );
}
discriminatorColumn.setJoins( secondaryTables );
discriminatorColumn.setPropertyHolder( propertyHolder );
- SimpleValue discrim = new SimpleValue( rootClass.getTable() );
+ SimpleValue discrim = new SimpleValue( mappings, rootClass.getTable() );
rootClass.setDiscriminator( discrim );
discriminatorColumn.linkWithValue( discrim );
discrim.setTypeName( discriminatorColumn.getDiscriminatorTypeName() );
@@ -2187,7 +2189,7 @@
Ejb3JoinColumn[] columns) {
Component comp;
if ( referencedEntityName != null ) {
- comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper );
+ comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper, mappings );
SecondPass sp = new CopyIdentifierComponentSecondPass(
comp,
referencedEntityName,
@@ -2265,7 +2267,7 @@
* Because it's a value type, there is no bidirectional association, hence second pass
* ordering does not matter
*/
- Component comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper );
+ Component comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper, mappings );
String subpath = BinderHelper.getPath( propertyHolder, inferredData );
log.trace( "Binding component with path: {}", subpath );
PropertyHolder subHolder = PropertyHolderBuilder.buildPropertyHolder(
@@ -2373,8 +2375,13 @@
return comp;
}
- public static Component createComponent(PropertyHolder propertyHolder, PropertyData inferredData, boolean isComponentEmbedded, boolean isIdentifierMapper) {
- Component comp = new Component( propertyHolder.getPersistentClass() );
+ public static Component createComponent(
+ PropertyHolder propertyHolder,
+ PropertyData inferredData,
+ boolean isComponentEmbedded,
+ boolean isIdentifierMapper,
+ ExtendedMappings mappings) {
+ Component comp = new Component( mappings, propertyHolder.getPersistentClass() );
comp.setEmbedded( isComponentEmbedded );
//yuk
comp.setTable( propertyHolder.getTable() );
@@ -2474,7 +2481,11 @@
}
}
- private static PropertyData getUniqueIdPropertyFromBaseClass(PropertyData inferredData, PropertyData baseInferredData, AccessType propertyAccessor, ExtendedMappings mappings) {
+ private static PropertyData getUniqueIdPropertyFromBaseClass(
+ PropertyData inferredData,
+ PropertyData baseInferredData,
+ AccessType propertyAccessor,
+ ExtendedMappings mappings) {
List<PropertyData> baseClassElements = new ArrayList<PropertyData>();
XClass baseReturnedClassOrElement = baseInferredData.getClassOrElement();
PropertyContainer propContainer = new PropertyContainer(
@@ -2482,8 +2493,7 @@
);
addElementsOfClass( baseClassElements, propertyAccessor, propContainer, mappings );
//Id properties are on top and there is only one
- final PropertyData idPropertyOnBaseClass = baseClassElements.get( 0 );
- return idPropertyOnBaseClass;
+ return baseClassElements.get( 0 );
}
private static void setupComponentTuplizer(XProperty property, Component component) {
@@ -2513,7 +2523,7 @@
ExtendedMappings mappings
) {
//All FK columns should be in the same table
- org.hibernate.mapping.ManyToOne value = new org.hibernate.mapping.ManyToOne( columns[0].getTable() );
+ org.hibernate.mapping.ManyToOne value = new org.hibernate.mapping.ManyToOne( mappings, columns[0].getTable() );
// This is a @OneToOne mapped to a physical o.h.mapping.ManyToOne
if ( unique ) {
value.markAsLogicalOneToOne();
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/BinderHelper.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -147,8 +147,8 @@
if ( properties != null ) {
//todo how about properties.size() == 1, this should be much simpler
Component embeddedComp = columnOwner instanceof PersistentClass ?
- new Component( (PersistentClass) columnOwner ) :
- new Component( (Join) columnOwner );
+ new Component( mappings, (PersistentClass) columnOwner ) :
+ new Component( mappings, (Join) columnOwner );
embeddedComp.setEmbedded( true );
embeddedComp.setNodeName( syntheticPropertyName );
embeddedComp.setComponentClassName( embeddedComp.getOwner().getClassName() );
@@ -533,7 +533,7 @@
boolean cascadeOnDelete, Nullability nullability, PropertyHolder propertyHolder,
EntityBinder entityBinder, boolean optional, ExtendedMappings mappings) {
//All FK columns should be in the same table
- Any value = new Any( columns[0].getTable() );
+ Any value = new Any( mappings, columns[0].getTable() );
AnyMetaDef metaAnnDef = inferredData.getProperty().getAnnotation( AnyMetaDef.class );
if ( metaAnnDef != null ) {
@@ -548,7 +548,7 @@
value.setMetaType( metaAnnDef.metaType() );
HashMap values = new HashMap();
- org.hibernate.type.Type metaType = TypeFactory.heuristicType( value.getMetaType() );
+ org.hibernate.type.Type metaType = mappings.getTypeResolver().heuristicType( value.getMetaType() );
for (MetaValue metaValue : metaAnnDef.metaValues()) {
try {
Object discrim = ( (org.hibernate.type.DiscriminatorType) metaType ).stringToObject( metaValue
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -82,7 +82,7 @@
//property.setOptional( property.isOptional() );
property.setPersistentClass( component.getOwner() );
property.setPropertyAccessorName( referencedProperty.getPropertyAccessorName() );
- SimpleValue value = new SimpleValue( component.getTable() );
+ SimpleValue value = new SimpleValue( mappings, component.getTable() );
property.setValue( value );
final SimpleValue referencedValue = (SimpleValue) referencedProperty.getValue();
value.setTypeName( referencedValue.getTypeName() );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -84,7 +84,7 @@
//TODO refactor this code, there is a lot of duplication in this method
public void doSecondPass(Map persistentClasses) throws MappingException {
org.hibernate.mapping.OneToOne value = new org.hibernate.mapping.OneToOne(
- propertyHolder.getTable(), propertyHolder.getPersistentClass()
+ mappings, propertyHolder.getTable(), propertyHolder.getPersistentClass()
);
final String propertyName = inferredData.getPropertyName();
value.setPropertyName( propertyName );
@@ -173,7 +173,7 @@
Join mappedByJoin = buildJoinFromMappedBySide(
(PersistentClass) persistentClasses.get( ownerEntity ), otherSideProperty, otherSideJoin
);
- ManyToOne manyToOne = new ManyToOne( mappedByJoin.getTable() );
+ ManyToOne manyToOne = new ManyToOne( mappings, mappedByJoin.getTable() );
//FIXME use ignore not found here
manyToOne.setIgnoreNotFound( ignoreNotFound );
manyToOne.setCascadeDeleteEnabled( value.isCascadeDeleteEnabled() );
@@ -249,7 +249,7 @@
//no check constraints available on joins
join.setTable( originalJoin.getTable() );
join.setInverse( true );
- SimpleValue key = new DependantValue( join.getTable(), persistentClass.getIdentifier() );
+ SimpleValue key = new DependantValue( mappings, join.getTable(), persistentClass.getIdentifier() );
//TODO support @ForeignKey
join.setKey( key );
join.setSequentialSelect( false );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1098,7 +1098,7 @@
.getRecursiveProperty( propRef )
.getValue();
}
- DependantValue key = new DependantValue( collValue.getCollectionTable(), keyVal );
+ DependantValue key = new DependantValue( mappings, collValue.getCollectionTable(), keyVal );
key.setTypeName( null );
Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() );
key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() );
@@ -1246,7 +1246,7 @@
ManyToOne element = null;
if ( isCollectionOfEntities ) {
element =
- new ManyToOne( collValue.getCollectionTable() );
+ new ManyToOne( mappings, collValue.getCollectionTable() );
collValue.setElement( element );
element.setReferencedEntityName( collType.getName() );
//element.setFetchMode( fetchMode );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -586,13 +586,11 @@
for (Ejb3JoinColumn joinColumn : ejb3JoinColumns) {
joinColumn.forceNotNull();
}
- bindJoinToPersistentClass( join, ejb3JoinColumns );
+ bindJoinToPersistentClass( join, ejb3JoinColumns, mappings );
}
- private void bindJoinToPersistentClass(
- Join join, Ejb3JoinColumn[] ejb3JoinColumns
- ) {
- SimpleValue key = new DependantValue( join.getTable(), persistentClass.getIdentifier() );
+ private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, ExtendedMappings mappings) {
+ SimpleValue key = new DependantValue( mappings, join.getTable(), persistentClass.getIdentifier() );
join.setKey( key );
setFKNameIfDefined( join );
key.setCascadeDeleteEnabled( false );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -133,7 +133,7 @@
);
}
org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection;
- Value indexValue = createFormulatedValue( mapProperty.getValue(), map, targetPropertyName, associatedClass );
+ Value indexValue = createFormulatedValue( mapProperty.getValue(), map, targetPropertyName, associatedClass, mappings );
map.setIndex( indexValue );
}
else {
@@ -165,7 +165,7 @@
ManyToOne element = null;
org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection;
if ( isIndexOfEntities ) {
- element = new ManyToOne( mapValue.getCollectionTable() );
+ element = new ManyToOne( mappings, mapValue.getCollectionTable() );
mapValue.setIndex( element );
element.setReferencedEntityName( mapKeyType );
//element.setFetchMode( fetchMode );
@@ -301,8 +301,11 @@
}
protected Value createFormulatedValue(
- Value value, Collection collection, String targetPropertyName, PersistentClass associatedClass
- ) {
+ Value value,
+ Collection collection,
+ String targetPropertyName,
+ PersistentClass associatedClass,
+ ExtendedMappings mappings) {
Value element = collection.getElement();
String fromAndWhere = null;
if ( !( element instanceof OneToMany ) ) {
@@ -346,7 +349,7 @@
if ( value instanceof Component ) {
Component component = (Component) value;
Iterator properties = component.getPropertyIterator();
- Component indexComponent = new Component( collection );
+ Component indexComponent = new Component( mappings, collection );
indexComponent.setComponentClassName( component.getComponentClassName() );
//TODO I don't know if this is appropriate
indexComponent.setNodeName( "index" );
@@ -366,9 +369,11 @@
newProperty.setPersistentClass( current.getPersistentClass() );
newProperty.setPropertyAccessorName( current.getPropertyAccessorName() );
newProperty.setSelectable( current.isSelectable() );
- newProperty.setValue( createFormulatedValue( current.getValue(), collection, targetPropertyName,
- associatedClass
- ) );
+ newProperty.setValue(
+ createFormulatedValue(
+ current.getValue(), collection, targetPropertyName, associatedClass, mappings
+ )
+ );
indexComponent.addProperty( newProperty );
}
return indexComponent;
@@ -378,7 +383,7 @@
SimpleValue targetValue;
if ( value instanceof ManyToOne ) {
ManyToOne sourceManyToOne = (ManyToOne) sourceValue;
- ManyToOne targetManyToOne = new ManyToOne( collection.getCollectionTable() );
+ ManyToOne targetManyToOne = new ManyToOne( mappings, collection.getCollectionTable() );
targetManyToOne.setFetchMode( FetchMode.DEFAULT );
targetManyToOne.setLazy( true );
//targetValue.setIgnoreNotFound( ); does not make sense for a map key
@@ -386,7 +391,7 @@
targetValue = targetManyToOne;
}
else {
- targetValue = new SimpleValue( collection.getCollectionTable() );
+ targetValue = new SimpleValue( mappings, collection.getCollectionTable() );
targetValue.setTypeName( sourceValue.getTypeName() );
targetValue.setTypeParameters( sourceValue.getTypeParameters() );
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -212,7 +212,7 @@
if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
Component identifier = (Component) rootClass.getIdentifier();
if (identifier == null) {
- identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false );
+ identifier = AnnotationBinder.createComponent( holder, new PropertyPreloadedData(null, null, null), true, false, mappings );
rootClass.setIdentifier( identifier );
identifier.setNullValue( "undefined" );
rootClass.setEmbeddedIdentifier( true );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -295,7 +295,7 @@
if ( table == null ) {
table = columns[0].getTable();
}
- simpleValue = new SimpleValue( table );
+ simpleValue = new SimpleValue( mappings, table );
linkWithValue();
Modified: core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/main/java/org/hibernate/type/WrappedMaterializedBlobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,42 +1,46 @@
+/*
+ * 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 org.hibernate.type.descriptor.java.ByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BlobTypeDescriptor;
+
/**
- * <tt>materialized_blob</tt>: A type that maps an SQL BLOB to Java Byte[].
+ * A type that maps JDBC {@link java.sql.Types#BLOB BLOB} and {@code Byte[]}.
+ * A type that maps an SQL BLOB to Java Byte[].
*
* @author Strong Liu
*/
-public class WrappedMaterializedBlobType extends MaterializedBlobType {
- public Class getReturnedClass() {
- return Byte[].class;
- }
+public class WrappedMaterializedBlobType extends AbstractSingleColumnStandardBasicType<Byte[]> {
+ public static final WrappedMaterializedBlobType INSTANCE = new WrappedMaterializedBlobType();
- protected Object toExternalFormat(byte[] bytes) {
- if (bytes == null)
- return null;
- return wrapPrimitive(bytes);
+ public WrappedMaterializedBlobType() {
+ super( BlobTypeDescriptor.INSTANCE, ByteArrayTypeDescriptor.INSTANCE );
}
- protected byte[] toInternalFormat(Object bytes) {
- if (bytes == null)
- return null;
- return unwrapNonPrimitive((Byte[]) bytes);
+ public String getName() {
+ // todo name these annotation types for addition to the registry
+ return null;
}
-
- private Byte[] wrapPrimitive(byte[] bytes) {
- int length = bytes.length;
- Byte[] result = new Byte[length];
- for (int index = 0; index < length; index++) {
- result[index] = Byte.valueOf(bytes[index]);
- }
- return result;
- }
-
- private byte[] unwrapNonPrimitive(Byte[] bytes) {
- int length = bytes.length;
- byte[] result = new byte[length];
- for (int i = 0; i < length; i++) {
- result[i] = bytes[i].byteValue();
- }
- return result;
- }
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/CharacterArrayTextType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -25,55 +25,24 @@
*/
package org.hibernate.test.annotations.lob;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import org.hibernate.type.AbstractSingleColumnStandardBasicType;
+import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
-import org.hibernate.HibernateException;
-
/**
- * A type that maps an SQL LONGVARCHAR to a Java Character [].
+ * A type that maps JDBC {@link java.sql.Types#LONGVARCHAR LONGVARCHAR} and {@code Character[]}.
*
* @author Strong Liu
*/
-public class CharacterArrayTextType extends PrimitiveCharacterArrayTextType {
-
- public Class getReturnedClass() {
- return Character[].class;
- }
+public class CharacterArrayTextType extends AbstractSingleColumnStandardBasicType<Character[]> {
+ public static final CharacterArrayTextType INSTANCE = new CharacterArrayTextType();
- @Override
- public Object get(ResultSet rs, String name) throws HibernateException,
- SQLException {
- char[] text = (char[]) super.get(rs, name);
- if (text == null)
- return null;
- return wrapPrimitive(text);
+ public CharacterArrayTextType() {
+ super( LongVarcharTypeDescriptor.INSTANCE, CharacterArrayTypeDescriptor.INSTANCE );
}
- @Override
- public void set(PreparedStatement st, Object value, int index)
- throws HibernateException, SQLException {
- Character[] cs = (Character[]) value;
- super.set(st, unwrapNonPrimitive(cs), index);
+ public String getName() {
+ // todo name these annotation types for addition to the registry
+ return null;
}
-
- private Character[] wrapPrimitive(char[] bytes) {
- int length = bytes.length;
- Character[] result = new Character[length];
- for (int index = 0; index < length; index++) {
- result[index] = Character.valueOf(bytes[index]);
- }
- return result;
- }
-
- private char[] unwrapNonPrimitive(Character[] bytes) {
- int length = bytes.length;
- char[] result = new char[length];
- for (int i = 0; i < length; i++) {
- result[i] = bytes[i].charValue();
- }
- return result;
- }
-
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/PrimitiveCharacterArrayTextType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -25,44 +25,24 @@
*/
package org.hibernate.test.annotations.lob;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import org.hibernate.type.AbstractSingleColumnStandardBasicType;
+import org.hibernate.type.descriptor.java.PrimitiveCharacterArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
-import org.hibernate.HibernateException;
-import org.hibernate.type.TextType;
-
/**
- * A type that maps an SQL LONGVARCHAR to a Java char [].
+ * A type that maps JDBC {@link java.sql.Types#LONGVARCHAR LONGVARCHAR} and {@code char[]}.
*
* @author Strong Liu
*/
-public class PrimitiveCharacterArrayTextType extends TextType {
- public Class getReturnedClass() {
- return char[].class;
- }
+public class PrimitiveCharacterArrayTextType extends AbstractSingleColumnStandardBasicType<char[]> {
+ public static final PrimitiveCharacterArrayTextType INSTANCE = new PrimitiveCharacterArrayTextType();
- @Override
- public Object get(ResultSet rs, String name) throws HibernateException,
- SQLException {
- String text = (String) super.get(rs, name);
- if (text == null)
- return null;
- return text.toCharArray();
+ public PrimitiveCharacterArrayTextType() {
+ super( LongVarcharTypeDescriptor.INSTANCE, PrimitiveCharacterArrayTypeDescriptor.INSTANCE );
}
- @Override
- public void set(PreparedStatement st, Object value, int index)
- throws HibernateException, SQLException {
- char[] cs = (char[]) value;
- String text = String.valueOf(cs);
-
- super.set(st, text, index);
+ public String getName() {
+ // todo name these annotation types for addition to the registry
+ return null;
}
-
- @Override
- public String toString(Object val) {
- return String.valueOf(val);
- }
-
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/SerializableToImageType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, 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
@@ -21,32 +20,31 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.test.annotations.lob;
import java.io.Serializable;
-import org.hibernate.type.ImageType;
-import org.hibernate.util.SerializationHelper;
+import org.hibernate.type.AbstractSingleColumnStandardBasicType;
+import org.hibernate.type.descriptor.java.SerializableTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarbinaryTypeDescriptor;
/**
- * A type that maps an SQL LONGVARBINARY to a serializable Java object.
+ * A type that maps JDBC {@link java.sql.Types#LONGVARBINARY LONGVARBINARY} and {@link Serializable}.
+ * </p>
+ * TODO : this should really have access to the actual Serializable class so we have access to the proper classloader
*
* @author Strong Liu
*/
-public class SerializableToImageType extends ImageType {
- public Class getReturnedClass() {
- return Serializable.class;
- }
+public class SerializableToImageType extends AbstractSingleColumnStandardBasicType<Serializable> {
+ public static final PrimitiveCharacterArrayTextType INSTANCE = new PrimitiveCharacterArrayTextType();
- protected Object toExternalFormat(byte[] bytes) {
- if (bytes == null)
- return null;
- return SerializationHelper.deserialize( bytes, getReturnedClass().getClassLoader() );
+ public SerializableToImageType() {
+ super( LongVarbinaryTypeDescriptor.INSTANCE, new SerializableTypeDescriptor<Serializable>( Serializable.class ) );
}
- protected byte[] toInternalFormat(Object bytes) {
- return SerializationHelper.serialize((Serializable) bytes);
+ public String getName() {
+ // todo name these annotation types for addition to the registry
+ return null;
}
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/WrappedImageType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, 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
@@ -21,46 +20,27 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.test.annotations.lob;
-import org.hibernate.type.ImageType;
+import org.hibernate.type.AbstractSingleColumnStandardBasicType;
+import org.hibernate.type.descriptor.java.ByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarbinaryTypeDescriptor;
/**
- * A type that maps an SQL LONGVARBINARY to Java Byte[].
+ * A type that maps JDBC {@link java.sql.Types#LONGVARBINARY LONGVARBINARY} and {@code Byte[]}
*
* @author Strong Liu
*/
-public class WrappedImageType extends ImageType{
- public Class getReturnedClass() {
- return Byte[].class;
- }
+public class WrappedImageType extends AbstractSingleColumnStandardBasicType<Byte[]> {
+ public static final WrappedImageType INSTANCE = new WrappedImageType();
- protected Object toExternalFormat(byte[] bytes) {
- if(bytes==null)return null;
- return wrapPrimitive(bytes);
+ public WrappedImageType() {
+ super( LongVarbinaryTypeDescriptor.INSTANCE, ByteArrayTypeDescriptor.INSTANCE );
}
- protected byte[] toInternalFormat(Object bytes) {
- if(bytes==null)return null;
- return unwrapNonPrimitive(( Byte[] ) bytes);
+ public String getName() {
+ // todo name these annotation types for addition to the registry
+ return null;
}
- private Byte[] wrapPrimitive(byte[] bytes) {
- int length = bytes.length;
- Byte[] result = new Byte[length];
- for ( int index = 0; index < length ; index++ ) {
- result[index] = Byte.valueOf( bytes[index] );
- }
- return result;
- }
-
- private byte[] unwrapNonPrimitive(Byte[] bytes) {
- int length = bytes.length;
- byte[] result = new byte[length];
- for ( int i = 0; i < length ; i++ ) {
- result[i] = bytes[i].byteValue();
- }
- return result;
- }
}
Modified: core/trunk/core/src/main/java/org/hibernate/Hibernate.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/Hibernate.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/Hibernate.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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;
@@ -67,7 +66,7 @@
import org.hibernate.type.LocaleType;
import org.hibernate.type.LongType;
import org.hibernate.type.ManyToOneType;
-import org.hibernate.type.NullableType;
+import org.hibernate.type.ObjectType;
import org.hibernate.type.SerializableType;
import org.hibernate.type.ShortType;
import org.hibernate.type.StringType;
@@ -77,6 +76,7 @@
import org.hibernate.type.TimestampType;
import org.hibernate.type.TrueFalseType;
import org.hibernate.type.Type;
+import org.hibernate.type.TypeFactory;
import org.hibernate.type.YesNoType;
import org.hibernate.type.CharArrayType;
import org.hibernate.type.WrapperBinaryType;
@@ -101,154 +101,187 @@
*/
public final class Hibernate {
+ /**
+ * Cannot be instantiated.
+ */
+ private Hibernate() {
+ throw new UnsupportedOperationException();
+ }
/**
* Hibernate <tt>long</tt> type.
+ * @deprecated Use {@link LongType#INSTANCE} instead.
*/
- public static final NullableType LONG = new LongType();
+ public static final LongType LONG = LongType.INSTANCE;
/**
* Hibernate <tt>short</tt> type.
+ * @deprecated Use {@link ShortType#INSTANCE} instead.
*/
- public static final NullableType SHORT = new ShortType();
+ public static final ShortType SHORT = ShortType.INSTANCE;
/**
* Hibernate <tt>integer</tt> type.
+ * @deprecated Use {@link IntegerType#INSTANCE} instead.
*/
- public static final NullableType INTEGER = new IntegerType();
+ public static final IntegerType INTEGER = IntegerType.INSTANCE;
/**
* Hibernate <tt>byte</tt> type.
+ * @deprecated Use {@link ByteType#INSTANCE} instead.
*/
- public static final NullableType BYTE = new ByteType();
+ public static final ByteType BYTE = ByteType.INSTANCE;
/**
* Hibernate <tt>float</tt> type.
+ * @deprecated Use {@link FloatType#INSTANCE} instead.
*/
- public static final NullableType FLOAT = new FloatType();
+ public static final FloatType FLOAT = FloatType.INSTANCE;
/**
* Hibernate <tt>double</tt> type.
+ * @deprecated Use {@link DoubleType#INSTANCE} instead.
*/
- public static final NullableType DOUBLE = new DoubleType();
+ public static final DoubleType DOUBLE = DoubleType.INSTANCE;
/**
* Hibernate <tt>character</tt> type.
+ * @deprecated Use {@link CharacterType#INSTANCE} instead.
*/
- public static final NullableType CHARACTER = new CharacterType();
+ public static final CharacterType CHARACTER = CharacterType.INSTANCE;
/**
* Hibernate <tt>string</tt> type.
+ * @deprecated Use {@link StringType#INSTANCE} instead.
*/
- public static final NullableType STRING = new StringType();
+ public static final StringType STRING = StringType.INSTANCE;
/**
* Hibernate <tt>time</tt> type.
+ * @deprecated Use {@link TimeType#INSTANCE} instead.
*/
- public static final NullableType TIME = new TimeType();
+ public static final TimeType TIME = TimeType.INSTANCE;
/**
* Hibernate <tt>date</tt> type.
+ * @deprecated Use {@link DateType#INSTANCE} instead.
*/
- public static final NullableType DATE = new DateType();
+ public static final DateType DATE = DateType.INSTANCE;
/**
* Hibernate <tt>timestamp</tt> type.
+ * @deprecated Use {@link TimestampType#INSTANCE} instead.
*/
- public static final NullableType TIMESTAMP = new TimestampType();
+ public static final TimestampType TIMESTAMP = TimestampType.INSTANCE;
/**
* Hibernate <tt>boolean</tt> type.
+ * @deprecated Use {@link BooleanType#INSTANCE} instead.
*/
- public static final NullableType BOOLEAN = new BooleanType();
+ public static final BooleanType BOOLEAN = BooleanType.INSTANCE;
/**
* Hibernate <tt>true_false</tt> type.
+ * @deprecated Use {@link TrueFalseType#INSTANCE} instead.
*/
- public static final NullableType TRUE_FALSE = new TrueFalseType();
+ public static final TrueFalseType TRUE_FALSE = TrueFalseType.INSTANCE;
/**
* Hibernate <tt>yes_no</tt> type.
+ * @deprecated Use {@link YesNoType#INSTANCE} instead.
*/
- public static final NullableType YES_NO = new YesNoType();
+ public static final YesNoType YES_NO = YesNoType.INSTANCE;
/**
* Hibernate <tt>big_decimal</tt> type.
+ * @deprecated Use {@link BigDecimalType#INSTANCE} instead.
*/
- public static final NullableType BIG_DECIMAL = new BigDecimalType();
+ public static final BigDecimalType BIG_DECIMAL = BigDecimalType.INSTANCE;
/**
* Hibernate <tt>big_integer</tt> type.
+ * @deprecated Use {@link BigIntegerType#INSTANCE} instead.
*/
- public static final NullableType BIG_INTEGER = new BigIntegerType();
+ public static final BigIntegerType BIG_INTEGER = BigIntegerType.INSTANCE;
/**
* Hibernate <tt>binary</tt> type.
+ * @deprecated Use {@link BinaryType#INSTANCE} instead.
*/
- public static final NullableType BINARY = new BinaryType();
+ public static final BinaryType BINARY = BinaryType.INSTANCE;
/**
* Hibernate <tt>wrapper-binary</tt> type.
+ * @deprecated Use {@link WrapperBinaryType#INSTANCE} instead.
*/
- public static final NullableType WRAPPER_BINARY = new WrapperBinaryType();
+ public static final WrapperBinaryType WRAPPER_BINARY = WrapperBinaryType.INSTANCE;
/**
* Hibernate char[] type.
+ * @deprecated Use {@link CharArrayType#INSTANCE} instead.
*/
- public static final NullableType CHAR_ARRAY = new CharArrayType();
+ public static final CharArrayType CHAR_ARRAY = CharArrayType.INSTANCE;
/**
* Hibernate Character[] type.
+ * @deprecated Use {@link CharacterArrayType#INSTANCE} instead.
*/
- public static final NullableType CHARACTER_ARRAY = new CharacterArrayType();
+ public static final CharacterArrayType CHARACTER_ARRAY = CharacterArrayType.INSTANCE;
/**
* Hibernate <tt>image</tt> type.
+ * @deprecated Use {@link ImageType#INSTANCE} instead.
*/
- public static final NullableType IMAGE = new ImageType();
+ public static final ImageType IMAGE = ImageType.INSTANCE;
/**
* Hibernate <tt>text</tt> type.
+ * @deprecated Use {@link TextType#INSTANCE} instead.
*/
- public static final NullableType TEXT = new TextType();
+ public static final TextType TEXT = TextType.INSTANCE;
/**
* Hibernate <tt>materialized_blob</tt> type.
+ * @deprecated Use {@link MaterializedBlobType#INSTANCE} instead.
*/
- public static final NullableType MATERIALIZED_BLOB = new MaterializedBlobType();
+ public static final MaterializedBlobType MATERIALIZED_BLOB = MaterializedBlobType.INSTANCE;
/**
* Hibernate <tt>materialized_clob</tt> type.
+ * @deprecated Use {@link MaterializedClobType#INSTANCE} instead.
*/
- public static final NullableType MATERIALIZED_CLOB = new MaterializedClobType();
+ public static final MaterializedClobType MATERIALIZED_CLOB = MaterializedClobType.INSTANCE;
/**
* Hibernate <tt>blob</tt> type.
+ * @deprecated Use {@link BlobType#INSTANCE} instead.
*/
- public static final Type BLOB = new BlobType();
+ public static final BlobType BLOB = BlobType.INSTANCE;
/**
* Hibernate <tt>clob</tt> type.
+ * @deprecated Use {@link ClobType#INSTANCE} instead.
*/
- public static final Type CLOB = new ClobType();
+ public static final ClobType CLOB = ClobType.INSTANCE;
/**
* Hibernate <tt>calendar</tt> type.
+ * @deprecated Use {@link CalendarType#INSTANCE} instead.
*/
- public static final NullableType CALENDAR = new CalendarType();
+ public static final CalendarType CALENDAR = CalendarType.INSTANCE;
/**
* Hibernate <tt>calendar_date</tt> type.
+ * @deprecated Use {@link CalendarDateType#INSTANCE} instead.
*/
- public static final NullableType CALENDAR_DATE = new CalendarDateType();
+ public static final CalendarDateType CALENDAR_DATE = CalendarDateType.INSTANCE;
/**
* Hibernate <tt>locale</tt> type.
+ * @deprecated Use {@link LocaleType#INSTANCE} instead.
*/
- public static final NullableType LOCALE = new LocaleType();
+ public static final LocaleType LOCALE = LocaleType.INSTANCE;
/**
* Hibernate <tt>currency</tt> type.
+ * @deprecated Use {@link CurrencyType#INSTANCE} instead.
*/
- public static final NullableType CURRENCY = new CurrencyType();
+ public static final CurrencyType CURRENCY = CurrencyType.INSTANCE;
/**
* Hibernate <tt>timezone</tt> type.
+ * @deprecated Use {@link TimeZoneType#INSTANCE} instead.
*/
- public static final NullableType TIMEZONE = new TimeZoneType();
+ public static final TimeZoneType TIMEZONE = TimeZoneType.INSTANCE;
/**
* Hibernate <tt>class</tt> type.
+ * @deprecated Use {@link ClassType#INSTANCE} instead.
*/
- public static final NullableType CLASS = new ClassType();
+ public static final ClassType CLASS = ClassType.INSTANCE;
/**
* Hibernate <tt>serializable</tt> type.
+ * @deprecated Use {@link SerializableType#INSTANCE} instead.
*/
- public static final NullableType SERIALIZABLE = new SerializableType( Serializable.class );
+ public static final SerializableType SERIALIZABLE = SerializableType.INSTANCE;
/**
* Hibernate <tt>object</tt> type.
+ * @deprecated Use {@link ObjectType#INSTANCE} instead.
*/
- public static final Type OBJECT = new AnyType();
+ public static final ObjectType OBJECT = ObjectType.INSTANCE;
-
/**
- * Cannot be instantiated.
- */
- private Hibernate() {
- throw new UnsupportedOperationException();
- }
-
- /**
* A Hibernate <tt>serializable</tt> type.
+ * @deprecated Use {@link SerializableType#SerializableType} instead.
*/
public static Type serializable(Class serializableClass) {
return new SerializableType( serializableClass );
@@ -320,12 +353,10 @@
public static Type custom(Class userTypeClass, Properties parameters)
throws HibernateException {
if ( CompositeUserType.class.isAssignableFrom( userTypeClass ) ) {
- CompositeCustomType type = new CompositeCustomType( userTypeClass, parameters );
- return type;
+ return TypeFactory.customComponent( userTypeClass, parameters );
}
else {
- CustomType type = new CustomType( userTypeClass, parameters );
- return type;
+ return TypeFactory.custom( userTypeClass, parameters );
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -132,8 +132,10 @@
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.TableMetadata;
import org.hibernate.tool.hbm2ddl.IndexMetadata;
+import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.SerializationException;
import org.hibernate.type.Type;
+import org.hibernate.type.TypeResolver;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.ConfigHelper;
@@ -187,6 +189,7 @@
protected Map extendsQueue;
protected Map sqlFunctions;
+ private TypeResolver typeResolver = new TypeResolver();
private EntityTuplizerFactory entityTuplizerFactory;
// private ComponentTuplizerFactory componentTuplizerFactory; todo : HHH-3517 and HHH-1907
@@ -2279,6 +2282,10 @@
sqlFunctions.put( functionName, function );
}
+ public TypeResolver getTypeResolver() {
+ return typeResolver;
+ }
+
public SessionFactoryObserver getSessionFactoryObserver() {
return sessionFactoryObserver;
}
@@ -2381,6 +2388,9 @@
Configuration.this.namingStrategy = namingStrategy;
}
+ public TypeResolver getTypeResolver() {
+ return typeResolver;
+ }
public Iterator iterateClasses() {
return classes.values().iterator();
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -411,7 +411,7 @@
java.util.Map inheritedMetas) throws MappingException {
String propertyName = idNode.attributeValue( "name" );
- SimpleValue id = new SimpleValue( entity.getTable() );
+ SimpleValue id = new SimpleValue( mappings, entity.getTable() );
entity.setIdentifier( id );
// if ( propertyName == null || entity.getPojoRepresentation() == null ) {
@@ -467,7 +467,7 @@
private static void bindCompositeId(Element idNode, RootClass entity, Mappings mappings,
java.util.Map inheritedMetas) throws MappingException {
String propertyName = idNode.attributeValue( "name" );
- Component id = new Component( entity );
+ Component id = new Component( mappings, entity );
entity.setIdentifier( id );
bindCompositeId( idNode, id, entity, propertyName, mappings, inheritedMetas );
if ( propertyName == null ) {
@@ -497,7 +497,7 @@
String name, RootClass entity, java.util.Map inheritedMetas) {
String propertyName = subnode.attributeValue( "name" );
- SimpleValue val = new SimpleValue( table );
+ SimpleValue val = new SimpleValue( mappings, table );
bindSimpleValue( subnode, val, false, propertyName, mappings );
if ( !val.isTypeSpecified() ) {
// this is either a <version/> tag with no type attribute,
@@ -530,7 +530,7 @@
private static void bindDiscriminatorProperty(Table table, RootClass entity, Element subnode,
Mappings mappings) {
- SimpleValue discrim = new SimpleValue( table );
+ SimpleValue discrim = new SimpleValue( mappings, table );
entity.setDiscriminator( discrim );
bindSimpleValue(
subnode,
@@ -930,7 +930,7 @@
// KEY
Element keyNode = node.element( "key" );
- SimpleValue key = new DependantValue( mytable, joinedSubclass.getIdentifier() );
+ SimpleValue key = new DependantValue( mappings, mytable, joinedSubclass.getIdentifier() );
joinedSubclass.setKey( key );
key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );
bindSimpleValue( keyNode, key, false, joinedSubclass.getEntityName(), mappings );
@@ -995,7 +995,7 @@
// KEY
Element keyNode = node.element( "key" );
- SimpleValue key = new DependantValue( table, persistentClass.getIdentifier() );
+ SimpleValue key = new DependantValue( mappings, table, persistentClass.getIdentifier() );
join.setKey( key );
key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );
bindSimpleValue( keyNode, key, false, persistentClass.getEntityName(), mappings );
@@ -1013,20 +1013,20 @@
Value value = null;
if ( "many-to-one".equals( name ) ) {
- value = new ManyToOne( table );
+ value = new ManyToOne( mappings, table );
bindManyToOne( subnode, (ManyToOne) value, propertyName, true, mappings );
}
else if ( "any".equals( name ) ) {
- value = new Any( table );
+ value = new Any( mappings, table );
bindAny( subnode, (Any) value, true, mappings );
}
else if ( "property".equals( name ) ) {
- value = new SimpleValue( table );
+ value = new SimpleValue( mappings, table );
bindSimpleValue( subnode, (SimpleValue) value, true, propertyName, mappings );
}
else if ( "component".equals( name ) || "dynamic-component".equals( name ) ) {
String subpath = StringHelper.qualify( path, propertyName );
- value = new Component( join );
+ value = new Component( mappings, join );
bindComponent(
subnode,
(Component) value,
@@ -1648,7 +1648,7 @@
Iterator iter = node.elementIterator( "meta-value" );
if ( iter.hasNext() ) {
HashMap values = new HashMap();
- org.hibernate.type.Type metaType = TypeFactory.heuristicType( any.getMetaType() );
+ org.hibernate.type.Type metaType = mappings.getTypeResolver().heuristicType( any.getMetaType() );
while ( iter.hasNext() ) {
Element metaValue = (Element) iter.next();
try {
@@ -1820,7 +1820,7 @@
if ( propertyName!=null ) {
throw new MappingException("cannot combine mapped=\"true\" with specified name");
}
- Component mapper = new Component(persistentClass);
+ Component mapper = new Component( mappings, persistentClass );
bindComponent(
node,
mapper,
@@ -1921,7 +1921,7 @@
value = collection;
}
else if ( "many-to-one".equals( name ) || "key-many-to-one".equals( name ) ) {
- value = new ManyToOne( component.getTable() );
+ value = new ManyToOne( mappings, component.getTable() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
@@ -1932,7 +1932,7 @@
bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
}
else if ( "one-to-one".equals( name ) ) {
- value = new OneToOne( component.getTable(), component.getOwner() );
+ value = new OneToOne( mappings, component.getTable(), component.getOwner() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
@@ -1943,11 +1943,11 @@
bindOneToOne( subnode, (OneToOne) value, relativePath, isNullable, mappings );
}
else if ( "any".equals( name ) ) {
- value = new Any( component.getTable() );
+ value = new Any( mappings, component.getTable() );
bindAny( subnode, (Any) value, isNullable, mappings );
}
else if ( "property".equals( name ) || "key-property".equals( name ) ) {
- value = new SimpleValue( component.getTable() );
+ value = new SimpleValue( mappings, component.getTable() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
@@ -1960,7 +1960,7 @@
else if ( "component".equals( name )
|| "dynamic-component".equals( name )
|| "nested-composite-element".equals( name ) ) {
- value = new Component( component ); // a nested composite element
+ value = new Component( mappings, component ); // a nested composite element
bindComponent(
subnode,
(Component) value,
@@ -2155,26 +2155,26 @@
value = collection;
}
else if ( "many-to-one".equals( name ) ) {
- value = new ManyToOne( table );
+ value = new ManyToOne( mappings, table );
bindManyToOne( subnode, (ManyToOne) value, propertyName, nullable, mappings );
}
else if ( "any".equals( name ) ) {
- value = new Any( table );
+ value = new Any( mappings, table );
bindAny( subnode, (Any) value, nullable, mappings );
}
else if ( "one-to-one".equals( name ) ) {
- value = new OneToOne( table, persistentClass );
+ value = new OneToOne( mappings, table, persistentClass );
bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
}
else if ( "property".equals( name ) ) {
- value = new SimpleValue( table );
+ value = new SimpleValue( mappings, table );
bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings );
}
else if ( "component".equals( name )
|| "dynamic-component".equals( name )
|| "properties".equals( name ) ) {
String subpath = StringHelper.qualify( entityName, propertyName );
- value = new Component( persistentClass );
+ value = new Component( mappings, persistentClass );
bindComponent(
subnode,
@@ -2320,7 +2320,7 @@
Element subnode = node.element( "list-index" );
if ( subnode == null ) subnode = node.element( "index" );
- SimpleValue iv = new SimpleValue( list.getCollectionTable() );
+ SimpleValue iv = new SimpleValue( mappings, list.getCollectionTable() );
bindSimpleValue(
subnode,
iv,
@@ -2357,7 +2357,7 @@
bindCollectionSecondPass( node, collection, persistentClasses, mappings, inheritedMetas );
Element subnode = node.element( "collection-id" );
- SimpleValue id = new SimpleValue( collection.getCollectionTable() );
+ SimpleValue id = new SimpleValue( mappings, collection.getCollectionTable() );
bindSimpleValue(
subnode,
id,
@@ -2384,7 +2384,7 @@
String name = subnode.getName();
if ( "index".equals( name ) || "map-key".equals( name ) ) {
- SimpleValue value = new SimpleValue( map.getCollectionTable() );
+ SimpleValue value = new SimpleValue( mappings, map.getCollectionTable() );
bindSimpleValue(
subnode,
value,
@@ -2400,7 +2400,7 @@
map.setIndexNodeName( subnode.attributeValue("node") );
}
else if ( "index-many-to-many".equals( name ) || "map-key-many-to-many".equals( name ) ) {
- ManyToOne mto = new ManyToOne( map.getCollectionTable() );
+ ManyToOne mto = new ManyToOne( mappings, map.getCollectionTable() );
bindManyToOne(
subnode,
mto,
@@ -2412,7 +2412,7 @@
}
else if ( "composite-index".equals( name ) || "composite-map-key".equals( name ) ) {
- Component component = new Component( map );
+ Component component = new Component( mappings, map );
bindComposite(
subnode,
component,
@@ -2424,7 +2424,7 @@
map.setIndex( component );
}
else if ( "index-many-to-any".equals( name ) ) {
- Any any = new Any( map.getCollectionTable() );
+ Any any = new Any( mappings, map.getCollectionTable() );
bindAny( subnode, any, map.isOneToMany(), mappings );
map.setIndex( any );
}
@@ -2497,7 +2497,7 @@
else {
keyVal = (KeyValue) collection.getOwner().getRecursiveProperty( propRef ).getValue();
}
- SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal );
+ SimpleValue key = new DependantValue( mappings, collection.getCollectionTable(), keyVal );
key.setCascadeDeleteEnabled( "cascade"
.equals( subnode.attributeValue( "on-delete" ) ) );
bindSimpleValue(
@@ -2518,7 +2518,7 @@
}
else if ( "element".equals( name ) ) {
- SimpleValue elt = new SimpleValue( collection.getCollectionTable() );
+ SimpleValue elt = new SimpleValue( mappings, collection.getCollectionTable() );
collection.setElement( elt );
bindSimpleValue(
subnode,
@@ -2529,7 +2529,7 @@
);
}
else if ( "many-to-many".equals( name ) ) {
- ManyToOne element = new ManyToOne( collection.getCollectionTable() );
+ ManyToOne element = new ManyToOne( mappings, collection.getCollectionTable() );
collection.setElement( element );
bindManyToOne(
subnode,
@@ -2541,7 +2541,7 @@
bindManyToManySubelements( collection, subnode, mappings );
}
else if ( "composite-element".equals( name ) ) {
- Component element = new Component( collection );
+ Component element = new Component( mappings, collection );
collection.setElement( element );
bindComposite(
subnode,
@@ -2553,7 +2553,7 @@
);
}
else if ( "many-to-any".equals( name ) ) {
- Any element = new Any( collection.getCollectionTable() );
+ Any element = new Any( mappings, collection.getCollectionTable() );
collection.setElement( element );
bindAny( subnode, element, true, mappings );
}
@@ -3001,7 +3001,7 @@
final String paramName = param.attributeValue( "name" );
final String paramType = param.attributeValue( "type" );
log.debug( "adding filter parameter : " + paramName + " -> " + paramType );
- final Type heuristicType = TypeFactory.heuristicType( paramType );
+ final Type heuristicType = mappings.getTypeResolver().heuristicType( paramType );
log.debug( "parameter heuristic type : " + heuristicType );
paramMappings.put( paramName, heuristicType );
}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -44,6 +44,7 @@
import org.hibernate.mapping.AuxiliaryDatabaseObject;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.FetchProfile;
+import org.hibernate.type.TypeResolver;
/**
* A collection of mappings from classes and collections to relational database tables. Represents a single
@@ -60,6 +61,12 @@
* @author Steve Ebersole
*/
public interface Mappings {
+ /**
+ * Retrieve the type resolver in effect.
+ *
+ * @return The type resolver.
+ */
+ public TypeResolver getTypeResolver();
/**
* Get the current naming strategy.
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/ResultSetMappingBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/ResultSetMappingBinder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/ResultSetMappingBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -81,7 +81,7 @@
String typeFromXML = HbmBinder.getTypeFromXML( returnElem );
Type type = null;
if(typeFromXML!=null) {
- type = TypeFactory.heuristicType( typeFromXML );
+ type = mappings.getTypeResolver().heuristicType( typeFromXML );
if ( type == null ) {
throw new MappingException( "could not determine type " + type );
}
Modified: core/trunk/core/src/main/java/org/hibernate/collection/PersistentIndexedElementHolder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/collection/PersistentIndexedElementHolder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/collection/PersistentIndexedElementHolder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -41,8 +41,8 @@
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
-import org.hibernate.type.NullableType;
import org.hibernate.type.Type;
+import org.hibernate.type.XmlRepresentableType;
import org.hibernate.util.CollectionHelper;
/**
@@ -164,7 +164,7 @@
final Type indexType = persister.getIndexType();
final Object indexValue = persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() );
- final String index = ( (NullableType) indexType ).toXMLString( indexValue, factory );
+ final String index = ( (XmlRepresentableType) indexType ).toXMLString( indexValue, factory );
setIndex(elem, indexNode, index);
return object;
}
@@ -202,13 +202,14 @@
HashMap deletes = (HashMap) snapshot.clone();
deletes.keySet().removeAll( ( (HashMap) getSnapshot(persister) ).keySet() );
ArrayList deleteList = new ArrayList( deletes.size() );
- Iterator iter = deletes.entrySet().iterator();
- while ( iter.hasNext() ) {
- Map.Entry me = (Map.Entry) iter.next();
+ for ( Object o : deletes.entrySet() ) {
+ Map.Entry me = (Map.Entry) o;
final Object object = indexIsFormula ?
- me.getValue() :
- ( (NullableType) indexType ).fromXMLString( (String) me.getKey(), persister.getFactory() );
- if (object!=null) deleteList.add(object);
+ me.getValue() :
+ ( (XmlRepresentableType) indexType ).fromXMLString( (String) me.getKey(), persister.getFactory() );
+ if ( object != null ) {
+ deleteList.add( object );
+ }
}
return deleteList.iterator();
@@ -233,7 +234,7 @@
public Object getIndex(Object entry, int i, CollectionPersister persister) {
String index = ( (IndexedValue) entry ).index;
final Type indexType = persister.getIndexType();
- return ( (NullableType) indexType ).fromXMLString( index, persister.getFactory() );
+ return ( (XmlRepresentableType) indexType ).fromXMLString( index, persister.getFactory() );
}
public Object getElement(Object entry) {
Modified: core/trunk/core/src/main/java/org/hibernate/collection/PersistentListElementHolder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/collection/PersistentListElementHolder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/collection/PersistentListElementHolder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.collection;
@@ -28,10 +27,10 @@
import java.util.List;
import org.dom4j.Element;
-import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
+import org.hibernate.type.IntegerType;
import org.hibernate.type.Type;
/**
@@ -73,7 +72,7 @@
for ( int i=0; i<length; i++ ) {
Element elem = (Element) elements.get(i);
Object object = elementType.fromXMLNode( elem, persister.getFactory() );
- Integer index = (Integer) Hibernate.INTEGER.fromStringValue( getIndex(elem, indexNodeName, i) );
+ Integer index = IntegerType.INSTANCE.fromString( getIndex(elem, indexNodeName, i) );
result[ index.intValue() ] = elementType.disassemble( object, getSession(), null );
}
return result;
Modified: core/trunk/core/src/main/java/org/hibernate/collection/PersistentMapElementHolder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/collection/PersistentMapElementHolder.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/collection/PersistentMapElementHolder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -31,8 +31,8 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
-import org.hibernate.type.NullableType;
import org.hibernate.type.Type;
+import org.hibernate.type.XmlRepresentableType;
/**
* @author Gavin King
@@ -64,7 +64,7 @@
Element subelement = element.addElement( persister.getElementNodeName() );
elementType.setToXMLNode( subelement, object, persister.getFactory() );
- String indexString = ( (NullableType) indexType ).toXMLString( index, persister.getFactory() );
+ String indexString = ( (XmlRepresentableType) indexType ).toXMLString( index, persister.getFactory() );
setIndex( subelement, indexNodeName, indexString );
}
@@ -83,12 +83,10 @@
Element elem = (Element) elements.get(i/2);
Object object = elementType.fromXMLNode( elem, persister.getFactory() );
final String indexString = getIndex(elem, indexNodeName, i);
- Object index = ( (NullableType) indexType ).fromXMLString( indexString, persister.getFactory() );
+ Object index = ( (XmlRepresentableType) indexType ).fromXMLString( indexString, persister.getFactory() );
result[i++] = indexType.disassemble( index, getSession(), null );
result[i++] = elementType.disassemble( object, getSession(), null );
}
return result;
}
-
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/CastFunction.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -56,7 +56,7 @@
throw new QueryException("cast() requires two arguments");
}
String type = (String) args.get(1);
- int[] sqlTypeCodes = TypeFactory.heuristicType(type).sqlTypes(factory);
+ int[] sqlTypeCodes = factory.getTypeResolver().heuristicType(type).sqlTypes(factory);
if ( sqlTypeCodes.length!=1 ) {
throw new QueryException("invalid Hibernate type for cast()");
}
Modified: core/trunk/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -52,6 +52,7 @@
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.stat.StatisticsImplementor;
import org.hibernate.type.Type;
+import org.hibernate.type.TypeResolver;
/**
* Defines the internal contract between the <tt>SessionFactory</tt> and other parts of
@@ -62,6 +63,12 @@
* @author Gavin King
*/
public interface SessionFactoryImplementor extends Mapping, SessionFactory {
+ /**
+ * Retrieve the {@link Type} resolver associated with this factory.
+ *
+ * @return The type resolver
+ */
+ public TypeResolver getTypeResolver();
/**
* Get a copy of the Properties used to configure this session factory.
Modified: core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/engine/jdbc/ClobProxy.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -44,6 +44,7 @@
public class ClobProxy implements InvocationHandler {
private static final Class[] PROXY_INTERFACES = new Class[] { Clob.class, ClobImplementer.class };
+ private String string;
private Reader reader;
private long length;
private boolean needsReset = false;
@@ -56,6 +57,7 @@
* @see #generateProxy(String)
*/
protected ClobProxy(String string) {
+ this.string = string;
reader = new StringReader(string);
length = string.length();
}
@@ -86,15 +88,24 @@
return reader;
}
+ protected String getSubString(long pos, int length) {
+ if ( string == null ) {
+ throw new UnsupportedOperationException( "Clob was not created from string; cannot substring" );
+ }
+ // naive impl...
+ return string.substring( (int)pos-1, (int)(pos+length-1) );
+ }
+
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException if any methods other than {@link Clob#length()},
* {@link Clob#getAsciiStream()}, or {@link Clob#getCharacterStream()} are invoked.
*/
+ @SuppressWarnings({ "UnnecessaryBoxing" })
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ( "length".equals( method.getName() ) ) {
- return new Long( getLength() );
+ return Long.valueOf( getLength() );
}
if ( "getAsciiStream".equals( method.getName() ) ) {
return getAsciiStream();
@@ -102,6 +113,9 @@
if ( "getCharacterStream".equals( method.getName() ) ) {
return getCharacterStream();
}
+ if ( "getSubString".equals( method.getName() ) ) {
+ return getSubString( (Long)args[0], (Integer)args[1] );
+ }
if ( "free".equals( method.getName() ) ) {
reader.close();
return null;
Modified: core/trunk/core/src/main/java/org/hibernate/event/def/DefaultFlushEntityEventListener.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/def/DefaultFlushEntityEventListener.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/event/def/DefaultFlushEntityEventListener.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -555,13 +555,30 @@
cannotDirtyCheck = false;
interceptorHandledDirtyCheck = true;
}
-
+
+ logDirtyProperties( id, dirtyProperties, persister );
+
event.setDirtyProperties(dirtyProperties);
event.setDirtyCheckHandledByInterceptor(interceptorHandledDirtyCheck);
event.setDirtyCheckPossible(!cannotDirtyCheck);
}
+ private void logDirtyProperties(Serializable id, int[] dirtyProperties, EntityPersister persister) {
+ if ( log.isTraceEnabled() && dirtyProperties != null && dirtyProperties.length > 0 ) {
+ final String[] allPropertyNames = persister.getPropertyNames();
+ final String[] dirtyPropertyNames = new String[ dirtyProperties.length ];
+ for ( int i = 0; i < dirtyProperties.length; i++ ) {
+ dirtyPropertyNames[i] = allPropertyNames[ dirtyProperties[i]];
+ }
+ log.trace(
+ "Found dirty properties [{}] : {}",
+ MessageHelper.infoString( persister.getEntityName(), id ),
+ dirtyPropertyNames
+ );
+ }
+ }
+
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
if ( persister.isSelectBeforeUpdateRequired() ) {
Object[] snapshot = session.getPersistenceContext()
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/BooleanLiteralNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/BooleanLiteralNode.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/BooleanLiteralNode.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -74,5 +74,6 @@
private LiteralType typeAsLiteralType() {
return (LiteralType) getDataType();
+
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/JavaConstantNode.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/JavaConstantNode.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/JavaConstantNode.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -55,7 +55,7 @@
if ( StringHelper.isNotEmpty( s ) ) {
constantExpression = s;
constantValue = ReflectHelper.getConstantValue( s );
- heuristicType = TypeFactory.heuristicType( constantValue.getClass().getName() );
+ heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() );
super.setText( s );
}
}
@@ -72,7 +72,12 @@
this.factory = factory;
}
- private String resolveToLiteralString(Type type) {
+ public String getRenderText(SessionFactoryImplementor sessionFactory) {
+ Type type = expectedType == null
+ ? heuristicType
+ : Number.class.isAssignableFrom( heuristicType.getReturnedClass() )
+ ? heuristicType
+ : expectedType;
try {
LiteralType literalType = ( LiteralType ) type;
Dialect dialect = factory.getDialect();
@@ -82,9 +87,4 @@
throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t );
}
}
-
- public String getRenderText(SessionFactoryImplementor sessionFactory) {
- Type type = expectedType == null ? heuristicType : expectedType;
- return resolveToLiteralString( type );
- }
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/util/LiteralProcessor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -185,7 +185,7 @@
}
Type type;
try {
- type = TypeFactory.heuristicType( value.getClass().getName() );
+ type = walker.getSessionFactoryHelper().getFactory().getTypeResolver().heuristicType( value.getClass().getName() );
}
catch ( MappingException me ) {
throw new QueryException( me );
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -395,7 +395,7 @@
Type argumentType = null;
if ( first != null ) {
if ( "cast".equals(functionName) ) {
- argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() );
+ argumentType = sfi.getTypeResolver().heuristicType( first.getNextSibling().getText() );
}
else if ( first instanceof SqlNode ) {
argumentType = ( (SqlNode) first ).getDataType();
Modified: core/trunk/core/src/main/java/org/hibernate/hql/classic/WhereParser.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/classic/WhereParser.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/hql/classic/WhereParser.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -427,7 +427,7 @@
) {
Type type;
try {
- type = TypeFactory.heuristicType( constant.getClass().getName() );
+ type = q.getFactory().getTypeResolver().heuristicType( constant.getClass().getName() );
}
catch ( MappingException me ) {
throw new QueryException( me );
Modified: core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -480,7 +480,7 @@
private Type guessType(Class clazz) throws HibernateException {
String typename = clazz.getName();
- Type type = TypeFactory.heuristicType(typename);
+ Type type = session.getFactory().getTypeResolver().heuristicType(typename);
boolean serializable = type!=null && type instanceof SerializableType;
if (type==null || serializable) {
try {
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -122,6 +122,7 @@
import org.hibernate.transaction.TransactionFactory;
import org.hibernate.type.AssociationType;
import org.hibernate.type.Type;
+import org.hibernate.type.TypeResolver;
import org.hibernate.util.CollectionHelper;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.EmptyIterator;
@@ -189,6 +190,7 @@
private final transient QueryPlanCache queryPlanCache = new QueryPlanCache( this );
private final transient Cache cacheAccess = new CacheImpl();
private transient boolean isClosed = false;
+ private final transient TypeResolver typeResolver;
public SessionFactoryImpl(
Configuration cfg,
@@ -231,6 +233,8 @@
}
};
+ this.typeResolver = cfg.getTypeResolver().scope( this );
+
this.filters = new HashMap();
this.filters.putAll( cfg.getFilterDefinitions() );
@@ -498,6 +502,10 @@
return null;
}
+ public TypeResolver getTypeResolver() {
+ return typeResolver;
+ }
+
private void registerEntityNameResolvers(EntityPersister persister) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizerMapping() == null ) {
return;
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -56,8 +56,8 @@
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.AssociationType;
+import org.hibernate.type.StringRepresentableType;
import org.hibernate.type.Type;
-import org.hibernate.type.NullableType;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.StringHelper;
@@ -548,8 +548,8 @@
}
// Convert the string value into the proper type.
- if ( type instanceof NullableType ) {
- NullableType nullableType = ( NullableType ) type;
+ if ( type instanceof StringRepresentableType ) {
+ StringRepresentableType nullableType = (StringRepresentableType) type;
value = nullableType.fromStringValue( stringValue );
}
else {
Modified: core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -583,7 +583,7 @@
int columnType = resultSetMetaData.getColumnType( columnPos );
int scale = resultSetMetaData.getScale( columnPos );
int precision = resultSetMetaData.getPrecision( columnPos );
- return TypeFactory.heuristicType(
+ return factory.getTypeResolver().heuristicType(
factory.getDialect().getHibernateTypeName(
columnType,
precision,
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/Any.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/Any.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/Any.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,18 +20,16 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
-
package org.hibernate.mapping;
import java.util.Map;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.type.MetaType;
import org.hibernate.type.AnyType;
import org.hibernate.type.Type;
-import org.hibernate.type.TypeFactory;
/**
* A Hibernate "any" type (ie. polymorphic association to
@@ -39,13 +37,12 @@
* @author Gavin King
*/
public class Any extends SimpleValue {
-
private String identifierTypeName;
private String metaTypeName = "string";
private Map metaValues;
- public Any(Table table) {
- super(table);
+ public Any(Mappings mappings, Table table) {
+ super( mappings, table );
}
public String getIdentifierType() {
@@ -57,11 +54,10 @@
}
public Type getType() throws MappingException {
+ final Type metaType = getMappings().getTypeResolver().heuristicType( metaTypeName );
return new AnyType(
- metaValues==null ?
- TypeFactory.heuristicType(metaTypeName) :
- new MetaType( metaValues, TypeFactory.heuristicType(metaTypeName) ),
- TypeFactory.heuristicType(identifierTypeName)
+ metaValues == null ? metaType : new MetaType( metaValues, metaType ),
+ getMappings().getTypeResolver().heuristicType( identifierTypeName )
);
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/Component.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/Component.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/Component.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -31,6 +31,7 @@
import org.hibernate.EntityMode;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
@@ -66,23 +67,23 @@
private java.util.Map tuplizerImpls;
- public Component(PersistentClass owner) throws MappingException {
- super( owner.getTable() );
+ public Component(Mappings mappings, PersistentClass owner) throws MappingException {
+ super( mappings, owner.getTable() );
this.owner = owner;
}
- public Component(Component component) throws MappingException {
- super( component.getTable() );
+ public Component(Mappings mappings, Component component) throws MappingException {
+ super( mappings, component.getTable() );
this.owner = component.getOwner();
}
- public Component(Join join) throws MappingException {
- super( join.getTable() );
+ public Component(Mappings mappings, Join join) throws MappingException {
+ super( mappings, join.getTable() );
this.owner = join.getPersistentClass();
}
- public Component(Collection collection) throws MappingException {
- super( collection.getCollectionTable() );
+ public Component(Mappings mappings, Collection collection) throws MappingException {
+ super( mappings, collection.getCollectionTable() );
this.owner = collection.getOwner();
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/DependantValue.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/DependantValue.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/DependantValue.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -25,6 +25,7 @@
package org.hibernate.mapping;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.type.Type;
/**
@@ -39,8 +40,8 @@
private boolean nullable;
private boolean updateable;
- public DependantValue(Table table, KeyValue prototype) {
- super(table);
+ public DependantValue(Mappings mappings, Table table, KeyValue prototype) {
+ super( mappings, table );
this.wrappedValue = prototype;
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -29,6 +29,7 @@
import java.util.Map;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.TypeFactory;
@@ -41,8 +42,8 @@
private boolean ignoreNotFound;
private boolean isLogicalOneToOne;
- public ManyToOne(Table table) {
- super(table);
+ public ManyToOne(Mappings mappings, Table table) {
+ super( mappings, table );
}
public Type getType() throws MappingException {
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/OneToOne.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/OneToOne.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/OneToOne.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -28,6 +28,7 @@
import java.util.Iterator;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.SpecialOneToOneType;
@@ -46,8 +47,8 @@
private String propertyName;
private String entityName;
- public OneToOne(Table table, PersistentClass owner) throws MappingException {
- super(table);
+ public OneToOne(Mappings mappings, Table table, PersistentClass owner) throws MappingException {
+ super( mappings, table );
this.identifier = owner.getKey();
this.entityName = owner.getEntityName();
}
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/SimpleValue.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/SimpleValue.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/SimpleValue.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.mapping;
@@ -31,6 +30,7 @@
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.Mapping;
import org.hibernate.id.IdentifierGenerator;
@@ -48,6 +48,8 @@
public class SimpleValue implements KeyValue {
public static final String DEFAULT_ID_GEN_STRATEGY = "assigned";
+ private final Mappings mappings;
+
private final List columns = new ArrayList();
private String typeName;
private Properties identifierGeneratorProperties;
@@ -59,6 +61,19 @@
private Properties typeParameters;
private boolean cascadeDeleteEnabled;
+ public SimpleValue(Mappings mappings) {
+ this.mappings = mappings;
+ }
+
+ public SimpleValue(Mappings mappings, Table table) {
+ this( mappings );
+ this.table = table;
+ }
+
+ public Mappings getMappings() {
+ return mappings;
+ }
+
public boolean isCascadeDeleteEnabled() {
return cascadeDeleteEnabled;
}
@@ -104,13 +119,7 @@
public void setTable(Table table) {
this.table = table;
}
-
- public SimpleValue(Table table) {
- this.table = table;
- }
- public SimpleValue() {}
-
public void createForeignKey() throws MappingException {}
public void createForeignKeyOfEntity(String entityName) {
@@ -278,7 +287,7 @@
if (typeName==null) {
throw new MappingException("No type name");
}
- Type result = TypeFactory.heuristicType(typeName, typeParameters);
+ Type result = mappings.getTypeResolver().heuristicType(typeName, typeParameters);
if (result==null) {
String msg = "Could not determine type for: " + typeName;
if(table != null){
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/ToOne.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/ToOne.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/ToOne.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -26,6 +26,7 @@
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
+import org.hibernate.cfg.Mappings;
import org.hibernate.engine.Mapping;
import org.hibernate.type.Type;
import org.hibernate.util.ReflectHelper;
@@ -43,8 +44,8 @@
private boolean lazy = true;
protected boolean unwrapProxy;
- protected ToOne(Table table) {
- super(table);
+ protected ToOne(Mappings mappings, Table table) {
+ super( mappings, table );
}
public FetchMode getFetchMode() {
@@ -122,10 +123,3 @@
}
}
-
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractBynaryType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractBynaryType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractBynaryType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -44,6 +43,8 @@
*
* @author Gavin King
* @author Emmanuel Bernard
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class AbstractBynaryType extends MutableType implements VersionType, Comparator {
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractCharArrayType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractCharArrayType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractCharArrayType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -40,6 +39,8 @@
* Logic to bind stream of char into a VARCHAR
*
* @author Emmanuel Bernard
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class AbstractCharArrayType extends MutableType {
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractComponentType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractLongBinaryType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractLongBinaryType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractLongBinaryType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
@@ -29,6 +27,8 @@
* An abstract type for mapping long binary SQL types to Java byte[].
*
* @author Gail Badner
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class AbstractLongBinaryType extends AbstractBynaryType {
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractLongStringType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractLongStringType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractLongStringType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
@@ -37,6 +35,8 @@
/**
* An abstract type for mapping long string SQL types to a Java String.
* @author Gavin King, Bertrand Renuart (from TextType)
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class AbstractLongStringType extends ImmutableType {
Added: core/trunk/core/src/main/java/org/hibernate/type/AbstractSingleColumnStandardBasicType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractSingleColumnStandardBasicType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractSingleColumnStandardBasicType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,103 @@
+/*
+ * 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 org.hibernate.HibernateException;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.jdbc.LobCreator;
+import org.hibernate.engine.jdbc.NonContextualLobCreator;
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractSingleColumnStandardBasicType<T>
+ extends AbstractStandardBasicType<T>
+ implements SingleColumnType<T> {
+
+ public AbstractSingleColumnStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
+ super( sqlTypeDescriptor, javaTypeDescriptor );
+ }
+
+ private static WrapperOptions NO_OPTIONS = new WrapperOptions() {
+ public boolean useStreamForLobBinding() {
+ return false;
+ }
+
+ public LobCreator getLobCreator() {
+ return NonContextualLobCreator.INSTANCE;
+ }
+ };
+
+ public final int sqlType() {
+ return getSqlTypeDescriptor().getSqlType();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException {
+ return nullSafeGet( rs, name, NO_OPTIONS );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
+ return nullSafeGet( rs, name );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session)
+ throws HibernateException, SQLException {
+ if ( settable[0] ) {
+ nullSafeSet( st, value, index, session );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void nullSafeSet(PreparedStatement st, T value, int index) throws HibernateException, SQLException {
+ nullSafeSet( st, value, index, NO_OPTIONS );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void set(PreparedStatement st, T value, int index) throws HibernateException, SQLException {
+ nullSafeSet( st, value, index );
+ }
+
+}
\ No newline at end of file
Added: core/trunk/core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,362 @@
+/*
+ * 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.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+import org.dom4j.Node;
+
+import org.hibernate.EntityMode;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.cfg.Environment;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.engine.jdbc.LobCreator;
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.MutabilityPlan;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
+import org.hibernate.util.ArrayHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractStandardBasicType<T>
+ implements BasicType, StringRepresentableType<T>, XmlRepresentableType<T> {
+
+ private final SqlTypeDescriptor sqlTypeDescriptor;
+ private final JavaTypeDescriptor<T> javaTypeDescriptor;
+
+ public AbstractStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
+ this.sqlTypeDescriptor = sqlTypeDescriptor;
+ this.javaTypeDescriptor = javaTypeDescriptor;
+ }
+
+ public T fromString(String string) {
+ return javaTypeDescriptor.fromString( string );
+ }
+
+ public String toString(T value) {
+ return javaTypeDescriptor.toString( value );
+ }
+
+ public T fromStringValue(String xml) throws HibernateException {
+ return fromString( xml );
+ }
+
+ public String toXMLString(T value, SessionFactoryImplementor factory) throws HibernateException {
+ return toString( value );
+ }
+
+ public T fromXMLString(String xml, Mapping factory) throws HibernateException {
+ return xml == null || xml.length() == 0 ? null : fromStringValue( xml );
+ }
+
+ protected MutabilityPlan<T> getMutabilityPlan() {
+ return javaTypeDescriptor.getMutabilityPlan();
+ }
+
+ protected T getReplacement(T original, T target) {
+ if ( !isMutable() ) {
+ return original;
+ }
+ else if ( isEqual( original, target ) ) {
+ return original;
+ }
+ else {
+ return deepCopy( original );
+ }
+ }
+
+ public boolean[] toColumnNullness(Object value, Mapping mapping) {
+ return value == null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
+ }
+
+ public String[] getRegistrationKeys() {
+ return registerUnderJavaType()
+ ? new String[] { getName(), javaTypeDescriptor.getJavaTypeClass().getName() }
+ : new String[] { getName() };
+ }
+
+ protected boolean registerUnderJavaType() {
+ return false;
+ }
+
+
+ // final implementations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public final JavaTypeDescriptor<T> getJavaTypeDescriptor() {
+ return javaTypeDescriptor;
+ }
+
+ public final SqlTypeDescriptor getSqlTypeDescriptor() {
+ return sqlTypeDescriptor;
+ }
+
+ public final Class getReturnedClass() {
+ return javaTypeDescriptor.getJavaTypeClass();
+ }
+
+ public final int[] sqlTypes(Mapping mapping) throws MappingException {
+ return new int[] { sqlTypeDescriptor.getSqlType() };
+ }
+
+ public final int getColumnSpan(Mapping mapping) throws MappingException {
+ return sqlTypes( mapping ).length;
+ }
+
+ public final boolean isAssociationType() {
+ return false;
+ }
+
+ public final boolean isCollectionType() {
+ return false;
+ }
+
+ public final boolean isComponentType() {
+ return false;
+ }
+
+ public final boolean isEntityType() {
+ return false;
+ }
+
+ public final boolean isAnyType() {
+ return false;
+ }
+
+ public final boolean isXMLElement() {
+ return false;
+ }
+
+ public final boolean isSame(Object x, Object y, EntityMode entityMode) {
+ return isSame( x, y );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ protected final boolean isSame(Object x, Object y) {
+ return isEqual( (T) x, (T) y );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final boolean isEqual(Object x, Object y, EntityMode entityMode) {
+ return isEqual( (T) x, (T) y );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory) {
+ return isEqual( (T) x, (T) y );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final boolean isEqual(T one, T another) {
+ return javaTypeDescriptor.areEqual( one, another );
+ }
+
+ public final int getHashCode(Object x, EntityMode entityMode) {
+ return getHashCode( x );
+ }
+
+ public final int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory) {
+ return getHashCode( x );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ protected final int getHashCode(Object x) {
+ return javaTypeDescriptor.extractHashCode( (T) x );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final int compare(Object x, Object y, EntityMode entityMode) {
+ return javaTypeDescriptor.getComparator().compare( (T) x, (T) y );
+ }
+
+ public final boolean isDirty(Object old, Object current, SessionImplementor session) {
+ return isDirty( old, current );
+ }
+
+ public final boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session) {
+ return checkable[0] && isDirty( old, current );
+ }
+
+ protected final boolean isDirty(Object old, Object current) {
+ return !isSame( old, current );
+ }
+
+ public final boolean isModified(
+ Object oldHydratedState,
+ Object currentState,
+ boolean[] checkable,
+ SessionImplementor session) {
+ return isDirty( oldHydratedState, currentState );
+ }
+
+ public final Object nullSafeGet(
+ ResultSet rs,
+ String[] names,
+ SessionImplementor session,
+ Object owner) throws SQLException {
+ return nullSafeGet( rs, names[0], session );
+ }
+
+ public final Object nullSafeGet(ResultSet rs, String name, SessionImplementor session, Object owner)
+ throws SQLException {
+ return nullSafeGet( rs, name, session );
+ }
+
+ public final T nullSafeGet(ResultSet rs, String name, final SessionImplementor session) throws SQLException {
+ // todo : have SessionImplementor extend WrapperOptions
+ final WrapperOptions options = new WrapperOptions() {
+ public boolean useStreamForLobBinding() {
+ return Environment.useStreamsForBinary();
+ }
+
+ public LobCreator getLobCreator() {
+ return Hibernate.getLobCreator( session );
+ }
+ };
+
+ return nullSafeGet( rs, name, options );
+ }
+
+ protected final T nullSafeGet(ResultSet rs, String name, WrapperOptions options) throws SQLException {
+ return sqlTypeDescriptor.getExtractor( javaTypeDescriptor ).extract( rs, name, options );
+ }
+
+ public Object get(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException {
+ return nullSafeGet( rs, name, session );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final void nullSafeSet(
+ PreparedStatement st,
+ Object value,
+ int index,
+ final SessionImplementor session) throws SQLException {
+ // todo : have SessionImplementor extend WrapperOptions
+ final WrapperOptions options = new WrapperOptions() {
+ public boolean useStreamForLobBinding() {
+ return Environment.useStreamsForBinary();
+ }
+
+ public LobCreator getLobCreator() {
+ return Hibernate.getLobCreator( session );
+ }
+ };
+
+ nullSafeSet( st, value, index, options );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ protected final void nullSafeSet(PreparedStatement st, Object value, int index, WrapperOptions options) throws SQLException {
+ sqlTypeDescriptor.getBinder( javaTypeDescriptor ).bind( st, (T) value, index, options );
+ }
+
+ public void set(PreparedStatement st, T value, int index, SessionImplementor session) throws HibernateException, SQLException {
+ nullSafeSet( st, value, index, session );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final String toLoggableString(Object value, SessionFactoryImplementor factory) {
+ return javaTypeDescriptor.extractLoggableRepresentation( (T) value );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) {
+ node.setText( toString( (T) value ) );
+ }
+
+ public final Object fromXMLNode(Node xml, Mapping factory) {
+ return fromString( xml.getText() );
+ }
+
+ public final boolean isMutable() {
+ return getMutabilityPlan().isMutable();
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory) {
+ return deepCopy( (T) value );
+ }
+
+ protected final T deepCopy(T value) {
+ return getMutabilityPlan().deepCopy( value );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final Serializable disassemble(Object value, SessionImplementor session, Object owner) throws HibernateException {
+ return getMutabilityPlan().disassemble( (T) value );
+ }
+
+ public final Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException {
+ return getMutabilityPlan().assemble( cached );
+ }
+
+ public final void beforeAssemble(Serializable cached, SessionImplementor session) {
+ }
+
+ public final Object hydrate(ResultSet rs, String[] names, SessionImplementor session, Object owner)
+ throws HibernateException, SQLException {
+ return nullSafeGet(rs, names, session, owner);
+ }
+
+ public final Object resolve(Object value, SessionImplementor session, Object owner) throws HibernateException {
+ return value;
+ }
+
+ public final Object semiResolve(Object value, SessionImplementor session, Object owner) throws HibernateException {
+ return value;
+ }
+
+ public final Type getSemiResolvedType(SessionFactoryImplementor factory) {
+ return this;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public final Object replace(Object original, Object target, SessionImplementor session, Object owner, Map copyCache) {
+ return getReplacement( (T) original, (T) target );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public Object replace(
+ Object original,
+ Object target,
+ SessionImplementor session,
+ Object owner,
+ Map copyCache,
+ ForeignKeyDirection foreignKeyDirection) {
+ return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT == foreignKeyDirection
+ ? getReplacement( (T) original, (T) target )
+ : target;
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/AbstractType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AbstractType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AbstractType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/AdaptedImmutableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AdaptedImmutableType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AdaptedImmutableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,69 +20,34 @@
* 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 org.hibernate.type.descriptor.java.ImmutableMutabilityPlan;
+import org.hibernate.type.descriptor.java.MutabilityPlan;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-
/**
* Optimize a mutable type, if the user promises not to mutable the
* instances.
*
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class AdaptedImmutableType extends ImmutableType {
-
- private final NullableType mutableType;
+public class AdaptedImmutableType<T> extends AbstractSingleColumnStandardBasicType<T> {
+ private final AbstractStandardBasicType<T> baseMutableType;
- public AdaptedImmutableType(NullableType mutableType) {
- this.mutableType = mutableType;
+ public AdaptedImmutableType(AbstractStandardBasicType<T> baseMutableType) {
+ super( baseMutableType.getSqlTypeDescriptor(), baseMutableType.getJavaTypeDescriptor() );
+ this.baseMutableType = baseMutableType;
}
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
- return mutableType.get(rs, name);
+ @Override
+ @SuppressWarnings({ "unchecked" })
+ protected MutabilityPlan<T> getMutabilityPlan() {
+ return ImmutableMutabilityPlan.INSTANCE;
}
- public void set(PreparedStatement st, Object value, int index) throws HibernateException,
- SQLException {
- mutableType.set(st, value, index);
- }
-
- public int sqlType() {
- return mutableType.sqlType();
- }
-
- public String toString(Object value) throws HibernateException {
- return mutableType.toString(value);
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- return mutableType.fromStringValue(xml);
- }
-
- public Class getReturnedClass() {
- return mutableType.getReturnedClass();
- }
-
public String getName() {
- return "imm_" + mutableType.getName();
+ return "imm_" + baseMutableType.getName();
}
-
- public boolean isEqual(Object x, Object y) {
- return mutableType.isEqual(x, y);
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- return mutableType.getHashCode(x, entityMode);
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return mutableType.compare(x, y, entityMode);
- }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/AnyType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AnyType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AnyType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -49,11 +48,11 @@
import org.hibernate.util.ArrayHelper;
/**
- * Handles "any" mappings and the old deprecated "object" type
+ * Handles "any" mappings
+ *
* @author Gavin King
*/
public class AnyType extends AbstractType implements AbstractComponentType, AssociationType {
-
private final Type identifierType;
private final Type metaType;
@@ -62,10 +61,6 @@
this.metaType = metaType;
}
- public AnyType() {
- this(Hibernate.STRING, Hibernate.SERIALIZABLE);
- }
-
public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory)
throws HibernateException {
return value;
Modified: core/trunk/core/src/main/java/org/hibernate/type/ArrayType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ArrayType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ArrayType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/AssociationType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/AssociationType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/AssociationType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/BagType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BagType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BagType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Added: core/trunk/core/src/main/java/org/hibernate/type/BasicType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+/**
+ * Marker interface for basic types.
+ *
+ * @author Steve Ebersole
+ */
+public interface BasicType extends Type {
+ /**
+ * Get the names under which this type should be registered in the type registry.
+ *
+ * @return The keys under which to register this type.
+ */
+ public String[] getRegistrationKeys();
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/BasicTypeRegistry.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,153 @@
+/*
+ * 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.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+
+/**
+ * A registry of {@link BasicType} instances
+ *
+ * @author Steve Ebersole
+ */
+public class BasicTypeRegistry implements Serializable {
+ private static final Logger log = LoggerFactory.getLogger( BasicTypeRegistry.class );
+
+ // TODO : analyze these sizing params; unfortunately this seems to be the only way to give a "concurrencyLevel"
+ private Map<String,BasicType> registry = new ConcurrentHashMap<String, BasicType>( 100, .75f, 1 );
+ private boolean locked = false;
+
+ public BasicTypeRegistry() {
+ register( BooleanType.INSTANCE );
+ register( NumericBooleanType.INSTANCE );
+ register( TrueFalseType.INSTANCE );
+ register( YesNoType.INSTANCE );
+
+ register( ByteType.INSTANCE );
+ register( CharacterType.INSTANCE );
+ register( ShortType.INSTANCE );
+ register( IntegerType.INSTANCE );
+ register( LongType.INSTANCE );
+ register( FloatType.INSTANCE );
+ register( DoubleType.INSTANCE );
+ register( BigDecimalType.INSTANCE );
+ register( BigIntegerType.INSTANCE );
+
+ register( StringType.INSTANCE );
+
+ register( DateType.INSTANCE );
+ register( TimeType.INSTANCE );
+ register( TimestampType.INSTANCE );
+ register( DbTimestampType.INSTANCE );
+ register( CalendarType.INSTANCE );
+ register( CalendarDateType.INSTANCE );
+
+ register( LocaleType.INSTANCE );
+ register( CurrencyType.INSTANCE );
+ register( TimeZoneType.INSTANCE );
+ register( ClassType.INSTANCE );
+
+ register( BinaryType.INSTANCE );
+ register( WrapperBinaryType.INSTANCE );
+ register( ImageType.INSTANCE );
+ register( CharArrayType.INSTANCE );
+ register( CharacterArrayType.INSTANCE );
+ register( TextType.INSTANCE );
+ register( BlobType.INSTANCE );
+ register( MaterializedBlobType.INSTANCE );
+ register( ClobType.INSTANCE );
+ register( MaterializedClobType.INSTANCE );
+ register( SerializableType.INSTANCE );
+
+ register( ObjectType.INSTANCE );
+
+ //noinspection unchecked
+ register( new AdaptedImmutableType( DateType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( TimeType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( TimestampType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( DbTimestampType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( CalendarType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( CalendarDateType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( BinaryType.INSTANCE ) );
+ //noinspection unchecked
+ register( new AdaptedImmutableType( SerializableType.INSTANCE ) );
+ }
+
+ /**
+ * Constructor version used during shallow copy
+ *
+ * @param registeredTypes The type map to copy over
+ */
+ @SuppressWarnings({ "UnusedDeclaration" })
+ private BasicTypeRegistry(Map<String, BasicType> registeredTypes) {
+ registry.putAll( registeredTypes );
+ locked = true;
+ }
+
+ public void register(BasicType type) {
+ if ( locked ) {
+ throw new HibernateException( "Can not alter TypeRegistry at this time" );
+ }
+
+ if ( type == null ) {
+ throw new HibernateException( "Type to register cannot be null" );
+ }
+
+ if ( type.getRegistrationKeys() == null || type.getRegistrationKeys().length == 0 ) {
+ log.warn( "Type [{}] defined no registration keys; ignoring", type );
+ }
+
+ for ( String key : type.getRegistrationKeys() ) {
+ // be safe...
+ if ( key == null ) {
+ continue;
+ }
+ log.debug( "Adding type registration {} -> {}", key, type );
+ final Type old = registry.put( key, type );
+ if ( old != null && old != type ) {
+ log.debug( " Overrides previous {}", old );
+ }
+ }
+ }
+
+ public BasicType getRegisteredType(String key) {
+ return registry.get( key );
+ }
+
+ public BasicTypeRegistry shallowCopy() {
+ return new BasicTypeRegistry( this.registry );
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/BigDecimalType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BigDecimalType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BigDecimalType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,70 +20,37 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.math.BigDecimal;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Types;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
+import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;
+import org.hibernate.type.descriptor.sql.NumericTypeDescriptor;
/**
- * <tt>big_decimal</tt>: A type that maps an SQL NUMERIC to a
- * <tt>java.math.BigDecimal</tt>
- * @see java.math.BigDecimal
+ * A type that maps between a {@link Types#NUMERIC NUMERIC} and {@link BigDecimal}.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class BigDecimalType extends ImmutableType {
+public class BigDecimalType extends AbstractSingleColumnStandardBasicType<BigDecimal> {
+ public static final BigDecimalType INSTANCE = new BigDecimalType();
- public Object get(ResultSet rs, String name)
- throws HibernateException, SQLException {
- return rs.getBigDecimal(name);
+ public BigDecimalType() {
+ super( NumericTypeDescriptor.INSTANCE, BigDecimalTypeDescriptor.INSTANCE );
}
- public void set(PreparedStatement st, Object value, int index)
- throws HibernateException, SQLException {
- st.setBigDecimal(index, (BigDecimal) value);
- }
-
- public int sqlType() {
- return Types.NUMERIC;
- }
-
- public String toString(Object value) throws HibernateException {
- return value.toString();
- }
-
- public Class getReturnedClass() {
- return BigDecimal.class;
- }
-
- public boolean isEqual(Object x, Object y) {
- return x==y || ( x!=null && y!=null && ( (BigDecimal) x ).compareTo( (BigDecimal) y )==0 );
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- return ( (BigDecimal) x ).intValue();
- }
-
+ /**
+ * {@inheritDoc}
+ */
public String getName() {
return "big_decimal";
}
- public Object fromStringValue(String xml) {
- return new BigDecimal(xml);
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
-
-
-}
-
-
-
-
-
-
+}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/type/BigIntegerType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BigIntegerType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BigIntegerType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,83 +20,55 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.math.BigDecimal;
import java.math.BigInteger;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Types;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;
+import org.hibernate.type.descriptor.sql.NumericTypeDescriptor;
/**
- * <tt>big_integer</tt>: A type that maps an SQL NUMERIC to a
- * <tt>java.math.BigInteger</tt>
- * @see java.math.BigInteger
+ * A type that maps between a {@link Types#NUMERIC NUMERIC} and {@link BigInteger}.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class BigIntegerType extends ImmutableType implements DiscriminatorType {
+public class BigIntegerType
+ extends AbstractSingleColumnStandardBasicType<BigInteger>
+ implements DiscriminatorType<BigInteger> {
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return value.toString();
- }
+ public static final BigIntegerType INSTANCE = new BigIntegerType();
- public Object stringToObject(String xml) throws Exception {
- return new BigInteger(xml);
+ public BigIntegerType() {
+ super( NumericTypeDescriptor.INSTANCE, BigIntegerTypeDescriptor.INSTANCE );
}
- public Object get(ResultSet rs, String name)
- throws HibernateException, SQLException {
- //return rs.getBigDecimal(name).toBigIntegerExact(); this 1.5 only.
- BigDecimal bigDecimal = rs.getBigDecimal(name);
- return bigDecimal==null ? null :
- bigDecimal.setScale(0, BigDecimal.ROUND_UNNECESSARY).unscaledValue();
- }
-
- public void set(PreparedStatement st, Object value, int index)
- throws HibernateException, SQLException {
- st.setBigDecimal( index, new BigDecimal( (BigInteger) value ) );
- }
-
- public int sqlType() {
- return Types.NUMERIC;
- }
-
- public String toString(Object value) throws HibernateException {
- return value.toString();
- }
-
- public Class getReturnedClass() {
- return BigInteger.class;
- }
-
- public boolean isEqual(Object x, Object y) {
- return x==y || ( x!=null && y!=null && ( (BigInteger) x ).compareTo( (BigInteger) y )==0 );
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- return ( (BigInteger) x ).intValue();
- }
-
+ /**
+ * {@inheritDoc}
+ */
public String getName() {
return "big_integer";
}
- public Object fromStringValue(String xml) {
- return new BigInteger(xml);
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ public String objectToSQLString(BigInteger value, Dialect dialect) {
+ return BigIntegerTypeDescriptor.INSTANCE.toString( value );
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public BigInteger stringToObject(String string) {
+ return BigIntegerTypeDescriptor.INSTANCE.fromString( string );
+ }
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/BinaryType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BinaryType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BinaryType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,28 +20,62 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
+import java.util.Comparator;
+
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor;
+
/**
- * <tt>binary</tt>: A type that maps an SQL VARBINARY to a Java byte[].
+ * A type that maps between a {@link java.sql.Types#NUMERIC NUMERIC} and {@code byte[]}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class BinaryType extends AbstractBynaryType {
+public class BinaryType
+ extends AbstractSingleColumnStandardBasicType<byte[]>
+ implements VersionType<byte[]> {
- protected Object toExternalFormat(byte[] bytes) {
- return bytes;
+ public static final BinaryType INSTANCE = new BinaryType();
+
+ public String getName() {
+ return "binary";
}
- protected byte[] toInternalFormat(Object bytes) {
- return (byte[]) bytes;
+ public BinaryType() {
+ super( VarbinaryTypeDescriptor.INSTANCE, PrimitiveByteArrayTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return byte[].class;
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), "byte[]", byte[].class.getName() };
}
- public String getName() { return "binary"; }
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] seed(SessionImplementor session) {
+ // Note : simply returns null for seed() and next() as the only known
+ // application of binary types for versioning is for use with the
+ // TIMESTAMP datatype supported by Sybase and SQL Server, which
+ // are completely db-generated values...
+ return null;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] next(byte[] current, SessionImplementor session) {
+ return current;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Comparator<byte[]> getComparator() {
+ return PrimitiveByteArrayTypeDescriptor.INSTANCE.getComparator();
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/BlobType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BlobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BlobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,254 +20,42 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.io.Serializable;
import java.sql.Blob;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Map;
-import org.dom4j.Node;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.Hibernate;
-import org.hibernate.engine.Mapping;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.jdbc.BlobImplementer;
-import org.hibernate.engine.jdbc.WrappedBlob;
-import org.hibernate.engine.jdbc.LobCreator;
-import org.hibernate.engine.jdbc.NonContextualLobCreator;
-import org.hibernate.util.ArrayHelper;
+import org.hibernate.type.descriptor.java.BlobTypeDescriptor;
/**
- * <tt>blob</tt>: A type that maps an SQL BLOB to a java.sql.Blob.
+ * A type that maps between {@link java.sql.Types#BLOB BLOB} and {@link Blob}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class BlobType extends AbstractType {
- /**
- * {@inheritDoc}
- */
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- boolean[] settable,
- SessionImplementor session) throws HibernateException, SQLException {
- if ( settable[0] ) {
- set( st, value, index, session );
- }
- }
+public class BlobType extends AbstractSingleColumnStandardBasicType<Blob> {
+ public static final BlobType INSTANCE = new BlobType();
- /**
- * {@inheritDoc}
- */
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- SessionImplementor session) throws HibernateException, SQLException {
- set( st, value, index, session );
+ public BlobType() {
+ super( org.hibernate.type.descriptor.sql.BlobTypeDescriptor.INSTANCE, BlobTypeDescriptor.INSTANCE );
}
- public void set(
- PreparedStatement st,
- Object value,
- int index,
- SessionImplementor session) throws HibernateException, SQLException {
- if ( value == null ) {
- st.setNull( index, Types.BLOB );
- return;
- }
-
- Blob blob = ( Blob ) value;
-
- if ( WrappedBlob.class.isInstance( blob ) ) {
- blob = ( (WrappedBlob) value ).getWrappedBlob();
- }
-
- final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob()
- && BlobImplementer.class.isInstance( blob );
-
- if ( useInputStream ) {
- st.setBinaryStream( index, blob.getBinaryStream(), (int) blob.length() );
- }
- else {
- st.setBlob( index, blob );
- }
- }
-
/**
* {@inheritDoc}
*/
- public Object nullSafeGet(
- ResultSet rs,
- String name,
- SessionImplementor session,
- Object owner) throws HibernateException, SQLException {
- return get( rs, name, Hibernate.getLobCreator( session ) );
- }
-
- /**
- * {@inheritDoc}
- */
- public Object nullSafeGet(
- ResultSet rs,
- String[] names,
- SessionImplementor session,
- Object owner) throws HibernateException, SQLException {
- return get( rs, names[0], Hibernate.getLobCreator( session ) );
- }
-
- /**
- * A method to extract the BLOB value from a result set.
- *
- * @param rs The result set
- * @param name The name of the column containing the BLOB
- *
- * @return The BLOB
- *
- * @throws SQLException Indicates a problem accessing the result set
- *
- * @deprecated Use {@link #get(ResultSet,String,LobCreator)} instead
- */
- public Object get(ResultSet rs, String name) throws SQLException {
- return get( rs, name, NonContextualLobCreator.INSTANCE );
- }
-
- public Object get(ResultSet rs, String name, LobCreator lobCreator) throws SQLException {
- Blob value = rs.getBlob( name );
- return rs.wasNull() ? null : lobCreator.wrap( value );
- }
-
- /**
- * {@inheritDoc}
- */
- public Class getReturnedClass() {
- return Blob.class;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isEqual(Object x, Object y, EntityMode entityMode) {
- return x == y;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getHashCode(Object x, EntityMode entityMode) {
- return System.identityHashCode(x);
- }
-
- /**
- * {@inheritDoc}
- */
- public int compare(Object x, Object y, EntityMode entityMode) {
- return 0; //lobs cannot be compared
- }
-
- /**
- * {@inheritDoc}
- */
public String getName() {
return "blob";
}
- /**
- * {@inheritDoc}
- */
- public Serializable disassemble(Object value, SessionImplementor session, Object owner)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Blobs are not cacheable");
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
- /**
- * {@inheritDoc}
- */
- public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory) {
- return value;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object fromXMLNode(Node xml, Mapping factory) {
- throw new UnsupportedOperationException("todo");
- }
-
- /**
- * {@inheritDoc}
- */
- public int getColumnSpan(Mapping mapping) {
- return 1;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isMutable() {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object replace(
- Object original,
- Object target,
- SessionImplementor session,
- Object owner,
- Map copyCache) throws HibernateException {
- //Blobs are ignored by merge()
+ @Override
+ protected Blob getReplacement(Blob original, Blob target) {
return target;
}
- /**
- * {@inheritDoc}
- */
- public int[] sqlTypes(Mapping mapping) throws MappingException {
- return new int[] { Types.BLOB };
- }
-
- /**
- * {@inheritDoc}
- */
- public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) {
- throw new UnsupportedOperationException("todo");
- }
-
- /**
- * {@inheritDoc}
- */
- public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
- return value==null ? "null" : value.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean[] toColumnNullness(Object value, Mapping mapping) {
- return value==null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
- }
-
- /**
- * {@inheritDoc}
- */
- 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/BooleanType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/BooleanType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/BooleanType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,63 +20,60 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BitTypeDescriptor;
+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
- * <tt>boolean</tt>: A type that maps an SQL BIT to a Java Boolean.
+ * A type that maps between {@link java.sql.Types#BIT BIT} and {@link Boolean}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class BooleanType extends PrimitiveType implements DiscriminatorType {
+public class BooleanType
+ extends AbstractSingleColumnStandardBasicType<Boolean>
+ implements PrimitiveType<Boolean>, DiscriminatorType<Boolean> {
+ public static final BooleanType INSTANCE = new BooleanType();
- public Serializable getDefaultValue() {
- return Boolean.FALSE;
+ public BooleanType() {
+ this( BitTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE );
}
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return rs.getBoolean(name) ? Boolean.TRUE : Boolean.FALSE;
- }
- public Class getPrimitiveClass() {
- return boolean.class;
+ protected BooleanType(SqlTypeDescriptor sqlTypeDescriptor, BooleanTypeDescriptor javaTypeDescriptor) {
+ super( sqlTypeDescriptor, javaTypeDescriptor );
}
- public Class getReturnedClass() {
- return Boolean.class;
+ public String getName() {
+ return "boolean";
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
- st.setBoolean( index, ( (Boolean) value ).booleanValue() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), boolean.class.getName(), Boolean.class.getName() };
}
- public int sqlType() {
- return Types.BIT;
+ public Class getPrimitiveClass() {
+ return boolean.class;
}
- public String getName() { return "boolean"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return dialect.toBooleanValueString( ( (Boolean) value ).booleanValue() );
+ public Serializable getDefaultValue() {
+ return Boolean.FALSE;
}
- public Object stringToObject(String xml) throws Exception {
- return fromStringValue(xml);
+ public Boolean stringToObject(String string) {
+ return fromString( string );
}
- public Object fromStringValue(String xml) {
- return Boolean.valueOf(xml);
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String objectToSQLString(Boolean value, Dialect dialect) {
+ return dialect.toBooleanValueString( value.booleanValue() );
}
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/ByteType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ByteType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ByteType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,77 +20,76 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import java.util.Comparator;
-import org.hibernate.util.ComparableComparator;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.descriptor.java.ByteTypeDescriptor;
+import org.hibernate.type.descriptor.sql.TinyIntTypeDescriptor;
/**
- * <tt>byte</tt>: A type that maps an SQL TINYINT to a Java Byte.
+ * A type that maps between {@link java.sql.Types#TINYINT TINYINT} and {@link Byte}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class ByteType extends PrimitiveType implements DiscriminatorType, VersionType {
+@SuppressWarnings({ "UnnecessaryBoxing" })
+public class ByteType
+ extends AbstractSingleColumnStandardBasicType<Byte>
+ implements PrimitiveType<Byte>, DiscriminatorType<Byte>, VersionType<Byte> {
+ public static final ByteType INSTANCE = new ByteType();
+
private static final Byte ZERO = new Byte( (byte) 0 );
- public Serializable getDefaultValue() {
- return ZERO;
+ public ByteType() {
+ super( TinyIntTypeDescriptor.INSTANCE, ByteTypeDescriptor.INSTANCE );
}
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Byte( rs.getByte(name) );
- }
- public Class getPrimitiveClass() {
- return byte.class;
+ public String getName() {
+ return "byte";
}
- public Class getReturnedClass() {
- return Byte.class;
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), byte.class.getName(), Byte.class.getName() };
}
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- st.setByte( index, ( (Byte) value ).byteValue() );
+ public Serializable getDefaultValue() {
+ return ZERO;
}
- public int sqlType() {
- return Types.TINYINT;
+ public Class getPrimitiveClass() {
+ return byte.class;
}
- public String getName() { return "byte"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return value.toString();
+ public String objectToSQLString(Byte value, Dialect dialect) {
+ return toString( value );
}
- public Object stringToObject(String xml) throws Exception {
- return new Byte(xml);
+ public Byte stringToObject(String xml) {
+ return fromString( xml );
}
- public Object fromStringValue(String xml) {
- return new Byte(xml);
+ public Byte fromStringValue(String xml) {
+ return fromString( xml );
}
- public Object next(Object current, SessionImplementor session) {
- return new Byte( (byte) ( ( (Byte) current ).byteValue() + 1 ) );
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public Byte next(Byte current, SessionImplementor session) {
+ return Byte.valueOf( (byte) ( current.byteValue() + 1 ) );
}
- public Object seed(SessionImplementor session) {
+ public Byte seed(SessionImplementor session) {
return ZERO;
}
- public Comparator getComparator() {
- return ComparableComparator.INSTANCE;
+ public Comparator<Byte> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
}
-
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CalendarDateType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CalendarDateType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CalendarDateType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,97 +20,27 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Date;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import java.util.Calendar;
-import java.util.GregorianCalendar;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.util.CalendarComparator;
+import org.hibernate.type.descriptor.java.CalendarTypeDescriptor;
+import org.hibernate.type.descriptor.sql.DateTypeDescriptor;
/**
- * <tt>calendar_date</tt>: A type mapping for a <tt>Calendar</tt>
- * object that represents a date.
+ * A type mapping {@link java.sql.Types#DATE DATE} and {@link Calendar}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CalendarDateType extends MutableType {
+public class CalendarDateType extends AbstractSingleColumnStandardBasicType<Calendar> {
+ public static final CalendarDateType INSTANCE = new CalendarDateType();
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
-
- Date date = rs.getDate(name);
- if (date!=null) {
- Calendar cal = new GregorianCalendar();
- cal.setTime(date);
- return cal;
- }
- else {
- return null;
- }
-
+ public CalendarDateType() {
+ super( DateTypeDescriptor.INSTANCE, CalendarTypeDescriptor.INSTANCE );
}
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- final Calendar cal = (Calendar) value;
- //st.setDate( index, new Date( cal.getTimeInMillis() ), cal ); //JDK 1.5 only
- st.setDate( index, new Date( cal.getTime().getTime() ), cal );
- }
-
- public int sqlType() {
- return Types.DATE;
- }
-
- public String toString(Object value) throws HibernateException {
- return Hibernate.DATE.toString( ( (Calendar) value ).getTime() );
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- Calendar result = new GregorianCalendar();
- result.setTime( ( (java.util.Date) Hibernate.DATE.fromStringValue(xml) ) );
- return result;
- }
-
- public Object deepCopyNotNull(Object value) {
- return ( (Calendar) value ).clone();
- }
-
- public Class getReturnedClass() {
- return Calendar.class;
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return CalendarComparator.INSTANCE.compare(x, y);
- }
-
- public boolean isEqual(Object x, Object y) {
- if (x==y) return true;
- if (x==null || y==null) return false;
-
- Calendar calendar1 = (Calendar) x;
- Calendar calendar2 = (Calendar) y;
-
- return calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH)
- && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)
- && calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR);
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- Calendar calendar = (Calendar) x;
- int hashCode = 1;
- hashCode = 31 * hashCode + calendar.get(Calendar.DAY_OF_MONTH);
- hashCode = 31 * hashCode + calendar.get(Calendar.MONTH);
- hashCode = 31 * hashCode + calendar.get(Calendar.YEAR);
- return hashCode;
- }
-
public String getName() {
return "calendar_date";
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CalendarType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CalendarType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CalendarType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,128 +20,52 @@
* 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.Timestamp;
-import java.sql.Types;
import java.util.Calendar;
import java.util.Comparator;
-import java.util.Date;
import java.util.GregorianCalendar;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.cfg.Environment;
-import org.hibernate.util.CalendarComparator;
+import org.hibernate.type.descriptor.java.CalendarTypeDescriptor;
+import org.hibernate.type.descriptor.sql.TimestampTypeDescriptor;
/**
- * <tt>calendar</tt>: A type mapping for a <tt>Calendar</tt> object that
- * represents a datetime.
+ * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link Calendar}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CalendarType extends MutableType implements VersionType {
+public class CalendarType
+ extends AbstractSingleColumnStandardBasicType<Calendar>
+ implements VersionType<Calendar> {
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
+ public static final CalendarType INSTANCE = new CalendarType();
- Timestamp ts = rs.getTimestamp(name);
- if (ts!=null) {
- Calendar cal = new GregorianCalendar();
- if ( Environment.jvmHasTimestampBug() ) {
- cal.setTime( new Date( ts.getTime() + ts.getNanos() / 1000000 ) );
- }
- else {
- cal.setTime(ts);
- }
- return cal;
- }
- else {
- return null;
- }
-
+ public CalendarType() {
+ super( TimestampTypeDescriptor.INSTANCE, CalendarTypeDescriptor.INSTANCE );
}
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- final Calendar cal = (Calendar) value;
- //st.setTimestamp( index, new Timestamp( cal.getTimeInMillis() ), cal ); //JDK 1.5 only
- st.setTimestamp( index, new Timestamp( cal.getTime().getTime() ), cal );
- }
-
- public int sqlType() {
- return Types.TIMESTAMP;
- }
-
- public String toString(Object value) throws HibernateException {
- return Hibernate.TIMESTAMP.toString( ( (Calendar) value ).getTime() );
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- Calendar result = new GregorianCalendar();
- result.setTime( ( (Date) Hibernate.TIMESTAMP.fromStringValue(xml) ) );
- return result;
- }
-
- public Object deepCopyNotNull(Object value) throws HibernateException {
- return ( (Calendar) value ).clone();
- }
-
- public Class getReturnedClass() {
- return Calendar.class;
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return CalendarComparator.INSTANCE.compare(x, y);
- }
-
- public boolean isEqual(Object x, Object y) {
- if (x==y) return true;
- if (x==null || y==null) return false;
-
- Calendar calendar1 = (Calendar) x;
- Calendar calendar2 = (Calendar) y;
-
- return calendar1.get(Calendar.MILLISECOND) == calendar2.get(Calendar.MILLISECOND)
- && calendar1.get(Calendar.SECOND) == calendar2.get(Calendar.SECOND)
- && calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE)
- && calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY)
- && calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH)
- && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)
- && calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR);
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- Calendar calendar = (Calendar) x;
- int hashCode = 1;
- hashCode = 31 * hashCode + calendar.get(Calendar.MILLISECOND);
- hashCode = 31 * hashCode + calendar.get(Calendar.SECOND);
- hashCode = 31 * hashCode + calendar.get(Calendar.MINUTE);
- hashCode = 31 * hashCode + calendar.get(Calendar.HOUR_OF_DAY);
- hashCode = 31 * hashCode + calendar.get(Calendar.DAY_OF_MONTH);
- hashCode = 31 * hashCode + calendar.get(Calendar.MONTH);
- hashCode = 31 * hashCode + calendar.get(Calendar.YEAR);
- return hashCode;
- }
-
public String getName() {
return "calendar";
}
- public Object next(Object current, SessionImplementor session) {
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), Calendar.class.getName(), GregorianCalendar.class.getName() };
+ }
+
+ public Calendar next(Calendar current, SessionImplementor session) {
return seed( session );
}
- public Object seed(SessionImplementor session) {
+ public Calendar seed(SessionImplementor session) {
return Calendar.getInstance();
}
- public Comparator getComparator() {
- return CalendarComparator.INSTANCE;
+ public Comparator<Calendar> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CharArrayType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CharArrayType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CharArrayType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,27 +20,31 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
+import org.hibernate.type.descriptor.java.PrimitiveCharacterArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
+
/**
- * put char[] into VARCHAR
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@code char[]}
+ *
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
-public class CharArrayType extends AbstractCharArrayType {
+public class CharArrayType extends AbstractSingleColumnStandardBasicType<char[]> {
+ public static final CharArrayType INSTANCE = new CharArrayType();
- protected Object toExternalFormat(char[] chars) {
- return chars;
+ public CharArrayType() {
+ super( VarcharTypeDescriptor.INSTANCE, PrimitiveCharacterArrayTypeDescriptor.INSTANCE );
}
- protected char[] toInternalFormat(Object chars) {
- return (char[]) chars;
+ public String getName() {
+ return "characters";
}
- public Class getReturnedClass() {
- return char[].class;
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), "char[]", char[].class.getName() };
}
-
- public String getName() { return "characters"; }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CharBooleanType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CharBooleanType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CharBooleanType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,74 +20,42 @@
* 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 org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
+import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
-import org.hibernate.HibernateException;
-import org.hibernate.dialect.Dialect;
-
-
/**
* Superclass for types that map Java boolean to SQL CHAR(1).
+ *
* @author Gavin King
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class CharBooleanType extends BooleanType {
+ private final String stringValueTrue;
+ private final String stringValueFalse;
- protected abstract String getTrueString();
- protected abstract String getFalseString();
+ protected CharBooleanType(char characterValueTrue, char characterValueFalse) {
+ super( CharTypeDescriptor.INSTANCE, new BooleanTypeDescriptor( characterValueTrue, characterValueFalse ) );
- public Object get(ResultSet rs, String name) throws SQLException {
- String code = rs.getString(name);
- if ( code==null || code.length()==0 ) {
- return null;
- }
- else {
- return getTrueString().equalsIgnoreCase( code.trim() ) ?
- Boolean.TRUE : Boolean.FALSE;
- }
+ stringValueTrue = String.valueOf( characterValueTrue );
+ stringValueFalse = String.valueOf( characterValueFalse );
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
- st.setString( index, toCharacter(value) );
-
+ /**
+ * @deprecated Pass the true/false values into constructor instead.
+ */
+ protected final String getTrueString() {
+ return stringValueTrue;
}
- public int sqlType() {
- return Types.CHAR;
+ /**
+ * @deprecated Pass the true/false values into constructor instead.
+ */
+ protected final String getFalseString() {
+ return stringValueFalse;
}
- private String toCharacter(Object value) {
- return ( (Boolean) value ).booleanValue() ? getTrueString() : getFalseString();
- }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return "'" + toCharacter(value) + "'";
- }
-
- public Object stringToObject(String xml) throws Exception {
- if ( getTrueString().equalsIgnoreCase(xml) ) {
- return Boolean.TRUE;
- }
- else if ( getFalseString().equalsIgnoreCase(xml) ) {
- return Boolean.FALSE;
- }
- else {
- throw new HibernateException("Could not interpret: " + xml);
- }
- }
-
}
-
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/CharacterArrayType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CharacterArrayType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CharacterArrayType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,41 +20,31 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import org.hibernate.HibernateException;
+import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
- * Bridge Character[] and VARCHAR
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@link Character Character[]}
+ *
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
-public class CharacterArrayType extends AbstractCharArrayType {
- protected Object toExternalFormat(char[] chars) {
- if (chars == null) return null;
- Character[] characters = new Character[chars.length];
- for (int i = 0 ; i < chars.length ; i++) {
- characters[i] = new Character( chars[i] );
- }
- return characters;
- }
+public class CharacterArrayType extends AbstractSingleColumnStandardBasicType<Character[]> {
+ public static final CharacterArrayType INSTANCE = new CharacterArrayType();
- protected char[] toInternalFormat(Object value) {
- if (value == null) return null;
- Character[] characters = (Character[]) value;
- char[] chars = new char[characters.length];
- for (int i = 0 ; i < characters.length ; i++) {
- if (characters[i] == null)
- throw new HibernateException("Unable to store an Character[] when one of its element is null");
- chars[i] = characters[i].charValue();
- }
- return chars;
+ public CharacterArrayType() {
+ super( VarcharTypeDescriptor.INSTANCE, CharacterArrayTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Character[].class;
+ public String getName() {
+ return "wrapper-characters";
}
- public String getName() { return "wrapper-characters"; }
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), Character[].class.getName(), "Character[]" };
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/CharacterType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CharacterType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CharacterType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,72 +20,54 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.CharacterTypeDescriptor;
+import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
/**
- * <tt>character</tt>: A type that maps an SQL CHAR(1) to a Java Character.
+ * A type that maps between {@link java.sql.Types#CHAR CHAR(1)} and {@link Character}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CharacterType extends PrimitiveType implements DiscriminatorType {
+public class CharacterType
+ extends AbstractSingleColumnStandardBasicType<Character>
+ implements PrimitiveType<Character>, DiscriminatorType<Character> {
- public Serializable getDefaultValue() {
- throw new UnsupportedOperationException("not a valid id type");
- }
-
- public Object get(ResultSet rs, String name) throws SQLException {
- String str = rs.getString(name);
- if (str==null) {
- return null;
- }
- else {
- return new Character( str.charAt(0) );
- }
- }
+ public static final CharacterType INSTANCE = new CharacterType();
- public Class getPrimitiveClass() {
- return char.class;
+ public CharacterType() {
+ super( CharTypeDescriptor.INSTANCE, CharacterTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Character.class;
+ public String getName() {
+ return "character";
}
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- st.setString( index, (value).toString() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), char.class.getName(), Character.class.getName() };
}
- public int sqlType() {
- return Types.CHAR;
+ public Serializable getDefaultValue() {
+ throw new UnsupportedOperationException( "not a valid id type" );
}
- public String getName() { return "character"; }
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return '\'' + value.toString() + '\'';
+ public Class getPrimitiveClass() {
+ return char.class;
}
- public Object stringToObject(String xml) throws Exception {
- if ( xml.length() != 1 ) throw new MappingException("multiple or zero characters found parsing string");
- return new Character( xml.charAt(0) );
+ public String objectToSQLString(Character value, Dialect dialect) {
+ return '\'' + toString( value ) + '\'';
}
- public Object fromStringValue(String xml) {
- return new Character( xml.charAt(0) );
+ public Character stringToObject(String xml) {
+ return fromString( xml );
}
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/ClassType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ClassType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ClassType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,73 +20,32 @@
* 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 org.hibernate.type.descriptor.java.ClassTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.util.ReflectHelper;
-
/**
- * <tt>class</tt>: A type that maps an SQL VARCHAR to a Java Class.
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@link Class}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class ClassType extends ImmutableType {
+public class ClassType extends AbstractSingleColumnStandardBasicType<Class> {
+ public static final ClassType INSTANCE = new ClassType();
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
- String str = (String) Hibernate.STRING.get(rs, name);
- if (str == null) {
- return null;
- }
- else {
- try {
- return ReflectHelper.classForName(str);
- }
- catch (ClassNotFoundException cnfe) {
- throw new HibernateException("Class not found: " + str);
- }
- }
+ public ClassType() {
+ super( VarcharTypeDescriptor.INSTANCE, ClassTypeDescriptor.INSTANCE );
}
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- //TODO: would be nice to handle proxy classes elegantly!
- Hibernate.STRING.set(st, ( (Class) value ).getName(), index);
- }
-
- public int sqlType() {
- return Hibernate.STRING.sqlType();
- }
-
- public String toString(Object value) throws HibernateException {
- return ( (Class) value ).getName();
- }
-
- public Class getReturnedClass() {
- return Class.class;
- }
-
public String getName() {
return "class";
}
- public Object fromStringValue(String xml) throws HibernateException {
- try {
- return ReflectHelper.classForName(xml);
- }
- catch (ClassNotFoundException cnfe) {
- throw new HibernateException("could not parse xml", cnfe);
- }
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/ClobType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ClobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ClobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,203 +20,38 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.io.Serializable;
import java.sql.Clob;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Map;
-import org.dom4j.Node;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.engine.Mapping;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.jdbc.LobCreator;
-import org.hibernate.engine.jdbc.NonContextualLobCreator;
-import org.hibernate.engine.jdbc.WrappedClob;
-import org.hibernate.engine.jdbc.ClobImplementer;
-import org.hibernate.util.ArrayHelper;
+import org.hibernate.type.descriptor.java.ClobTypeDescriptor;
/**
- * <tt>clob</tt>: A type that maps an SQL CLOB to a java.sql.Clob.
+ * A type that maps between {@link java.sql.Types#CLOB CLOB} and {@link Clob}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class ClobType extends AbstractType {
+public class ClobType extends AbstractSingleColumnStandardBasicType<Clob> {
+ public static final ClobType INSTANCE = new ClobType();
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- boolean[] settable,
- SessionImplementor session) throws SQLException {
- if ( settable[0] ) {
- set( st, value, index, session );
- }
+ public ClobType() {
+ super( org.hibernate.type.descriptor.sql.ClobTypeDescriptor.INSTANCE, ClobTypeDescriptor.INSTANCE );
}
- public void nullSafeSet(
- PreparedStatement st,
- Object value,
- int index,
- SessionImplementor session) throws SQLException {
- set( st, value, index, session );
- }
-
- public void set(
- PreparedStatement st,
- Object value,
- int index,
- SessionImplementor session) throws SQLException {
- if ( value == null ) {
- st.setNull( index, Types.CLOB );
- return;
- }
-
- Clob clob = ( Clob ) value;
-
- if ( WrappedClob.class.isInstance( clob ) ) {
- clob = ( (WrappedClob) value ).getWrappedClob();
- }
-
- final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob()
- && ClobImplementer.class.isInstance( clob );
-
- if ( useInputStream ) {
- st.setCharacterStream( index, clob.getCharacterStream(), (int) clob.length() );
- }
- else {
- st.setClob( index, clob );
- }
- }
-
- public Object nullSafeGet(
- ResultSet rs,
- String name,
- SessionImplementor session,
- Object owner) throws SQLException {
- return get( rs, name, Hibernate.getLobCreator( session ) );
- }
-
- public Object nullSafeGet(
- ResultSet rs,
- String[] names,
- SessionImplementor session,
- Object owner) throws SQLException {
- return get( rs, names[0], Hibernate.getLobCreator( session ) );
- }
-
- /**
- * A method to extract the CLOB value from a result set.
- *
- * @param rs The result set
- * @param name The name of the column containing the CLOB
- *
- * @return The CLOB
- *
- * @throws SQLException Indicates a problem accessing the result set
- *
- * @deprecated Use {@link #get(ResultSet,String,LobCreator)} instead
- */
- public Object get(ResultSet rs, String name) throws SQLException {
- return get( rs, name, NonContextualLobCreator.INSTANCE );
- }
-
- public Clob get(ResultSet rs, String name, LobCreator lobCreator) throws SQLException {
- Clob value = rs.getClob( name );
- return rs.wasNull() ? null : lobCreator.wrap( value );
- }
-
- public Class getReturnedClass() {
- return Clob.class;
- }
-
- public boolean isEqual(Object x, Object y, EntityMode entityMode) {
- return x == y;
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- return System.identityHashCode(x);
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return 0; //lobs cannot be compared
- }
-
public String getName() {
return "clob";
}
-
- public Serializable disassemble(Object value, SessionImplementor session, Object owner)
- throws HibernateException {
- throw new UnsupportedOperationException("Clobs are not cacheable");
- }
- public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory) {
- return value;
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
-
- public Object fromXMLNode(Node xml, Mapping factory) {
- return Hibernate.createClob( xml.getText() );
- }
-
- public int getColumnSpan(Mapping mapping) {
- return 1;
- }
-
- public boolean isMutable() {
- return false;
- }
-
- public Object replace(Object original, Object target,
- SessionImplementor session, Object owner, Map copyCache)
- throws HibernateException {
- //Clobs are ignored by merge() operation
+
+ @Override
+ protected Clob getReplacement(Clob original, Clob target) {
return target;
}
-
- public int[] sqlTypes(Mapping mapping) throws MappingException {
- return new int[] { Types.CLOB };
- }
-
- public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory) {
- if (value!=null) {
- Clob clob = (Clob) value;
- try {
- int len = (int) clob.length();
- node.setText( clob.getSubString(0, len) );
- }
- catch (SQLException sqle) {
- throw new HibernateException("could not read XML from Clob", sqle);
- }
- }
- }
-
- public String toLoggableString(Object value, SessionFactoryImplementor factory)
- throws HibernateException {
- return value==null ? "null" : value.toString();
- }
- public boolean[] toColumnNullness(Object value, Mapping mapping) {
- return value==null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
- }
-
- 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/CollectionType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CollectionType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -76,7 +75,7 @@
this.foreignKeyPropertyName = foreignKeyPropertyName;
this.isEmbeddedInXML = isEmbeddedInXML;
}
-
+
public boolean isEmbeddedInXML() {
return isEmbeddedInXML;
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ComponentType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CompositeCustomType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -48,39 +47,13 @@
* Adapts <tt>CompositeUserType</tt> to <tt>Type</tt> interface
* @author Gavin King
*/
-public class CompositeCustomType extends AbstractType
- implements AbstractComponentType {
-
+public class CompositeCustomType extends AbstractType implements AbstractComponentType {
private final CompositeUserType userType;
private final String name;
- public CompositeCustomType(Class userTypeClass, Properties parameters)
- throws MappingException {
- name = userTypeClass.getName();
-
- if ( !CompositeUserType.class.isAssignableFrom(userTypeClass) ) {
- throw new MappingException(
- "Custom type does not implement CompositeUserType: " +
- userTypeClass.getName()
- );
- }
-
- try {
- userType = (CompositeUserType) userTypeClass.newInstance();
- }
- catch (InstantiationException ie) {
- throw new MappingException(
- "Cannot instantiate custom type: " +
- userTypeClass.getName()
- );
- }
- catch (IllegalAccessException iae) {
- throw new MappingException(
- "IllegalAccessException trying to instantiate custom type: " +
- userTypeClass.getName()
- );
- }
- TypeFactory.injectParameters(userType, parameters);
+ public CompositeCustomType(CompositeUserType userType) {
+ this.userType = userType;
+ this.name = userType.getClass().getName();
}
public boolean isMethodOf(Method method) {
Modified: core/trunk/core/src/main/java/org/hibernate/type/CurrencyType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CurrencyType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CurrencyType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,146 +20,41 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.lang.reflect.Method;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.util.Currency;
-import org.hibernate.AssertionFailure;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.CurrencyTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
- * <tt>currency</tt>: A type that maps an SQL VARCHAR to a
- * <tt>java.util.Currency</tt>
- * @see java.util.Currency
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@link Currency}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class CurrencyType extends ImmutableType implements LiteralType {
+public class CurrencyType
+ extends AbstractSingleColumnStandardBasicType<Currency>
+ implements LiteralType<Currency> {
- public static final Class CURRENCY_CLASS;
- private static final Method CURRENCY_GET_INSTANCE;
- private static final Method CURRENCY_GET_CODE;
+ public static final CurrencyType INSTANCE = new CurrencyType();
- static {
- Class clazz;
- try {
- clazz = Class.forName("java.util.Currency");
- }
- catch (ClassNotFoundException cnfe) {
- clazz = null;
- }
- if (clazz==null) {
- CURRENCY_CLASS = null;
- CURRENCY_GET_INSTANCE = null;
- CURRENCY_GET_CODE = null;
- }
- else {
- CURRENCY_CLASS = clazz;
- try {
- CURRENCY_GET_INSTANCE = clazz.getMethod("getInstance", new Class[] { String.class } );
- CURRENCY_GET_CODE = clazz.getMethod("getCurrencyCode", new Class[0] );
- }
- catch (Exception e) {
- throw new AssertionFailure("Exception in static initializer of CurrencyType", e);
- }
- }
+ public CurrencyType() {
+ super( VarcharTypeDescriptor.INSTANCE, CurrencyTypeDescriptor.INSTANCE );
}
- /**
- * @see org.hibernate.type.NullableType#get(ResultSet, String)
- */
- public Object get(ResultSet rs, String name)
- throws HibernateException, SQLException {
- String code = (String) Hibernate.STRING.nullSafeGet(rs, name);
- try {
- return code==null ? null :
- CURRENCY_GET_INSTANCE.invoke(null, new Object[] { code } );
- }
- catch (Exception e) {
- throw new HibernateException("Could not resolve currency code: " + code);
- }
- }
-
- /**
- * @see org.hibernate.type.NullableType#set(PreparedStatement, Object, int)
- */
- public void set(PreparedStatement st, Object value, int index)
- throws HibernateException, SQLException {
- Object code;
- try {
- code = CURRENCY_GET_CODE.invoke(value, null);
- }
- catch (Exception e) {
- throw new HibernateException("Could not get Currency code", e);
- }
- Hibernate.STRING.set(st, code, index);
- }
-
- /**
- * @see org.hibernate.type.NullableType#sqlType()
- */
- public int sqlType() {
- return Hibernate.STRING.sqlType();
- }
-
- /**
- */
- public String toString(Object value) throws HibernateException {
- try {
- return (String) CURRENCY_GET_CODE.invoke(value, null);
- }
- catch (Exception e) {
- throw new HibernateException("Could not get Currency code", e);
- }
- }
-
- /**
- * @see org.hibernate.type.Type#getReturnedClass()
- */
- public Class getReturnedClass() {
- return CURRENCY_CLASS;
- }
-
- /**
- * @see org.hibernate.type.Type#getName()
- */
public String getName() {
return "currency";
}
- /**
- * @see org.hibernate.type.LiteralType#objectToSQLString(Object, Dialect)
- */
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- String code;
- try {
- code = (String) CURRENCY_GET_CODE.invoke(value, null);
- }
- catch (Exception e) {
- throw new HibernateException("Could not get Currency code", e);
- }
- return ( (LiteralType) Hibernate.STRING ).objectToSQLString(code, dialect);
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
- public Object fromStringValue(String xml) throws HibernateException {
- try {
- return CURRENCY_GET_INSTANCE.invoke( null, new Object[] {xml} );
- }
- catch (Exception e) {
- throw new HibernateException("Could not resolve currency code: " + xml);
- }
+ public String objectToSQLString(Currency value, Dialect dialect) throws Exception {
+ return "\'" + toString( value ) + "\'";
}
-
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/CustomCollectionType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CustomCollectionType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CustomCollectionType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/CustomType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/CustomType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/CustomType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -31,9 +30,9 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
-import java.util.Properties;
import org.dom4j.Node;
+
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
@@ -42,9 +41,9 @@
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.usertype.EnhancedUserType;
+import org.hibernate.usertype.LoggableUserType;
import org.hibernate.usertype.UserType;
import org.hibernate.usertype.UserVersionType;
-import org.hibernate.usertype.LoggableUserType;
/**
* Adapts {@link UserType} to the generic {@link Type} interface, in order
@@ -60,37 +59,11 @@
private final int[] types;
private final boolean customLogging;
- public CustomType(Class userTypeClass, Properties parameters) throws MappingException {
-
- if ( !UserType.class.isAssignableFrom( userTypeClass ) ) {
- throw new MappingException(
- "Custom type does not implement UserType: " +
- userTypeClass.getName()
- );
- }
-
- name = userTypeClass.getName();
-
- try {
- userType = ( UserType ) userTypeClass.newInstance();
- }
- catch ( InstantiationException ie ) {
- throw new MappingException(
- "Cannot instantiate custom type: " +
- userTypeClass.getName()
- );
- }
- catch ( IllegalAccessException iae ) {
- throw new MappingException(
- "IllegalAccessException trying to instantiate custom type: " +
- userTypeClass.getName()
- );
- }
-
- TypeFactory.injectParameters( userType, parameters );
- types = userType.sqlTypes();
-
- customLogging = LoggableUserType.class.isAssignableFrom( userTypeClass );
+ public CustomType(UserType userType) throws MappingException {
+ this.userType = userType;
+ this.name = userType.getClass().getName();
+ this.types = userType.sqlTypes();
+ this.customLogging = LoggableUserType.class.isInstance( userType );
}
public UserType getUserType() {
Modified: core/trunk/core/src/main/java/org/hibernate/type/DateType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/DateType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/DateType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,111 +20,48 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Date;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
+import java.util.Date;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.JdbcDateTypeDescriptor;
/**
- * <tt>date</tt>: A type that maps an SQL DATE to a Java Date.
+ * A type that maps between {@link java.sql.Types#DATE DATE} and {@link java.sql.Date}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class DateType extends MutableType implements IdentifierType, LiteralType {
+public class DateType
+ extends AbstractSingleColumnStandardBasicType<Date>
+ implements IdentifierType<Date>, LiteralType<Date> {
- private static final String DATE_FORMAT = "dd MMMM yyyy";
+ public static final DateType INSTANCE = new DateType();
- public Object get(ResultSet rs, String name) throws SQLException {
- return rs.getDate(name);
+ public DateType() {
+ super( org.hibernate.type.descriptor.sql.DateTypeDescriptor.INSTANCE, JdbcDateTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return java.util.Date.class;
+ public String getName() {
+ return "date";
}
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
-
- Date sqlDate;
- if ( value instanceof Date) {
- sqlDate = (Date) value;
- }
- else {
- sqlDate = new Date( ( (java.util.Date) value ).getTime() );
- }
- st.setDate(index, sqlDate);
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
- public int sqlType() {
- return Types.DATE;
+ public String objectToSQLString(Date value, Dialect dialect) throws Exception {
+ final java.sql.Date jdbcDate = java.sql.Date.class.isInstance( value )
+ ? ( java.sql.Date ) value
+ : new java.sql.Date( value.getTime() );
+ // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd format
+ return StringType.INSTANCE.objectToSQLString( jdbcDate.toString(), dialect );
}
- public boolean isEqual(Object x, Object y) {
-
- if (x==y) return true;
- if (x==null || y==null) return false;
-
- java.util.Date xdate = (java.util.Date) x;
- java.util.Date ydate = (java.util.Date) y;
-
- if ( xdate.getTime()==ydate.getTime() ) return true;
-
- Calendar calendar1 = java.util.Calendar.getInstance();
- Calendar calendar2 = java.util.Calendar.getInstance();
- calendar1.setTime( xdate );
- calendar2.setTime( ydate );
-
- return Hibernate.CALENDAR_DATE.isEqual(calendar1, calendar2);
+ public Date stringToObject(String xml) {
+ return fromString( xml );
}
-
- public int getHashCode(Object x, EntityMode entityMode) {
- Calendar calendar = java.util.Calendar.getInstance();
- calendar.setTime( (java.util.Date) x );
- return Hibernate.CALENDAR_DATE.getHashCode(calendar, entityMode);
- }
-
- public String getName() { return "date"; }
-
- public String toString(Object val) {
- return new SimpleDateFormat(DATE_FORMAT).format( (java.util.Date) val );
- }
-
- public Object deepCopyNotNull(Object value) {
- return new Date( ( (java.util.Date) value ).getTime() );
- }
-
- public Object stringToObject(String xml) throws Exception {
- return DateFormat.getDateInstance().parse(xml);
- }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return '\'' + new Date( ( (java.util.Date) value ).getTime() ).toString() + '\'';
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- try {
- return new SimpleDateFormat(DATE_FORMAT).parse(xml);
- }
- catch (ParseException pe) {
- throw new HibernateException("could not parse XML", pe);
- }
- }
-
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/DbTimestampType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/DbTimestampType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/DbTimestampType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -29,6 +28,7 @@
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.CallableStatement;
+import java.util.Date;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.dialect.Dialect;
@@ -48,13 +48,21 @@
*
* @author Steve Ebersole
*/
-public class DbTimestampType extends TimestampType implements VersionType {
+public class DbTimestampType extends TimestampType {
+ public static final DbTimestampType INSTANCE = new DbTimestampType();
private static final Logger log = LoggerFactory.getLogger( DbTimestampType.class );
- public String getName() { return "dbtimestamp"; }
+ public String getName() {
+ return "dbtimestamp";
+ }
- public Object seed(SessionImplementor session) {
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName() };
+ }
+
+ public Date seed(SessionImplementor session) {
if ( session == null ) {
log.trace( "incoming session was null; using current jvm time" );
return super.seed( session );
@@ -68,7 +76,7 @@
}
}
- private Timestamp getCurrentTimestamp(SessionImplementor session) {
+ private Date getCurrentTimestamp(SessionImplementor session) {
Dialect dialect = session.getFactory().getDialect();
String timestampSelectString = dialect.getCurrentTimestampSelectString();
if ( dialect.isCurrentTimestampSelectStringCallable() ) {
Modified: core/trunk/core/src/main/java/org/hibernate/type/DiscriminatorType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/DiscriminatorType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/DiscriminatorType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,19 +20,14 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
/**
- * A <tt>Type</tt> that may be used for a discriminator column.
+ * Additional contract for a {@link Type} may be used for a discriminator.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public interface DiscriminatorType extends IdentifierType, LiteralType {
+public interface DiscriminatorType<T> extends IdentifierType<T>, LiteralType<T> {
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/DoubleType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/DoubleType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/DoubleType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,62 +20,48 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.DoubleTypeDescriptor;
/**
- * <tt>double</tt>: A type that maps an SQL DOUBLE to a Java Double.
+ * A type that maps between {@link java.sql.Types#DOUBLE DOUBLE} and {@link Double}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class DoubleType extends PrimitiveType {
+public class DoubleType extends AbstractSingleColumnStandardBasicType<Double> implements PrimitiveType<Double> {
+ public static final DoubleType INSTANCE = new DoubleType();
- public Serializable getDefaultValue() {
- return new Double(0.0);
- }
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Double( rs.getDouble(name) );
- }
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public static final Double ZERO = Double.valueOf( 0.0 );
- public Class getPrimitiveClass() {
- return double.class;
+ public DoubleType() {
+ super( org.hibernate.type.descriptor.sql.DoubleTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Double.class;
+ public String getName() {
+ return "double";
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
-
- st.setDouble( index, ( (Double) value ).doubleValue() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), double.class.getName(), Double.class.getName() };
}
- public int sqlType() {
- return Types.DOUBLE;
+ public Serializable getDefaultValue() {
+ return ZERO;
}
- public String getName() { return "double"; }
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return value.toString();
+ public Class getPrimitiveClass() {
+ return double.class;
}
- public Object fromStringValue(String xml) {
- return new Double(xml);
+ public String objectToSQLString(Double value, Dialect dialect) throws Exception {
+ return toString( value );
}
-
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/EmbeddedComponentType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/EmbeddedComponentType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/EmbeddedComponentType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/EntityType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/EntityType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/EntityType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/FloatType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/FloatType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/FloatType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,60 +20,50 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.FloatTypeDescriptor;
/**
- * <tt>float</tt>: A type that maps an SQL FLOAT to a Java Float.
+ * A type that maps between {@link java.sql.Types#FLOAT FLOAT} and {@link Float}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class FloatType extends PrimitiveType {
+public class FloatType extends AbstractSingleColumnStandardBasicType<Float> implements PrimitiveType<Float> {
+ public static final FloatType INSTANCE = new FloatType();
- public Serializable getDefaultValue() {
- return new Float(0.0);
- }
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Float( rs.getFloat(name) );
- }
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public static final Float ZERO = Float.valueOf( 0.0f );
- public Class getPrimitiveClass() {
- return float.class;
+ public FloatType() {
+ super( org.hibernate.type.descriptor.sql.FloatTypeDescriptor.INSTANCE, FloatTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Float.class;
+ public String getName() {
+ return "float";
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
-
- st.setFloat( index, ( (Float) value ).floatValue() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), float.class.getName(), Float.class.getName() };
}
- public int sqlType() {
- return Types.FLOAT;
+ public Serializable getDefaultValue() {
+ return ZERO;
}
- public String getName() { return "float"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return value.toString();
+ public Class getPrimitiveClass() {
+ return float.class;
}
- public Object fromStringValue(String xml) {
- return new Float(xml);
+ public String objectToSQLString(Float value, Dialect dialect) throws Exception {
+ return toString( value );
}
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/ForeignKeyDirection.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ForeignKeyDirection.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ForeignKeyDirection.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/IdentifierBagType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/IdentifierBagType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/IdentifierBagType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/IdentifierType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/IdentifierType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/IdentifierType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,28 +20,25 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
/**
- * A <tt>Type</tt> that may be used as an identifier.
+ * Additional contract for a {@link Type} may be used for a discriminator. THis contract is used to process
+ * the string representation as presented in metadata, especially in <tt>XML</tt> files.
+ *
* @author Gavin King
*/
-public interface IdentifierType extends Type {
+public interface IdentifierType<T> extends Type {
/**
* Convert the value from the mapping file to a Java object.
+ *
* @param xml the value of <tt>discriminator-value</tt> or <tt>unsaved-value</tt> attribute
- * @return Object
- * @throws Exception
+ * @return The converted value of the string representation.
+ *
+ * @throws Exception Indicates a problem converting from the string
*/
- public Object stringToObject(String xml) throws Exception;
+ public T stringToObject(String xml) throws Exception;
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/ImageType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ImageType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ImageType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,21 +20,25 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Types;
+import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarbinaryTypeDescriptor;
/**
- * <tt>image</tt>: A type that maps an SQL LONGVARBINARY to Java byte[].
+ * A type that maps between {@link java.sql.Types#LONGVARBINARY LONGVARBINARY} and {@code byte[]}
*
+ * @author Gavin King
+ * @author Emmanuel Bernard
* @author Gail Badner
+ * @author Steve Ebersole
*/
-public class ImageType extends AbstractLongBinaryType {
+public class ImageType extends AbstractSingleColumnStandardBasicType<byte[]> {
+ public static final ImageType INSTANCE = new ImageType();
- public int sqlType() {
- return Types.LONGVARBINARY;
+ public ImageType() {
+ super( LongVarbinaryTypeDescriptor.INSTANCE, PrimitiveByteArrayTypeDescriptor.INSTANCE );
}
public String getName() {
Modified: core/trunk/core/src/main/java/org/hibernate/type/ImmutableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ImmutableType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ImmutableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -34,6 +33,8 @@
/**
* Superclass of nullable immutable types.
* @author Gavin King
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class ImmutableType extends NullableType {
Modified: core/trunk/core/src/main/java/org/hibernate/type/IntegerType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/IntegerType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/IntegerType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,78 +20,69 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import java.util.Comparator;
-import org.hibernate.util.ComparableComparator;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.descriptor.java.IntegerTypeDescriptor;
/**
- * <tt>integer</tt>: A type that maps an SQL INT to a Java Integer.
+ * A type that maps between {@link java.sql.Types#INTEGER INTEGER} and @link Integer}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class IntegerType extends PrimitiveType implements DiscriminatorType, VersionType {
+public class IntegerType extends AbstractSingleColumnStandardBasicType<Integer>
+ implements PrimitiveType<Integer>, DiscriminatorType<Integer>, VersionType<Integer> {
- private static final Integer ZERO = new Integer(0);
+ public static final IntegerType INSTANCE = new IntegerType();
- public Serializable getDefaultValue() {
- return ZERO;
- }
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Integer( rs.getInt(name) );
- }
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public static final Integer ZERO = Integer.valueOf( 0 );
- public Class getPrimitiveClass() {
- return int.class;
+ public IntegerType() {
+ super( org.hibernate.type.descriptor.sql.IntegerTypeDescriptor.INSTANCE, IntegerTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Integer.class;
+ public String getName() {
+ return "integer";
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
- st.setInt( index, ( (Integer) value ).intValue() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), int.class.getName(), Integer.class.getName() };
}
- public int sqlType() {
- return Types.INTEGER;
+ public Serializable getDefaultValue() {
+ return ZERO;
}
- public String getName() { return "integer"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return value.toString();
+ public Class getPrimitiveClass() {
+ return int.class;
}
- public Object stringToObject(String xml) throws Exception {
- return new Integer(xml);
+ public String objectToSQLString(Integer value, Dialect dialect) throws Exception {
+ return toString( value );
}
- public Object next(Object current, SessionImplementor session) {
- return new Integer( ( (Integer) current ).intValue() + 1 );
+ public Integer stringToObject(String xml) {
+ return fromString( xml );
}
- public Object seed(SessionImplementor session) {
+ public Integer seed(SessionImplementor session) {
return ZERO;
}
- public Comparator getComparator() {
- return ComparableComparator.INSTANCE;
+ @SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
+ public Integer next(Integer current, SessionImplementor session) {
+ return Integer.valueOf( current.intValue() + 1 );
}
-
- public Object fromStringValue(String xml) {
- return new Integer(xml);
- }
+ public Comparator<Integer> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/ListType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ListType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ListType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/LiteralType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/LiteralType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/LiteralType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,31 +20,29 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import org.hibernate.dialect.Dialect;
/**
- * A type that may appear as an SQL literal
+ * Additional contract for a {@link Type} that may appear as an SQL literal
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public interface LiteralType {
+public interface LiteralType<T> {
/**
- * String representation of the value, suitable for embedding in
- * an SQL statement.
- * @param value
- * @param dialect
- * @return String the value, as it appears in a SQL query
- * @throws Exception
+ * Convert the value into a string representation, suitable for embedding in an SQL statement as a
+ * literal.
+ *
+ * @param value The value to convert
+ * @param dialect The SQL dialect
+ *
+ * @return The value's string representation
+ *
+ * @throws Exception Indicates an issue converting the value to literal string.
*/
- public String objectToSQLString(Object value, Dialect dialect) throws Exception;
+ public String objectToSQLString(T value, Dialect dialect) throws Exception;
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/LocaleType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/LocaleType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/LocaleType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,82 +20,40 @@
* 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.util.Locale;
-import java.util.StringTokenizer;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
- * <tt>locale</tt>: A type that maps an SQL VARCHAR to a Java Locale.
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and @link Locale}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class LocaleType extends ImmutableType implements LiteralType {
+public class LocaleType extends AbstractSingleColumnStandardBasicType<Locale>
+ implements LiteralType<Locale> {
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
- return fromStringValue( (String) Hibernate.STRING.get(rs, name) );
- }
+ public static final LocaleType INSTANCE = new LocaleType();
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- Hibernate.STRING.set(st, value.toString(), index);
+ public LocaleType() {
+ super( VarcharTypeDescriptor.INSTANCE, LocaleTypeDescriptor.INSTANCE );
}
- public Object fromStringValue(String string) {
- if (string == null) {
- return null;
- }
- else {
- StringTokenizer tokens = new StringTokenizer(string, "_");
- String language = tokens.hasMoreTokens() ? tokens.nextToken() : "";
- String country = tokens.hasMoreTokens() ? tokens.nextToken() : "";
- // Need to account for allowable '_' within the variant
- String variant = "";
- String sep = "";
- while ( tokens.hasMoreTokens() ) {
- variant += sep + tokens.nextToken();
- sep = "_";
- }
- return new Locale(language, country, variant);
- }
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return x.toString().compareTo( y.toString() );
- }
-
- public int sqlType() {
- return Hibernate.STRING.sqlType();
- }
-
- public String toString(Object value) throws HibernateException {
- return value.toString();
- }
-
- public Class getReturnedClass() {
- return Locale.class;
- }
-
public String getName() {
return "locale";
}
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return ( (LiteralType) Hibernate.STRING ).objectToSQLString( value.toString(), dialect );
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
+ public String objectToSQLString(Locale value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( toString( value ), dialect );
+ }
}
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/LongType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/LongType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/LongType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,80 +20,71 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import java.util.Comparator;
-import org.hibernate.util.ComparableComparator;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.descriptor.java.LongTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BigIntTypeDescriptor;
/**
- * <tt>long</tt>: A type that maps an SQL BIGINT to a Java Long.
+ * A type that maps between {@link java.sql.Types#BIGINT BIGINT} and {@link Long}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class LongType extends PrimitiveType implements DiscriminatorType, VersionType {
+public class LongType
+ extends AbstractSingleColumnStandardBasicType<Long>
+ implements PrimitiveType<Long>, DiscriminatorType<Long>, VersionType<Long> {
- private static final Long ZERO = new Long(0);
+ public static final LongType INSTANCE = new LongType();
- public Serializable getDefaultValue() {
- return ZERO;
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ private static final Long ZERO = Long.valueOf( 0 );
+
+ public LongType() {
+ super( BigIntTypeDescriptor.INSTANCE, LongTypeDescriptor.INSTANCE );
}
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Long( rs.getLong(name) );
- }
- public Class getPrimitiveClass() {
- return long.class;
+ public String getName() {
+ return "long";
}
- public Class getReturnedClass() {
- return Long.class;
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), long.class.getName(), Long.class.getName() };
}
- public void set(PreparedStatement st, Object value, int index)
- throws SQLException {
-
- st.setLong( index, ( (Long) value ).longValue() );
+ public Serializable getDefaultValue() {
+ return ZERO;
}
- public int sqlType() {
- return Types.BIGINT;
+ public Class getPrimitiveClass() {
+ return long.class;
}
- public String getName() { return "long"; }
-
- public Object stringToObject(String xml) throws Exception {
+ public Long stringToObject(String xml) throws Exception {
return new Long(xml);
}
- public Object next(Object current, SessionImplementor session) {
- return new Long( ( (Long) current ).longValue() + 1 );
+ @SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
+ public Long next(Long current, SessionImplementor session) {
+ return Long.valueOf( current.longValue() + 1 );
}
- public Object seed(SessionImplementor session) {
+ public Long seed(SessionImplementor session) {
return ZERO;
}
- public Comparator getComparator() {
- return ComparableComparator.INSTANCE;
+ public Comparator<Long> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
}
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
+ public String objectToSQLString(Long value, Dialect dialect) throws Exception {
return value.toString();
}
-
- public Object fromStringValue(String xml) {
- return new Long(xml);
- }
-
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/MapType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/MapType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/MapType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/MaterializedBlobType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/MaterializedBlobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/MaterializedBlobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,21 +20,25 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Types;
+import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.BlobTypeDescriptor;
/**
- * <tt>materialized_blob</tt>: A type that maps an SQL BLOB to Java byte[].
+ * A type that maps between {@link java.sql.Types#BLOB BLOB} and {@code byte[]}
*
+ * @author Gavin King
+ * @author Emmanuel Bernard
* @author Gail Badner
+ * @author Steve Ebersole
*/
-public class MaterializedBlobType extends AbstractLongBinaryType {
+public class MaterializedBlobType extends AbstractSingleColumnStandardBasicType<byte[]> {
+ public static final MaterializedBlobType INSTANCE = new MaterializedBlobType();
- public int sqlType() {
- return Types.BLOB;
+ public MaterializedBlobType() {
+ super( BlobTypeDescriptor.INSTANCE, PrimitiveByteArrayTypeDescriptor.INSTANCE );
}
public String getName() {
Modified: core/trunk/core/src/main/java/org/hibernate/type/MaterializedClobType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/MaterializedClobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/MaterializedClobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,22 +20,27 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Types;
+import org.hibernate.type.descriptor.java.StringTypeDescriptor;
+import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
/**
- * <tt>materialized_clob</tt>: A type that maps an SQL CLOB to a Java String.
+ * A type that maps between {@link java.sql.Types#CLOB CLOB} and {@link String}
*
+ * @author Gavin King
* @author Gail Badner
+ * @author Steve Ebersole
*/
-public class MaterializedClobType extends AbstractLongStringType {
+public class MaterializedClobType extends AbstractSingleColumnStandardBasicType<String> {
+ public static final MaterializedClobType INSTANCE = new MaterializedClobType();
- public int sqlType() {
- return Types.CLOB;
+ public MaterializedClobType() {
+ super( ClobTypeDescriptor.INSTANCE, StringTypeDescriptor.INSTANCE );
}
- public String getName() { return "materialized_clob"; }
+ public String getName() {
+ return "materialized_clob";
+ }
}
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/type/MetaType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/MetaType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/MetaType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -43,6 +42,7 @@
* @author Gavin King
*/
public class MetaType extends AbstractType {
+ public static final String[] REGISTRATION_KEYS = new String[0];
private final Map values;
private final Map keys;
@@ -59,6 +59,10 @@
}
}
+ public String[] getRegistrationKeys() {
+ return REGISTRATION_KEYS;
+ }
+
public int[] sqlTypes(Mapping mapping) throws MappingException {
return baseType.sqlTypes(mapping);
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/MutableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/MutableType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/MutableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -34,6 +33,8 @@
/**
* Superclass for mutable nullable types
* @author Gavin King
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class MutableType extends NullableType {
Modified: core/trunk/core/src/main/java/org/hibernate/type/NullableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/NullableType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/NullableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -45,8 +44,10 @@
* Superclass of single-column nullable types.
*
* @author Gavin King
+ *
+ * @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
-public abstract class NullableType extends AbstractType {
+public abstract class NullableType extends AbstractType implements StringRepresentableType, XmlRepresentableType {
/**
* This is the old scheme where logging of parameter bindings and value extractions
Modified: core/trunk/core/src/main/java/org/hibernate/type/NumericBooleanType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/NumericBooleanType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/NumericBooleanType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,75 +20,48 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.PreparedStatement;
-import java.sql.Types;
+import java.io.Serializable;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
+import org.hibernate.type.descriptor.sql.IntegerTypeDescriptor;
/**
- * Maps {@link Types#INTEGER interger} database values to boolean java values. Zero is considered false;
- * <tt>NULL</tt> maps to {@link #getDefaultValue()}; any other value is considered true.
+ * A type that maps between {@link java.sql.Types#INTEGER INTEGER} and {@link Boolean} (using 1 and 0)
*
* @author Steve Ebersole
- * @see #getName()
*/
-public class NumericBooleanType extends BooleanType {
+public class NumericBooleanType
+ extends AbstractSingleColumnStandardBasicType<Boolean>
+ implements PrimitiveType<Boolean>, DiscriminatorType<Boolean> {
- /**
- * {@inheritDoc}
- * <p/>
- * This type's name is <tt>numeric_boolean</tt>
- */
+ public static final NumericBooleanType INSTANCE = new NumericBooleanType();
+
+ public NumericBooleanType() {
+ super( IntegerTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE );
+ }
+
public String getName() {
return "numeric_boolean";
}
- /**
- * {@inheritDoc}
- */
- public Object get(ResultSet rs, String name) throws SQLException {
- int value = rs.getInt( name );
- if ( rs.wasNull() ) {
- return getDefaultValue();
- }
- else if ( value == 0 ) {
- return Boolean.FALSE;
- }
- else {
- return Boolean.TRUE;
- }
+ public Class getPrimitiveClass() {
+ return boolean.class;
}
- /**
- * {@inheritDoc}
- */
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- if ( value == null ) {
- st.setNull( index, Types.INTEGER );
- }
- else {
- boolean bool = ( ( Boolean ) value ).booleanValue();
- st.setInt( index, bool ? 1 : 0 );
- }
+ public Serializable getDefaultValue() {
+ return Boolean.FALSE;
}
- /**
- * {@inheritDoc}
- */
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return ( ( Boolean ) value ).booleanValue() ? "1" : "0";
+ public Boolean stringToObject(String string) {
+ return fromString( string );
}
- /**
- * {@inheritDoc}
- */
- public int sqlType() {
- return Types.INTEGER;
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String objectToSQLString(Boolean value, Dialect dialect) {
+ return value.booleanValue() ? "1" : "0";
}
}
Added: core/trunk/core/src/main/java/org/hibernate/type/ObjectType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ObjectType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/ObjectType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+/**
+ * Specific adaptation of the "any" type to the old deprecated "object" type
+ *
+ * @author Gavin King
+ * @author Steve Ebersole
+ */
+public class ObjectType extends AnyType implements BasicType {
+ public static final ObjectType INSTANCE = new ObjectType();
+
+ public ObjectType() {
+ super( StringType.INSTANCE, SerializableType.INSTANCE );
+ }
+
+ public String getName() {
+ return "object";
+ }
+
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), Object.class.getName() };
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/OneToOneType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/OneToOneType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/OneToOneType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/OrderedMapType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/OrderedSetType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/PrimitiveType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/PrimitiveType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/PrimitiveType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,29 +20,39 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
/**
- * Superclass of primitive / primitive wrapper types.
+ * Additional contract for primitive / primitive wrapper types.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public abstract class PrimitiveType extends ImmutableType implements LiteralType {
-
+public interface PrimitiveType<T> extends LiteralType<T> {
+ /**
+ * Retrieve the primitive counterpart to the wrapper type identified by
+ * {@link org.hibernate.type.Type#getReturnedClass()}.
+ *
+ * @return The primitive Java type.
+ */
public abstract Class getPrimitiveClass();
- public String toString(Object value) {
- return value.toString();
- }
-
+ /**
+ * Retrieve the string representation of the given value.
+ *
+ * @param value The value to be stringified.
+ *
+ * @return The string representation
+ */
+ public String toString(T value);
+
+ /**
+ * Get this type's default value.
+ *
+ * @return The default value.
+ */
public abstract Serializable getDefaultValue();
-
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/SerializableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SerializableType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SerializableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,110 +20,31 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.util.SerializationHelper;
+import org.hibernate.type.descriptor.java.SerializableTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor;
/**
- * <tt>serializable</tt>: A type that maps an SQL VARBINARY to a
- * serializable Java object.
+ * A type that maps between a {@link java.sql.Types#VARBINARY VARBINARY} and {@link Serializable} classes.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class SerializableType extends MutableType {
+public class SerializableType<T extends Serializable> extends AbstractSingleColumnStandardBasicType<T> {
+ public static final SerializableType<Serializable> INSTANCE = new SerializableType<Serializable>( Serializable.class );
- private final Class serializableClass;
+ private final Class<T> serializableClass;
- public SerializableType(Class serializableClass) {
+ public SerializableType(Class<T> serializableClass) {
+ super( VarbinaryTypeDescriptor.INSTANCE, new SerializableTypeDescriptor<T>( serializableClass ) );
this.serializableClass = serializableClass;
}
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- Hibernate.BINARY.set(st, toBytes(value), index);
- }
-
- public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
- byte[] bytes = (byte[]) Hibernate.BINARY.get(rs, name);
- // Some JDBC drivers erroneously return an empty array here for a null DB value :/
- if ( bytes == null || bytes.length == 0 ) {
- return null;
- }
- else {
- return fromBytes(bytes);
- }
- }
-
- public Class getReturnedClass() {
- return serializableClass;
- }
-
- public boolean isEqual(Object x, Object y) throws HibernateException {
- if ( x == y ) {
- return true;
- }
- if ( x == null || y == null ) {
- return false;
- }
- return x.equals( y ) || Hibernate.BINARY.isEqual( toBytes( x ), toBytes( y ) );
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- return Hibernate.BINARY.getHashCode( toBytes(x), entityMode );
- }
-
- public String toString(Object value) throws HibernateException {
- return Hibernate.BINARY.toString( toBytes(value) );
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- return fromBytes( (byte[]) Hibernate.BINARY.fromStringValue(xml) );
- }
-
public String getName() {
return (serializableClass==Serializable.class) ? "serializable" : serializableClass.getName();
}
-
- public Object deepCopyNotNull(Object value) throws HibernateException {
- return fromBytes( toBytes(value) );
- }
-
- private static byte[] toBytes(Object object) throws SerializationException {
- return SerializationHelper.serialize( (Serializable) object );
- }
-
- private Object fromBytes(byte[] bytes) throws SerializationException {
- return SerializationHelper.deserialize( bytes, getReturnedClass().getClassLoader() );
- }
-
- public int sqlType() {
- return Hibernate.BINARY.sqlType();
- }
-
- public Object assemble(Serializable cached, SessionImplementor session, Object owner)
- throws HibernateException {
- return (cached==null) ? null : fromBytes( (byte[]) cached );
- }
-
- public Serializable disassemble(Object value, SessionImplementor session, Object owner)
- throws HibernateException {
- return (value==null) ? null : toBytes(value);
- }
-
}
-
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/SerializationException.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SerializationException.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SerializationException.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/SetType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SetType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SetType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/ShortType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ShortType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/ShortType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,78 +20,73 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
import java.util.Comparator;
-import org.hibernate.util.ComparableComparator;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.descriptor.java.ShortTypeDescriptor;
+import org.hibernate.type.descriptor.sql.SmallIntTypeDescriptor;
/**
- * <tt>short</tt>: A type that maps an SQL SMALLINT to a Java Short.
+ * A type that maps between {@link java.sql.Types#SMALLINT SMALLINT} and {@link Short}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class ShortType extends PrimitiveType implements DiscriminatorType, VersionType {
+public class ShortType
+ extends AbstractSingleColumnStandardBasicType<Short>
+ implements PrimitiveType<Short>, DiscriminatorType<Short>, VersionType<Short> {
- private static final Short ZERO = new Short( (short) 0 );
+ public static final ShortType INSTANCE = new ShortType();
- public Serializable getDefaultValue() {
- return ZERO;
- }
-
- public Object get(ResultSet rs, String name) throws SQLException {
- return new Short( rs.getShort(name) );
- }
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ private static final Short ZERO = Short.valueOf( (short) 0 );
- public Class getPrimitiveClass() {
- return short.class;
+ public ShortType() {
+ super( SmallIntTypeDescriptor.INSTANCE, ShortTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Short.class;
+ public String getName() {
+ return "short";
}
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- st.setShort( index, ( (Short) value ).shortValue() );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), short.class.getName(), Short.class.getName() };
}
- public int sqlType() {
- return Types.SMALLINT;
+ public Serializable getDefaultValue() {
+ return ZERO;
}
+
+ public Class getPrimitiveClass() {
+ return short.class;
+ }
- public String getName() { return "short"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
+ public String objectToSQLString(Short value, Dialect dialect) throws Exception {
return value.toString();
}
- public Object stringToObject(String xml) throws Exception {
+ public Short stringToObject(String xml) throws Exception {
return new Short(xml);
}
- public Object next(Object current, SessionImplementor session) {
- return new Short( (short) ( ( (Short) current ).shortValue() + 1 ) );
+ @SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
+ public Short next(Short current, SessionImplementor session) {
+ return Short.valueOf( (short) ( current.shortValue() + 1 ) );
}
- public Object seed(SessionImplementor session) {
+ public Short seed(SessionImplementor session) {
return ZERO;
}
- public Comparator getComparator() {
- return ComparableComparator.INSTANCE;
+ public Comparator<Short> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
}
-
- public Object fromStringValue(String xml) {
- return new Short(xml);
- }
}
Added: core/trunk/core/src/main/java/org/hibernate/type/SingleColumnType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SingleColumnType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/SingleColumnType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,121 @@
+/*
+ * 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 org.hibernate.HibernateException;
+import org.hibernate.engine.SessionImplementor;
+
+/**
+ * Provide convenient methods for binding and extracting values for use with {@link BasicType}. Most of this
+ * is copied from the (now deprecated) {@link NullableType}.
+ * <p/>
+ * Glaring omission are the forms that do not take
+ *
+ * @author Steve Ebersole
+ */
+public interface SingleColumnType<T> extends Type {
+
+ public int sqlType();
+
+ public String toString(T value) throws HibernateException;
+
+ public T fromStringValue(String xml) throws HibernateException;
+
+ /**
+ * @deprecated Use {@link #nullSafeGet(ResultSet, String, SessionImplementor)} instead
+ */
+ @SuppressWarnings({ "JavaDoc" })
+ public T nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException;
+
+ /**
+ * Get a column value from a result set by name.
+ *
+ * @param rs The result set from which to extract the value.
+ * @param name The name of the value to extract.
+ * @param session The session from which the request originates
+ *
+ * @return The extracted value.
+ *
+ * @throws org.hibernate.HibernateException Generally some form of mismatch error.
+ * @throws java.sql.SQLException Indicates problem making the JDBC call(s).
+ */
+ public T nullSafeGet(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException;
+
+ /**
+ * DO NOT USER THIS FORM!
+ *
+ * @deprecated Use {@link #get(ResultSet, String, SessionImplementor)} instead.
+ */
+ @SuppressWarnings({ "JavaDoc" })
+ public Object get(ResultSet rs, String name) throws HibernateException, SQLException;
+
+ /**
+ * Get a column value from a result set, without worrying about the possibility of null values.
+ *
+ * @param rs The result set from which to extract the value.
+ * @param name The name of the value to extract.
+ * @param session The session from which the request originates
+ *
+ * @return The extracted value.
+ *
+ * @throws org.hibernate.HibernateException Generally some form of mismatch error.
+ * @throws java.sql.SQLException Indicates problem making the JDBC call(s).
+ */
+ public Object get(ResultSet rs, String name, SessionImplementor session) throws HibernateException, SQLException;
+
+ /**
+ * DO NOT USE THIS FORM!
+ *
+ * @deprecated Use {@link #nullSafeSet(PreparedStatement, Object, int, SessionImplementor)} instead.
+ */
+ @SuppressWarnings({ "JavaDoc" })
+ public void nullSafeSet(PreparedStatement st, T value, int index) throws HibernateException, SQLException;
+
+ /**
+ * DO NOT USE THIS FORM!
+ *
+ * @deprecated Use {@link #set(PreparedStatement, Object, int, SessionImplementor)} instead.
+ */
+ @SuppressWarnings({ "JavaDoc" })
+ public void set(PreparedStatement st, T value, int index) throws HibernateException, SQLException;
+
+ /**
+ * Set a parameter value without worrying about the possibility of null
+ * values. Called from {@link #nullSafeSet} after nullness checks have
+ * been performed.
+ *
+ * @param st The statement into which to bind the parameter value.
+ * @param value The parameter value to bind.
+ * @param index The position or index at which to bind the param value.
+ * @param session The session from which the request originates
+ *
+ * @throws org.hibernate.HibernateException Generally some form of mismatch error.
+ * @throws java.sql.SQLException Indicates problem making the JDBC call(s).
+ */
+ public void set(PreparedStatement st, T value, int index, SessionImplementor session) throws HibernateException, SQLException;
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/SortedMapType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SortedMapType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SortedMapType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/SortedSetType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SortedSetType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SortedSetType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Modified: core/trunk/core/src/main/java/org/hibernate/type/SpecialOneToOneType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/SpecialOneToOneType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/SpecialOneToOneType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
Added: core/trunk/core/src/main/java/org/hibernate/type/StringRepresentableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/StringRepresentableType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/StringRepresentableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,55 @@
+/*
+ * 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 org.hibernate.HibernateException;
+
+/**
+ * Additional, optional contract for types capable of rendering and consuming their values to/from strings.
+ *
+ * @author Steve Ebersole
+ */
+public interface StringRepresentableType<T> {
+ /**
+ * Render the value to the string representation.
+ *
+ * @param value The value to render to string.
+ *
+ * @return The string representation
+ *
+ * @throws HibernateException Problem rendering
+ */
+ public abstract String toString(T value) throws HibernateException;
+
+ /**
+ * Consume the given string representation back into this types java form.
+ *
+ * @param string The string representation to be consumed.
+ *
+ * @return The java type representation
+ *
+ * @throws HibernateException Problem consuming
+ */
+ public abstract T fromStringValue(String string) throws HibernateException;
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/StringType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/StringType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/StringType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,60 +20,47 @@
* 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 org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.StringTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
- * <tt>string</tt>: A type that maps an SQL VARCHAR to a Java String.
+ * A type that maps between {@link java.sql.Types#VARCHAR VARCHAR} and {@link String}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class StringType extends ImmutableType implements DiscriminatorType {
+public class StringType
+ extends AbstractSingleColumnStandardBasicType<String>
+ implements DiscriminatorType<String> {
- public Object get(ResultSet rs, String name) throws SQLException {
- return rs.getString(name);
- }
+ public static final StringType INSTANCE = new StringType();
- public Class getReturnedClass() {
- return String.class;
+ public StringType() {
+ super( VarcharTypeDescriptor.INSTANCE, StringTypeDescriptor.INSTANCE );
}
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- st.setString(index, (String) value);
+ public String getName() {
+ return "string";
}
- public int sqlType() {
- return Types.VARCHAR;
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
- public String getName() { return "string"; }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return '\'' + (String) value + '\'';
+ public String objectToSQLString(String value, Dialect dialect) throws Exception {
+ return '\'' + value + '\'';
}
- public Object stringToObject(String xml) throws Exception {
+ public String stringToObject(String xml) throws Exception {
return xml;
}
- public String toString(Object value) {
- return (String) value;
+ public String toString(String value) {
+ return value;
}
-
- public Object fromStringValue(String xml) {
- return xml;
- }
-
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/TextType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TextType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TextType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,11 +1,10 @@
-//$Id: $
/*
* 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
@@ -21,30 +20,28 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import java.sql.Types;
+import org.hibernate.type.descriptor.java.StringTypeDescriptor;
+import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
/**
- * <tt>text</tt>: A type that maps an SQL LONGVARCHAR to a Java String.
+ * A type that maps between {@link java.sql.Types#LONGVARCHAR LONGVARCHAR} and {@link String}
*
- * @author Gavin King, Bertrand Renuart
+ * @author Gavin King,
+ * @author Bertrand Renuart
+ * @author Steve Ebersole
*/
-public class TextType extends AbstractLongStringType {
+public class TextType extends AbstractSingleColumnStandardBasicType<String> {
+ public static final TextType INSTANCE = new TextType();
- public int sqlType() {
- return Types.LONGVARCHAR;
+ public TextType() {
+ super( LongVarcharTypeDescriptor.INSTANCE, StringTypeDescriptor.INSTANCE );
}
- public String getName() { return "text"; }
+ public String getName() {
+ return "text";
+ }
}
-
-
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/TimeType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TimeType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TimeType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,111 +20,45 @@
* 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.Time;
-import java.sql.Types;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
import java.util.Date;
-import org.hibernate.EntityMode;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.JdbcTimeTypeDescriptor;
/**
- * <tt>time</tt>: A type that maps an SQL TIME to a Java
- * java.util.Date or java.sql.Time.
+ * A type that maps between {@link java.sql.Types#TIME TIME} and {@link Time}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class TimeType extends MutableType implements LiteralType {
+public class TimeType
+ extends AbstractSingleColumnStandardBasicType<Date>
+ implements LiteralType<Date> {
- private static final String TIME_FORMAT = "HH:mm:ss";
+ public static final TimeType INSTANCE = new TimeType();
- public Object get(ResultSet rs, String name) throws SQLException {
- return rs.getTime(name);
+ public TimeType() {
+ super( org.hibernate.type.descriptor.sql.TimeTypeDescriptor.INSTANCE, JdbcTimeTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return java.util.Date.class;
- }
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- Time time;
- if (value instanceof Time) {
- time = (Time) value;
- }
- else {
- time = new Time( ( (java.util.Date) value ).getTime() );
- }
- st.setTime(index, time);
+ public String getName() {
+ return "time";
}
- public int sqlType() {
- return Types.TIME;
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
- public String getName() { return "time"; }
- public String toString(Object val) {
- return new SimpleDateFormat(TIME_FORMAT).format( (java.util.Date) val );
+ public String objectToSQLString(Date value, Dialect dialect) throws Exception {
+ Time jdbcTime = Time.class.isInstance( value )
+ ? ( Time ) value
+ : new Time( value.getTime() );
+ // TODO : use JDBC time literal escape syntax? -> {t 'time-string'} in hh:mm:ss format
+ return StringType.INSTANCE.objectToSQLString( jdbcTime.toString(), dialect );
}
- public boolean isEqual(Object x, Object y) {
-
- if (x==y) return true;
- if (x==null || y==null) return false;
-
- Date xdate = (Date) x;
- Date ydate = (Date) y;
-
- if ( xdate.getTime()==ydate.getTime() ) return true;
-
- Calendar calendar1 = java.util.Calendar.getInstance();
- Calendar calendar2 = java.util.Calendar.getInstance();
- calendar1.setTime( xdate );
- calendar2.setTime( ydate );
-
- return calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY)
- && calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE)
- && calendar1.get(Calendar.SECOND) == calendar2.get(Calendar.SECOND)
- && calendar1.get(Calendar.MILLISECOND) == calendar2.get(Calendar.MILLISECOND);
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- Calendar calendar = java.util.Calendar.getInstance();
- calendar.setTime( (java.util.Date) x );
- int hashCode = 1;
- hashCode = 31 * hashCode + calendar.get(Calendar.HOUR_OF_DAY);
- hashCode = 31 * hashCode + calendar.get(Calendar.MINUTE);
- hashCode = 31 * hashCode + calendar.get(Calendar.SECOND);
- hashCode = 31 * hashCode + calendar.get(Calendar.MILLISECOND);
- return hashCode;
- }
-
- public Object deepCopyNotNull(Object value) {
- return new Time( ( (java.util.Date) value ).getTime() );
- }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return '\'' + new Time( ( (java.util.Date) value ).getTime() ).toString() + '\'';
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- try {
- return new SimpleDateFormat(TIME_FORMAT).parse(xml);
- }
- catch (ParseException pe) {
- throw new HibernateException("could not parse XML", pe);
- }
- }
-
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/TimeZoneType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TimeZoneType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TimeZoneType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,73 +20,42 @@
* 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.util.TimeZone;
-import org.hibernate.EntityMode;
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.TimeZoneTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
- * <tt>timezone</tt>: A type that maps an SQL VARCHAR to a
- * <tt>java.util.TimeZone</tt>
- * @see java.util.TimeZone
+ * A type mapping {@link java.sql.Types#VARCHAR VARCHAR} and {@link TimeZone}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class TimeZoneType extends ImmutableType implements LiteralType {
+public class TimeZoneType
+ extends AbstractSingleColumnStandardBasicType<TimeZone>
+ implements LiteralType<TimeZone> {
- public Object get(ResultSet rs, String name)
- throws HibernateException, SQLException {
- String id = (String) Hibernate.STRING.nullSafeGet(rs, name);
- return (id==null) ? null : TimeZone.getTimeZone(id);
- }
+ public static final TimeZoneType INSTANCE = new TimeZoneType();
-
- public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
- Hibernate.STRING.set(st, ( (TimeZone) value ).getID(), index);
+ public TimeZoneType() {
+ super( VarcharTypeDescriptor.INSTANCE, TimeZoneTypeDescriptor.INSTANCE );
}
- public int sqlType() {
- return Hibernate.STRING.sqlType();
- }
-
- public String toString(Object value) throws HibernateException {
- return ( (TimeZone) value ).getID();
- }
-
- public int compare(Object x, Object y, EntityMode entityMode) {
- return ( (TimeZone) x ).getID().compareTo( ( (TimeZone) y ).getID() );
- }
-
- public Object fromStringValue(String xml) throws HibernateException {
- return TimeZone.getTimeZone(xml);
- }
-
- public Class getReturnedClass() {
- return TimeZone.class;
- }
-
public String getName() {
return "timezone";
}
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return ( (LiteralType) Hibernate.STRING ).objectToSQLString(
- ( (TimeZone) value ).getID(), dialect
- );
+ @Override
+ protected boolean registerUnderJavaType() {
+ return true;
}
-}
+ public String objectToSQLString(TimeZone value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( value.getID(), dialect );
+ }
-
-
-
-
-
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/TimestampType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TimestampType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TimestampType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,139 +20,66 @@
* 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.Timestamp;
-import java.sql.Types;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Comparator;
+import java.util.Date;
-import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.util.ComparableComparator;
+import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor;
+import org.hibernate.type.descriptor.sql.TimestampTypeDescriptor;
/**
- * <tt>timestamp</tt>: A type that maps an SQL TIMESTAMP to a Java
- * java.util.Date or java.sql.Timestamp.
+ * A type that maps between {@link java.sql.Types#TIMESTAMP TIMESTAMP} and {@link java.sql.Timestamp}
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class TimestampType extends MutableType implements VersionType, LiteralType {
+public class TimestampType
+ extends AbstractSingleColumnStandardBasicType<Date>
+ implements VersionType<Date>, LiteralType<Date> {
- private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss";
+ public static final TimestampType INSTANCE = new TimestampType();
- public Object get(ResultSet rs, String name) throws SQLException {
- return rs.getTimestamp(name);
+ public TimestampType() {
+ super( TimestampTypeDescriptor.INSTANCE, JdbcTimestampTypeDescriptor.INSTANCE );
}
-
- public Class getReturnedClass() {
- return java.util.Date.class;
- }
-
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- Timestamp ts;
- if (value instanceof Timestamp) {
- ts = (Timestamp) value;
- }
- else {
- ts = new Timestamp( ( (java.util.Date) value ).getTime() );
- }
- st.setTimestamp(index, ts);
- }
- public int sqlType() {
- return Types.TIMESTAMP;
+ public String getName() {
+ return "timestamp";
}
-
- public String getName() { return "timestamp"; }
- public String toString(Object val) {
- return new SimpleDateFormat(TIMESTAMP_FORMAT).format( (java.util.Date) val );
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), Timestamp.class.getName(), java.util.Date.class.getName() };
}
- public Object deepCopyNotNull(Object value) {
- if ( value instanceof Timestamp ) {
- Timestamp orig = (Timestamp) value;
- Timestamp ts = new Timestamp( orig.getTime() );
- ts.setNanos( orig.getNanos() );
- return ts;
- }
- else {
- java.util.Date orig = (java.util.Date) value;
- return new java.util.Date( orig.getTime() );
- }
- }
-
- public boolean isEqual(Object x, Object y) {
-
- if (x==y) return true;
- if (x==null || y==null) return false;
-
- long xTime = ( (java.util.Date) x ).getTime();
- long yTime = ( (java.util.Date) y ).getTime();
- boolean xts = x instanceof Timestamp;
- boolean yts = y instanceof Timestamp;
- int xNanos = xts ? ( (Timestamp) x ).getNanos() : 0;
- int yNanos = yts ? ( (Timestamp) y ).getNanos() : 0;
- if ( !Environment.jvmHasJDK14Timestamp() ) {
- xTime += xNanos / 1000000;
- yTime += yNanos / 1000000;
- }
- if ( xTime!=yTime ) return false;
- if (xts && yts) {
- // both are Timestamps
- int xn = xNanos % 1000000;
- int yn = yNanos % 1000000;
- return xn==yn;
- }
- else {
- // at least one is a plain old Date
- return true;
- }
-
- }
-
- public int getHashCode(Object x, EntityMode entityMode) {
- java.util.Date ts = (java.util.Date) x;
- return new Long( ts.getTime() / 1000 ).hashCode();
- }
-
- public Object next(Object current, SessionImplementor session) {
+ public Date next(Date current, SessionImplementor session) {
return seed( session );
}
- public Object seed(SessionImplementor session) {
+ public Date seed(SessionImplementor session) {
return new Timestamp( System.currentTimeMillis() );
}
- public Comparator getComparator() {
- return ComparableComparator.INSTANCE;
+ public Comparator<Date> getComparator() {
+ return getJavaTypeDescriptor().getComparator();
}
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return '\'' + new Timestamp( ( (java.util.Date) value ).getTime() ).toString() + '\'';
+ public String objectToSQLString(Date value, Dialect dialect) throws Exception {
+ final Timestamp ts = Timestamp.class.isInstance( value )
+ ? ( Timestamp ) value
+ : new Timestamp( value.getTime() );
+ // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd hh:mm:ss[.f...] format
+ return StringType.INSTANCE.objectToSQLString( ts.toString(), dialect );
}
- public Object fromStringValue(String xml) throws HibernateException {
- try {
- return new Timestamp( new SimpleDateFormat(TIMESTAMP_FORMAT).parse(xml).getTime() );
- }
- catch (ParseException pe) {
- throw new HibernateException("could not parse XML", pe);
- }
+ public Date fromStringValue(String xml) throws HibernateException {
+ return fromString( xml );
}
}
-
-
-
-
-
Modified: core/trunk/core/src/main/java/org/hibernate/type/TrueFalseType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TrueFalseType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TrueFalseType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,22 +20,50 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
+import java.io.Serializable;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
+import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
+
/**
- * <tt>true_false</tt>: A type that maps an SQL CHAR(1) to a Java Boolean.
+ * A type that maps between {@link java.sql.Types#CHAR CHAR(1)} and {@link Boolean} (using 'T' and 'F')
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class TrueFalseType extends CharBooleanType {
+public class TrueFalseType
+ extends AbstractSingleColumnStandardBasicType<Boolean>
+ implements PrimitiveType<Boolean>, DiscriminatorType<Boolean> {
- protected final String getTrueString() {
- return "T";
+ public static final TrueFalseType INSTANCE = new TrueFalseType();
+
+ public TrueFalseType() {
+ super( CharTypeDescriptor.INSTANCE, new BooleanTypeDescriptor( 'T', 'F' ) );
}
- protected final String getFalseString() {
- return "F";
+
+ public String getName() {
+ return "true_false";
}
- public String getName() { return "true_false"; }
+ public Class getPrimitiveClass() {
+ return boolean.class;
+ }
+
+ public Boolean stringToObject(String xml) throws Exception {
+ return fromString( xml );
+ }
+
+ public Serializable getDefaultValue() {
+ return Boolean.FALSE;
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String objectToSQLString(Boolean value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( value.booleanValue() ? "T" : "F", dialect );
+ }
+
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/Type.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/Type.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/Type.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -39,170 +38,242 @@
import org.hibernate.engine.SessionImplementor;
/**
- * Defines a mapping from a Java type to an JDBC datatype. This interface is intended to
- * be implemented by applications that need custom types.<br>
- * <br>
- * Implementors should usually be immutable and <b>must</b> certainly be threadsafe.
+ * Defines a mapping between a Java type and one or more JDBC {@linkplain java.sql.Types types}, as well
+ * as describing the in-memory semantics of the given java type (how do we check it for 'dirtiness', how do
+ * we copy values, etc).
+ * <p/>
+ * Application developers needing custom types can implement this interface (either directly or via subclassing an
+ * existing impl) or by the (slightly more stable, though more limited) {@link org.hibernate.usertype.UserType}
+ * interface.
+ * <p/>
+ * Implementations of this interface must certainly be thread-safe. It is recommended that they be immutable as
+ * well, though that is difficult to achieve completely given the no-arg constructor requirement for custom types.
*
* @author Gavin King
+ * @author Steve Ebersole
*/
public interface Type extends Serializable {
-
/**
- * Return true if the implementation is castable to
- * <tt>AssociationType</tt>. This does not necessarily imply that
- * the type actually represents an association.
- * @see AssociationType
- * @return boolean
+ * Return true if the implementation is castable to {@link AssociationType}. This does not necessarily imply that
+ * the type actually represents an association. Essentially a polymorphic version of
+ * {@code (type instanceof AssociationType.class)}
+ *
+ * @return True if this type is also an {@link AssociationType} implementor; false otherwise.
*/
public boolean isAssociationType();
+
/**
- * Is this type a collection type.
+ * Return true if the implementation is castable to {@link CollectionType}. Essentially a polymorphic version of
+ * {@code (type instanceof CollectionType.class)}
+ * <p/>
+ * A {@link CollectionType} is additionally an {@link AssociationType}; so if this method returns true,
+ * {@link #isAssociationType()} should also return true.
+ *
+ * @return True if this type is also an {@link CollectionType} implementor; false otherwise.
*/
public boolean isCollectionType();
/**
- * Is this type a component type. If so, the implementation
- * must be castable to <tt>AbstractComponentType</tt>. A component
- * type may own collections or associations and hence must provide
- * certain extra functionality.
- * @see AbstractComponentType
- * @return boolean
+ * Return true if the implementation is castable to {@link EntityType}. Essentially a polymorphic
+ * version of {@code (type instanceof EntityType.class)}.
+ * <p/>
+ * An {@link EntityType} is additionally an {@link AssociationType}; so if this method returns true,
+ * {@link #isAssociationType()} should also return true.
+ *
+ * @return True if this type is also an {@link EntityType} implementor; false otherwise.
*/
- public boolean isComponentType();
+ public boolean isEntityType();
/**
- * Is this type an entity type?
- * @return boolean
+ * Return true if the implementation is castable to {@link AnyType}. Essentially a polymorphic
+ * version of {@code (type instanceof AnyType.class)}.
+ * <p/>
+ * An {@link AnyType} is additionally an {@link AssociationType}; so if this method returns true,
+ * {@link #isAssociationType()} should also return true.
+ *
+ * @return True if this type is also an {@link AnyType} implementor; false otherwise.
*/
- public boolean isEntityType();
+ public boolean isAnyType();
/**
- * Is this an "any" type.
+ * Return true if the implementation is castable to {@link AbstractComponentType}. Essentially a polymorphic
+ * version of {@code (type instanceof AbstractComponentType.class)}. A component type may own collections or
+ * associations and hence must provide certain extra functionality.
*
- * i.e. a reference to a persistent entity
- * that is not modelled as a (foreign key) association.
+ * @return True if this type is also an {@link CollectionType} implementor; false otherwise.
*/
- public boolean isAnyType();
-
- public boolean isXMLElement();
+ public boolean isComponentType();
/**
- * Return the SQL type codes for the columns mapped by this type. The codes
- * are defined on <tt>java.sql.Types</tt>.
- * @see java.sql.Types
- * @return the typecodes
- * @throws MappingException
+ * Return the JDBC types codes (per {@link java.sql.Types}) for the columns mapped by this type.
+ *
+ * @param mapping The mapping object :/
+ *
+ * @return The JDBC type codes.
+ *
+ * @throws MappingException Generally indicates an issue accessing the passed mapping object.
*/
public int[] sqlTypes(Mapping mapping) throws MappingException;
/**
- * How many columns are used to persist this type.
+ * How many columns are used to persist this type. Always the same as {@code sqlTypes(mapping).length}
+ *
+ * @param mapping The mapping object :/
+ *
+ * @return The number of columns
+ *
+ * @throws MappingException Generally indicates an issue accessing the passed mapping object.
*/
public int getColumnSpan(Mapping mapping) throws MappingException;
/**
- * The class returned by <tt>nullSafeGet()</tt> methods. This is used to
- * establish the class of an array of this type.
+ * The class returned by {@link #nullSafeGet} methods. This is used to establish the class of an array of
+ * this type.
*
- * @return Class
+ * @return The java type class handled by this type.
*/
public Class getReturnedClass();
+
+ public boolean isXMLElement();
/**
- * Compare two instances of the class mapped by this type for persistence
- * "equality" - equality of persistent state - taking a shortcut for
- * entity references.
- * @param x
- * @param y
- * @param entityMode
+ * Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
+ * state) taking a shortcut for entity references.
+ * <p/>
+ * For most types this should equate to {@link #equals} check on the values. For associations the implication
+ * is a bit different. For most types it is conceivable to simply delegate to {@link #isEqual}
*
- * @return boolean
- * @throws HibernateException
+ * @param x The first value
+ * @param y The second value
+ * @param entityMode The entity mode of the values.
+ *
+ * @return True if there are considered the same (see discussion above).
+ *
+ * @throws HibernateException A problem occurred performing the comparison
*/
public boolean isSame(Object x, Object y, EntityMode entityMode) throws HibernateException;
/**
- * Compare two instances of the class mapped by this type for persistence
- * "equality" - equality of persistent state.
- * @param x
- * @param y
- * @param entityMode
+ * Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
+ * state).
+ * <p/>
+ * This should always equate to some form of comparison of the value's internal state. As an example, for
+ * something like a date the comparison should be based on its internal "time" state based on the specific portion
+ * it is meant to represent (timestamp, date, time).
*
- * @return boolean
- * @throws HibernateException
+ * @param x The first value
+ * @param y The second value
+ * @param entityMode The entity mode of the values.
+ *
+ * @return True if there are considered equal (see discussion above).
+ *
+ * @throws HibernateException A problem occurred performing the comparison
*/
public boolean isEqual(Object x, Object y, EntityMode entityMode) throws HibernateException;
/**
- * Compare two instances of the class mapped by this type for persistence
- * "equality" - equality of persistent state.
- * @param x
- * @param y
- * @param entityMode
+ * Compare two instances of the class mapped by this type for persistence "equality" (equality of persistent
+ * state).
+ * <p/>
+ * This should always equate to some form of comparison of the value's internal state. As an example, for
+ * something like a date the comparison should be based on its internal "time" state based on the specific portion
+ * it is meant to represent (timestamp, date, time).
*
- * @return boolean
- * @throws HibernateException
+ * @param x The first value
+ * @param y The second value
+ * @param entityMode The entity mode of the values.
+ * @param factory The session factory
+ *
+ * @return True if there are considered equal (see discussion above).
+ *
+ * @throws HibernateException A problem occurred performing the comparison
*/
- public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory)
- throws HibernateException;
+ public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory)
+ throws HibernateException;
/**
- * Get a hashcode, consistent with persistence "equality"
- * @param x
- * @param entityMode
+ * Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to
+ * delegate to the value's {@link #hashCode}.
+ *
+ * @param x The value for which to retrieve a hash code
+ * @param entityMode The entity mode of the value.
+ *
+ * @return The hash code
+ *
+ * @throws HibernateException A problem occurred calculating the hash code
*/
public int getHashCode(Object x, EntityMode entityMode) throws HibernateException;
/**
- * Get a hashcode, consistent with persistence "equality"
- * @param x
- * @param entityMode
- * @param factory
+ * Get a hash code, consistent with persistence "equality". Again for most types the normal usage is to
+ * delegate to the value's {@link #hashCode}.
+ *
+ * @param x The value for which to retrieve a hash code
+ * @param entityMode The entity mode of the value.
+ * @param factory The session factory
+ *
+ * @return The hash code
+ *
+ * @throws HibernateException A problem occurred calculating the hash code
*/
- public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory)
- throws HibernateException;
+ public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory) throws HibernateException;
/**
- * compare two instances of the type
- * @param entityMode
+ * Perform a {@link java.util.Comparator} style comparison between values
+ *
+ * @param x The first value
+ * @param y The second value
+ * @param entityMode The entity mode of the values.
+ *
+ * @return The comparison result. See {@link java.util.Comparator#compare} for a discussion.
*/
public int compare(Object x, Object y, EntityMode entityMode);
/**
- * Should the parent be considered dirty, given both the old and current field or
- * element value?
+ * Should the parent be considered dirty, given both the old and current value?
*
* @param old the old value
* @param current the current value
- * @param session
+ * @param session The session from which the request originated.
+ *
* @return true if the field is dirty
+ *
+ * @throws HibernateException A problem occurred performing the checking
*/
- public boolean isDirty(Object old, Object current, SessionImplementor session)
- throws HibernateException;
+ public boolean isDirty(Object old, Object current, SessionImplementor session) throws HibernateException;
+
/**
- * Should the parent be considered dirty, given both the old and current field or
- * element value?
- *
- * @param old the old value
- * @param current the current value
- * @param checkable which columns are actually updatable
- * @param session
+ * Should the parent be considered dirty, given both the old and current value?
+ *
+ * @param oldState the old value
+ * @param currentState the current value
+ * @param checkable An array of booleans indicating which columns making up the value are actually checkable
+ * @param session The session from which the request originated.
+ *
* @return true if the field is dirty
+ *
+ * @throws HibernateException A problem occurred performing the checking
*/
- public boolean isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
- throws HibernateException;
+ public boolean isDirty(Object oldState, Object currentState, boolean[] checkable, SessionImplementor session)
+ throws HibernateException;
/**
- * Has the parent object been modified, compared to the current database state?
- * @param oldHydratedState the database state, in a "hydrated" form, with identifiers unresolved
+ * Has the value been modified compared to the current database state? The difference between this
+ * and the {@link #isDirty} methods is that here we need to account for "partially" built values. This is really
+ * only an issue with association types. For most type implementations it is enough to simply delegate to
+ * {@link #isDirty} here/
+ *
+ * @param dbState the database state, in a "hydrated" form, with identifiers unresolved
* @param currentState the current state of the object
* @param checkable which columns are actually updatable
- * @param session
+ * @param session The session from which the request originated.
+ *
* @return true if the field has been modified
+ *
+ * @throws HibernateException A problem occurred performing the checking
*/
- public boolean isModified(Object oldHydratedState, Object currentState, boolean[] checkable, SessionImplementor session)
- throws HibernateException;
+ public boolean isModified(Object dbState, Object currentState, boolean[] checkable, SessionImplementor session)
+ throws HibernateException;
/**
* Retrieve an instance of the mapped class from a JDBC resultset. Implementors
Modified: core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,147 +20,148 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Collections;
import java.util.Comparator;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
import java.util.Properties;
-import java.util.TimeZone;
-import org.hibernate.Hibernate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.classic.Lifecycle;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
-import org.hibernate.intercept.LazyPropertyInitializer;
-import org.hibernate.property.BackrefPropertyAccessor;
import org.hibernate.tuple.StandardProperty;
import org.hibernate.usertype.CompositeUserType;
-import org.hibernate.usertype.UserType;
import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.usertype.UserType;
import org.hibernate.util.ReflectHelper;
/**
* Used internally to obtain instances of <tt>Type</tt>. Applications should use static methods
* and constants on <tt>org.hibernate.Hibernate</tt>.
*
- * @see org.hibernate.Hibernate
* @author Gavin King
+ * @author Steve Ebersole
*/
-public final class TypeFactory {
+@SuppressWarnings({ "unchecked" })
+public final class TypeFactory implements Serializable {
+ private static final Logger log = LoggerFactory.getLogger( TypeFactory.class );
- private static final Map BASIC_TYPES;
+ private final TypeScopeImpl typeScope = new TypeScopeImpl();
- static {
- HashMap basics = new HashMap();
- basics.put( boolean.class.getName(), Hibernate.BOOLEAN );
- basics.put( long.class.getName(), Hibernate.LONG );
- basics.put( short.class.getName(), Hibernate.SHORT );
- basics.put( int.class.getName(), Hibernate.INTEGER );
- basics.put( byte.class.getName(), Hibernate.BYTE );
- basics.put( float.class.getName(), Hibernate.FLOAT );
- basics.put( double.class.getName(), Hibernate.DOUBLE );
- basics.put( char.class.getName(), Hibernate.CHARACTER );
- basics.put( Hibernate.CHARACTER.getName(), Hibernate.CHARACTER );
- basics.put( Hibernate.INTEGER.getName(), Hibernate.INTEGER );
- basics.put( Hibernate.STRING.getName(), Hibernate.STRING );
- basics.put( Hibernate.DATE.getName(), Hibernate.DATE );
- basics.put( Hibernate.TIME.getName(), Hibernate.TIME );
- basics.put( Hibernate.TIMESTAMP.getName(), Hibernate.TIMESTAMP );
- basics.put( "dbtimestamp", new DbTimestampType() );
- basics.put( Hibernate.LOCALE.getName(), Hibernate.LOCALE );
- basics.put( Hibernate.CALENDAR.getName(), Hibernate.CALENDAR );
- basics.put( Hibernate.CALENDAR_DATE.getName(), Hibernate.CALENDAR_DATE );
- basics.put( Hibernate.CURRENCY.getName(), Hibernate.CURRENCY );
- basics.put( Hibernate.TIMEZONE.getName(), Hibernate.TIMEZONE );
- basics.put( Hibernate.CLASS.getName(), Hibernate.CLASS );
- basics.put( Hibernate.TRUE_FALSE.getName(), Hibernate.TRUE_FALSE );
- basics.put( Hibernate.YES_NO.getName(), Hibernate.YES_NO );
- basics.put( Hibernate.BINARY.getName(), Hibernate.BINARY );
- basics.put( Hibernate.IMAGE.getName(), Hibernate.IMAGE );
- basics.put( Hibernate.TEXT.getName(), Hibernate.TEXT );
- basics.put( Hibernate.MATERIALIZED_BLOB.getName(), Hibernate.MATERIALIZED_BLOB );
- basics.put( Hibernate.MATERIALIZED_CLOB.getName(), Hibernate.MATERIALIZED_CLOB );
- basics.put( Hibernate.BLOB.getName(), Hibernate.BLOB );
- basics.put( Hibernate.CLOB.getName(), Hibernate.CLOB );
- basics.put( Hibernate.BIG_DECIMAL.getName(), Hibernate.BIG_DECIMAL );
- basics.put( Hibernate.BIG_INTEGER.getName(), Hibernate.BIG_INTEGER );
- basics.put( Hibernate.SERIALIZABLE.getName(), Hibernate.SERIALIZABLE );
- basics.put( Hibernate.OBJECT.getName(), Hibernate.OBJECT );
- basics.put( Boolean.class.getName(), Hibernate.BOOLEAN );
- basics.put( Long.class.getName(), Hibernate.LONG );
- basics.put( Short.class.getName(), Hibernate.SHORT );
- basics.put( Integer.class.getName(), Hibernate.INTEGER );
- basics.put( Byte.class.getName(), Hibernate.BYTE );
- basics.put( Float.class.getName(), Hibernate.FLOAT );
- basics.put( Double.class.getName(), Hibernate.DOUBLE );
- basics.put( Character.class.getName(), Hibernate.CHARACTER );
- basics.put( String.class.getName(), Hibernate.STRING );
- basics.put( java.util.Date.class.getName(), Hibernate.TIMESTAMP );
- basics.put( Time.class.getName(), Hibernate.TIME );
- basics.put( Timestamp.class.getName(), Hibernate.TIMESTAMP );
- basics.put( java.sql.Date.class.getName(), Hibernate.DATE );
- basics.put( BigDecimal.class.getName(), Hibernate.BIG_DECIMAL );
- basics.put( BigInteger.class.getName(), Hibernate.BIG_INTEGER );
- basics.put( Locale.class.getName(), Hibernate.LOCALE );
- basics.put( Calendar.class.getName(), Hibernate.CALENDAR );
- basics.put( GregorianCalendar.class.getName(), Hibernate.CALENDAR );
- if ( CurrencyType.CURRENCY_CLASS != null ) {
- basics.put( CurrencyType.CURRENCY_CLASS.getName(), Hibernate.CURRENCY );
+ public static interface TypeScope extends Serializable {
+ public SessionFactoryImplementor resolveFactory();
+ }
+
+ private static class TypeScopeImpl implements TypeFactory.TypeScope {
+ private SessionFactoryImplementor factory;
+
+ public void injectSessionFactory(SessionFactoryImplementor factory) {
+ if ( factory != null ) {
+ log.warn( "Scoping types to session factory7 after already scoped" );
+ }
+ this.factory = factory;
}
- basics.put( TimeZone.class.getName(), Hibernate.TIMEZONE );
- basics.put( Object.class.getName(), Hibernate.OBJECT );
- basics.put( Class.class.getName(), Hibernate.CLASS );
- basics.put( byte[].class.getName(), Hibernate.BINARY );
- basics.put( "byte[]", Hibernate.BINARY );
- basics.put( Byte[].class.getName(), Hibernate.WRAPPER_BINARY );
- basics.put( "Byte[]", Hibernate.WRAPPER_BINARY );
- basics.put( char[].class.getName(), Hibernate.CHAR_ARRAY );
- basics.put( "char[]", Hibernate.CHAR_ARRAY );
- basics.put( Character[].class.getName(), Hibernate.CHARACTER_ARRAY );
- basics.put( "Character[]", Hibernate.CHARACTER_ARRAY );
- basics.put( Blob.class.getName(), Hibernate.BLOB );
- basics.put( Clob.class.getName(), Hibernate.CLOB );
- basics.put( Serializable.class.getName(), Hibernate.SERIALIZABLE );
- Type type = new AdaptedImmutableType(Hibernate.DATE);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.TIME);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.TIMESTAMP);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType( new DbTimestampType() );
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.CALENDAR);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.CALENDAR_DATE);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.SERIALIZABLE);
- basics.put( type.getName(), type );
- type = new AdaptedImmutableType(Hibernate.BINARY);
- basics.put( type.getName(), type );
+ public SessionFactoryImplementor resolveFactory() {
+ if ( factory == null ) {
+ throw new HibernateException( "SessionFactory for type scoping not yet known" );
+ }
+ return factory;
+ }
+ }
- BASIC_TYPES = Collections.unmodifiableMap( basics );
+ public void injectSessionFactory(SessionFactoryImplementor factory) {
+ typeScope.injectSessionFactory( factory );
}
- private TypeFactory() {
- throw new UnsupportedOperationException();
+ public Type byClass(Class clazz, Properties parameters) {
+ if ( Type.class.isAssignableFrom( clazz ) ) {
+ return type( (Class<Type>) clazz, parameters );
+ }
+
+ if ( CompositeUserType.class.isAssignableFrom( clazz ) ) {
+ return customComponent( (Class<CompositeUserType>) clazz, parameters );
+ }
+
+ if ( UserType.class.isAssignableFrom( clazz ) ) {
+ return custom( (Class<UserType>) clazz, parameters );
+ }
+
+ if ( Lifecycle.class.isAssignableFrom( clazz ) ) {
+ // not really a many-to-one association *necessarily*
+ return new ManyToOneType( clazz.getName() );
+ }
+
+ if ( Serializable.class.isAssignableFrom( clazz ) ) {
+ return serializable( clazz );
+ }
+
+ return null;
}
+ public Type type(Class<Type> typeClass, Properties parameters) {
+ try {
+ Type type = typeClass.newInstance();
+ injectParameters( type, parameters );
+ return type;
+ }
+ catch (Exception e) {
+ throw new MappingException( "Could not instantiate Type: " + typeClass.getName(), e );
+ }
+ }
+
+ public static void injectParameters(Object type, Properties parameters) {
+ if ( ParameterizedType.class.isInstance( type ) ) {
+ ( (ParameterizedType) type ).setParameterValues(parameters);
+ }
+ else if ( parameters!=null && !parameters.isEmpty() ) {
+ throw new MappingException( "type is not parameterized: " + type.getClass().getName() );
+ }
+ }
+
+ public static CompositeCustomType customComponent(Class<CompositeUserType> typeClass, Properties parameters) {
+ try {
+ CompositeUserType userType = typeClass.newInstance();
+ injectParameters( userType, parameters );
+ return new CompositeCustomType( userType );
+ }
+ catch ( Exception e ) {
+ throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e );
+ }
+ }
+
+ public static CustomType custom(Class<UserType> typeClass, Properties parameters) {
+ try {
+ UserType userType = typeClass.newInstance();
+ injectParameters( userType, parameters );
+ return new CustomType( userType );
+ }
+ catch ( Exception e ) {
+ throw new MappingException( "Unable to instantiate custom type: " + typeClass.getName(), e );
+ }
+ }
+
/**
+ * Build a {@link SerializableType} from the given {@link Serializable} class.
+ *
+ * @param serializableClass The {@link Serializable} class.
+ * @param <T> The actual class type (extends Serializable)
+ *
+ * @return The built {@link SerializableType}
+ */
+ public static <T extends Serializable> SerializableType<T> serializable(Class<T> serializableClass) {
+ return new SerializableType<T>( serializableClass );
+ }
+
+
+ /**
* A one-to-one association type for the given class
*/
public static EntityType oneToOne(
@@ -245,68 +246,6 @@
}
/**
- * Given the name of a Hibernate basic type, return an instance of
- * <tt>org.hibernate.type.Type</tt>.
- */
- public static Type basic(String name) {
- return (Type) BASIC_TYPES.get( name );
- }
-
- /**
- * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class.
- * Return an instance of <tt>org.hibernate.type.Type</tt>.
- */
- public static Type heuristicType(String typeName) throws MappingException {
- return heuristicType( typeName, null );
- }
-
- /**
- * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class.
- * Return an instance of <tt>org.hibernate.type.Type</tt>.
- */
- public static Type heuristicType(String typeName, Properties parameters)
- throws MappingException {
- Type type = TypeFactory.basic( typeName );
- if ( type == null ) {
- Class typeClass;
- try {
- typeClass = ReflectHelper.classForName( typeName );
- }
- catch (ClassNotFoundException cnfe) {
- typeClass = null;
- }
- if ( typeClass != null ) {
- if ( Type.class.isAssignableFrom( typeClass ) ) {
- try {
- type = (Type) typeClass.newInstance();
- }
- catch (Exception e) {
- throw new MappingException(
- "Could not instantiate Type: " + typeClass.getName(),
- e
- );
- }
- injectParameters(type, parameters);
- }
- else if ( CompositeUserType.class.isAssignableFrom( typeClass ) ) {
- type = new CompositeCustomType( typeClass, parameters );
- }
- else if ( UserType.class.isAssignableFrom( typeClass ) ) {
- type = new CustomType( typeClass, parameters );
- }
- else if ( Lifecycle.class.isAssignableFrom( typeClass ) ) {
- type = Hibernate.entity( typeClass );
- }
- else if ( Serializable.class.isAssignableFrom( typeClass ) ) {
- type = Hibernate.serializable( typeClass );
- }
- }
- }
- return type;
-
- }
-
- /**
* The legacy contract.
*
* @deprecated Use {@link #customCollection(String, java.util.Properties, String, String, boolean)} instead
@@ -384,21 +323,9 @@
return new SortedSetType( role, propertyRef, comparator, embedded );
}
- public static void injectParameters(Object type, Properties parameters) {
- if (type instanceof ParameterizedType) {
- ( (ParameterizedType) type ).setParameterValues(parameters);
- }
- else if ( parameters!=null && !parameters.isEmpty() ) {
- throw new MappingException(
- "type is not parameterized: " +
- type.getClass().getName()
- );
- }
- }
+ // convenience methods relating to operations across arrays of types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // convenience methods relating to operations across arrays of types...
-
/**
* Deep copy a series of values from one array to another...
*
@@ -406,7 +333,9 @@
* @param types The value types
* @param copy an array indicating which values to include in the copy
* @param target The array into which to copy the values
- * @param session The orginating session
+ * @param session The originating session
+ *
+ * @deprecated Use {@link TypeHelper#deepCopy} instead
*/
public static void deepCopy(
final Object[] values,
@@ -414,18 +343,7 @@
final boolean[] copy,
final Object[] target,
final SessionImplementor session) {
- for ( int i = 0; i < types.length; i++ ) {
- if ( copy[i] ) {
- if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || values[i] == BackrefPropertyAccessor.UNKNOWN ) {
- target[i] = values[i];
- }
- else {
- target[i] = types[i].deepCopy( values[i], session.getEntityMode(), session
- .getFactory() );
- }
- }
- }
+ TypeHelper.deepCopy( values, types, copy, target, session );
}
/**
@@ -433,18 +351,15 @@
*
* @param row The values
* @param types The value types
- * @param session The orginating session
+ * @param session The originating session
+ *
+ * @deprecated Use {@link TypeHelper#beforeAssemble} instead
*/
public static void beforeAssemble(
final Serializable[] row,
final Type[] types,
final SessionImplementor session) {
- for ( int i = 0; i < types.length; i++ ) {
- if ( row[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
- && row[i] != BackrefPropertyAccessor.UNKNOWN ) {
- types[i].beforeAssemble( row[i], session );
- }
- }
+ TypeHelper.beforeAssemble( row, types, session );
}
/**
@@ -452,25 +367,19 @@
*
* @param row The values
* @param types The value types
- * @param session The orginating session
+ * @param session The originating session
* @param owner The entity "owning" the values
+ *
* @return The assembled state
+ *
+ * @deprecated Use {@link TypeHelper#assemble} instead
*/
public static Object[] assemble(
final Serializable[] row,
final Type[] types,
final SessionImplementor session,
final Object owner) {
- Object[] assembled = new Object[row.length];
- for ( int i = 0; i < types.length; i++ ) {
- if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
- assembled[i] = row[i];
- }
- else {
- assembled[i] = types[i].assemble( row[i], session, owner );
- }
- }
- return assembled;
+ return TypeHelper.assemble( row, types, session, owner );
}
/**
@@ -478,10 +387,13 @@
*
* @param row The values
* @param types The value types
- * @param nonCacheable An array indicating which values to include in the disassemled state
- * @param session The orginating session
+ * @param nonCacheable An array indicating which values to include in the disassembled state
+ * @param session The originating session
* @param owner The entity "owning" the values
+ *
* @return The disassembled state
+ *
+ * @deprecated Use {@link TypeHelper#disassemble} instead
*/
public static Serializable[] disassemble(
final Object[] row,
@@ -489,19 +401,7 @@
final boolean[] nonCacheable,
final SessionImplementor session,
final Object owner) {
- Serializable[] disassembled = new Serializable[row.length];
- for ( int i = 0; i < row.length; i++ ) {
- if ( nonCacheable!=null && nonCacheable[i] ) {
- disassembled[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
- }
- else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
- disassembled[i] = (Serializable) row[i];
- }
- else {
- disassembled[i] = types[i].disassemble( row[i], session, owner );
- }
- }
- return disassembled;
+ return TypeHelper.disassemble( row, types, nonCacheable, session, owner );
}
/**
@@ -510,10 +410,13 @@
* @param original The source of the state
* @param target The target into which to replace the source values.
* @param types The value types
- * @param session The orginating session
+ * @param session The originating session
* @param owner The entity "owning" the values
* @param copyCache A map representing a cache of already replaced state
+ *
* @return The replaced state
+ *
+ * @deprecated Use {@link TypeHelper#replace} instead
*/
public static Object[] replace(
final Object[] original,
@@ -522,17 +425,7 @@
final SessionImplementor session,
final Object owner,
final Map copyCache) {
- Object[] copied = new Object[original.length];
- for ( int i = 0; i < types.length; i++ ) {
- if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
- copied[i] = target[i];
- }
- else {
- copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache );
- }
- }
- return copied;
+ return TypeHelper.replace( original, target, types, session, owner, copyCache );
}
/**
@@ -541,11 +434,14 @@
* @param original The source of the state
* @param target The target into which to replace the source values.
* @param types The value types
- * @param session The orginating session
+ * @param session The originating session
* @param owner The entity "owning" the values
* @param copyCache A map representing a cache of already replaced state
* @param foreignKeyDirection FK directionality to be applied to the replacement
+ *
* @return The replaced state
+ *
+ * @deprecated Use {@link TypeHelper#replace} instead
*/
public static Object[] replace(
final Object[] original,
@@ -555,34 +451,27 @@
final Object owner,
final Map copyCache,
final ForeignKeyDirection foreignKeyDirection) {
- Object[] copied = new Object[original.length];
- for ( int i = 0; i < types.length; i++ ) {
- if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
- copied[i] = target[i];
- }
- else {
- copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
- }
- }
- return copied;
+ return TypeHelper.replace( original, target, types, session, owner, copyCache, foreignKeyDirection );
}
/**
* Apply the {@link Type#replace} operation across a series of values, as
* long as the corresponding {@link Type} is an association.
* <p/>
- * If the corresponding type is a component type, then apply {@link #replaceAssociations}
- * accross the component subtypes but do not replace the component value itself.
+ * If the corresponding type is a component type, then apply {@link Type#replace}
+ * across the component subtypes but do not replace the component value itself.
*
* @param original The source of the state
* @param target The target into which to replace the source values.
* @param types The value types
- * @param session The orginating session
+ * @param session The originating session
* @param owner The entity "owning" the values
* @param copyCache A map representing a cache of already replaced state
* @param foreignKeyDirection FK directionality to be applied to the replacement
+ *
* @return The replaced state
+ *
+ * @deprecated Use {@link TypeHelper#replaceAssociations} instead
*/
public static Object[] replaceAssociations(
final Object[] original,
@@ -592,29 +481,7 @@
final Object owner,
final Map copyCache,
final ForeignKeyDirection foreignKeyDirection) {
- Object[] copied = new Object[original.length];
- for ( int i = 0; i < types.length; i++ ) {
- if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
- copied[i] = target[i];
- }
- else if ( types[i].isComponentType() ) {
- // need to extract the component values and check for subtype replacements...
- AbstractComponentType componentType = ( AbstractComponentType ) types[i];
- Type[] subtypes = componentType.getSubtypes();
- Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
- Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
- replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
- copied[i] = target[i];
- }
- else if ( !types[i].isAssociationType() ) {
- copied[i] = target[i];
- }
- else {
- copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
- }
- }
- return copied;
+ return TypeHelper.replaceAssociations( original, target, types, session, owner, copyCache, foreignKeyDirection );
}
/**
@@ -629,7 +496,10 @@
* @param includeColumns Columns to be included in the dirty checking, per property
* @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
* @param session The session from which the dirty check request originated.
+ *
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
+ *
+ * @deprecated Use {@link TypeHelper#findDirty} instead
*/
public static int[] findDirty(
final StandardProperty[] properties,
@@ -638,30 +508,8 @@
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
final SessionImplementor session) {
- int[] results = null;
- int count = 0;
- int span = properties.length;
-
- for ( int i = 0; i < span; i++ ) {
- final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
- && properties[i].isDirtyCheckable( anyUninitializedProperties )
- && properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
- if ( dirty ) {
- if ( results == null ) {
- results = new int[span];
- }
- results[count++] = i;
- }
- }
-
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
+ return TypeHelper.findDirty( properties, currentState, previousState,
+ includeColumns, anyUninitializedProperties, session );
}
/**
@@ -676,7 +524,10 @@
* @param includeColumns Columns to be included in the mod checking, per property
* @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
* @param session The session from which the dirty check request originated.
+ *
* @return Array containing indices of the modified properties, or null if no properties considered modified.
+ *
+ * @deprecated Use {@link TypeHelper#findModified} instead
*/
public static int[] findModified(
final StandardProperty[] properties,
@@ -685,31 +536,8 @@
final boolean[][] includeColumns,
final boolean anyUninitializedProperties,
final SessionImplementor session) {
- int[] results = null;
- int count = 0;
- int span = properties.length;
-
- for ( int i = 0; i < span; i++ ) {
- final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
- && properties[i].isDirtyCheckable(anyUninitializedProperties)
- && properties[i].getType().isModified( previousState[i], currentState[i], includeColumns[i], session );
-
- if ( modified ) {
- if ( results == null ) {
- results = new int[span];
- }
- results[count++] = i;
- }
- }
-
- if ( count == 0 ) {
- return null;
- }
- else {
- int[] trimmed = new int[count];
- System.arraycopy( results, 0, trimmed, 0, count );
- return trimmed;
- }
+ return TypeHelper.findModified( properties, currentState, previousState,
+ includeColumns, anyUninitializedProperties, session );
}
}
Added: core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeHelper.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,359 @@
+/*
+ * 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.io.Serializable;
+import java.util.Map;
+
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.intercept.LazyPropertyInitializer;
+import org.hibernate.property.BackrefPropertyAccessor;
+import org.hibernate.tuple.StandardProperty;
+
+/**
+ * Collection of convenience methods relating to operations across arrays of types...
+ *
+ * @author Steve Ebersole
+ */
+public class TypeHelper {
+ /**
+ * Disallow instantiation
+ */
+ private TypeHelper() {
+ }
+
+ /**
+ * Deep copy a series of values from one array to another...
+ *
+ * @param values The values to copy (the source)
+ * @param types The value types
+ * @param copy an array indicating which values to include in the copy
+ * @param target The array into which to copy the values
+ * @param session The originating session
+ */
+ public static void deepCopy(
+ final Object[] values,
+ final Type[] types,
+ final boolean[] copy,
+ final Object[] target,
+ final SessionImplementor session) {
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( copy[i] ) {
+ if ( values[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
+ || values[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ target[i] = values[i];
+ }
+ else {
+ target[i] = types[i].deepCopy( values[i], session.getEntityMode(), session
+ .getFactory() );
+ }
+ }
+ }
+ }
+
+ /**
+ * Apply the {@link Type#beforeAssemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The originating session
+ */
+ public static void beforeAssemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session) {
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( row[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && row[i] != BackrefPropertyAccessor.UNKNOWN ) {
+ types[i].beforeAssemble( row[i], session );
+ }
+ }
+ }
+
+ /**
+ * Apply the {@link Type#assemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param session The originating session
+ * @param owner The entity "owning" the values
+ * @return The assembled state
+ */
+ public static Object[] assemble(
+ final Serializable[] row,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner) {
+ Object[] assembled = new Object[row.length];
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ assembled[i] = row[i];
+ }
+ else {
+ assembled[i] = types[i].assemble( row[i], session, owner );
+ }
+ }
+ return assembled;
+ }
+
+ /**
+ * Apply the {@link Type#disassemble} operation across a series of values.
+ *
+ * @param row The values
+ * @param types The value types
+ * @param nonCacheable An array indicating which values to include in the disassemled state
+ * @param session The originating session
+ * @param owner The entity "owning" the values
+ * @return The disassembled state
+ */
+ public static Serializable[] disassemble(
+ final Object[] row,
+ final Type[] types,
+ final boolean[] nonCacheable,
+ final SessionImplementor session,
+ final Object owner) {
+ Serializable[] disassembled = new Serializable[row.length];
+ for ( int i = 0; i < row.length; i++ ) {
+ if ( nonCacheable!=null && nonCacheable[i] ) {
+ disassembled[i] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
+ }
+ else if ( row[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY || row[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ disassembled[i] = (Serializable) row[i];
+ }
+ else {
+ disassembled[i] = types[i].disassemble( row[i], session, owner );
+ }
+ }
+ return disassembled;
+ }
+
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The originating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache) {
+ Object[] copied = new Object[original.length];
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
+ || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ copied[i] = target[i];
+ }
+ else {
+ copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache );
+ }
+ }
+ return copied;
+ }
+
+ /**
+ * Apply the {@link Type#replace} operation across a series of values.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The originating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @param foreignKeyDirection FK directionality to be applied to the replacement
+ * @return The replaced state
+ */
+ public static Object[] replace(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache,
+ final ForeignKeyDirection foreignKeyDirection) {
+ Object[] copied = new Object[original.length];
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
+ || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ copied[i] = target[i];
+ }
+ else {
+ copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
+ }
+ }
+ return copied;
+ }
+
+ /**
+ * Apply the {@link Type#replace} operation across a series of values, as
+ * long as the corresponding {@link Type} is an association.
+ * <p/>
+ * If the corresponding type is a component type, then apply {@link Type#replace}
+ * across the component subtypes but do not replace the component value itself.
+ *
+ * @param original The source of the state
+ * @param target The target into which to replace the source values.
+ * @param types The value types
+ * @param session The originating session
+ * @param owner The entity "owning" the values
+ * @param copyCache A map representing a cache of already replaced state
+ * @param foreignKeyDirection FK directionality to be applied to the replacement
+ *
+ * @return The replaced state
+ */
+ public static Object[] replaceAssociations(
+ final Object[] original,
+ final Object[] target,
+ final Type[] types,
+ final SessionImplementor session,
+ final Object owner,
+ final Map copyCache,
+ final ForeignKeyDirection foreignKeyDirection) {
+ Object[] copied = new Object[original.length];
+ for ( int i = 0; i < types.length; i++ ) {
+ if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
+ || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
+ copied[i] = target[i];
+ }
+ else if ( types[i].isComponentType() ) {
+ // need to extract the component values and check for subtype replacements...
+ AbstractComponentType componentType = ( AbstractComponentType ) types[i];
+ Type[] subtypes = componentType.getSubtypes();
+ Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
+ Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
+ replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
+ copied[i] = target[i];
+ }
+ else if ( !types[i].isAssociationType() ) {
+ copied[i] = target[i];
+ }
+ else {
+ copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
+ }
+ }
+ return copied;
+ }
+
+ /**
+ * Determine if any of the given field values are dirty, returning an array containing
+ * indices of the dirty fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the dirty checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the dirty properties, or null if no properties considered dirty.
+ */
+ public static int[] findDirty(
+ final StandardProperty[] properties,
+ final Object[] currentState,
+ final Object[] previousState,
+ final boolean[][] includeColumns,
+ final boolean anyUninitializedProperties,
+ final SessionImplementor session) {
+ int[] results = null;
+ int count = 0;
+ int span = properties.length;
+
+ for ( int i = 0; i < span; i++ ) {
+ final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && properties[i].isDirtyCheckable( anyUninitializedProperties )
+ && properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
+ if ( dirty ) {
+ if ( results == null ) {
+ results = new int[span];
+ }
+ results[count++] = i;
+ }
+ }
+
+ if ( count == 0 ) {
+ return null;
+ }
+ else {
+ int[] trimmed = new int[count];
+ System.arraycopy( results, 0, trimmed, 0, count );
+ return trimmed;
+ }
+ }
+
+ /**
+ * Determine if any of the given field values are modified, returning an array containing
+ * indices of the modified fields.
+ * <p/>
+ * If it is determined that no fields are dirty, null is returned.
+ *
+ * @param properties The property definitions
+ * @param currentState The current state of the entity
+ * @param previousState The baseline state of the entity
+ * @param includeColumns Columns to be included in the mod checking, per property
+ * @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
+ * @param session The session from which the dirty check request originated.
+ * @return Array containing indices of the modified properties, or null if no properties considered modified.
+ */
+ public static int[] findModified(
+ final StandardProperty[] properties,
+ final Object[] currentState,
+ final Object[] previousState,
+ final boolean[][] includeColumns,
+ final boolean anyUninitializedProperties,
+ final SessionImplementor session) {
+ int[] results = null;
+ int count = 0;
+ int span = properties.length;
+
+ for ( int i = 0; i < span; i++ ) {
+ final boolean modified = currentState[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY
+ && properties[i].isDirtyCheckable(anyUninitializedProperties)
+ && properties[i].getType().isModified( previousState[i], currentState[i], includeColumns[i], session );
+
+ if ( modified ) {
+ if ( results == null ) {
+ results = new int[span];
+ }
+ results[count++] = i;
+ }
+ }
+
+ if ( count == 0 ) {
+ return null;
+ }
+ else {
+ int[] trimmed = new int[count];
+ System.arraycopy( results, 0, trimmed, 0, count );
+ return trimmed;
+ }
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeResolver.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,122 @@
+/*
+ * 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.io.Serializable;
+import java.util.Properties;
+
+import org.hibernate.MappingException;
+import org.hibernate.classic.Lifecycle;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.usertype.UserType;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * Acts as the contract for getting types and as the mediator between {@link BasicTypeRegistry} and {@link TypeFactory}.
+ *
+ * @author Steve Ebersole
+ */
+public class TypeResolver implements Serializable {
+ private final BasicTypeRegistry basicTypeRegistry;
+ private final TypeFactory typeFactory;
+
+ public TypeResolver() {
+ this( new BasicTypeRegistry(), new TypeFactory() );
+ }
+
+ public TypeResolver(BasicTypeRegistry basicTypeRegistry, TypeFactory typeFactory) {
+ this.basicTypeRegistry = basicTypeRegistry;
+ this.typeFactory = typeFactory;
+ }
+
+ public TypeResolver scope(SessionFactoryImplementor factory) {
+ typeFactory.injectSessionFactory( factory );
+ return new TypeResolver( basicTypeRegistry.shallowCopy(), typeFactory );
+ }
+
+ /**
+ * Locate a Hibernate {@linkplain BasicType basic type} given (one of) its registration name(s).
+ *
+ * @param name The registration name
+ *
+ * @return The registered type
+ */
+ public BasicType basic(String name) {
+ return basicTypeRegistry.getRegisteredType( name );
+ }
+
+ /**
+ * See {@link #heuristicType(String, Properties)}
+ *
+ * @param typeName The name (see heuristic algorithm discussion on {@link #heuristicType(String, Properties)}).
+ *
+ * @return The deduced type; may be null.
+ *
+ * @throws MappingException Can be thrown from {@link #heuristicType(String, Properties)}
+ */
+ public Type heuristicType(String typeName) throws MappingException {
+ return heuristicType( typeName, null );
+ }
+
+ /**
+ * Uses heuristics to deduce the proper {@link Type} given a string naming the type or Java class.
+ * <p/>
+ * The search goes as follows:<ol>
+ * <li>search for a basic type with 'typeName' as a registration key</li>
+ * <li>
+ * look for 'typeName' as a class name and<ol>
+ * <li>if it names a {@link Type} implementor, return an instance</li>
+ * <li>if it names a {@link CompositeUserType} or a {@link UserType}, return an instance of class wrapped intot the appropriate {@link Type} adapter</li>
+ * <li>if it implements {@link Lifecycle}, return the corresponding entity type</li>
+ * <li>if it implements {@link Serializable}, return the corresponding serializable type</li>
+ * </ol>
+ * </li>
+ * </ol>
+ *
+ * @param typeName The name (see heuristic algorithm above).
+ * @param parameters Any parameters for the type. Only applied if built!
+ *
+ * @return The deduced type; may be null.
+ *
+ * @throws MappingException Indicates a problem attempting to resolve 'typeName' as a {@link Class}
+ */
+ public Type heuristicType(String typeName, Properties parameters) throws MappingException {
+ Type type = basic( typeName );
+ if ( type != null ) {
+ return type;
+ }
+
+ try {
+ Class typeClass = ReflectHelper.classForName( typeName );
+ if ( typeClass != null ) {
+ return typeFactory.byClass( typeClass, parameters );
+ }
+ }
+ catch ( ClassNotFoundException ignore ) {
+ }
+
+ return null;
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/VersionType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/VersionType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/VersionType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type;
@@ -29,17 +28,19 @@
import org.hibernate.engine.SessionImplementor;
/**
- * A <tt>Type</tt> that may be used to version data.
+ * Additional contract for types which may be used to version (and optimistic lock) data.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public interface VersionType extends Type {
+public interface VersionType<T> extends Type {
/**
* Generate an initial version.
*
* @param session The session from which this request originates.
* @return an instance of the type
*/
- public Object seed(SessionImplementor session);
+ public T seed(SessionImplementor session);
/**
* Increment the version.
@@ -48,14 +49,14 @@
* @param current the current version
* @return an instance of the type
*/
- public Object next(Object current, SessionImplementor session);
+ public T next(T current, SessionImplementor session);
/**
* Get a comparator for version values.
*
* @return The comparator to use to compare different version values.
*/
- public Comparator getComparator();
+ public Comparator<T> getComparator();
/**
* Are the two version values considered equal?
@@ -64,7 +65,7 @@
* @param y The other value to check.
* @return true if the values are equal, false otherwise.
*/
- public boolean isEqual(Object x, Object y);
+ public boolean isEqual(T x, T y);
}
Modified: core/trunk/core/src/main/java/org/hibernate/type/WrapperBinaryType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/WrapperBinaryType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/WrapperBinaryType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,41 +20,28 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
-import org.hibernate.HibernateException;
+import org.hibernate.type.descriptor.java.ByteArrayTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor;
/**
+ * A type mapping {@link java.sql.Types#VARBINARY VARBINARY} and {@link Byte Byte[]}
+ *
* @author Emmanuel Bernard
+ * @author Steve Ebersole
*/
-public class WrapperBinaryType extends AbstractBynaryType {
- protected Object toExternalFormat(byte[] bytes) {
- if (bytes == null) return null;
- int length = bytes.length;
- Byte[] result = new Byte[length];
- for ( int index = 0; index < length ; index++ ) {
- result[index] = new Byte( bytes[index] );
- }
- return result;
- }
+public class WrapperBinaryType extends AbstractSingleColumnStandardBasicType<Byte[]> {
+ public static final WrapperBinaryType INSTANCE = new WrapperBinaryType();
- protected byte[] toInternalFormat(Object val) {
- if (val == null) return null;
- Byte[] bytes = (Byte[]) val;
- int length = bytes.length;
- byte[] result = new byte[length];
- for ( int i = 0; i < length ; i++ ) {
- if (bytes[i] == null)
- throw new HibernateException("Unable to store an Byte[] when one of its element is null");
- result[i] = bytes[i].byteValue();
- }
- return result;
+ public WrapperBinaryType() {
+ super( VarbinaryTypeDescriptor.INSTANCE, ByteArrayTypeDescriptor.INSTANCE );
}
- public Class getReturnedClass() {
- return Byte[].class;
+ @Override
+ public String[] getRegistrationKeys() {
+ return new String[] { getName(), "Byte[]", Byte[].class.getName() };
}
public String getName() {
Added: core/trunk/core/src/main/java/org/hibernate/type/XmlRepresentableType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/XmlRepresentableType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/XmlRepresentableType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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 org.hibernate.HibernateException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+
+/**
+ * Additional, optional contract for types whose values can be represented as XML text (either as attribute or
+ * element value).
+ *
+ * @author Steve Ebersole
+ */
+public interface XmlRepresentableType<T> {
+ public String toXMLString(T value, SessionFactoryImplementor factory) throws HibernateException;
+
+ public T fromXMLString(String xml, Mapping factory) throws HibernateException;
+}
Modified: core/trunk/core/src/main/java/org/hibernate/type/YesNoType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/YesNoType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/YesNoType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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,29 +20,49 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.type;
+import java.io.Serializable;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
+import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
+
/**
- * <tt>yes_no</tt>: A type that maps an SQL CHAR(1) to a Java Boolean.
+ * A type that maps between {@link java.sql.Types#CHAR CHAR(1)} and {@link Boolean} (using 'Y' and 'N')
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class YesNoType extends CharBooleanType {
+public class YesNoType
+ extends AbstractSingleColumnStandardBasicType<Boolean>
+ implements PrimitiveType<Boolean>, DiscriminatorType<Boolean> {
- protected final String getTrueString() {
- return "Y";
+ public static final YesNoType INSTANCE = new YesNoType();
+
+ public YesNoType() {
+ super( CharTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE );
}
- protected final String getFalseString() {
- return "N";
+
+ public String getName() {
+ return "yes_no";
}
- public String getName() { return "yes_no"; }
-}
+ public Class getPrimitiveClass() {
+ return boolean.class;
+ }
+ public Boolean stringToObject(String xml) throws Exception {
+ return fromString( xml );
+ }
+ public Serializable getDefaultValue() {
+ return Boolean.FALSE;
+ }
-
-
-
-
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String objectToSQLString(Boolean value, Dialect dialect) throws Exception {
+ return StringType.INSTANCE.objectToSQLString( value.booleanValue() ? "Y" : "N", dialect );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/AbstractTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/AbstractTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/AbstractTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,123 @@
+/*
+ * 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.Comparator;
+
+import org.hibernate.HibernateException;
+import org.hibernate.util.ComparableComparator;
+import org.hibernate.util.EqualsHelper;
+
+/**
+ * Abstract adapter for Java type descriptors.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractTypeDescriptor<T> implements JavaTypeDescriptor<T>, Serializable {
+ private final Class<T> type;
+ private final MutabilityPlan<T> mutabilityPlan;
+ private final Comparator<T> comparator;
+
+ /**
+ * Initialize a type descriptor for the given type. Assumed immutable.
+ *
+ * @param type The Java type.
+ *
+ * @see #AbstractTypeDescriptor(Class, MutabilityPlan)
+ */
+ @SuppressWarnings({ "unchecked" })
+ protected AbstractTypeDescriptor(Class<T> type) {
+ this( type, (MutabilityPlan<T>) ImmutableMutabilityPlan.INSTANCE );
+ }
+
+ /**
+ * Initialize a type descriptor for the given type. Assumed immutable.
+ *
+ * @param type The Java type.
+ * @param mutabilityPlan The plan for handling mutability aspects of the java type.
+ */
+ @SuppressWarnings({ "unchecked" })
+ protected AbstractTypeDescriptor(Class<T> type, MutabilityPlan<T> mutabilityPlan) {
+ this.type = type;
+ this.mutabilityPlan = mutabilityPlan;
+ this.comparator = Comparable.class.isAssignableFrom( type )
+ ? (Comparator<T>)ComparableComparator.INSTANCE
+ : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MutabilityPlan<T> getMutabilityPlan() {
+ return mutabilityPlan;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Class<T> getJavaTypeClass() {
+ return type;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int extractHashCode(T value) {
+ return value.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean areEqual(T one, T another) {
+ return EqualsHelper.equals( one, another );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Comparator<T> getComparator() {
+ return comparator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String extractLoggableRepresentation(T value) {
+ return (value == null) ? "null" : value.toString();
+ }
+
+ protected HibernateException unknownUnwrap(Class conversionType) {
+ throw new HibernateException(
+ "Unknown unwrap conversion requested: " + type.getName() + " to " + conversionType.getName()
+ );
+ }
+
+ protected HibernateException unknownWrap(Class conversionType) {
+ throw new HibernateException(
+ "Unknown wrap conversion requested: " + conversionType.getName() + " to " + type.getName()
+ );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ArrayMutabilityPlan.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ArrayMutabilityPlan.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ArrayMutabilityPlan.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,48 @@
+/*
+ * 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.lang.reflect.Array;
+
+/**
+ * A mutability plan for arrays. Specifically arrays of immutable element type; since the elements themselves
+ * are immutable, a shallow copy is enough.
+ *
+ * @author Steve Ebersole
+ */
+public class ArrayMutabilityPlan<T> extends MutableMutabilityPlan<T> {
+ public static final ArrayMutabilityPlan INSTANCE = new ArrayMutabilityPlan();
+
+ @SuppressWarnings({ "unchecked", "SuspiciousSystemArraycopy" })
+ public T deepCopyNotNull(T value) {
+ if ( ! value.getClass().isArray() ) {
+ // ugh! cannot find a way to properly define the type signature here to
+ throw new IllegalArgumentException( "Value was not an array [" + value.getClass().getName() + "]" );
+ }
+ final int length = Array.getLength( value );
+ T copy = (T) Array.newInstance( value.getClass().getComponentType(), length );
+ System.arraycopy( value, 0, copy, 0, length );
+ return copy;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigDecimalTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,106 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link BigDecimal} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BigDecimalTypeDescriptor extends AbstractTypeDescriptor<BigDecimal> {
+ public static final BigDecimalTypeDescriptor INSTANCE = new BigDecimalTypeDescriptor();
+
+ public BigDecimalTypeDescriptor() {
+ super( BigDecimal.class );
+ }
+
+ public String toString(BigDecimal value) {
+ return value.toString();
+ }
+
+ public BigDecimal fromString(String string) {
+ return new BigDecimal( string );
+ }
+
+ @Override
+ public boolean areEqual(BigDecimal one, BigDecimal another) {
+ return one == another || ( one != null && another != null && one.compareTo( another ) == 0 );
+ }
+
+ @Override
+ public int extractHashCode(BigDecimal value) {
+ return value.intValue();
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(BigDecimal value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) value.toBigIntegerExact();
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> BigDecimal wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( BigDecimal.class.isInstance( value ) ) {
+ return (BigDecimal) value;
+ }
+ if ( BigInteger.class.isInstance( value ) ) {
+ return new BigDecimal( (BigInteger) value );
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return BigDecimal.valueOf( ( (Number) value ).doubleValue() );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BigIntegerTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.java;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link BigInteger} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BigIntegerTypeDescriptor extends AbstractTypeDescriptor<BigInteger> {
+ public static final BigIntegerTypeDescriptor INSTANCE = new BigIntegerTypeDescriptor();
+
+ public BigIntegerTypeDescriptor() {
+ super( BigInteger.class );
+ }
+
+ public String toString(BigInteger value) {
+ return value.toString();
+ }
+
+ public BigInteger fromString(String string) {
+ return new BigInteger( string );
+ }
+
+ @Override
+ public int extractHashCode(BigInteger value) {
+ return value.intValue();
+ }
+
+ @Override
+ public boolean areEqual(BigInteger one, BigInteger another) {
+ return one == another || ( one != null && another != null && one.compareTo( another ) == 0 );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(BigInteger value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) new BigDecimal( value );
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public <X> BigInteger wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( BigInteger.class.isInstance( value ) ) {
+ return (BigInteger) value;
+ }
+ if ( BigDecimal.class.isInstance( value ) ) {
+ return ( (BigDecimal) value ).toBigIntegerExact();
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return BigInteger.valueOf( ( (Number) value ).longValue() );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BlobTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BlobTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BlobTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,134 @@
+/*
+ * 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.sql.Blob;
+import java.sql.SQLException;
+import java.util.Comparator;
+
+import org.hibernate.HibernateException;
+import org.hibernate.engine.jdbc.BlobProxy;
+import org.hibernate.engine.jdbc.WrappedBlob;
+
+/**
+ * Descriptor for {@link Blob} handling.
+ * <p/>
+ * Note, {@link Blob blobs} really are mutable (their internal state can in fact be mutated). We simply
+ * treat them as immutable because we cannot properly check them for changes nor deep copy them.
+ *
+ * @author Steve Ebersole
+ */
+public class BlobTypeDescriptor extends AbstractTypeDescriptor<Blob> {
+ public static final BlobTypeDescriptor INSTANCE = new BlobTypeDescriptor();
+
+ public static class BlobMutabilityPlan implements MutabilityPlan<Blob> {
+ public static final BlobMutabilityPlan INSTANCE = new BlobMutabilityPlan();
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Blob deepCopy(Blob value) {
+ return value;
+ }
+
+ public Serializable disassemble(Blob value) {
+ throw new UnsupportedOperationException( "Blobs are not cacheable" );
+ }
+
+ public Blob assemble(Serializable cached) {
+ throw new UnsupportedOperationException( "Blobs are not cacheable" );
+ }
+ }
+
+ public BlobTypeDescriptor() {
+ super( Blob.class, BlobMutabilityPlan.INSTANCE );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(Blob value) {
+ final byte[] bytes;
+ try {
+ bytes = DataHelper.extractBytes( value.getBinaryStream() );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access blob stream", e );
+ }
+ return PrimitiveByteArrayTypeDescriptor.INSTANCE.toString( bytes );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Blob fromString(String string) {
+ return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) );
+ }
+
+ @Override
+ @SuppressWarnings({ "unchecked" })
+ public Comparator<Blob> getComparator() {
+ return IncomparableComparator.INSTANCE;
+ }
+
+ @Override
+ public int extractHashCode(Blob value) {
+ return System.identityHashCode( value );
+ }
+
+ @Override
+ public boolean areEqual(Blob one, Blob another) {
+ return one == another;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Blob value, Class<X> type, WrapperOptions options) {
+ if ( !Blob.class.isAssignableFrom( type ) ) {
+ throw unknownUnwrap( type );
+ }
+
+ if ( value == null ) {
+ return null;
+ }
+
+ final Blob blob = WrappedBlob.class.isInstance( value )
+ ? ( (WrappedBlob) value ).getWrappedBlob()
+ : value;
+ return (X) blob;
+ }
+
+ public <X> Blob wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+
+ if ( ! Blob.class.isAssignableFrom( value.getClass() ) ) {
+ throw unknownWrap( value.getClass() );
+ }
+
+ return options.getLobCreator().wrap( (Blob) value );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/BooleanTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,145 @@
+/*
+ * 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 static java.lang.Boolean.TRUE;
+import static java.lang.Boolean.FALSE;
+
+/**
+ * Descriptor for {@link Boolean} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BooleanTypeDescriptor extends AbstractTypeDescriptor<Boolean> {
+ public static final BooleanTypeDescriptor INSTANCE = new BooleanTypeDescriptor();
+
+ private final char characterValueTrue;
+ private final char characterValueFalse;
+
+ private final char characterValueTrueLC;
+
+ private final String stringValueTrue;
+ private final String stringValueFalse;
+
+ public BooleanTypeDescriptor() {
+ this( 'Y', 'N' );
+ }
+
+ public BooleanTypeDescriptor(char characterValueTrue, char characterValueFalse) {
+ super( Boolean.class );
+ this.characterValueTrue = Character.toUpperCase( characterValueTrue );
+ this.characterValueFalse = Character.toUpperCase( characterValueFalse );
+
+ characterValueTrueLC = Character.toLowerCase( characterValueTrue );
+
+ stringValueTrue = String.valueOf( characterValueTrue );
+ stringValueFalse = String.valueOf( characterValueFalse );
+ }
+
+ public String toString(Boolean value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Boolean fromString(String string) {
+ return Boolean.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Boolean value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Boolean.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) toByte( value );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) toShort( value );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) toInteger( value );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) toInteger( value );
+ }
+ if ( Character.class.isAssignableFrom( type ) ) {
+ return (X) Character.valueOf( value ? characterValueTrue : characterValueFalse );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) (value ? stringValueTrue : stringValueFalse);
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public <X> Boolean wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Boolean.class.isInstance( value ) ) {
+ return (Boolean) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ final int intValue = ( (Number) value ).intValue();
+ return intValue == 0 ? FALSE : TRUE;
+ }
+ if ( Character.class.isInstance( value ) ) {
+ return isTrue( ( (Character) value ).charValue() ) ? TRUE : FALSE;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return isTrue( ( (String) value ).charAt( 0 ) ) ? TRUE : FALSE;
+ }
+ throw unknownWrap( value.getClass() );
+ }
+
+ private boolean isTrue(char charValue) {
+ return charValue == characterValueTrue || charValue == characterValueTrueLC;
+ }
+
+ public int toInt(Boolean value) {
+ return value ? 1 : 0;
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Byte toByte(Boolean value) {
+ return Byte.valueOf( (byte) toInt( value ) );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Short toShort(Boolean value) {
+ return Short.valueOf( (short ) toInt( value ) );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Integer toInteger(Boolean value) {
+ return Integer.valueOf( toInt( value ) );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Long toLong(Boolean value) {
+ return Long.valueOf( toInt( value ) );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,144 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.InputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ByteArrayTypeDescriptor extends AbstractTypeDescriptor<Byte[]> {
+ public static final ByteArrayTypeDescriptor INSTANCE = new ByteArrayTypeDescriptor();
+
+ @SuppressWarnings({ "unchecked" })
+ public ByteArrayTypeDescriptor() {
+ super( Byte[].class, ArrayMutabilityPlan.INSTANCE );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String toString(Byte[] bytes) {
+ final StringBuffer buf = new StringBuffer();
+ for ( Byte aByte : bytes ) {
+ final String hexStr = Integer.toHexString( aByte.byteValue() - Byte.MIN_VALUE );
+ if ( hexStr.length() == 1 ) {
+ buf.append( '0' );
+ }
+ buf.append( hexStr );
+ }
+ return buf.toString();
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Byte[] fromString(String string) {
+ if ( string == null ) {
+ return null;
+ }
+ if ( string.length() % 2 != 0 ) {
+ throw new IllegalArgumentException( "The string is not a valid string representation of a binary content." );
+ }
+ Byte[] bytes = new Byte[string.length() / 2];
+ for ( int i = 0; i < bytes.length; i++ ) {
+ final String hexStr = string.substring( i * 2, (i + 1) * 2 );
+ bytes[i] = Byte.valueOf( (byte) (Integer.parseInt(hexStr, 16) + Byte.MIN_VALUE) );
+ }
+ return bytes;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Byte[] value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Byte[].class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( byte[].class.isAssignableFrom( type ) ) {
+ return (X) unwrapBytes( value );
+ }
+ if ( InputStream.class.isAssignableFrom( type ) ) {
+ return (X) new ByteArrayInputStream( unwrapBytes( value ) );
+ }
+ if ( Blob.class.isAssignableFrom( type ) ) {
+ return (X) options.getLobCreator().createBlob( unwrapBytes( value ) );
+ }
+
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Byte[] wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Byte[].class.isInstance( value ) ) {
+ return (Byte[]) value;
+ }
+ if ( byte[].class.isInstance( value ) ) {
+ return wrapBytes( (byte[]) value );
+ }
+ if ( InputStream.class.isInstance( value ) ) {
+ return wrapBytes( DataHelper.extractBytes( (InputStream) value ) );
+ }
+ if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
+ try {
+ return wrapBytes( DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() ) );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access lob stream", e );
+ }
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ private Byte[] wrapBytes(byte[] bytes) {
+ if ( bytes == null ) {
+ return null;
+ }
+ final Byte[] result = new Byte[bytes.length];
+ for ( int i = 0; i < bytes.length; i++ ) {
+ result[i] = Byte.valueOf( bytes[i] );
+ }
+ return result;
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ private byte[] unwrapBytes(Byte[] bytes) {
+ if ( bytes == null ) {
+ return null;
+ }
+ final byte[] result = new byte[bytes.length];
+ for ( int i = 0; i < bytes.length; i++ ) {
+ result[i] = bytes[i].byteValue();
+ }
+ return result;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ByteTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+/**
+ * Descriptor for {@link Byte} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class ByteTypeDescriptor extends AbstractTypeDescriptor<Byte> {
+ public static final ByteTypeDescriptor INSTANCE = new ByteTypeDescriptor();
+
+ public ByteTypeDescriptor() {
+ super( Byte.class );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public String toString(Byte value) {
+ return Integer.toHexString( value.byteValue() - Byte.MIN_VALUE );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Byte fromString(String string) {
+ return Byte.valueOf( (byte) (Integer.parseInt( string, 16) + Byte.MIN_VALUE) );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Byte value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Byte wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Byte.class.isInstance( value ) ) {
+ return (Byte) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Byte.valueOf( ( (Number) value ).byteValue() );
+ }
+ if ( String.class.isInstance( value ) ) {
+ return Byte.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.util.CalendarComparator;
+
+/**
+ * Descriptor for {@link java.util.Calendar} handling, but just for the date (month, day, year) portion.
+ *
+ * @author Steve Ebersole
+ */
+public class CalendarDateTypeDescriptor extends AbstractTypeDescriptor<Calendar> {
+ public static final CalendarDateTypeDescriptor INSTANCE = new CalendarDateTypeDescriptor();
+
+ protected CalendarDateTypeDescriptor() {
+ super( Calendar.class, CalendarTypeDescriptor.CalendarMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Calendar value) {
+ return DateTypeDescriptor.INSTANCE.toString( value.getTime() );
+ }
+
+ public Calendar fromString(String string) {
+ Calendar result = new GregorianCalendar();
+ result.setTime( DateTypeDescriptor.INSTANCE.fromString( string ) );
+ return result;
+ }
+
+ @Override
+ public boolean areEqual(Calendar one, Calendar another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+
+ return one.get(Calendar.DAY_OF_MONTH) == another.get(Calendar.DAY_OF_MONTH)
+ && one.get(Calendar.MONTH) == another.get(Calendar.MONTH)
+ && one.get(Calendar.YEAR) == another.get(Calendar.YEAR);
+ }
+
+ @Override
+ public int extractHashCode(Calendar value) {
+ int hashCode = 1;
+ hashCode = 31 * hashCode + value.get(Calendar.DAY_OF_MONTH);
+ hashCode = 31 * hashCode + value.get(Calendar.MONTH);
+ hashCode = 31 * hashCode + value.get(Calendar.YEAR);
+ return hashCode;
+ }
+
+ @Override
+ public Comparator<Calendar> getComparator() {
+ return CalendarComparator.INSTANCE;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Calendar value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Date( value.getTimeInMillis() );
+ }
+ if ( java.sql.Time.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Time( value.getTimeInMillis() );
+ }
+ if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Timestamp( value.getTimeInMillis() );
+ }
+ if ( Date.class.isAssignableFrom( type ) ) {
+ return (X) new Date( value.getTimeInMillis() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Calendar wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Calendar.class.isInstance( value ) ) {
+ return (Calendar) value;
+ }
+
+ if ( ! Date.class.isInstance( value ) ) {
+ throw unknownWrap( value.getClass() );
+ }
+
+ Calendar cal = new GregorianCalendar();
+ if ( Environment.jvmHasTimestampBug() ) {
+ final long milliseconds = ( (Date) value ).getTime();
+ final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
+ ? ( (java.sql.Timestamp) value ).getNanos()
+ : 0;
+ cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) );
+ }
+ else {
+ cal.setTime( (Date) value );
+ }
+ return cal;
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CalendarTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,148 @@
+/*
+ * 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.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.cfg.Environment;
+import org.hibernate.util.CalendarComparator;
+
+/**
+ * Descriptor for {@link Calendar} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class CalendarTypeDescriptor extends AbstractTypeDescriptor<Calendar> {
+ public static final CalendarTypeDescriptor INSTANCE = new CalendarTypeDescriptor();
+
+ public static class CalendarMutabilityPlan extends MutableMutabilityPlan<Calendar> {
+ public static final CalendarMutabilityPlan INSTANCE = new CalendarMutabilityPlan();
+
+ public Calendar deepCopyNotNull(Calendar value) {
+ return (Calendar) value.clone();
+ }
+ }
+
+ protected CalendarTypeDescriptor() {
+ super( Calendar.class, CalendarMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Calendar value) {
+ return DateTypeDescriptor.INSTANCE.toString( value.getTime() );
+ }
+
+ public Calendar fromString(String string) {
+ Calendar result = new GregorianCalendar();
+ result.setTime( DateTypeDescriptor.INSTANCE.fromString( string ) );
+ return result;
+ }
+
+ @Override
+ public boolean areEqual(Calendar one, Calendar another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+
+ return one.get(Calendar.MILLISECOND) == another.get(Calendar.MILLISECOND)
+ && one.get(Calendar.SECOND) == another.get(Calendar.SECOND)
+ && one.get(Calendar.MINUTE) == another.get(Calendar.MINUTE)
+ && one.get(Calendar.HOUR_OF_DAY) == another.get(Calendar.HOUR_OF_DAY)
+ && one.get(Calendar.DAY_OF_MONTH) == another.get(Calendar.DAY_OF_MONTH)
+ && one.get(Calendar.MONTH) == another.get(Calendar.MONTH)
+ && one.get(Calendar.YEAR) == another.get(Calendar.YEAR);
+ }
+
+ @Override
+ public int extractHashCode(Calendar value) {
+ int hashCode = 1;
+ hashCode = 31 * hashCode + value.get(Calendar.MILLISECOND);
+ hashCode = 31 * hashCode + value.get(Calendar.SECOND);
+ hashCode = 31 * hashCode + value.get(Calendar.MINUTE);
+ hashCode = 31 * hashCode + value.get(Calendar.HOUR_OF_DAY);
+ hashCode = 31 * hashCode + value.get(Calendar.DAY_OF_MONTH);
+ hashCode = 31 * hashCode + value.get(Calendar.MONTH);
+ hashCode = 31 * hashCode + value.get(Calendar.YEAR);
+ return hashCode;
+ }
+
+ @Override
+ public Comparator<Calendar> getComparator() {
+ return CalendarComparator.INSTANCE;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Calendar value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Date( value.getTimeInMillis() );
+ }
+ if ( java.sql.Time.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Time( value.getTimeInMillis() );
+ }
+ if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
+ return (X) new java.sql.Timestamp( value.getTimeInMillis() );
+ }
+ if ( java.util.Date.class.isAssignableFrom( type ) ) {
+ return (X) new java.util.Date( value.getTimeInMillis() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Calendar wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Calendar.class.isInstance( value ) ) {
+ return (Calendar) value;
+ }
+
+ if ( ! java.util.Date.class.isInstance( value ) ) {
+ throw unknownWrap( value.getClass() );
+ }
+
+ Calendar cal = new GregorianCalendar();
+ if ( Environment.jvmHasTimestampBug() ) {
+ final long milliseconds = ( (java.util.Date) value ).getTime();
+ final long nanoseconds = java.sql.Timestamp.class.isInstance( value )
+ ? ( (java.sql.Timestamp) value ).getNanos()
+ : 0;
+ cal.setTime( new Date( milliseconds + nanoseconds / 1000000 ) );
+ }
+ else {
+ cal.setTime( (java.util.Date) value );
+ }
+ return cal;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,137 @@
+/*
+ * 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.Reader;
+import java.io.StringReader;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CharacterArrayTypeDescriptor extends AbstractTypeDescriptor<Character[]> {
+ public static final CharacterArrayTypeDescriptor INSTANCE = new CharacterArrayTypeDescriptor();
+
+ @SuppressWarnings({ "unchecked" })
+ public CharacterArrayTypeDescriptor() {
+ super( Character[].class, ArrayMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Character[] value) {
+ return new String( unwrapChars( value ) );
+ }
+
+ public Character[] fromString(String string) {
+ return wrapChars( string.toCharArray() );
+ }
+
+ @Override
+ public boolean areEqual(Character[] one, Character[] another) {
+ return one == another
+ || ( one != null && another != null && Arrays.equals( one, another ) );
+ }
+
+ @Override
+ public int extractHashCode(Character[] chars) {
+ int hashCode = 1;
+ for ( Character aChar : chars ) {
+ hashCode = 31 * hashCode + aChar;
+ }
+ return hashCode;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Character[] value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Character[].class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) new String( unwrapChars( value ) );
+ }
+ if ( Clob.class.isAssignableFrom( type ) ) {
+ return (X) options.getLobCreator().createClob( new String( unwrapChars( value ) ) );
+ }
+ if ( Reader.class.isAssignableFrom( type ) ) {
+ return (X) new StringReader( new String( unwrapChars( value ) ) );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Character[] wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Character[].class.isInstance( value ) ) {
+ return (Character[]) value;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return wrapChars( ( (String) value ).toCharArray() );
+ }
+ if ( Clob.class.isInstance( value ) ) {
+ try {
+ return wrapChars( DataHelper.extractString( ( (Clob) value ).getCharacterStream() ).toCharArray() );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access lob stream", e );
+ }
+ }
+ if ( Reader.class.isInstance( value ) ) {
+ return wrapChars( DataHelper.extractString( (Reader) value ).toCharArray() );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ private Character[] wrapChars(char[] chars) {
+ if ( chars == null ) {
+ return null;
+ }
+ final Character[] result = new Character[chars.length];
+ for ( int i = 0; i < chars.length; i++ ) {
+ result[i] = Character.valueOf( chars[i] );
+ }
+ return result;
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ private char[] unwrapChars(Character[] chars) {
+ if ( chars == null ) {
+ return null;
+ }
+ final char[] result = new char[chars.length];
+ for ( int i = 0; i < chars.length; i++ ) {
+ result[i] = chars[i].charValue();
+ }
+ return result;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CharacterTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,88 @@
+/*
+ * 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 org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+
+/**
+ * Descriptor for {@link Character} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class CharacterTypeDescriptor extends AbstractTypeDescriptor<Character> {
+ public static final CharacterTypeDescriptor INSTANCE = new CharacterTypeDescriptor();
+
+ public CharacterTypeDescriptor() {
+ super( Character.class );
+ }
+
+ public String toString(Character value) {
+ return value.toString();
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public Character fromString(String string) {
+ if ( string.length() != 1 ) {
+ throw new HibernateException( "multiple or zero characters found parsing string" );
+ }
+ return Character.valueOf( string.charAt( 0 ) );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Character value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Character.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ if ( Number.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( (short)value.charValue() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Character wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Character.class.isInstance( value ) ) {
+ return (Character) value;
+ }
+ if ( String.class.isInstance( value ) ) {
+ final String str = (String) value;
+ return Character.valueOf( str.charAt(0) );
+ }
+ if ( Number.class.isInstance( value ) ) {
+ final Number nbr = (Number) value;
+ return Character.valueOf( (char)nbr.shortValue() );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClassTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClassTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClassTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,84 @@
+/*
+ * 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 org.hibernate.HibernateException;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ClassTypeDescriptor extends AbstractTypeDescriptor<Class> {
+ public static final ClassTypeDescriptor INSTANCE = new ClassTypeDescriptor();
+
+ public ClassTypeDescriptor() {
+ super( Class.class );
+ }
+
+ public String toString(Class value) {
+ return value.getName();
+ }
+
+ public Class fromString(String string) {
+ if ( string == null ) {
+ return null;
+ }
+
+ try {
+ return ReflectHelper.classForName( string );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new HibernateException( "Unable to locate named class " + string );
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Class value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Class.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) toString( value );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Class wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Class.class.isInstance( value ) ) {
+ return (Class) value;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return fromString( (String)value );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ClobTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,126 @@
+/*
+ * 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.sql.Clob;
+import java.sql.SQLException;
+import java.util.Comparator;
+
+import org.hibernate.HibernateException;
+import org.hibernate.engine.jdbc.ClobProxy;
+import org.hibernate.engine.jdbc.WrappedClob;
+
+/**
+ * Descriptor for {@link Clob} handling.
+ * <p/>
+ * Note, {@link Clob clobs} really are mutable (their internal state can in fact be mutated). We simply
+ * treat them as immutable because we cannot properly check them for changes nor deep copy them.
+ *
+ * @author Steve Ebersole
+ */
+public class ClobTypeDescriptor extends AbstractTypeDescriptor<Clob> {
+ public static final ClobTypeDescriptor INSTANCE = new ClobTypeDescriptor();
+
+ public static class ClobMutabilityPlan implements MutabilityPlan<Clob> {
+ public static final ClobMutabilityPlan INSTANCE = new ClobMutabilityPlan();
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Clob deepCopy(Clob value) {
+ return value;
+ }
+
+ public Serializable disassemble(Clob value) {
+ throw new UnsupportedOperationException( "Clobs are not cacheable" );
+ }
+
+ public Clob assemble(Serializable cached) {
+ throw new UnsupportedOperationException( "Clobs are not cacheable" );
+ }
+ }
+
+ public ClobTypeDescriptor() {
+ super( Clob.class, ClobMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Clob value) {
+ try {
+ return DataHelper.extractString( value.getCharacterStream() );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access clob stream", e );
+ }
+ }
+
+ public Clob fromString(String string) {
+ return ClobProxy.generateProxy( string );
+ }
+
+ @Override
+ @SuppressWarnings({ "unchecked" })
+ public Comparator<Clob> getComparator() {
+ return IncomparableComparator.INSTANCE;
+ }
+
+ @Override
+ public int extractHashCode(Clob value) {
+ return System.identityHashCode( value );
+ }
+
+ @Override
+ public boolean areEqual(Clob one, Clob another) {
+ return one == another;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Clob value, Class<X> type, WrapperOptions options) {
+ if ( !Clob.class.isAssignableFrom( type ) ) {
+ throw unknownUnwrap( type );
+ }
+
+ if ( value == null ) {
+ return null;
+ }
+
+ final Clob clob = WrappedClob.class.isInstance( value )
+ ? ( (WrappedClob) value ).getWrappedClob()
+ : value;
+ return (X) clob;
+ }
+
+ public <X> Clob wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+
+ if ( ! Clob.class.isAssignableFrom( value.getClass() ) ) {
+ throw unknownWrap( value.getClass() );
+ }
+
+ return options.getLobCreator().wrap( (Clob) value );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/CurrencyTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,68 @@
+/*
+ * 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.util.Currency;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CurrencyTypeDescriptor extends AbstractTypeDescriptor<Currency> {
+ public static final CurrencyTypeDescriptor INSTANCE = new CurrencyTypeDescriptor();
+
+ public CurrencyTypeDescriptor() {
+ super( Currency.class );
+ }
+
+ public String toString(Currency value) {
+ return value.getCurrencyCode();
+ }
+
+ public Currency fromString(String string) {
+ return Currency.getInstance( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Currency value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.getCurrencyCode();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Currency wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return Currency.getInstance( (String) value );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,119 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.HibernateException;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DataHelper {
+ private static final Logger log = LoggerFactory.getLogger( DataHelper.class );
+
+ private static Class nClobClass;
+ static {
+ try {
+ // NClobs are only JDBC 4 (JDK 1.6) and higher
+ nClobClass = ReflectHelper.classForName( "java.sql.NClob", DataHelper.class );
+ }
+ catch ( ClassNotFoundException e ) {
+ e.printStackTrace();
+ }
+ }
+
+ public static boolean isNClob(Class type) {
+ return nClobClass != null && nClobClass.isAssignableFrom( type );
+ }
+
+ public static String extractString(Reader reader) {
+ // read the Reader contents into a buffer and return the complete string
+ final StringBuilder stringBuilder = new StringBuilder();
+ try {
+ char[] buffer = new char[2048];
+ while (true) {
+ int amountRead = reader.read( buffer, 0, buffer.length );
+ if ( amountRead == -1 ) {
+ break;
+ }
+ stringBuilder.append( buffer, 0, amountRead );
+ }
+ }
+ catch ( IOException ioe) {
+ throw new HibernateException( "IOException occurred reading text", ioe );
+ }
+ finally {
+ try {
+ reader.close();
+ }
+ catch (IOException e) {
+ log.warn( "IOException occurred closing stream", e );
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+ public static byte[] extractBytes(InputStream inputStream) {
+ // read the stream contents into a buffer and return the complete byte[]
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
+ try {
+ byte[] buffer = new byte[2048];
+ while (true) {
+ int amountRead = inputStream.read( buffer );
+ if ( amountRead == -1 ) {
+ break;
+ }
+ outputStream.write( buffer, 0, amountRead );
+ }
+ }
+ catch ( IOException ioe ) {
+ throw new HibernateException( "IOException occurred reading a binary value", ioe );
+ }
+ finally {
+ try {
+ inputStream.close();
+ }
+ catch ( IOException e ) {
+ log.warn( "IOException occurred closing input stream", e );
+ }
+ try {
+ outputStream.close();
+ }
+ catch ( IOException e ) {
+ log.warn( "IOException occurred closing output stream", e );
+ }
+ }
+ return outputStream.toByteArray();
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DateTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DateTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DateTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,143 @@
+/*
+ * 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DateTypeDescriptor extends AbstractTypeDescriptor<Date> {
+ public static final DateTypeDescriptor INSTANCE = new DateTypeDescriptor();
+ public static final String DATE_FORMAT = "dd MMMM yyyy";
+
+ public static class DateMutabilityPlan extends MutableMutabilityPlan<Date> {
+ public static final DateMutabilityPlan INSTANCE = new DateMutabilityPlan();
+
+ public Date deepCopyNotNull(Date value) {
+ return new Date( value.getTime() );
+ }
+ }
+
+ public DateTypeDescriptor() {
+ super( Date.class, DateMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Date value) {
+ return new SimpleDateFormat( DATE_FORMAT ).format( value );
+ }
+
+ public Date fromString(String string) {
+ try {
+ return new SimpleDateFormat(DATE_FORMAT).parse( string );
+ }
+ catch ( ParseException pe) {
+ throw new HibernateException( "could not parse date string" + string, pe );
+ }
+ }
+
+ @Override
+ public boolean areEqual(Date one, Date another) {
+ if ( one == another) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+
+ return one.getTime() == another.getTime();
+ }
+
+ @Override
+ public int extractHashCode(Date value) {
+ Calendar calendar = java.util.Calendar.getInstance();
+ calendar.setTime( value );
+ return CalendarTypeDescriptor.INSTANCE.extractHashCode( calendar );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ final java.sql.Date rtn = java.sql.Date.class.isInstance( value )
+ ? ( java.sql.Date ) value
+ : new java.sql.Date( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Time.class.isAssignableFrom( type ) ) {
+ final java.sql.Time rtn = java.sql.Time.class.isInstance( value )
+ ? ( java.sql.Time ) value
+ : new java.sql.Time( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
+ final java.sql.Timestamp rtn = java.sql.Timestamp.class.isInstance( value )
+ ? ( java.sql.Timestamp ) value
+ : new java.sql.Timestamp( value.getTime() );
+ return (X) rtn;
+ }
+ if ( Date.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ final GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeInMillis( value.getTime() );
+ return (X) cal;
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.getTime() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public <X> Date wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Date.class.isInstance( value ) ) {
+ return (Date) value;
+ }
+
+ if ( Long.class.isInstance( value ) ) {
+ return new Date( ( (Long) value ).longValue() );
+ }
+
+ if ( Calendar.class.isInstance( value ) ) {
+ return new Date( ( (Calendar) value ).getTimeInMillis() );
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/DoubleTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,100 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link Double} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class DoubleTypeDescriptor extends AbstractTypeDescriptor<Double> {
+ public static final DoubleTypeDescriptor INSTANCE = new DoubleTypeDescriptor();
+
+ public DoubleTypeDescriptor() {
+ super( Double.class );
+ }
+
+ public String toString(Double value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Double fromString(String string) {
+ return Double.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Double value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) BigInteger.valueOf( value.longValue() );
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) BigDecimal.valueOf( value );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Double wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Double.class.isInstance( value ) ) {
+ return (Double) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Double.valueOf( ( (Number) value ).doubleValue() );
+ }
+ else if ( String.class.isInstance( value ) ) {
+ return Double.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/FloatTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,100 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link Float} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class FloatTypeDescriptor extends AbstractTypeDescriptor<Float> {
+ public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
+
+ public FloatTypeDescriptor() {
+ super( Float.class );
+ }
+
+ public String toString(Float value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Float fromString(String string) {
+ return Float.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Float value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) BigInteger.valueOf( value.longValue() );
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) BigDecimal.valueOf( value );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Float wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Float.class.isInstance( value ) ) {
+ return (Float) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Float.valueOf( ( (Number) value ).floatValue() );
+ }
+ else if ( String.class.isInstance( value ) ) {
+ return Float.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ImmutableMutabilityPlan.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ImmutableMutabilityPlan.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ImmutableMutabilityPlan.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.java;
+
+import java.io.Serializable;
+
+/**
+ * Mutability plan for immutable objects
+ *
+ * @author Steve Ebersole
+ */
+public class ImmutableMutabilityPlan<T> implements MutabilityPlan<T> {
+ public static final ImmutableMutabilityPlan INSTANCE = new ImmutableMutabilityPlan();
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMutable() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public T deepCopy(T value) {
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable disassemble(T value) {
+ return (Serializable) value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public T assemble(Serializable cached) {
+ return (T) cached;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IncomparableComparator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IncomparableComparator.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IncomparableComparator.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,39 @@
+/*
+ * 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.util.Comparator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class IncomparableComparator implements Comparator {
+ public static final IncomparableComparator INSTANCE = new IncomparableComparator();
+
+ public int compare(Object o1, Object o2) {
+ return 0;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IntegerTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IntegerTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/IntegerTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,100 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link Integer} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class IntegerTypeDescriptor extends AbstractTypeDescriptor<Integer> {
+ public static final IntegerTypeDescriptor INSTANCE = new IntegerTypeDescriptor();
+
+ public IntegerTypeDescriptor() {
+ super( Integer.class );
+ }
+
+ public String toString(Integer value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Integer fromString(String string) {
+ return string == null ? null : Integer.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Integer value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) BigInteger.valueOf( value );
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) BigDecimal.valueOf( value );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Integer wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Integer.class.isInstance( value ) ) {
+ return (Integer) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Integer.valueOf( ( (Number) value ).intValue() );
+ }
+ if ( String.class.isInstance( value ) ) {
+ return Integer.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,118 @@
+/*
+ * 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.Comparator;
+
+/**
+ * Descriptor for the Java side of a value mapping.
+ *
+ * @author Steve Ebersole
+ */
+public interface JavaTypeDescriptor<T> extends Serializable {
+ /**
+ * Retrieve the Java type handled here.
+ *
+ * @return The Java type.
+ */
+ public Class<T> getJavaTypeClass();
+
+ /**
+ * Retrieve the mutability plan for this Java type.
+ *
+ * @return The mutability plan
+ */
+ public MutabilityPlan<T> getMutabilityPlan();
+
+ /**
+ * Retrieve the natural comparator for this type.
+ *
+ * @return The natural comparator.
+ */
+ public Comparator<T> getComparator();
+
+ /**
+ * Extract a proper hash code for this value.
+ *
+ * @param value The value for which to extract a hash code.
+ *
+ * @return The extracted hash code.
+ */
+ public int extractHashCode(T value);
+
+ /**
+ * Determine if two instances are equal
+ *
+ * @param one One instance
+ * @param another The other instance
+ *
+ * @return True if the two are considered equal; false otherwise.
+ */
+ public boolean areEqual(T one, T another);
+
+ /**
+ * Extract a loggable representation of the value.
+ *
+ * @param value The value for which to extract a loggable representation.
+ *
+ * @return The loggable representation
+ */
+ public String extractLoggableRepresentation(T value);
+
+ public String toString(T value);
+
+ public T fromString(String string);
+
+ /**
+ * Unwrap an instance of our handled Java type into the requested type.
+ * <p/>
+ * As an example, if this is a {@code JavaTypeDescriptor<Integer>} and we are asked to unwrap
+ * the {@code Integer value} as a {@code Long} we would return something like
+ * <code>Long.valueOf( value.longValue() )</code>.
+ * <p/>
+ * Intended use is during {@link java.sql.PreparedStatement} binding.
+ *
+ * @param value The value to unwrap
+ * @param type The type as which to unwrap
+ * @param options The options
+ * @param <X> The conversion type.
+ *
+ * @return The unwrapped value.
+ */
+ public <X> X unwrap(T value, Class<X> type, WrapperOptions options);
+
+ /**
+ * Wrap a value as our handled Java type.
+ * <p/>
+ * Intended use is during {@link java.sql.ResultSet} extraction.
+ *
+ * @param value The value to wrap.
+ * @param options The options
+ * @param <X> The conversion type.
+ *
+ * @return The wrapped value.
+ */
+ public <X> T wrap(X value, WrapperOptions options);
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcDateTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,164 @@
+/*
+ * 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class JdbcDateTypeDescriptor extends AbstractTypeDescriptor<Date> {
+ public static final JdbcDateTypeDescriptor INSTANCE = new JdbcDateTypeDescriptor();
+ public static final String DATE_FORMAT = "dd MMMM yyyy";
+
+ public static class DateMutabilityPlan extends MutableMutabilityPlan<Date> {
+ public static final DateMutabilityPlan INSTANCE = new DateMutabilityPlan();
+
+ public Date deepCopyNotNull(Date value) {
+ return java.sql.Date.class.isInstance( value )
+ ? new java.sql.Date( value.getTime() )
+ : new Date( value.getTime() );
+ }
+ }
+
+ public JdbcDateTypeDescriptor() {
+ super( Date.class, DateMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Date value) {
+ return new SimpleDateFormat( DATE_FORMAT ).format( value );
+ }
+
+ public Date fromString(String string) {
+ try {
+ return new Date( new SimpleDateFormat(DATE_FORMAT).parse( string ).getTime() );
+ }
+ catch ( ParseException pe) {
+ throw new HibernateException( "could not parse date string" + string, pe );
+ }
+ }
+
+ @Override
+ public boolean areEqual(Date one, Date another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+
+ if ( one.getTime() == another.getTime() ) {
+ return true;
+ }
+
+ Calendar calendar1 = Calendar.getInstance();
+ Calendar calendar2 = Calendar.getInstance();
+ calendar1.setTime( one );
+ calendar2.setTime( another );
+
+ return calendar1.get( Calendar.MONTH ) == calendar2.get( Calendar.MONTH )
+ && calendar1.get( Calendar.DAY_OF_MONTH ) == calendar2.get( Calendar.DAY_OF_MONTH )
+ && calendar1.get( Calendar.YEAR ) == calendar2.get( Calendar.YEAR );
+ }
+
+ @Override
+ public int extractHashCode(Date value) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime( value );
+ int hashCode = 1;
+ hashCode = 31 * hashCode + calendar.get( Calendar.MONTH );
+ hashCode = 31 * hashCode + calendar.get( Calendar.DAY_OF_MONTH );
+ hashCode = 31 * hashCode + calendar.get( Calendar.YEAR );
+ return hashCode;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ final java.sql.Date rtn = java.sql.Date.class.isInstance( value )
+ ? ( java.sql.Date ) value
+ : new java.sql.Date( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Time.class.isAssignableFrom( type ) ) {
+ final java.sql.Time rtn = java.sql.Time.class.isInstance( value )
+ ? ( java.sql.Time ) value
+ : new java.sql.Time( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
+ final java.sql.Timestamp rtn = java.sql.Timestamp.class.isInstance( value )
+ ? ( java.sql.Timestamp ) value
+ : new java.sql.Timestamp( value.getTime() );
+ return (X) rtn;
+ }
+ if ( Date.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ final GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeInMillis( value.getTime() );
+ return (X) cal;
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.getTime() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public <X> Date wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Date.class.isInstance( value ) ) {
+ return (Date) value;
+ }
+
+ if ( Long.class.isInstance( value ) ) {
+ return new java.sql.Date( ( (Long) value ).longValue() );
+ }
+
+ if ( Calendar.class.isInstance( value ) ) {
+ return new java.sql.Date( ( (Calendar) value ).getTimeInMillis() );
+ }
+
+ if ( java.util.Date.class.isInstance( value ) ) {
+ return new java.sql.Date( ( (java.util.Date) value ).getTime() );
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimeTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,167 @@
+/*
+ * 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.sql.Time;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class JdbcTimeTypeDescriptor extends AbstractTypeDescriptor<Date> {
+ public static final JdbcTimeTypeDescriptor INSTANCE = new JdbcTimeTypeDescriptor();
+ public static final String TIME_FORMAT = "HH:mm:ss";
+
+ public static class TimeMutabilityPlan extends MutableMutabilityPlan<Date> {
+ public static final TimeMutabilityPlan INSTANCE = new TimeMutabilityPlan();
+
+ public Date deepCopyNotNull(Date value) {
+ return Time.class.isInstance( value )
+ ? new Time( value.getTime() )
+ : new Date( value.getTime() );
+ }
+ }
+
+ public JdbcTimeTypeDescriptor() {
+ super( Date.class, TimeMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Date value) {
+ return new SimpleDateFormat( TIME_FORMAT ).format( value );
+ }
+
+ public java.util.Date fromString(String string) {
+ try {
+ return new Time( new SimpleDateFormat( TIME_FORMAT ).parse( string ).getTime() );
+ }
+ catch ( ParseException pe ) {
+ throw new HibernateException( "could not parse time string" + string, pe );
+ }
+ }
+
+ @Override
+ public int extractHashCode(Date value) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime( value );
+ int hashCode = 1;
+ hashCode = 31 * hashCode + calendar.get( Calendar.HOUR_OF_DAY );
+ hashCode = 31 * hashCode + calendar.get( Calendar.MINUTE );
+ hashCode = 31 * hashCode + calendar.get( Calendar.SECOND );
+ hashCode = 31 * hashCode + calendar.get( Calendar.MILLISECOND );
+ return hashCode;
+ }
+
+ @Override
+ public boolean areEqual(Date one, Date another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+
+ if ( one.getTime() == another.getTime() ) {
+ return true;
+ }
+
+ Calendar calendar1 = Calendar.getInstance();
+ Calendar calendar2 = Calendar.getInstance();
+ calendar1.setTime( one );
+ calendar2.setTime( another );
+
+ return calendar1.get( Calendar.HOUR_OF_DAY ) == calendar2.get( Calendar.HOUR_OF_DAY )
+ && calendar1.get( Calendar.MINUTE ) == calendar2.get( Calendar.MINUTE )
+ && calendar1.get( Calendar.SECOND ) == calendar2.get( Calendar.SECOND )
+ && calendar1.get( Calendar.MILLISECOND ) == calendar2.get( Calendar.MILLISECOND );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Time.class.isAssignableFrom( type ) ) {
+ final Time rtn = Time.class.isInstance( value )
+ ? ( Time ) value
+ : new Time( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ final java.sql.Date rtn = java.sql.Date.class.isInstance( value )
+ ? ( java.sql.Date ) value
+ : new java.sql.Date( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
+ final java.sql.Timestamp rtn = java.sql.Timestamp.class.isInstance( value )
+ ? ( java.sql.Timestamp ) value
+ : new java.sql.Timestamp( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.util.Date.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ final GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeInMillis( value.getTime() );
+ return (X) cal;
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.getTime() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public <X> Date wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Time.class.isInstance( value ) ) {
+ return (Time) value;
+ }
+
+ if ( Long.class.isInstance( value ) ) {
+ return new Time( ( (Long) value ).longValue() );
+ }
+
+ if ( Calendar.class.isInstance( value ) ) {
+ return new Time( ( (Calendar) value ).getTimeInMillis() );
+ }
+
+ if ( Date.class.isInstance( value ) ) {
+ return (Date) value;
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/JdbcTimestampTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,183 @@
+/*
+ * 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.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.hibernate.HibernateException;
+import org.hibernate.cfg.Environment;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class JdbcTimestampTypeDescriptor extends AbstractTypeDescriptor<Date> {
+ public static final JdbcTimestampTypeDescriptor INSTANCE = new JdbcTimestampTypeDescriptor();
+ public static final String TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+ public static class TimestampMutabilityPlan extends MutableMutabilityPlan<Date> {
+ public static final TimestampMutabilityPlan INSTANCE = new TimestampMutabilityPlan();
+
+ public Date deepCopyNotNull(Date value) {
+ if ( value instanceof Timestamp ) {
+ Timestamp orig = (Timestamp) value;
+ Timestamp ts = new Timestamp( orig.getTime() );
+ ts.setNanos( orig.getNanos() );
+ return ts;
+ }
+ else {
+ Date orig = value;
+ return new Date( orig.getTime() );
+ }
+ }
+ }
+
+ public JdbcTimestampTypeDescriptor() {
+ super( Date.class, TimestampMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(Date value) {
+ return new SimpleDateFormat( TIMESTAMP_FORMAT ).format( value );
+ }
+
+ public Date fromString(String string) {
+ try {
+ return new Timestamp( new SimpleDateFormat( TIMESTAMP_FORMAT ).parse( string ).getTime() );
+ }
+ catch ( ParseException pe) {
+ throw new HibernateException( "could not parse timestamp string" + string, pe );
+ }
+ }
+
+ @Override
+ public boolean areEqual(Date one, Date another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null) {
+ return false;
+ }
+
+ long t1 = one.getTime();
+ long t2 = another.getTime();
+
+ boolean oneIsTimestamp = Timestamp.class.isInstance( one );
+ boolean anotherIsTimestamp = Timestamp.class.isInstance( another );
+
+ int n1 = oneIsTimestamp ? ( (Timestamp) one ).getNanos() : 0;
+ int n2 = anotherIsTimestamp ? ( (Timestamp) another ).getNanos() : 0;
+
+ if ( !Environment.jvmHasJDK14Timestamp() ) {
+ t1 += n1 / 1000000;
+ t2 += n2 / 1000000;
+ }
+
+ if ( t1 != t2 ) {
+ return false;
+ }
+
+ if ( oneIsTimestamp && anotherIsTimestamp ) {
+ // both are Timestamps
+ int nn1 = n1 % 1000000;
+ int nn2 = n2 % 1000000;
+ return nn1 == nn2;
+ }
+ else {
+ // at least one is a plain old Date
+ return true;
+ }
+ }
+
+ @Override
+ public int extractHashCode(Date value) {
+ return Long.valueOf( value.getTime() / 1000 ).hashCode();
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Timestamp.class.isAssignableFrom( type ) ) {
+ final Timestamp rtn = Timestamp.class.isInstance( value )
+ ? ( Timestamp ) value
+ : new Timestamp( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Date.class.isAssignableFrom( type ) ) {
+ final java.sql.Date rtn = java.sql.Date.class.isInstance( value )
+ ? ( java.sql.Date ) value
+ : new java.sql.Date( value.getTime() );
+ return (X) rtn;
+ }
+ if ( java.sql.Time.class.isAssignableFrom( type ) ) {
+ final java.sql.Time rtn = java.sql.Time.class.isInstance( value )
+ ? ( java.sql.Time ) value
+ : new java.sql.Time( value.getTime() );
+ return (X) rtn;
+ }
+ if ( Date.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Calendar.class.isAssignableFrom( type ) ) {
+ final GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeInMillis( value.getTime() );
+ return (X) cal;
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.getTime() );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryUnboxing" })
+ public <X> Date wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Timestamp.class.isInstance( value ) ) {
+ return (Timestamp) value;
+ }
+
+ if ( Long.class.isInstance( value ) ) {
+ return new Timestamp( ( (Long) value ).longValue() );
+ }
+
+ if ( Calendar.class.isInstance( value ) ) {
+ return new Timestamp( ( (Calendar) value ).getTimeInMillis() );
+ }
+
+ if ( Date.class.isInstance( value ) ) {
+ return (Date) value;
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LocaleTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,93 @@
+/*
+ * 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.util.Comparator;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class LocaleTypeDescriptor extends AbstractTypeDescriptor<Locale> {
+ public static final LocaleTypeDescriptor INSTANCE = new LocaleTypeDescriptor();
+
+ public static class LocaleComparator implements Comparator<Locale> {
+ public static final LocaleComparator INSTANCE = new LocaleComparator();
+
+ public int compare(Locale o1, Locale o2) {
+ return o1.toString().compareTo( o2.toString() );
+ }
+ }
+
+ public LocaleTypeDescriptor() {
+ super( Locale.class );
+ }
+
+ @Override
+ public Comparator<Locale> getComparator() {
+ return LocaleComparator.INSTANCE;
+ }
+
+ public String toString(Locale value) {
+ return value.toString();
+ }
+
+ public Locale fromString(String string) {
+ StringTokenizer tokens = new StringTokenizer( string, "_" );
+ String language = tokens.hasMoreTokens() ? tokens.nextToken() : "";
+ String country = tokens.hasMoreTokens() ? tokens.nextToken() : "";
+ // Need to account for allowable '_' within the variant
+ String variant = "";
+ String sep = "";
+ while ( tokens.hasMoreTokens() ) {
+ variant += sep + tokens.nextToken();
+ sep = "_";
+ }
+ return new Locale( language, country, variant );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Locale value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> Locale wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return fromString( (String) value );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/LongTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,100 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.BigInteger;
+
+/**
+ * Descriptor for {@link Long} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class LongTypeDescriptor extends AbstractTypeDescriptor<Long> {
+ public static final LongTypeDescriptor INSTANCE = new LongTypeDescriptor();
+
+ public LongTypeDescriptor() {
+ super( Long.class );
+ }
+
+ public String toString(Long value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Long fromString(String string) {
+ return Long.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Long value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) Short.valueOf( value.shortValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ if ( BigInteger.class.isAssignableFrom( type ) ) {
+ return (X) BigInteger.valueOf( value );
+ }
+ if ( BigDecimal.class.isAssignableFrom( type ) ) {
+ return (X) BigDecimal.valueOf( value );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Long wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Long.class.isInstance( value ) ) {
+ return (Long) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Long.valueOf( ( (Number) value ).longValue() );
+ }
+ else if ( String.class.isInstance( value ) ) {
+ return Long.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutabilityPlan.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutabilityPlan.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutabilityPlan.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.java;
+
+import java.io.Serializable;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface MutabilityPlan<T> extends Serializable {
+ /**
+ * Can the internal state of instances of <tt>T</tt> be changed?
+ *
+ * @return True if the internal state can be changed; false otherwise.
+ */
+ public boolean isMutable();
+
+ /**
+ * Return a deep copy of the value.
+ *
+ * @param value The value to deep copy
+ *
+ * @return The deep copy.
+ */
+ public T deepCopy(T value);
+
+ /**
+ * Return a "disassembled" representation of the value. This is used to push values onto the
+ * second level cache. Compliment to {@link #assemble}
+ *
+ * @param value The value to disassemble
+ *
+ * @return The disassembled value.
+ *
+ * @see #assemble
+ */
+ public Serializable disassemble(T value);
+
+ /**
+ * Assemble a previously {@linkplain #disassemble disassembled} value. This is used when pulling values from the
+ * second level cache. Compliment to {@link #disassemble}
+ *
+ * @param cached The disassembled state
+ *
+ * @return The re-assembled value.
+ *
+ * @see #disassemble
+ */
+ public T assemble(Serializable cached);
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutableMutabilityPlan.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutableMutabilityPlan.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/MutableMutabilityPlan.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+/**
+ * Mutability plan for mutable objects
+ *
+ * @author Steve Ebersole
+ */
+public abstract class MutableMutabilityPlan<T> implements MutabilityPlan<T> {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isMutable() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable disassemble(T value) {
+ return (Serializable) deepCopy( value );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public T assemble(Serializable cached) {
+ return (T) deepCopy( (T) cached );
+ }
+
+ public final T deepCopy(T value) {
+ return value == null ? null : deepCopyNotNull( value );
+ }
+
+ protected abstract T deepCopyNotNull(T value);
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveByteArrayTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,128 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.InputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Descriptor for {@code byte[]} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class PrimitiveByteArrayTypeDescriptor extends AbstractTypeDescriptor<byte[]> {
+ public static final PrimitiveByteArrayTypeDescriptor INSTANCE = new PrimitiveByteArrayTypeDescriptor();
+
+ @SuppressWarnings({ "unchecked" })
+ public PrimitiveByteArrayTypeDescriptor() {
+ super( byte[].class, ArrayMutabilityPlan.INSTANCE );
+ }
+
+ @Override
+ public boolean areEqual(byte[] one, byte[] another) {
+ return one == another
+ || ( one != null && another != null && Arrays.equals( one, another ) );
+ }
+
+ @Override
+ public int extractHashCode(byte[] bytes) {
+ int hashCode = 1;
+ for ( byte aByte : bytes ) {
+ hashCode = 31 * hashCode + aByte;
+ }
+ return hashCode;
+ }
+
+ public String toString(byte[] bytes) {
+ final StringBuffer buf = new StringBuffer();
+ for ( byte aByte : bytes ) {
+ final String hexStr = Integer.toHexString( aByte - Byte.MIN_VALUE );
+ if ( hexStr.length() == 1 ) {
+ buf.append( '0' );
+ }
+ buf.append( hexStr );
+ }
+ return buf.toString();
+ }
+
+ public byte[] fromString(String string) {
+ if ( string == null ) {
+ return null;
+ }
+ if ( string.length() % 2 != 0 ) {
+ throw new IllegalArgumentException( "The string is not a valid string representation of a binary content." );
+ }
+ byte[] bytes = new byte[string.length() / 2];
+ for ( int i = 0; i < bytes.length; i++ ) {
+ final String hexStr = string.substring( i * 2, (i + 1) * 2 );
+ bytes[i] = (byte) (Integer.parseInt(hexStr, 16) + Byte.MIN_VALUE);
+ }
+ return bytes;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(byte[] value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( byte[].class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( InputStream.class.isAssignableFrom( type ) ) {
+ return (X) new ByteArrayInputStream( value );
+ }
+ if ( Blob.class.isAssignableFrom( type ) ) {
+ return (X) options.getLobCreator().createBlob( value );
+ }
+
+ throw unknownUnwrap( type );
+ }
+
+ public <X> byte[] wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( byte[].class.isInstance( value ) ) {
+ return (byte[]) value;
+ }
+ if ( InputStream.class.isInstance( value ) ) {
+ return DataHelper.extractBytes( (InputStream) value );
+ }
+ if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
+ try {
+ return DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access lob stream", e );
+ }
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/PrimitiveCharacterArrayTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,113 @@
+/*
+ * 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.Reader;
+import java.io.StringReader;
+import java.sql.Clob;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.hibernate.HibernateException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class PrimitiveCharacterArrayTypeDescriptor extends AbstractTypeDescriptor<char[]> {
+ public static final PrimitiveCharacterArrayTypeDescriptor INSTANCE = new PrimitiveCharacterArrayTypeDescriptor();
+
+ @SuppressWarnings({ "unchecked" })
+ protected PrimitiveCharacterArrayTypeDescriptor() {
+ super( char[].class, ArrayMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(char[] value) {
+ return new String( value );
+ }
+
+ public char[] fromString(String string) {
+ return string.toCharArray();
+ }
+
+ @Override
+ public boolean areEqual(char[] one, char[] another) {
+ return one == another
+ || ( one != null && another != null && Arrays.equals( one, another ) );
+ }
+
+ @Override
+ public int extractHashCode(char[] chars) {
+ int hashCode = 1;
+ for ( char aChar : chars ) {
+ hashCode = 31 * hashCode + aChar;
+ }
+ return hashCode;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(char[] value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( char[].class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) new String( value );
+ }
+ if ( Clob.class.isAssignableFrom( type ) ) {
+ return (X) options.getLobCreator().createClob( new String( value ) );
+ }
+ if ( Reader.class.isAssignableFrom( type ) ) {
+ return (X) new StringReader( new String( value ) );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> char[] wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( char[].class.isInstance( value ) ) {
+ return (char[]) value;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return ( (String) value ).toCharArray();
+ }
+ if ( Clob.class.isInstance( value ) ) {
+ try {
+ return DataHelper.extractString( ( (Clob) value ).getCharacterStream() ).toCharArray();
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access lob stream", e );
+ }
+ }
+ if ( Reader.class.isInstance( value ) ) {
+ return DataHelper.extractString( ( (Reader) value ) ).toCharArray();
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.java;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Serializable;
+
+import org.hibernate.util.SerializationHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class SerializableTypeDescriptor<T extends Serializable> extends AbstractTypeDescriptor<T> {
+ // unfortunately the param types cannot be the same so use something other than 'T' here to make that obvious
+ public static class SerializableMutabilityPlan<S extends Serializable> extends MutableMutabilityPlan<S> {
+ public static final SerializableMutabilityPlan INSTANCE = new SerializableMutabilityPlan();
+ @SuppressWarnings({ "unchecked" })
+ public S deepCopyNotNull(S value) {
+ return (S) SerializationHelper.clone( value );
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public SerializableTypeDescriptor(Class<T> type) {
+ super( type, SerializableMutabilityPlan.INSTANCE );
+ }
+
+ public String toString(T value) {
+ return PrimitiveByteArrayTypeDescriptor.INSTANCE.toString( toBytes( value ) );
+ }
+
+ public T fromString(String string) {
+ return fromBytes( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) );
+ }
+
+ @Override
+ public boolean areEqual(T one, T another) {
+ if ( one == another ) {
+ return true;
+ }
+ if ( one == null || another == null ) {
+ return false;
+ }
+ return one.equals( another )
+ || PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual( toBytes( one ), toBytes( another ) );
+ }
+
+ @Override
+ public int extractHashCode(T value) {
+ return PrimitiveByteArrayTypeDescriptor.INSTANCE.extractHashCode( toBytes( value ) );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(T value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( byte[].class.isAssignableFrom( type ) ) {
+ return (X) toBytes( value );
+ }
+ if ( InputStream.class.isAssignableFrom( type ) ) {
+ return (X) new ByteArrayInputStream( toBytes( value ) );
+ }
+ throw unknownUnwrap( type );
+ }
+
+ public <X> T wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( byte[].class.isInstance( value ) ) {
+ return fromBytes( (byte[]) value );
+ }
+ if ( InputStream.class.isInstance( value ) ) {
+ return fromBytes( DataHelper.extractBytes( (InputStream) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+
+ protected byte[] toBytes(T value) {
+ return SerializationHelper.serialize( value );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ protected T fromBytes(byte[] bytes) {
+ return (T) SerializationHelper.deserialize( bytes, getJavaTypeClass().getClassLoader() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/ShortTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+/**
+ * Descriptor for {@link Short} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class ShortTypeDescriptor extends AbstractTypeDescriptor<Short> {
+ public static final ShortTypeDescriptor INSTANCE = new ShortTypeDescriptor();
+
+ public ShortTypeDescriptor() {
+ super( Short.class );
+ }
+
+ public String toString(Short value) {
+ return value == null ? null : value.toString();
+ }
+
+ public Short fromString(String string) {
+ return Short.valueOf( string );
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(Short value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Short.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Byte.class.isAssignableFrom( type ) ) {
+ return (X) Byte.valueOf( value.byteValue() );
+ }
+ if ( Integer.class.isAssignableFrom( type ) ) {
+ return (X) Integer.valueOf( value.intValue() );
+ }
+ if ( Long.class.isAssignableFrom( type ) ) {
+ return (X) Long.valueOf( value.longValue() );
+ }
+ if ( Double.class.isAssignableFrom( type ) ) {
+ return (X) Double.valueOf( value.doubleValue() );
+ }
+ if ( Float.class.isAssignableFrom( type ) ) {
+ return (X) Float.valueOf( value.floatValue() );
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value.toString();
+ }
+ throw unknownUnwrap( type );
+ }
+
+ @SuppressWarnings({ "UnnecessaryBoxing" })
+ public <X> Short wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( Short.class.isInstance( value ) ) {
+ return (Short) value;
+ }
+ if ( Number.class.isInstance( value ) ) {
+ return Short.valueOf( ( (Number) value ).shortValue() );
+ }
+ if ( String.class.isInstance( value ) ) {
+ return Short.valueOf( ( (String) value ) );
+ }
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/StringTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,95 @@
+/*
+ * 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.Reader;
+import java.io.StringReader;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Descriptor for {@link String} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class StringTypeDescriptor extends AbstractTypeDescriptor<String> {
+ public static final StringTypeDescriptor INSTANCE = new StringTypeDescriptor();
+
+ public StringTypeDescriptor() {
+ super( String.class );
+ }
+
+ public String toString(String value) {
+ return value;
+ }
+
+ public String fromString(String string) {
+ return string;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(String value, Class<X> type, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isAssignableFrom( type ) ) {
+ return (X) value;
+ }
+ if ( Reader.class.isAssignableFrom( type ) ) {
+ return (X) new StringReader( (String) value );
+ }
+ if ( Clob.class.isAssignableFrom( type ) ) {
+ return (X) options.getLobCreator().createClob( value );
+ }
+ if ( DataHelper.isNClob( type ) ) {
+ return (X) options.getLobCreator().createNClob( value );
+ }
+
+ throw unknownUnwrap( type );
+ }
+
+ public <X> String wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return (String) value;
+ }
+ if ( Reader.class.isInstance( value ) ) {
+ return DataHelper.extractString( (Reader) value );
+ }
+ if ( Clob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
+ try {
+ return DataHelper.extractString( ( (Clob) value ).getCharacterStream() );
+ }
+ catch ( SQLException e ) {
+ throw new HibernateException( "Unable to access lob stream", e );
+ }
+ }
+
+ throw unknownWrap( value.getClass() );
+ }
+}
Added: 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 (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/TimeZoneTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,82 @@
+/*
+ * 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.util.Comparator;
+import java.util.TimeZone;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class TimeZoneTypeDescriptor extends AbstractTypeDescriptor<TimeZone> {
+ public static final TimeZoneTypeDescriptor INSTANCE = new TimeZoneTypeDescriptor();
+
+ public static class TimeZoneComparator implements Comparator<TimeZone> {
+ public static final TimeZoneComparator INSTANCE = new TimeZoneComparator();
+
+ public int compare(TimeZone o1, TimeZone o2) {
+ return o1.getID().compareTo( o2.getID() );
+ }
+ }
+
+ public TimeZoneTypeDescriptor() {
+ super( TimeZone.class );
+ }
+
+ public String toString(TimeZone value) {
+ return value.getID();
+ }
+
+ public TimeZone fromString(String string) {
+ return TimeZone.getTimeZone( string );
+ }
+
+ @Override
+ public Comparator<TimeZone> getComparator() {
+ return TimeZoneComparator.INSTANCE;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public <X> X unwrap(TimeZone 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> TimeZone wrap(X value, WrapperOptions options) {
+ if ( value == null ) {
+ return null;
+ }
+ if ( String.class.isInstance( value ) ) {
+ return fromString( (String) value );
+ }
+ throw unknownUnwrap( value.getClass() );
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/WrapperOptions.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/WrapperOptions.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/java/WrapperOptions.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,36 @@
+/*
+ * 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 org.hibernate.engine.jdbc.LobCreator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface WrapperOptions {
+ public boolean useStreamForLobBinding();
+ public LobCreator getLobCreator();
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicBinder.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.descriptor.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+import static org.hibernate.type.descriptor.sql.SqlTypeDescriptor.Binder;
+
+/**
+ * Convenience base implementation of {@link Binder}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class BasicBinder<J> implements Binder<J> {
+ private static final Logger log = LoggerFactory.getLogger( BasicBinder.class );
+
+ private final JavaTypeDescriptor<J> javaDescriptor;
+ private final SqlTypeDescriptor sqlDescriptor;
+
+ public JavaTypeDescriptor<J> getJavaDescriptor() {
+ return javaDescriptor;
+ }
+
+ public SqlTypeDescriptor getSqlDescriptor() {
+ return sqlDescriptor;
+ }
+
+ public BasicBinder(JavaTypeDescriptor<J> javaDescriptor, SqlTypeDescriptor sqlDescriptor) {
+ this.javaDescriptor = javaDescriptor;
+ this.sqlDescriptor = sqlDescriptor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException {
+ if ( value == null ) {
+ log.trace( "binding [null] to parameter [{}]", index );
+ st.setNull( index, sqlDescriptor.getSqlType() );
+ }
+ else {
+ log.trace( "binding [{}] to parameter [{}]", getJavaDescriptor().extractLoggableRepresentation( value ), index );
+ doBind( st, value, index, options );
+ }
+ }
+
+ /**
+ * Perform the binding. Safe to assume that value is not null.
+ *
+ * @param st The prepared statement
+ * @param value The value to bind (not null).
+ * @param index The index at which to bind
+ * @param options The binding options
+ *
+ * @throws SQLException Indicates a problem binding to the prepared statement.
+ */
+ protected abstract void doBind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException;
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BasicExtractor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,91 @@
+/*
+ * 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.sql;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+import static org.hibernate.type.descriptor.sql.SqlTypeDescriptor.Extractor;
+
+/**
+ * Convenience base implementation of {@link Extractor}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class BasicExtractor<J> implements Extractor<J> {
+ private static final Logger log = LoggerFactory.getLogger( BasicExtractor.class );
+
+ private final JavaTypeDescriptor<J> javaDescriptor;
+ private final SqlTypeDescriptor sqlDescriptor;
+
+ public BasicExtractor(JavaTypeDescriptor<J> javaDescriptor, SqlTypeDescriptor sqlDescriptor) {
+ this.javaDescriptor = javaDescriptor;
+ this.sqlDescriptor = sqlDescriptor;
+ }
+
+ public JavaTypeDescriptor<J> getJavaDescriptor() {
+ return javaDescriptor;
+ }
+
+ public SqlTypeDescriptor getSqlDescriptor() {
+ return sqlDescriptor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public J extract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
+ final J value = doExtract( rs, name, options );
+ if ( value == null || rs.wasNull() ) {
+ log.trace( "found [null] as column [{}]", name );
+ return null;
+ }
+ else {
+ log.trace( "found [{}] as column [{}]", getJavaDescriptor().extractLoggableRepresentation( value ), name );
+ return value;
+ }
+ }
+
+ /**
+ * Perform the extraction.
+ * <p/>
+ * Called from {@link #extract}. Null checking of the value (as well as consulting {@link ResultSet#wasNull}) is
+ * done there.
+ *
+ * @param rs The result set
+ * @param name The value name in the result set
+ * @param options The binding options
+ *
+ * @return The extracted value.
+ *
+ * @throws SQLException Indicates a problem access the result set
+ */
+ protected abstract J doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException;
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BigIntTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BigIntTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BigIntTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#BIGINT BIGINT} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BigIntTypeDescriptor implements SqlTypeDescriptor {
+ public static final BigIntTypeDescriptor INSTANCE = new BigIntTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.BIGINT;
+ }
+
+ public <X> Binder<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.setLong( index, javaTypeDescriptor.unwrap( value, Long.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getLong( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BinaryTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BinaryTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BinaryTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link java.sql.Types#BINARY BINARY} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BinaryTypeDescriptor extends VarbinaryTypeDescriptor {
+ public static final BinaryTypeDescriptor INSTANCE = new BinaryTypeDescriptor();
+
+ @Override
+ public int getSqlType() {
+ return Types.BINARY;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BitTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BitTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BitTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,66 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#BIT BIT} handling.
+ * <p/>
+ * Note that JDBC is very specific about its use of the type BIT to mean a single binary digit, whereas
+ * SQL defines BIT having a parameterized length.
+ *
+ * @author Steve Ebersole
+ */
+public class BitTypeDescriptor implements SqlTypeDescriptor {
+ public static final BitTypeDescriptor INSTANCE = new BitTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.BIT;
+ }
+
+ public <X> Binder<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.setBoolean( index, javaTypeDescriptor.unwrap( value, Boolean.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getBoolean( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/BlobTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,70 @@
+/*
+ * 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.sql;
+
+import java.io.InputStream;
+import java.sql.Blob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#BLOB BLOB} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class BlobTypeDescriptor implements SqlTypeDescriptor {
+ public static final BlobTypeDescriptor INSTANCE = new BlobTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.BLOB;
+ }
+
+ public <X> Binder<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 {
+ if ( options.useStreamForLobBinding() ) {
+ st.setBinaryStream( index, getJavaDescriptor().unwrap( value, InputStream.class, options ) );
+ }
+ else {
+ st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) );
+ }
+ }
+ };
+ }
+
+ public <X> Extractor<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.getBlob( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/CharTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/CharTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/CharTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link Types#CHAR CHAR} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class CharTypeDescriptor extends VarcharTypeDescriptor {
+ public static final CharTypeDescriptor INSTANCE = new CharTypeDescriptor();
+
+ @Override
+ public int getSqlType() {
+ return Types.CHAR;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/ClobTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/ClobTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/ClobTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,70 @@
+/*
+ * 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.sql;
+
+import java.io.Reader;
+import java.sql.Clob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#CLOB CLOB} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class ClobTypeDescriptor implements SqlTypeDescriptor {
+ public static final ClobTypeDescriptor INSTANCE = new ClobTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.CLOB;
+ }
+
+ public <X> Binder<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 {
+ if ( options.useStreamForLobBinding() ) {
+ st.setCharacterStream( index, getJavaDescriptor().unwrap( value, Reader.class, options ) );
+ }
+ else {
+ st.setClob( index, javaTypeDescriptor.unwrap( value, Clob.class, options ) );
+ }
+ }
+ };
+ }
+
+ public <X> Extractor<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.getClob( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DateTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.sql;
+
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#DATE DATE} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class DateTypeDescriptor implements SqlTypeDescriptor {
+ public static final DateTypeDescriptor INSTANCE = new DateTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.DATE;
+ }
+
+ public <X> Binder<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.setDate( index, javaTypeDescriptor.unwrap( value, Date.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getDate( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DecimalTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DecimalTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DecimalTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.sql;
+
+import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#DECIMAL DECIMAL} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class DecimalTypeDescriptor implements SqlTypeDescriptor {
+ public static final DecimalTypeDescriptor INSTANCE = new DecimalTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.DECIMAL;
+ }
+
+ public <X> Binder<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.setBigDecimal( index, javaTypeDescriptor.unwrap( value, BigDecimal.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getBigDecimal( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DoubleTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DoubleTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/DoubleTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#DOUBLE DOUBLE} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class DoubleTypeDescriptor implements SqlTypeDescriptor {
+ public static final DoubleTypeDescriptor INSTANCE = new DoubleTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.DOUBLE;
+ }
+
+ public <X> Binder<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.setDouble( index, javaTypeDescriptor.unwrap( value, Double.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getDouble( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/FloatTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/FloatTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/FloatTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,39 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link Types#FLOAT FLOAT} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class FloatTypeDescriptor extends RealTypeDescriptor {
+ public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.FLOAT;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/IntegerTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/IntegerTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/IntegerTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#INTEGER INTEGER} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class IntegerTypeDescriptor implements SqlTypeDescriptor {
+ public static final IntegerTypeDescriptor INSTANCE = new IntegerTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.INTEGER;
+ }
+
+ public <X> Binder<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.setInt( index, javaTypeDescriptor.unwrap( value, Integer.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getInt( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarbinaryTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarbinaryTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarbinaryTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link Types#LONGVARBINARY LONGVARBINARY} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class LongVarbinaryTypeDescriptor extends VarbinaryTypeDescriptor {
+ public static final LongVarbinaryTypeDescriptor INSTANCE = new LongVarbinaryTypeDescriptor();
+
+ @Override
+ public int getSqlType() {
+ return Types.LONGVARBINARY;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarcharTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarcharTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/LongVarcharTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link Types#LONGVARCHAR LONGVARCHAR} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class LongVarcharTypeDescriptor extends VarcharTypeDescriptor {
+ public static final LongVarcharTypeDescriptor INSTANCE = new LongVarcharTypeDescriptor();
+
+ @Override
+ public int getSqlType() {
+ return Types.LONGVARCHAR;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/NumericTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/NumericTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/NumericTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,40 @@
+/*
+ * 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.sql;
+
+import java.sql.Types;
+
+/**
+ * Descriptor for {@link Types#NUMERIC NUMERIC} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class NumericTypeDescriptor extends DecimalTypeDescriptor {
+ public static final NumericTypeDescriptor INSTANCE = new NumericTypeDescriptor();
+
+ @Override
+ public int getSqlType() {
+ return Types.NUMERIC;
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/RealTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/RealTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/RealTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#REAL REAL} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class RealTypeDescriptor implements SqlTypeDescriptor {
+ public static final RealTypeDescriptor INSTANCE = new RealTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.REAL;
+ }
+
+ public <X> Binder<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.setFloat( index, javaTypeDescriptor.unwrap( value, Float.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getFloat( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SmallIntTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SmallIntTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SmallIntTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#SMALLINT SMALLINT} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class SmallIntTypeDescriptor implements SqlTypeDescriptor {
+ public static final SmallIntTypeDescriptor INSTANCE = new SmallIntTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.SMALLINT;
+ }
+
+ public <X> Binder<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.setShort( index, javaTypeDescriptor.unwrap( value, Short.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getShort( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SqlTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SqlTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/SqlTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,58 @@
+/*
+ * 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.sql;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for the <tt>SQL</tt>/<tt>JDBC</tt> side of a value mapping.
+ *
+ * @author Steve Ebersole
+ */
+public interface SqlTypeDescriptor extends Serializable {
+ /**
+ * Return the {@linkplain java.sql.Types JDBC type-code} for the column mapped by this type.
+ *
+ * @return The JDBC type-code
+ */
+ public int getSqlType();
+
+ public static interface Binder<X> {
+ public void bind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException;
+ }
+
+ public <X> Binder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
+
+ public static interface Extractor<X> {
+ public X extract(ResultSet rs, String name, WrapperOptions options) throws SQLException;
+ }
+
+ public <X> Extractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimeTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#TIME TIME} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class TimeTypeDescriptor implements SqlTypeDescriptor {
+ public static final TimeTypeDescriptor INSTANCE = new TimeTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.TIME;
+ }
+
+ public <X> Binder<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.setTime( index, javaTypeDescriptor.unwrap( value, Time.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getTime( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TimestampTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#TIMESTAMP TIMESTAMP} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class TimestampTypeDescriptor implements SqlTypeDescriptor {
+ public static final TimestampTypeDescriptor INSTANCE = new TimestampTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.TIMESTAMP;
+ }
+
+ public <X> Binder<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.setTimestamp( index, javaTypeDescriptor.unwrap( value, Timestamp.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getTimestamp( name ), options );
+ }
+ };
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TinyIntTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TinyIntTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/TinyIntTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,66 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#TINYINT TINYINT} handling.
+ * <p/>
+ * Note that <tt>JDBC</tt> states that TINYINT should be mapped to either byte or short, but points out
+ * that using byte can in fact lead to loss of data.
+ *
+ * @author Steve Ebersole
+ */
+public class TinyIntTypeDescriptor implements SqlTypeDescriptor {
+ public static final TinyIntTypeDescriptor INSTANCE = new TinyIntTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.TINYINT;
+ }
+
+ public <X> Binder<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.setByte( index, javaTypeDescriptor.unwrap( value, Byte.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getByte( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarbinaryTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarbinaryTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarbinaryTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#VARBINARY VARBINARY} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class VarbinaryTypeDescriptor implements SqlTypeDescriptor {
+ public static final VarbinaryTypeDescriptor INSTANCE = new VarbinaryTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.VARBINARY;
+ }
+
+ public <X> Binder<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.setBytes( index, javaTypeDescriptor.unwrap( value, byte[].class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
+ return new BasicExtractor<X>( javaTypeDescriptor, this ) {
+ @Override
+ protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
+ final byte[] bytes = rs.getBytes( name );
+ return javaTypeDescriptor.wrap( bytes, options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarcharTypeDescriptor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarcharTypeDescriptor.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/VarcharTypeDescriptor.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,63 @@
+/*
+ * 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.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+
+/**
+ * Descriptor for {@link Types#VARCHAR VARCHAR} handling.
+ *
+ * @author Steve Ebersole
+ */
+public class VarcharTypeDescriptor implements SqlTypeDescriptor {
+ public static final VarcharTypeDescriptor INSTANCE = new VarcharTypeDescriptor();
+
+ public int getSqlType() {
+ return Types.VARCHAR;
+ }
+
+ public <X> Binder<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.setString( index, javaTypeDescriptor.unwrap( value, String.class, options ) );
+ }
+ };
+ }
+
+ public <X> Extractor<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.getString( name ), options );
+ }
+ };
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/package.html
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/package.html (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/type/descriptor/sql/package.html 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,49 @@
+<!--
+ ~ 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
+ -->
+
+<html>
+<head></head>
+<body>
+<p>
+ Defines handling of the standard <tt>JDBC</tt>-defined types, as declared by {@link java.sql.Types}.
+</p>
+<p>
+ We omit certain <tt>JDBC</tt> types here solely because Hibernate does not use them itself, not due to any
+ inability to provide proper descriptors for them. Known omissions include:
+</p>
+<ul>
+ <li>{@link java.sql.Types#ARRAY ARRAY}</li>
+ <li>{@link java.sql.Types#DATALINK DATALINK}</li>
+ <li>{@link java.sql.Types#DISTINCT DISTINCT}</li>
+ <li>{@link java.sql.Types#STRUCT STRUCT}</li>
+ <li>{@link java.sql.Types#REF REF}</li>
+ <li>{@link java.sql.Types#JAVA_OBJECT JAVA_OBJECT}</li>
+</ul>
+<p>
+See <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.html#996857">http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.html#996857</a>
+for more information.
+</p>
+
+</body>
+</html>
\ No newline at end of file
Modified: core/trunk/core/src/main/java/org/hibernate/type/package.html
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/package.html 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/type/package.html 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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
- ~
-->
<html>
Modified: core/trunk/core/src/main/java/org/hibernate/util/CalendarComparator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/CalendarComparator.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/util/CalendarComparator.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -30,16 +30,16 @@
/**
* @author Gavin King
*/
-public class CalendarComparator implements Comparator {
+public class CalendarComparator implements Comparator<Calendar> {
+ public static final CalendarComparator INSTANCE = new CalendarComparator();
- public int compare(Object x, Object y) {
- Calendar xcal = (Calendar) x;
- Calendar ycal = (Calendar) y;
- if ( xcal.before(ycal) ) return -1;
- if ( xcal.after(ycal) ) return 1;
+ public int compare(Calendar x, Calendar y) {
+ if ( x.before( y ) ) {
+ return -1;
+ }
+ if ( x.after( y ) ) {
+ return 1;
+ }
return 0;
}
-
- public static final Comparator INSTANCE = new CalendarComparator();
-
}
Modified: core/trunk/core/src/main/java/org/hibernate/util/ComparableComparator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/util/ComparableComparator.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/core/src/main/java/org/hibernate/util/ComparableComparator.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -24,18 +24,20 @@
*/
package org.hibernate.util;
+import java.io.Serializable;
import java.util.Comparator;
/**
* Delegates to Comparable
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class ComparableComparator implements Comparator {
+public class ComparableComparator implements Comparator<Comparable>, Serializable {
+ public static final Comparator INSTANCE = new ComparableComparator();
- public int compare(Object x, Object y) {
- return ( (Comparable) x ).compareTo(y);
+ @SuppressWarnings({ "unchecked" })
+ public int compare(Comparable one, Comparable another) {
+ return one.compareTo( another );
}
-
- public static final Comparator INSTANCE = new ComparableComparator();
-
}
Added: core/trunk/core/src/test/java/org/hibernate/type/TypeTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/TypeTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/TypeTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,348 @@
+/*
+ * 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.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Currency;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.SimpleTimeZone;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+import org.hibernate.EntityMode;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.util.ArrayHelper;
+import org.hibernate.util.SerializationHelper;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class TypeTest extends TestCase {
+ public void testBigDecimalType() {
+ final BigDecimal original = BigDecimal.valueOf( 100 );
+ final BigDecimal copy = BigDecimal.valueOf( 100 );
+ final BigDecimal different = BigDecimal.valueOf( 999 );
+
+ runBasicTests( BigDecimalType.INSTANCE, original, copy, different );
+ }
+
+ public void testBigIntegerType() {
+ final BigInteger original = BigInteger.valueOf( 100 );
+ final BigInteger copy = BigInteger.valueOf( 100 );
+ final BigInteger different = BigInteger.valueOf( 999 );
+
+ runBasicTests( BigIntegerType.INSTANCE, original, copy, different );
+ }
+
+ public void testBinaryType() {
+ final byte[] original = new byte[] { 1, 2, 3, 4 };
+ final byte[] copy = new byte[] { 1, 2, 3, 4 };
+ final byte[] different = new byte[] { 4, 3, 2, 1 };
+
+ runBasicTests( BinaryType.INSTANCE, original, copy, different );
+ runBasicTests( ImageType.INSTANCE, original, copy, different );
+ runBasicTests( MaterializedBlobType.INSTANCE, original, copy, different );
+ }
+
+ public void testBooleanType() {
+ final Boolean original = Boolean.TRUE;
+ final Boolean copy = new Boolean( true );
+ final Boolean different = Boolean.FALSE;
+
+ runBasicTests( BooleanType.INSTANCE, original, copy, different );
+ runBasicTests( NumericBooleanType.INSTANCE, original, copy, different );
+ runBasicTests( YesNoType.INSTANCE, original, copy, different );
+ runBasicTests( TrueFalseType.INSTANCE, original, copy, different );
+ }
+
+ public void testByteType() {
+ final Byte original = 0;
+ final Byte copy = new Byte( (byte) 0 );
+ final Byte different = 9;
+
+ runBasicTests( ByteType.INSTANCE, original, copy, different );
+ }
+
+ public void testCalendarDateType() {
+ final Calendar original = new GregorianCalendar();
+ final Calendar copy = new GregorianCalendar();
+ final Calendar different = new GregorianCalendar();
+ different.set( Calendar.MONTH, 9 );
+ different.set( Calendar.DAY_OF_MONTH, 9 );
+ different.set( Calendar.YEAR, 2999 );
+
+ runBasicTests( CalendarDateType.INSTANCE, original, copy, different );
+ }
+
+ public void testCalendarType() {
+ final long now = System.currentTimeMillis();
+ final Calendar original = new GregorianCalendar();
+ original.clear();
+ original.setTimeInMillis( now );
+ final Calendar copy = new GregorianCalendar();
+ copy.clear();
+ copy.setTimeInMillis( now );
+ final Calendar different = new GregorianCalendar();
+ different.setTimeInMillis( now + 9999 );
+
+ runBasicTests( CalendarType.INSTANCE, original, copy, different );
+ }
+
+ public void testCharacterArrayType() {
+ final Character[] original = new Character[] { 'a', 'b' };
+ final Character[] copy = new Character[] { 'a', 'b' };
+ final Character[] different = new Character[] { 'a', 'b', 'c' };
+
+ runBasicTests( CharacterArrayType.INSTANCE, original, copy, different );
+ }
+
+ public void testCharacterType() {
+ final Character original = 'a';
+ final Character copy = new Character( 'a' );
+ final Character different = 'b';
+
+ runBasicTests( CharacterType.INSTANCE, original, copy, different );
+ }
+
+ public void testCharArrayType() {
+ final char[] original = new char[] { 'a', 'b' };
+ final char[] copy = new char[] { 'a', 'b' };
+ final char[] different = new char[] { 'a', 'b', 'c' };
+
+ runBasicTests( CharArrayType.INSTANCE, original, copy, different );
+ runBasicTests( CharArrayType.INSTANCE, original, copy, different );
+ }
+
+ public void testClassType() {
+ final Class original = TypeTest.class;
+ final Class copy = (Class) SerializationHelper.clone( original );
+ final Class different = TestCase.class;
+
+ runBasicTests( ClassType.INSTANCE, original, copy, different );
+ }
+
+ public void testCurrencyType() {
+ final Currency original = Currency.getInstance( Locale.US );
+ final Currency copy = Currency.getInstance( Locale.US );
+ final Currency different = Currency.getInstance( Locale.UK );
+
+ runBasicTests( CurrencyType.INSTANCE, original, copy, different );
+ }
+
+ public void testDateType() {
+ final long now = System.currentTimeMillis();
+ final java.sql.Date original = new java.sql.Date( now );
+ final java.sql.Date copy = new java.sql.Date( now );
+ Calendar cal = new GregorianCalendar();
+ cal.clear();
+ cal.setTimeInMillis( now );
+ cal.add( Calendar.YEAR, 1 );
+ final java.sql.Date different = new java.sql.Date( cal.getTime().getTime() );
+
+ runBasicTests( DateType.INSTANCE, original, copy, different );
+ }
+
+ public void testDoubleType() {
+ final Double original = Double.valueOf( 100 );
+ final Double copy = Double.valueOf( 100 );
+ final Double different = Double.valueOf( 999 );
+
+ runBasicTests( DoubleType.INSTANCE, original, copy, different );
+ }
+
+ public void testFloatType() {
+ final Float original = Float.valueOf( 100 );
+ final Float copy = Float.valueOf( 100 );
+ final Float different = Float.valueOf( 999 );
+
+ runBasicTests( FloatType.INSTANCE, original, copy, different );
+ }
+
+ public void testIntegerType() {
+ final Integer original = 100;
+ final Integer copy = new Integer( 100 );
+ final Integer different = 999;
+
+ runBasicTests( IntegerType.INSTANCE, original, copy, different );
+ }
+
+ public void testLocaleType() {
+ final Locale original = new Locale( "ab" );
+ final Locale copy = new Locale( "ab" );
+ final Locale different = new Locale( "yz" );
+
+ runBasicTests( LocaleType.INSTANCE, original, copy, different );
+ }
+
+ public void testLongType() {
+ final Long original = 100L;
+ final Long copy = new Long( 100L );
+ final Long different = 999L;
+
+ runBasicTests( LongType.INSTANCE, original, copy, different );
+ }
+
+ private static class SerializableImpl implements Serializable {
+ private final int number;
+ SerializableImpl(int number) {
+ this.number = number;
+ }
+ public boolean equals(Object obj) {
+ return this.number == ( (SerializableImpl) obj ).number;
+ }
+ }
+ public void testSerializableType() {
+ final Serializable original = new SerializableImpl(1);
+ final Serializable copy = new SerializableImpl(1);
+ final Serializable different = new SerializableImpl(2);
+
+ runBasicTests( SerializableType.INSTANCE, original, copy, different );
+ }
+
+ public void testShortType() {
+ final Short original = 100;
+ final Short copy = new Short( (short) 100 );
+ final Short different = 999;
+
+ runBasicTests( ShortType.INSTANCE, original, copy, different );
+ }
+
+ public void testStringType() {
+ final String original = "abc";
+ final String copy = new String( original.toCharArray() );
+ final String different = "xyz";
+
+ runBasicTests( StringType.INSTANCE, original, copy, different );
+ runBasicTests( TextType.INSTANCE, original, copy, different );
+ runBasicTests( MaterializedClobType.INSTANCE, original, copy, different );
+ }
+
+ public void testTimestampType() {
+ final long now = System.currentTimeMillis();
+ final Timestamp original = new Timestamp( now );
+ final Timestamp copy = new Timestamp( now );
+ final Timestamp different = new Timestamp( now + 9999 );
+
+ runBasicTests( TimestampType.INSTANCE, original, copy, different );
+ }
+
+ public void testTimeType() {
+ final long now = System.currentTimeMillis();
+ final Time original = new Time( now );
+ final Time copy = new Time( now );
+ final Time different = new Time( now + 9999 );
+
+ runBasicTests( TimeType.INSTANCE, original, copy, different );
+ }
+
+ public void testDates() {
+ final long now = System.currentTimeMillis();
+ final java.util.Date original = new java.util.Date( now );
+ final java.util.Date copy = new java.util.Date( now );
+ final java.util.Date different = new java.util.Date( now + 9999 );
+ final java.util.Date different2 = new java.util.Date( now + ( 1000L * 60L * 60L * 24L * 365L ) );
+
+ runBasicTests( TimeType.INSTANCE, original, copy, different );
+ runBasicTests( TimestampType.INSTANCE, original, copy, different );
+ runBasicTests( DateType.INSTANCE, original, copy, different2 );
+ }
+
+ public void testTimeZoneType() {
+ final TimeZone original = new SimpleTimeZone( -1, "abc" );
+ final TimeZone copy = new SimpleTimeZone( -1, "abc" );
+ final TimeZone different = new SimpleTimeZone( -2, "xyz" );
+
+ runBasicTests( TimeZoneType.INSTANCE, original, copy, different );
+ }
+
+
+
+ protected <T> void runBasicTests(AbstractSingleColumnStandardBasicType<T> type, T original, T copy, T different) {
+ final boolean nonCopyable = Class.class.isInstance( original )
+ || Currency.class.isInstance( original );
+ if ( ! nonCopyable ) {
+ // these checks exclude classes which cannot really be cloned (singetons/enums)
+ assertFalse( original == copy );
+ }
+
+ assertTrue( original == type.replace( original, copy, null, null, null ) );
+
+ assertTrue( type.isSame( original, copy, EntityMode.POJO ) );
+ assertTrue( type.isEqual( original, copy ) );
+ assertTrue( type.isEqual( original, copy, EntityMode.POJO ) );
+ assertTrue( type.isEqual( original, copy, EntityMode.POJO, null ) );
+
+ assertFalse( type.isSame( original, different, EntityMode.POJO ) );
+ assertFalse( type.isEqual( original, different ) );
+ assertFalse( type.isEqual( original, different, EntityMode.POJO ) );
+ assertFalse( type.isEqual( original, different, EntityMode.POJO, null ) );
+
+ assertFalse( type.isDirty( original, copy , session ) );
+ assertFalse( type.isDirty( original, copy , ArrayHelper.FALSE, session ) );
+ assertFalse( type.isDirty( original, copy , ArrayHelper.TRUE, session ) );
+
+ assertTrue( type.isDirty( original, different , session ) );
+ assertFalse( type.isDirty( original, different , ArrayHelper.FALSE, session ) );
+ assertTrue( type.isDirty( original, different , ArrayHelper.TRUE, session ) );
+
+ assertFalse( type.isModified( original, copy, ArrayHelper.FALSE, session ) );
+ assertFalse( type.isModified( original, copy, ArrayHelper.TRUE, session ) );
+
+ assertTrue( type.isModified( original, different, ArrayHelper.FALSE, session ) );
+ assertTrue( type.isModified( original, different, ArrayHelper.TRUE, session ) );
+ }
+
+ private SessionImplementor session;
+
+ @Override
+ protected void setUp() throws Exception {
+ session = (SessionImplementor) Proxy.newProxyInstance(
+ getClass().getClassLoader(),
+ new Class[] { Session.class, SessionImplementor.class },
+ new SessionProxyHandler()
+ );
+ }
+
+ public static class SessionProxyHandler implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ( "getEntityMode".equals( method.getName() ) ) {
+ return EntityMode.POJO;
+ }
+ throw new UnsupportedOperationException( "Unexpected method call : " + method.getName() );
+ }
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/AbstractDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,104 @@
+/*
+ * 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.sql.Blob;
+import java.sql.Clob;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractDescriptorTest<T> extends TestCase {
+ protected class Data<T> {
+ private final T originalValue;
+ private final T copyOfOriginalValue;
+ private final T differentValue;
+
+ public Data(T originalValue, T copyOfOriginalValue, T differentValue) {
+ this.originalValue = originalValue;
+ this.copyOfOriginalValue = copyOfOriginalValue;
+ this.differentValue = differentValue;
+ }
+ }
+
+ private final JavaTypeDescriptor<T> typeDescriptor;
+
+ public AbstractDescriptorTest(JavaTypeDescriptor<T> typeDescriptor) {
+ this.typeDescriptor = typeDescriptor;
+ }
+
+ private Data<T> testData;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ testData = getTestData();
+ }
+
+ protected abstract Data<T> getTestData();
+
+ protected abstract boolean shouldBeMutable();
+
+ public void testEquality() {
+ assertFalse( testData.originalValue == testData.copyOfOriginalValue );
+ assertTrue( typeDescriptor.areEqual( testData.originalValue, testData.originalValue ) );
+ assertTrue( typeDescriptor.areEqual( testData.originalValue, testData.copyOfOriginalValue ) );
+ assertFalse( typeDescriptor.areEqual( testData.originalValue, testData.differentValue ) );
+ }
+
+ public void testExternalization() {
+ // ensure the symmetry of toString/fromString
+ String externalized = typeDescriptor.toString( testData.originalValue );
+ T consumed = typeDescriptor.fromString( externalized );
+ assertTrue( typeDescriptor.areEqual( testData.originalValue, consumed ) );
+ }
+
+ public void testMutabilityPlan() {
+ assertTrue( shouldBeMutable() == typeDescriptor.getMutabilityPlan().isMutable() );
+
+ if ( Clob.class.isInstance( testData.copyOfOriginalValue )
+ || Blob.class.isInstance( testData.copyOfOriginalValue ) ) {
+ return;
+ }
+
+ T copy = typeDescriptor.getMutabilityPlan().deepCopy( testData.copyOfOriginalValue );
+ assertTrue( typeDescriptor.areEqual( copy, testData.copyOfOriginalValue ) );
+ if ( ! shouldBeMutable() ) {
+ assertTrue( copy == testData.copyOfOriginalValue );
+ }
+
+ // ensure the symmetry of assemble/disassebly
+ Serializable cached = typeDescriptor.getMutabilityPlan().disassemble( testData.copyOfOriginalValue );
+ if ( ! shouldBeMutable() ) {
+ assertTrue( cached == testData.copyOfOriginalValue );
+ }
+ T reassembled = typeDescriptor.getMutabilityPlan().assemble( cached );
+ assertTrue( typeDescriptor.areEqual( testData.originalValue, reassembled ) );
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigDecimalDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.descriptor.java;
+
+import java.math.BigDecimal;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BigDecimalDescriptorTest extends AbstractDescriptorTest<BigDecimal> {
+ final BigDecimal original = new BigDecimal( 100 );
+ final BigDecimal copy = new BigDecimal( 100 );
+ final BigDecimal different = new BigDecimal( 999 );
+
+ public BigDecimalDescriptorTest() {
+ super( BigDecimalTypeDescriptor.INSTANCE );
+ }
+
+ @Override
+ protected Data<BigDecimal> getTestData() {
+ return new Data<BigDecimal>( original, copy, different );
+ }
+
+ @Override
+ protected boolean shouldBeMutable() {
+ return false;
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BigIntegerDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.descriptor.java;
+
+import java.math.BigInteger;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BigIntegerDescriptorTest extends AbstractDescriptorTest<BigInteger> {
+ final BigInteger original = BigInteger.valueOf( 100 );
+ final BigInteger copy = BigInteger.valueOf( 100 );
+ final BigInteger different = BigInteger.valueOf( 999 );
+
+ public BigIntegerDescriptorTest() {
+ super( BigIntegerTypeDescriptor.INSTANCE );
+ }
+
+ @Override
+ protected Data<BigInteger> getTestData() {
+ return new Data<BigInteger>( original, copy, different );
+ }
+
+ @Override
+ protected boolean shouldBeMutable() {
+ return false;
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BlobDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -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.type.descriptor.java;
+
+import java.sql.Blob;
+import java.sql.SQLException;
+
+import org.hibernate.engine.jdbc.BlobProxy;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
+ final Blob original = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } );
+ final Blob copy = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } );
+ final Blob different = BlobProxy.generateProxy( new byte[] { 3, 2, 1 } );
+
+ public BlobDescriptorTest() {
+ super( BlobTypeDescriptor.INSTANCE );
+ }
+
+ @Override
+ protected Data<Blob> getTestData() {
+ return new Data<Blob>( original, copy, different );
+ }
+
+ @Override
+ protected boolean shouldBeMutable() {
+ return false;
+ }
+
+ @Override
+ public void testEquality() {
+ // blobs of the same internal value are not really comparable
+ assertFalse( original == copy );
+ assertTrue( BlobTypeDescriptor.INSTANCE.areEqual( original, original ) );
+ assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, copy ) );
+ assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) );
+ }
+
+ @Override
+ public void testExternalization() {
+ // blobs of the same internal value are not really comparable
+ String externalized = BlobTypeDescriptor.INSTANCE.toString( original );
+ Blob consumed = BlobTypeDescriptor.INSTANCE.fromString( externalized );
+ try {
+ PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual(
+ DataHelper.extractBytes( original.getBinaryStream() ),
+ DataHelper.extractBytes( consumed.getBinaryStream() )
+ );
+ }
+ catch ( SQLException e ) {
+ fail( "SQLException accessing blob : " + e.getMessage() );
+ }
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/BooleanDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class BooleanDescriptorTest extends AbstractDescriptorTest<Boolean> {
+ final Boolean original = Boolean.TRUE;
+ final Boolean copy = new Boolean( true );
+ final Boolean different = Boolean.FALSE;
+
+ public BooleanDescriptorTest() {
+ super( BooleanTypeDescriptor.INSTANCE );
+ }
+
+ @Override
+ protected Data<Boolean> getTestData() {
+ return new Data<Boolean>( original, copy, different );
+ }
+
+ @Override
+ protected boolean shouldBeMutable() {
+ return false;
+ }
+}
\ No newline at end of file
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/java/StringDescriptorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StringDescriptorTest extends AbstractDescriptorTest<String> {
+ final String original = "abc";
+ final String copy = new String( original.toCharArray() );
+ final String different = "xyz";
+
+ public StringDescriptorTest() {
+ super( StringTypeDescriptor.INSTANCE );
+ }
+
+ @Override
+ protected Data<String> getTestData() {
+ return new Data<String>( original, copy, different );
+ }
+
+ @Override
+ protected boolean shouldBeMutable() {
+ return false;
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/PreparedStatementProxy.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,109 @@
+/*
+ * 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.sql;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.Clob;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import junit.framework.Assert;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class PreparedStatementProxy<T> implements InvocationHandler {
+ public static PreparedStatement generateProxy(PreparedStatementProxy handler) {
+ return (PreparedStatement) Proxy.newProxyInstance(
+ getProxyClassLoader(),
+ new Class[] { PreparedStatement.class },
+ handler
+ );
+ }
+
+ private static ClassLoader getProxyClassLoader() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if ( cl == null ) {
+ cl = PreparedStatement.class.getClassLoader();
+ }
+ return cl;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ( value == null ) {
+ Assert.assertEquals( "Expecting setNull call", "setNull", method.getName() );
+ return null;
+ }
+ if ( method.getName().equals( methodName ) && args.length >= 1 ) {
+ checkValue( (T) args[1] );
+ return null;
+ }
+ throw new UnsupportedOperationException( "Unexpected call PreparedStatement." + method.getName() );
+ }
+
+ protected void checkValue(T arg) throws SQLException {
+ Assert.assertEquals( value, arg );
+ }
+
+ protected final String extractString(Clob clob) throws SQLException {
+ if ( StringClobImpl.class.isInstance( clob ) ) {
+ return ( (StringClobImpl) clob ).getValue();
+ }
+ return clob.getSubString( 1, (int)clob.length() );
+ }
+
+ private final String methodName;
+ private final T value;
+
+ public T getValue() {
+ return value;
+ }
+
+ protected PreparedStatementProxy(String methodName, T value) {
+ this.methodName = methodName;
+ this.value = value;
+ }
+
+ public static PreparedStatement generateProxy(final String value) {
+ return generateProxy(
+ new PreparedStatementProxy<String>( "setString", value )
+ );
+ }
+
+ public static PreparedStatement generateProxy(Clob value) {
+ return generateProxy(
+ new PreparedStatementProxy<Clob>( "setClob", value ) {
+ @Override
+ protected void checkValue(Clob arg) throws SQLException {
+ Assert.assertEquals( extractString( getValue() ), extractString( arg ) );
+ }
+ }
+ );
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/ResultSetProxy.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,83 @@
+/*
+ * 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.sql;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.Clob;
+import java.sql.ResultSet;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class ResultSetProxy<T> implements InvocationHandler {
+ public static ResultSet generateProxy(ResultSetProxy handler) {
+ return ( ResultSet ) Proxy.newProxyInstance(
+ getProxyClassLoader(),
+ new Class[] { ResultSet.class },
+ handler
+ );
+ }
+
+ private static ClassLoader getProxyClassLoader() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if ( cl == null ) {
+ cl = ResultSet.class.getClassLoader();
+ }
+ return cl;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ( method.getName().equals( methodName ) && args.length >= 1 ) {
+ return value;
+ }
+ if ( method.getName().equals( "wasNull" ) ) {
+ return value == null;
+ }
+ throw new UnsupportedOperationException( "Unexpected call ResultSet." + method.getName() );
+ }
+
+ private final String methodName;
+ private final T value;
+
+ protected ResultSetProxy(String methodName, T value) {
+ this.methodName = methodName;
+ this.value = value;
+ }
+
+ public static ResultSet generateProxy(final String value) {
+ return generateProxy(
+ new ResultSetProxy<String>( "getString", value )
+ );
+ }
+
+ public static ResultSet generateProxy(final Clob value) {
+ return generateProxy(
+ new ResultSetProxy<Clob>( "getClob", value )
+ );
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringClobImpl.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,99 @@
+/*
+ * 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.sql;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StringClobImpl implements Clob {
+ private final String value;
+
+ public StringClobImpl(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public long length() throws SQLException {
+ return value.length();
+ }
+
+ public String getSubString(long pos, int length) throws SQLException {
+ return value.substring( (int)pos, (int)(pos+length) );
+ }
+
+ public Reader getCharacterStream() throws SQLException {
+ return new StringReader( value );
+ }
+
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
+ return new StringReader( getSubString( pos, (int)length ) );
+ }
+
+ public InputStream getAsciiStream() throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public long position(String searchstr, long start) throws SQLException {
+ return value.indexOf( searchstr, (int)start );
+ }
+
+ public long position(Clob searchstr, long start) throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public int setString(long pos, String str) throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public int setString(long pos, String str, int offset, int len) throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public OutputStream setAsciiStream(long pos) throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public Writer setCharacterStream(long pos) throws SQLException {
+ throw new UnsupportedOperationException( "not supported" );
+ }
+
+ public void truncate(long len) throws SQLException {
+ }
+
+ public void free() throws SQLException {
+ }
+}
Added: core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java (rev 0)
+++ core/trunk/core/src/test/java/org/hibernate/type/descriptor/sql/StringValueMappingTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -0,0 +1,122 @@
+/*
+ * 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.sql;
+
+import java.sql.Clob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+import org.hibernate.engine.jdbc.LobCreator;
+import org.hibernate.engine.jdbc.NonContextualLobCreator;
+import org.hibernate.type.descriptor.java.StringTypeDescriptor;
+import org.hibernate.type.descriptor.java.WrapperOptions;
+import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
+import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
+import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class StringValueMappingTest extends TestCase {
+ private final StringTypeDescriptor stringJavaDescriptor = new StringTypeDescriptor();
+
+ private final VarcharTypeDescriptor varcharSqlDescriptor = new VarcharTypeDescriptor();
+ private final ClobTypeDescriptor clobSqlDescriptor = new ClobTypeDescriptor();
+
+ private final WrapperOptions wrapperOptions = new WrapperOptions() {
+ public boolean useStreamForLobBinding() {
+ return false;
+ }
+
+ public LobCreator getLobCreator() {
+ return NonContextualLobCreator.INSTANCE;
+ }
+ };
+
+ public static final String COLUMN_NAME = "n/a";
+ public static final int BIND_POSITION = -1;
+
+ public void testNormalVarcharHandling() throws SQLException {
+ final SqlTypeDescriptor.Extractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
+ final SqlTypeDescriptor.Binder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
+
+ final String fixture = "string value";
+
+ ResultSet resultSet = ResultSetProxy.generateProxy( fixture );
+ final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions );
+ assertEquals( fixture, value );
+
+ PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture );
+ binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
+ }
+
+ public void testNullVarcharHandling() throws SQLException {
+ final SqlTypeDescriptor.Extractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
+ final SqlTypeDescriptor.Binder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
+
+ final String fixture = null;
+
+ ResultSet resultSet = ResultSetProxy.generateProxy( fixture );
+ final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions );
+ assertEquals( fixture, value );
+
+ PreparedStatement ps = PreparedStatementProxy.generateProxy( fixture );
+ binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
+ }
+
+ public void testNormalClobHandling() throws SQLException {
+ final SqlTypeDescriptor.Extractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
+ final SqlTypeDescriptor.Binder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );
+
+ final String fixture = "clob string";
+ final Clob clob = new StringClobImpl( fixture );
+
+ ResultSet resultSet = ResultSetProxy.generateProxy( clob );
+ final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions );
+ assertEquals( fixture, value );
+
+ PreparedStatement ps = PreparedStatementProxy.generateProxy( clob );
+ binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
+ }
+
+ public void testNullClobHandling() throws SQLException {
+ final SqlTypeDescriptor.Extractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
+ final SqlTypeDescriptor.Binder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );
+
+ final String fixture = null;
+ final Clob clob = null;
+
+ ResultSet resultSet = ResultSetProxy.generateProxy( clob );
+ final String value = extractor.extract( resultSet, COLUMN_NAME, wrapperOptions );
+ assertNull( value );
+
+ PreparedStatement ps = PreparedStatementProxy.generateProxy( clob );
+ binder.bind( ps, fixture, BIND_POSITION, wrapperOptions );
+ }
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -55,6 +55,7 @@
import org.hibernate.TypeMismatchException;
import org.hibernate.SQLQuery;
import org.hibernate.ejb.util.LockModeTypeHelper;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.query.NamedParameterDescriptor;
import org.hibernate.engine.query.OrdinalParameterDescriptor;
import org.hibernate.hql.QueryExecutionRequestException;
@@ -104,7 +105,7 @@
Class javaType = namedParameterTypeRedefinition.get( name );
if ( javaType != null && mightNeedRedefinition( javaType ) ) {
descriptor.resetExpectedType(
- TypeFactory.heuristicType( javaType.getName() )
+ sfi().getTypeResolver().heuristicType( javaType.getName() )
);
}
else if ( descriptor.getExpectedType() != null ) {
@@ -140,6 +141,10 @@
this.parameters = java.util.Collections.unmodifiableSet( parameters );
}
+ private SessionFactoryImplementor sfi() {
+ return (SessionFactoryImplementor) getEntityManager().getFactory().getSessionFactory();
+ }
+
private boolean mightNeedRedefinition(Class javaType) {
// for now, only really no for dates/times/timestamps
return java.util.Date.class.isAssignableFrom( javaType );
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -185,7 +185,7 @@
public String getCastType(Class javaType) {
SessionFactoryImplementor factory =
( SessionFactoryImplementor ) entityManager.getFactory().getSessionFactory();
- Type hibernateType = TypeFactory.heuristicType( javaType.getName() );
+ Type hibernateType = factory.getTypeResolver().heuristicType( javaType.getName() );
if ( hibernateType == null ) {
throw new IllegalArgumentException(
"Could not convert java type [" + javaType.getName() + "] to Hibernate type"
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/BasicMetadataGenerator.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -33,10 +33,9 @@
import org.hibernate.mapping.Column;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value;
+import org.hibernate.type.BasicType;
import org.hibernate.type.CompositeCustomType;
import org.hibernate.type.CustomType;
-import org.hibernate.type.ImmutableType;
-import org.hibernate.type.MutableType;
import org.hibernate.type.Type;
/**
@@ -48,7 +47,7 @@
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
Type type = value.getType();
- if (type instanceof ImmutableType || type instanceof MutableType) {
+ if ( type instanceof BasicType ) {
addSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key);
} else if (type instanceof CustomType || type instanceof CompositeCustomType) {
addCustomValue(parent, propertyAuditingData, value, mapper, insertable, key);
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/CompositeTestUserType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -28,9 +28,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.IntegerType;
+import org.hibernate.type.StringType;
import org.hibernate.type.Type;
import org.hibernate.usertype.CompositeUserType;
@@ -44,7 +45,7 @@
}
public Type[] getPropertyTypes() {
- return new Type[] { Hibernate.STRING, Hibernate.INTEGER };
+ return new Type[] { StringType.INSTANCE, IntegerType.INSTANCE };
}
public Object getPropertyValue(final Object component, final int property) throws HibernateException {
@@ -106,8 +107,8 @@
throws HibernateException, SQLException
{
if (value == null) {
- st.setNull(index, Hibernate.STRING.sqlType());
- st.setNull(index + 1, Hibernate.INTEGER.sqlType());
+ st.setNull(index, StringType.INSTANCE.sqlType());
+ st.setNull(index + 1, IntegerType.INSTANCE.sqlType());
} else {
final Component comp = (Component) value;
st.setString(index, comp.getProp1());
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/customtype/ParametrizedTestUserType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -32,6 +32,7 @@
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
+import org.hibernate.type.StringType;
import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
@@ -54,7 +55,7 @@
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
- return Hibernate.STRING.nullSafeGet(rs, names[0]);
+ return StringType.INSTANCE.nullSafeGet( rs, names[0] );
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
@@ -66,10 +67,11 @@
if (!v.endsWith(param2)) {
v = v + param2;
}
- Hibernate.STRING.nullSafeSet(st, v, index);
- } else {
- Hibernate.STRING.nullSafeSet(st, value, index);
+ StringType.INSTANCE.nullSafeSet(st, v, index);
}
+ else {
+ StringType.INSTANCE.nullSafeSet( st, null, index );
+ }
}
public int[] sqlTypes() {
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/entitymode/dom4j/accessors/Dom4jAccessorTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/entitymode/dom4j/accessors/Dom4jAccessorTest.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/entitymode/dom4j/accessors/Dom4jAccessorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -9,6 +9,8 @@
import org.dom4j.util.NodeComparator;
import org.hibernate.EntityMode;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Mappings;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
@@ -25,10 +27,17 @@
public static final Element DOM = generateTestElement();
+ private Mappings mappings;
+
public Dom4jAccessorTest(String name) {
super( name );
}
+ @Override
+ protected void setUp() throws Exception {
+ mappings = new Configuration().createMappings();
+ }
+
public void testStringElementExtraction() throws Throwable {
Property property = generateNameProperty();
Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
@@ -108,7 +117,7 @@
}
private Property generateIdProperty() {
- SimpleValue value = new SimpleValue();
+ SimpleValue value = new SimpleValue( mappings );
value.setTypeName( "long" );
Property property = new Property();
@@ -120,7 +129,7 @@
}
private Property generateTextProperty() {
- SimpleValue value = new SimpleValue();
+ SimpleValue value = new SimpleValue(mappings);
value.setTypeName( "string" );
Property property = new Property();
@@ -132,7 +141,7 @@
}
private Property generateAccountIdProperty() {
- SimpleValue value = new SimpleValue();
+ SimpleValue value = new SimpleValue(mappings);
value.setTypeName( "long" );
Property property = new Property();
@@ -144,7 +153,7 @@
}
private Property generateNameProperty() {
- SimpleValue value = new SimpleValue();
+ SimpleValue value = new SimpleValue(mappings);
value.setTypeName( "string" );
Property property = new Property();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ClassificationType.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ClassificationType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ClassificationType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,5 +1,6 @@
package org.hibernate.test.hql;
+import org.hibernate.type.IntegerType;
import org.hibernate.usertype.EnhancedUserType;
import org.hibernate.HibernateException;
import org.hibernate.Hibernate;
@@ -46,7 +47,7 @@
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
- Integer ordinal = ( Integer ) Hibernate.INTEGER.nullSafeGet( rs, names[0] );
+ Integer ordinal = ( Integer ) IntegerType.INSTANCE.nullSafeGet( rs, names[0] );
return Classification.valueOf( ordinal );
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/QueryTranslatorTestCase.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/QueryTranslatorTestCase.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -477,7 +477,7 @@
assertEquals( "Column names were different", oldmeta.getColumnName(i), newmeta.getColumnName(i) );
assertEquals( "Column types were different", oldmeta.getColumnType(i), newmeta.getColumnType(i) );
assertEquals( "Java types were different", oldmeta.getColumnClassName(i), newmeta.getColumnClassName(i) );
- types[i] = TypeFactory.basic( oldmeta.getColumnClassName(i) );
+ types[i] = sfi().getTypeResolver().basic( oldmeta.getColumnClassName(i) );
}
}
catch( Throwable t ) {
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/instrument/domain/CustomBlobType.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/instrument/domain/CustomBlobType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/instrument/domain/CustomBlobType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -20,7 +20,7 @@
*/
public Object nullSafeGet(ResultSet rs, String names[], Object owner) throws SQLException {
// cast just to make sure...
- return ( byte[] ) Hibernate.BINARY.nullSafeGet( rs, names );
+ return ( byte[] ) Hibernate.BINARY.nullSafeGet( rs, names[0] );
}
/**
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/interfaceproxy/InterfaceProxyTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -41,11 +41,11 @@
Transaction t = s.beginTransaction();
Document d = new DocumentImpl();
d.setName("Hibernate in Action");
- d.setContent( Hibernate.createBlob( "blah blah blah".getBytes() ) );
+ d.setContent( Hibernate.createBlob( "blah blah blah".getBytes(), s ) );
Long did = (Long) s.save(d);
SecureDocument d2 = new SecureDocumentImpl();
d2.setName("Secret");
- d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes() ) );
+ d2.setContent( Hibernate.createBlob( "wxyz wxyz".getBytes(), s ) );
// SybaseASE15Dialect only allows 7-bits in a byte to be inserted into a tinyint
// column (0 <= val < 128)
d2.setPermissionBits( (byte) 127 );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/DoubleStringType.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/DoubleStringType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/DoubleStringType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -10,6 +10,7 @@
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.StringType;
import org.hibernate.type.Type;
import org.hibernate.usertype.CompositeUserType;
@@ -50,8 +51,8 @@
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
- String first = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
- String second = (String) Hibernate.STRING.nullSafeGet(rs, names[1]);
+ String first = StringType.INSTANCE.nullSafeGet( rs, names[0], session );
+ String second = StringType.INSTANCE.nullSafeGet( rs, names[1], session );
return ( first==null && second==null ) ? null : new String[] { first, second };
}
@@ -61,8 +62,8 @@
String[] strings = (value==null) ? new String[2] : (String[]) value;
- Hibernate.STRING.nullSafeSet(st, strings[0], index);
- Hibernate.STRING.nullSafeSet(st, strings[1], index+1);
+ StringType.INSTANCE.nullSafeSet( st, strings[0], index, session );
+ StringType.INSTANCE.nullSafeSet( st, strings[1], index+1, session );
}
public String[] getPropertyNames() {
@@ -70,7 +71,7 @@
}
public Type[] getPropertyTypes() {
- return new Type[] { Hibernate.STRING, Hibernate.STRING };
+ return new Type[] { StringType.INSTANCE, StringType.INSTANCE };
}
public Object getPropertyValue(Object component, int property) {
@@ -103,10 +104,3 @@
}
}
-
-
-
-
-
-
-
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiplicityType.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiplicityType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiplicityType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -10,6 +10,8 @@
import org.hibernate.HibernateException;
import org.hibernate.engine.ForeignKeys;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.IntegerType;
+import org.hibernate.type.StringType;
import org.hibernate.type.Type;
import org.hibernate.usertype.CompositeUserType;
@@ -19,10 +21,10 @@
"count", "glarch"
};
private static final int[] SQL_TYPES = new int[] {
- Hibernate.INTEGER.sqlType(), Hibernate.STRING.sqlType()
+ IntegerType.INSTANCE.getSqlTypeDescriptor().getSqlType(), StringType.INSTANCE.getSqlTypeDescriptor().getSqlType()
};
private static final Type[] TYPES = new Type[] {
- Hibernate.INTEGER, Hibernate.entity(Glarch.class)
+ IntegerType.INSTANCE, Hibernate.entity(Glarch.class)
};
public String[] getPropertyNames() {
@@ -78,7 +80,7 @@
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
- Integer c = (Integer) Hibernate.INTEGER.nullSafeGet( rs, names[0] );
+ Integer c = (Integer) IntegerType.INSTANCE.nullSafeGet( rs, names[0], session );
GlarchProxy g = (GlarchProxy) Hibernate.entity(Glarch.class).nullSafeGet(rs, names[1], session, owner);
Multiplicity m = new Multiplicity();
m.count = c==null ? 0 : c.intValue();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/mapping/ValueVisitorTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -7,6 +7,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Mappings;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Array;
import org.hibernate.mapping.Bag;
@@ -170,23 +172,26 @@
};
public void testProperCallbacks() {
+ final Mappings mappings = new Configuration().createMappings();
+ final Table tbl = new Table();
+ final RootClass rootClass = new RootClass();
ValueVisitor vv = new ValueVisitorValidator();
- new Any(new Table()).accept(vv);
- new Array(new RootClass()).accept(vv);
- new Bag(new RootClass()).accept(vv);
- new Component(new RootClass()).accept(vv);
- new DependantValue(null,null).accept(vv);
- new IdentifierBag(null).accept(vv);
- new List(null).accept(vv);
- new ManyToOne(null).accept(vv);
- new Map(null).accept(vv);
- new OneToMany(null).accept(vv);
- new OneToOne(null, new RootClass() ).accept(vv);
- new PrimitiveArray(null).accept(vv);
- new Set(null).accept(vv);
- new SimpleValue().accept(vv);
+ new Any(mappings, tbl).accept(vv);
+ new Array( rootClass ).accept(vv);
+ new Bag( rootClass ).accept(vv);
+ new Component( mappings, rootClass ).accept(vv);
+ new DependantValue( mappings, tbl, null ).accept(vv);
+ new IdentifierBag( rootClass ).accept(vv);
+ new List( rootClass ).accept(vv);
+ new ManyToOne( mappings, tbl ).accept(vv);
+ new Map( rootClass ).accept(vv);
+ new OneToMany( rootClass ).accept(vv);
+ new OneToOne( mappings, tbl, rootClass ).accept(vv);
+ new PrimitiveArray( rootClass ).accept(vv);
+ new Set( rootClass ).accept(vv);
+ new SimpleValue( mappings ).accept(vv);
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -67,7 +67,7 @@
String blah = "blah";
String select = "select blah from blah";
NativeSQLQueryReturn[] queryReturns =
- new NativeSQLQueryScalarReturn[] {new NativeSQLQueryScalarReturn(blah, TypeFactory.basic( "int" ) ) };
+ new NativeSQLQueryScalarReturn[] {new NativeSQLQueryScalarReturn(blah, sfi().getTypeResolver().basic( "int" ) ) };
NativeSQLQuerySpecification spec = new NativeSQLQuerySpecification(select,
queryReturns, null);
return spec;
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/queryplan/NativeSQLQueryReturnEqualsAndHashCodeTest.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2010, 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,19 +20,13 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.test.queryplan;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Map;
import org.hibernate.LockMode;
-import org.hibernate.Session;
-import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.query.HQLQueryPlan;
-import org.hibernate.engine.query.QueryPlanCache;
import org.hibernate.engine.query.sql.NativeSQLQueryCollectionReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryJoinReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
@@ -56,13 +50,13 @@
}
public void testNativeSQLQueryScalarReturn() {
- NativeSQLQueryScalarReturn typeNoAlias = new NativeSQLQueryScalarReturn( null, TypeFactory.basic( "int" ) );
+ NativeSQLQueryScalarReturn typeNoAlias = new NativeSQLQueryScalarReturn( null, sfi().getTypeResolver().basic( "int" ) );
NativeSQLQueryScalarReturn aliasNoType = new NativeSQLQueryScalarReturn( "abc", null );
- NativeSQLQueryScalarReturn aliasTypeInt = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "int" ) );
- NativeSQLQueryScalarReturn aliasTypeLong = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "long" ) );
- NativeSQLQueryScalarReturn aliasTypeLongClass = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( Long.class.getName() ) );
- NativeSQLQueryScalarReturn aliasTypeString = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "string" ) );
- NativeSQLQueryScalarReturn aliasTypeStringClass = new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( String.class.getName() ) );
+ NativeSQLQueryScalarReturn aliasTypeInt = new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "int" ) );
+ NativeSQLQueryScalarReturn aliasTypeLong = new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "long" ) );
+ NativeSQLQueryScalarReturn aliasTypeLongClass = new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( Long.class.getName() ) );
+ NativeSQLQueryScalarReturn aliasTypeString = new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "string" ) );
+ NativeSQLQueryScalarReturn aliasTypeStringClass = new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( String.class.getName() ) );
check( false, typeNoAlias, aliasNoType );
check( false, typeNoAlias, aliasTypeInt );
@@ -91,13 +85,13 @@
check( true, aliasTypeString, aliasTypeStringClass );
- check( true, typeNoAlias, new NativeSQLQueryScalarReturn( null, TypeFactory.basic( "int" ) ) );
+ check( true, typeNoAlias, new NativeSQLQueryScalarReturn( null, sfi().getTypeResolver().basic( "int" ) ) );
check( true, aliasNoType, new NativeSQLQueryScalarReturn( "abc", null ) );
- check( true, aliasTypeInt, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "int" ) ) );
- check( true, aliasTypeLong, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "long" ) ) );
- check( true, aliasTypeLongClass, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( Long.class.getName() ) ) );
- check( true, aliasTypeString, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( "string" ) ) );
- check( true, aliasTypeStringClass, new NativeSQLQueryScalarReturn( "abc", TypeFactory.basic( String.class.getName() ) ) );
+ check( true, aliasTypeInt, new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "int" ) ) );
+ check( true, aliasTypeLong, new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "long" ) ) );
+ check( true, aliasTypeLongClass, new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( Long.class.getName() ) ) );
+ check( true, aliasTypeString, new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( "string" ) ) );
+ check( true, aliasTypeStringClass, new NativeSQLQueryScalarReturn( "abc", sfi().getTypeResolver().basic( String.class.getName() ) ) );
}
public void testNativeSQLQueryRootReturn() {
@@ -247,7 +241,7 @@
}
public void testNativeSQLQueryReturnTypes() {
- NativeSQLQueryScalarReturn r1 = new NativeSQLQueryScalarReturn( "a", TypeFactory.basic( "int" ) );
+ NativeSQLQueryScalarReturn r1 = new NativeSQLQueryScalarReturn( "a", sfi().getTypeResolver().basic( "int" ) );
NativeSQLQueryRootReturn r2 = new NativeSQLQueryRootReturn( "a", "b", LockMode.NONE );
NativeSQLQueryJoinReturn r3 = new NativeSQLQueryJoinReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE );
NativeSQLQueryCollectionReturn r4 = new NativeSQLQueryCollectionReturn( "a", "b", "c", Collections.singletonMap( "key", "value" ), LockMode.NONE);
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/where/File.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/where/File.hbm.xml 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/where/File.hbm.xml 2010-05-01 18:20:26 UTC (rev 19335)
@@ -13,7 +13,7 @@
<generator class="increment"/>
</id>
<property name="name"/>
- <property name="deleted" type="org.hibernate.test.where.NumericTrueFalseType"/>
+ <property name="deleted" type="numeric_boolean"/>
<many-to-one name="parent"/>
<set name="children" inverse="true" where="deleted=0">
<key column="parent"/>
Deleted: core/trunk/testsuite/src/test/java/org/hibernate/test/where/NumericTrueFalseType.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/where/NumericTrueFalseType.java 2010-05-01 14:28:08 UTC (rev 19334)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/where/NumericTrueFalseType.java 2010-05-01 18:20:26 UTC (rev 19335)
@@ -1,53 +0,0 @@
-package org.hibernate.test.where;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.PreparedStatement;
-import java.sql.Types;
-
-import org.hibernate.type.BooleanType;
-import org.hibernate.dialect.Dialect;
-
-/**
- * Maps int db values to boolean java values. Zero is considered false; any
- * non-zero value is considered true.
- *
- * @author Steve Ebersole
- */
-public class NumericTrueFalseType extends BooleanType {
-
- public Object get(ResultSet rs, String name) throws SQLException {
- int value = rs.getInt( name );
- if ( rs.wasNull() ) {
- return getDefaultValue();
- }
- else if ( value == 0 ) {
- return Boolean.FALSE;
- }
- else {
- return Boolean.TRUE;
- }
- }
-
- public void set(PreparedStatement st, Object value, int index) throws SQLException {
- if ( value == null ) {
- st.setNull( index, Types.INTEGER );
- }
- else {
- boolean bool = ( ( Boolean ) value ).booleanValue();
- st.setInt( index, bool ? 1 : 0 );
- }
- }
-
- public String objectToSQLString(Object value, Dialect dialect) throws Exception {
- return ( ( Boolean ) value ).booleanValue() ? "1" : "0";
- }
-
- public int sqlType() {
- return Types.INTEGER;
- }
-
- public String getName() {
- return "numeric_boolean";
- }
-}
14 years, 8 months
Hibernate SVN: r19334 - search/trunk.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-05-01 10:28:08 -0400 (Sat, 01 May 2010)
New Revision: 19334
Modified:
search/trunk/pom.xml
Log:
HSEARCH-506 Bump dependency to core 3.5.1-Final
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-05-01 14:21:56 UTC (rev 19333)
+++ search/trunk/pom.xml 2010-05-01 14:28:08 UTC (rev 19334)
@@ -127,7 +127,7 @@
<properties>
<slf4jVersion>1.5.8</slf4jVersion>
<luceneVersion>2.9.2</luceneVersion>
- <hibernateVersion>3.5.0-Final</hibernateVersion>
+ <hibernateVersion>3.5.1-Final</hibernateVersion>
<hibernateCommonsAnnotationVersion>3.2.0.Final</hibernateCommonsAnnotationVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
14 years, 8 months
Hibernate SVN: r19333 - search/trunk.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-05-01 10:21:56 -0400 (Sat, 01 May 2010)
New Revision: 19333
Modified:
search/trunk/pom.xml
Log:
HSEARCH-519 Update JGroups dependencies
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-04-30 21:47:10 UTC (rev 19332)
+++ search/trunk/pom.xml 2010-05-01 14:21:56 UTC (rev 19333)
@@ -284,7 +284,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.7.GA</version>
+ <version>2.9.0.GA</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
14 years, 8 months