HHH-5138 - Redesign types + introduce TypeRegistry & TypeResolver

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19335 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-05-01 18:20:26 +00:00
parent 4c764f0294
commit 421789ddcd
223 changed files with 9983 additions and 3332 deletions

View File

@ -655,7 +655,7 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
( RootClass ) persistentClass,
discriminatorColumn,
entityBinder.getSecondaryTables(),
propertyHolder
propertyHolder,
mappings
);
entityBinder.bindDiscriminatorValue();//bind it again since the type might have changed
}
@ -1229,7 +1230,7 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
* 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 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
}
}
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 @@ public final class AnnotationBinder {
);
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 @@ public final class AnnotationBinder {
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();

View File

@ -147,8 +147,8 @@ public class BinderHelper {
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 @@ public class BinderHelper {
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 @@ public class BinderHelper {
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

View File

@ -82,7 +82,7 @@ public class CopyIdentifierComponentSecondPass implements SecondPass {
//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() );

View File

@ -84,7 +84,7 @@ public class OneToOneSecondPass implements SecondPass {
//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 @@ public class OneToOneSecondPass implements SecondPass {
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 @@ public class OneToOneSecondPass implements SecondPass {
//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 );

View File

@ -1098,7 +1098,7 @@ public abstract class CollectionBinder {
.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 @@ public abstract class CollectionBinder {
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 );

View File

@ -586,13 +586,11 @@ public class EntityBinder {
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 );

View File

@ -133,7 +133,7 @@ public class MapBinder extends CollectionBinder {
);
}
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 @@ public class MapBinder extends CollectionBinder {
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 @@ public class MapBinder extends CollectionBinder {
}
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 @@ public class MapBinder extends CollectionBinder {
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 @@ public class MapBinder extends CollectionBinder {
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 @@ public class MapBinder extends CollectionBinder {
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 @@ public class MapBinder extends CollectionBinder {
targetValue = targetManyToOne;
}
else {
targetValue = new SimpleValue( collection.getCollectionTable() );
targetValue = new SimpleValue( mappings, collection.getCollectionTable() );
targetValue.setTypeName( sourceValue.getTypeName() );
targetValue.setTypeParameters( sourceValue.getTypeParameters() );
}

View File

@ -212,7 +212,7 @@ public class PropertyBinder {
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 );

View File

@ -295,7 +295,7 @@ public class SimpleValueBinder {
if ( table == null ) {
table = columns[0].getTable();
}
simpleValue = new SimpleValue( table );
simpleValue = new SimpleValue( mappings, table );
linkWithValue();

View File

@ -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();
public WrappedMaterializedBlobType() {
super( BlobTypeDescriptor.INSTANCE, ByteArrayTypeDescriptor.INSTANCE );
}
protected Object toExternalFormat(byte[] bytes) {
if (bytes == null)
return null;
return wrapPrimitive(bytes);
}
protected byte[] toInternalFormat(Object bytes) {
if (bytes == null)
return null;
return unwrapNonPrimitive((Byte[]) bytes);
}
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;
public String getName() {
// todo name these annotation types for addition to the registry
return null;
}
}

View File

@ -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.HibernateException;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.java.CharacterArrayTypeDescriptor;
import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
/**
* 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();
public CharacterArrayTextType() {
super( LongVarcharTypeDescriptor.INSTANCE, CharacterArrayTypeDescriptor.INSTANCE );
}
@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 String getName() {
// todo name these annotation types for addition to the registry
return null;
}
@Override
public void set(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
Character[] cs = (Character[]) value;
super.set(st, unwrapNonPrimitive(cs), index);
}
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;
}
}

View File

@ -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.HibernateException;
import org.hibernate.type.TextType;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.java.PrimitiveCharacterArrayTypeDescriptor;
import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
/**
* 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();
public PrimitiveCharacterArrayTextType() {
super( LongVarcharTypeDescriptor.INSTANCE, PrimitiveCharacterArrayTypeDescriptor.INSTANCE );
}
@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 String getName() {
// todo name these annotation types for addition to the registry
return null;
}
@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);
}
@Override
public String toString(Object val) {
return String.valueOf(val);
}
}

View File

@ -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();
public SerializableToImageType() {
super( LongVarbinaryTypeDescriptor.INSTANCE, new SerializableTypeDescriptor<Serializable>( Serializable.class ) );
}
protected Object toExternalFormat(byte[] bytes) {
if (bytes == null)
return null;
return SerializationHelper.deserialize( bytes, getReturnedClass().getClassLoader() );
}
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;
}
}

View File

@ -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();
public WrappedImageType() {
super( LongVarbinaryTypeDescriptor.INSTANCE, ByteArrayTypeDescriptor.INSTANCE );
}
protected Object toExternalFormat(byte[] bytes) {
if(bytes==null)return null;
return wrapPrimitive(bytes);
}
protected byte[] toInternalFormat(Object bytes) {
if(bytes==null)return null;
return unwrapNonPrimitive(( Byte[] ) bytes);
}
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;
public String getName() {
// todo name these annotation types for addition to the registry
return null;
}
}

View File

@ -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.IntegerType;
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.TimeZoneType;
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,145 +101,6 @@ import org.hibernate.usertype.CompositeUserType;
*/
public final class Hibernate {
/**
* Hibernate <tt>long</tt> type.
*/
public static final NullableType LONG = new LongType();
/**
* Hibernate <tt>short</tt> type.
*/
public static final NullableType SHORT = new ShortType();
/**
* Hibernate <tt>integer</tt> type.
*/
public static final NullableType INTEGER = new IntegerType();
/**
* Hibernate <tt>byte</tt> type.
*/
public static final NullableType BYTE = new ByteType();
/**
* Hibernate <tt>float</tt> type.
*/
public static final NullableType FLOAT = new FloatType();
/**
* Hibernate <tt>double</tt> type.
*/
public static final NullableType DOUBLE = new DoubleType();
/**
* Hibernate <tt>character</tt> type.
*/
public static final NullableType CHARACTER = new CharacterType();
/**
* Hibernate <tt>string</tt> type.
*/
public static final NullableType STRING = new StringType();
/**
* Hibernate <tt>time</tt> type.
*/
public static final NullableType TIME = new TimeType();
/**
* Hibernate <tt>date</tt> type.
*/
public static final NullableType DATE = new DateType();
/**
* Hibernate <tt>timestamp</tt> type.
*/
public static final NullableType TIMESTAMP = new TimestampType();
/**
* Hibernate <tt>boolean</tt> type.
*/
public static final NullableType BOOLEAN = new BooleanType();
/**
* Hibernate <tt>true_false</tt> type.
*/
public static final NullableType TRUE_FALSE = new TrueFalseType();
/**
* Hibernate <tt>yes_no</tt> type.
*/
public static final NullableType YES_NO = new YesNoType();
/**
* Hibernate <tt>big_decimal</tt> type.
*/
public static final NullableType BIG_DECIMAL = new BigDecimalType();
/**
* Hibernate <tt>big_integer</tt> type.
*/
public static final NullableType BIG_INTEGER = new BigIntegerType();
/**
* Hibernate <tt>binary</tt> type.
*/
public static final NullableType BINARY = new BinaryType();
/**
* Hibernate <tt>wrapper-binary</tt> type.
*/
public static final NullableType WRAPPER_BINARY = new WrapperBinaryType();
/**
* Hibernate char[] type.
*/
public static final NullableType CHAR_ARRAY = new CharArrayType();
/**
* Hibernate Character[] type.
*/
public static final NullableType CHARACTER_ARRAY = new CharacterArrayType();
/**
* Hibernate <tt>image</tt> type.
*/
public static final NullableType IMAGE = new ImageType();
/**
* Hibernate <tt>text</tt> type.
*/
public static final NullableType TEXT = new TextType();
/**
* Hibernate <tt>materialized_blob</tt> type.
*/
public static final NullableType MATERIALIZED_BLOB = new MaterializedBlobType();
/**
* Hibernate <tt>materialized_clob</tt> type.
*/
public static final NullableType MATERIALIZED_CLOB = new MaterializedClobType();
/**
* Hibernate <tt>blob</tt> type.
*/
public static final Type BLOB = new BlobType();
/**
* Hibernate <tt>clob</tt> type.
*/
public static final Type CLOB = new ClobType();
/**
* Hibernate <tt>calendar</tt> type.
*/
public static final NullableType CALENDAR = new CalendarType();
/**
* Hibernate <tt>calendar_date</tt> type.
*/
public static final NullableType CALENDAR_DATE = new CalendarDateType();
/**
* Hibernate <tt>locale</tt> type.
*/
public static final NullableType LOCALE = new LocaleType();
/**
* Hibernate <tt>currency</tt> type.
*/
public static final NullableType CURRENCY = new CurrencyType();
/**
* Hibernate <tt>timezone</tt> type.
*/
public static final NullableType TIMEZONE = new TimeZoneType();
/**
* Hibernate <tt>class</tt> type.
*/
public static final NullableType CLASS = new ClassType();
/**
* Hibernate <tt>serializable</tt> type.
*/
public static final NullableType SERIALIZABLE = new SerializableType( Serializable.class );
/**
* Hibernate <tt>object</tt> type.
*/
public static final Type OBJECT = new AnyType();
/**
* Cannot be instantiated.
*/
@ -247,8 +108,180 @@ public final class Hibernate {
throw new UnsupportedOperationException();
}
/**
* Hibernate <tt>long</tt> type.
* @deprecated Use {@link LongType#INSTANCE} instead.
*/
public static final LongType LONG = LongType.INSTANCE;
/**
* Hibernate <tt>short</tt> type.
* @deprecated Use {@link ShortType#INSTANCE} instead.
*/
public static final ShortType SHORT = ShortType.INSTANCE;
/**
* Hibernate <tt>integer</tt> type.
* @deprecated Use {@link IntegerType#INSTANCE} instead.
*/
public static final IntegerType INTEGER = IntegerType.INSTANCE;
/**
* Hibernate <tt>byte</tt> type.
* @deprecated Use {@link ByteType#INSTANCE} instead.
*/
public static final ByteType BYTE = ByteType.INSTANCE;
/**
* Hibernate <tt>float</tt> type.
* @deprecated Use {@link FloatType#INSTANCE} instead.
*/
public static final FloatType FLOAT = FloatType.INSTANCE;
/**
* Hibernate <tt>double</tt> type.
* @deprecated Use {@link DoubleType#INSTANCE} instead.
*/
public static final DoubleType DOUBLE = DoubleType.INSTANCE;
/**
* Hibernate <tt>character</tt> type.
* @deprecated Use {@link CharacterType#INSTANCE} instead.
*/
public static final CharacterType CHARACTER = CharacterType.INSTANCE;
/**
* Hibernate <tt>string</tt> type.
* @deprecated Use {@link StringType#INSTANCE} instead.
*/
public static final StringType STRING = StringType.INSTANCE;
/**
* Hibernate <tt>time</tt> type.
* @deprecated Use {@link TimeType#INSTANCE} instead.
*/
public static final TimeType TIME = TimeType.INSTANCE;
/**
* Hibernate <tt>date</tt> type.
* @deprecated Use {@link DateType#INSTANCE} instead.
*/
public static final DateType DATE = DateType.INSTANCE;
/**
* Hibernate <tt>timestamp</tt> type.
* @deprecated Use {@link TimestampType#INSTANCE} instead.
*/
public static final TimestampType TIMESTAMP = TimestampType.INSTANCE;
/**
* Hibernate <tt>boolean</tt> type.
* @deprecated Use {@link BooleanType#INSTANCE} instead.
*/
public static final BooleanType BOOLEAN = BooleanType.INSTANCE;
/**
* Hibernate <tt>true_false</tt> type.
* @deprecated Use {@link TrueFalseType#INSTANCE} instead.
*/
public static final TrueFalseType TRUE_FALSE = TrueFalseType.INSTANCE;
/**
* Hibernate <tt>yes_no</tt> type.
* @deprecated Use {@link YesNoType#INSTANCE} instead.
*/
public static final YesNoType YES_NO = YesNoType.INSTANCE;
/**
* Hibernate <tt>big_decimal</tt> type.
* @deprecated Use {@link BigDecimalType#INSTANCE} instead.
*/
public static final BigDecimalType BIG_DECIMAL = BigDecimalType.INSTANCE;
/**
* Hibernate <tt>big_integer</tt> type.
* @deprecated Use {@link BigIntegerType#INSTANCE} instead.
*/
public static final BigIntegerType BIG_INTEGER = BigIntegerType.INSTANCE;
/**
* Hibernate <tt>binary</tt> type.
* @deprecated Use {@link BinaryType#INSTANCE} instead.
*/
public static final BinaryType BINARY = BinaryType.INSTANCE;
/**
* Hibernate <tt>wrapper-binary</tt> type.
* @deprecated Use {@link WrapperBinaryType#INSTANCE} instead.
*/
public static final WrapperBinaryType WRAPPER_BINARY = WrapperBinaryType.INSTANCE;
/**
* Hibernate char[] type.
* @deprecated Use {@link CharArrayType#INSTANCE} instead.
*/
public static final CharArrayType CHAR_ARRAY = CharArrayType.INSTANCE;
/**
* Hibernate Character[] type.
* @deprecated Use {@link CharacterArrayType#INSTANCE} instead.
*/
public static final CharacterArrayType CHARACTER_ARRAY = CharacterArrayType.INSTANCE;
/**
* Hibernate <tt>image</tt> type.
* @deprecated Use {@link ImageType#INSTANCE} instead.
*/
public static final ImageType IMAGE = ImageType.INSTANCE;
/**
* Hibernate <tt>text</tt> type.
* @deprecated Use {@link TextType#INSTANCE} instead.
*/
public static final TextType TEXT = TextType.INSTANCE;
/**
* Hibernate <tt>materialized_blob</tt> type.
* @deprecated Use {@link MaterializedBlobType#INSTANCE} instead.
*/
public static final MaterializedBlobType MATERIALIZED_BLOB = MaterializedBlobType.INSTANCE;
/**
* Hibernate <tt>materialized_clob</tt> type.
* @deprecated Use {@link MaterializedClobType#INSTANCE} instead.
*/
public static final MaterializedClobType MATERIALIZED_CLOB = MaterializedClobType.INSTANCE;
/**
* Hibernate <tt>blob</tt> type.
* @deprecated Use {@link BlobType#INSTANCE} instead.
*/
public static final BlobType BLOB = BlobType.INSTANCE;
/**
* Hibernate <tt>clob</tt> type.
* @deprecated Use {@link ClobType#INSTANCE} instead.
*/
public static final ClobType CLOB = ClobType.INSTANCE;
/**
* Hibernate <tt>calendar</tt> type.
* @deprecated Use {@link CalendarType#INSTANCE} instead.
*/
public static final CalendarType CALENDAR = CalendarType.INSTANCE;
/**
* Hibernate <tt>calendar_date</tt> type.
* @deprecated Use {@link CalendarDateType#INSTANCE} instead.
*/
public static final CalendarDateType CALENDAR_DATE = CalendarDateType.INSTANCE;
/**
* Hibernate <tt>locale</tt> type.
* @deprecated Use {@link LocaleType#INSTANCE} instead.
*/
public static final LocaleType LOCALE = LocaleType.INSTANCE;
/**
* Hibernate <tt>currency</tt> type.
* @deprecated Use {@link CurrencyType#INSTANCE} instead.
*/
public static final CurrencyType CURRENCY = CurrencyType.INSTANCE;
/**
* Hibernate <tt>timezone</tt> type.
* @deprecated Use {@link TimeZoneType#INSTANCE} instead.
*/
public static final TimeZoneType TIMEZONE = TimeZoneType.INSTANCE;
/**
* Hibernate <tt>class</tt> type.
* @deprecated Use {@link ClassType#INSTANCE} instead.
*/
public static final ClassType CLASS = ClassType.INSTANCE;
/**
* Hibernate <tt>serializable</tt> type.
* @deprecated Use {@link SerializableType#INSTANCE} instead.
*/
public static final SerializableType SERIALIZABLE = SerializableType.INSTANCE;
/**
* Hibernate <tt>object</tt> type.
* @deprecated Use {@link ObjectType#INSTANCE} instead.
*/
public static final ObjectType OBJECT = ObjectType.INSTANCE;
/**
* 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 final class Hibernate {
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 );
}
}

View File

@ -132,8 +132,10 @@ import org.hibernate.secure.JACCConfiguration;
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 @@ public class Configuration implements Serializable {
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 @@ public class Configuration implements Serializable {
sqlFunctions.put( functionName, function );
}
public TypeResolver getTypeResolver() {
return typeResolver;
}
public SessionFactoryObserver getSessionFactoryObserver() {
return sessionFactoryObserver;
}
@ -2381,6 +2388,9 @@ public class Configuration implements Serializable {
Configuration.this.namingStrategy = namingStrategy;
}
public TypeResolver getTypeResolver() {
return typeResolver;
}
public Iterator iterateClasses() {
return classes.values().iterator();

View File

@ -411,7 +411,7 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
// 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 @@ public final class HbmBinder {
// 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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
}
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
}
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 @@ public final class HbmBinder {
);
}
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 @@ public final class HbmBinder {
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 @@ public final class HbmBinder {
);
}
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 @@ public final class HbmBinder {
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 );
}

View File

@ -44,6 +44,7 @@ import org.hibernate.mapping.TypeDef;
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 @@ import org.hibernate.mapping.FetchProfile;
* @author Steve Ebersole
*/
public interface Mappings {
/**
* Retrieve the type resolver in effect.
*
* @return The type resolver.
*/
public TypeResolver getTypeResolver();
/**
* Get the current naming strategy.

View File

@ -81,7 +81,7 @@ public abstract class ResultSetMappingBinder {
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 );
}

View File

@ -41,8 +41,8 @@ import org.hibernate.loader.CollectionAliases;
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 @@ public abstract class PersistentIndexedElementHolder extends AbstractPersistentC
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 @@ public abstract class PersistentIndexedElementHolder extends AbstractPersistentC
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 abstract class PersistentIndexedElementHolder extends AbstractPersistentC
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) {

View File

@ -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.io.Serializable;
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 @@ public class PersistentListElementHolder extends PersistentIndexedElementHolder
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;

View File

@ -31,8 +31,8 @@ import org.dom4j.Element;
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 @@ public class PersistentMapElementHolder extends PersistentIndexedElementHolder {
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 @@ public class PersistentMapElementHolder extends PersistentIndexedElementHolder {
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;
}
}

View File

@ -56,7 +56,7 @@ public class CastFunction implements SQLFunction {
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()");
}

View File

@ -52,6 +52,7 @@ import org.hibernate.exception.SQLExceptionConverter;
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 @@ import org.hibernate.type.Type;
* @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.

View File

@ -44,6 +44,7 @@ import java.io.IOException;
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 @@ public class ClobProxy implements InvocationHandler {
* @see #generateProxy(String)
*/
protected ClobProxy(String string) {
this.string = string;
reader = new StringReader(string);
length = string.length();
}
@ -86,15 +88,24 @@ public class ClobProxy implements InvocationHandler {
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 @@ public class ClobProxy implements InvocationHandler {
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;

View File

@ -555,13 +555,30 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
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()

View File

@ -74,5 +74,6 @@ public class BooleanLiteralNode extends LiteralNode implements ExpectedTypeAware
private LiteralType typeAsLiteralType() {
return (LiteralType) getDataType();
}
}

View File

@ -55,7 +55,7 @@ public class JavaConstantNode extends Node implements ExpectedTypeAwareNode, Ses
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 @@ public class JavaConstantNode extends Node implements ExpectedTypeAwareNode, Ses
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 @@ public class JavaConstantNode extends Node implements ExpectedTypeAwareNode, Ses
throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + constantExpression, t );
}
}
public String getRenderText(SessionFactoryImplementor sessionFactory) {
Type type = expectedType == null ? heuristicType : expectedType;
return resolveToLiteralString( type );
}
}

View File

@ -185,7 +185,7 @@ public class LiteralProcessor implements HqlSqlTokenTypes {
}
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 );

View File

@ -395,7 +395,7 @@ public class SessionFactoryHelper {
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();

View File

@ -427,7 +427,7 @@ public class WhereParser implements Parser {
) {
Type type;
try {
type = TypeFactory.heuristicType( constant.getClass().getName() );
type = q.getFactory().getTypeResolver().heuristicType( constant.getClass().getName() );
}
catch ( MappingException me ) {
throw new QueryException( me );

View File

@ -480,7 +480,7 @@ public abstract class AbstractQueryImpl implements Query {
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 {

View File

@ -122,6 +122,7 @@ import org.hibernate.tool.hbm2ddl.SchemaValidator;
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 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
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 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
}
};
this.typeResolver = cfg.getTypeResolver().scope( this );
this.filters = new HashMap();
this.filters.putAll( cfg.getFilterDefinitions() );
@ -498,6 +502,10 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
return null;
}
public TypeResolver getTypeResolver() {
return typeResolver;
}
private void registerEntityNameResolvers(EntityPersister persister) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizerMapping() == null ) {
return;

View File

@ -56,8 +56,8 @@ import org.hibernate.persister.entity.Loadable;
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 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
}
// 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 {

View File

@ -583,7 +583,7 @@ public class CustomLoader extends Loader {
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,

View File

@ -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 @@ import org.hibernate.type.TypeFactory;
* @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 class Any extends SimpleValue {
}
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 )
);
}

View File

@ -31,6 +31,7 @@ import java.util.Map;
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 @@ public class Component extends SimpleValue implements MetaAttributable {
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();
}

View File

@ -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 @@ public class DependantValue extends SimpleValue {
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;
}

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
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 @@ public class ManyToOne extends ToOne {
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 {

View File

@ -28,6 +28,7 @@ import java.util.ArrayList;
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 @@ public class OneToOne extends ToOne {
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();
}

View File

@ -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 java.util.Properties;
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 @@ import org.hibernate.util.ReflectHelper;
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 @@ public class SimpleValue implements KeyValue {
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,12 +119,6 @@ public class SimpleValue implements KeyValue {
public void setTable(Table table) {
this.table = table;
}
public SimpleValue(Table table) {
this.table = table;
}
public SimpleValue() {}
public void createForeignKey() throws MappingException {}
@ -278,7 +287,7 @@ public class SimpleValue implements KeyValue {
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){

View File

@ -26,6 +26,7 @@ package org.hibernate.mapping;
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 @@ public abstract class ToOne extends SimpleValue implements Fetchable {
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 @@ public abstract class ToOne extends SimpleValue implements Fetchable {
}
}

View File

@ -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 @@ import org.hibernate.cfg.Environment;
*
* @author Gavin King
* @author Emmanuel Bernard
*
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class AbstractBynaryType extends MutableType implements VersionType, Comparator {

View File

@ -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 @@ import org.hibernate.dialect.Dialect;
* 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 {

View File

@ -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;

View File

@ -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 @@ package org.hibernate.type;
* 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 {

View File

@ -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 @@ import org.hibernate.HibernateException;
/**
* 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 {

View File

@ -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 );
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan;
import org.hibernate.type.descriptor.java.MutabilityPlan;
/**
* 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);
}
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();
@Override
@SuppressWarnings({ "unchecked" })
protected MutabilityPlan<T> getMutabilityPlan() {
return ImmutableMutabilityPlan.INSTANCE;
}
public String getName() {
return "imm_" + mutableType.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);
return "imm_" + baseMutableType.getName();
}
}

View File

@ -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.proxy.HibernateProxyHelper;
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 @@ public class AnyType extends AbstractType implements AbstractComponentType, Asso
this.metaType = metaType;
}
public AnyType() {
this(Hibernate.STRING, Hibernate.SERIALIZABLE);
}
public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory)
throws HibernateException {
return value;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}

View File

@ -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 );
}
}

View File

@ -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 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();
public BigDecimalType() {
super( NumericTypeDescriptor.INSTANCE, BigDecimalTypeDescriptor.INSTANCE );
}
/**
* {@inheritDoc}
*/
public String getName() {
return "big_decimal";
}
public Object fromStringValue(String xml) {
return new BigDecimal(xml);
@Override
protected boolean registerUnderJavaType() {
return true;
}
}
}

View File

@ -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 Object stringToObject(String xml) throws Exception {
return new BigInteger(xml);
}
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();
public static final BigIntegerType INSTANCE = new BigIntegerType();
public BigIntegerType() {
super( NumericTypeDescriptor.INSTANCE, BigIntegerTypeDescriptor.INSTANCE );
}
/**
* {@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 );
}
}

View File

@ -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();
}
}

View File

@ -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,158 +20,24 @@
* 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 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
public BlobType() {
super( org.hibernate.type.descriptor.sql.BlobTypeDescriptor.INSTANCE, BlobTypeDescriptor.INSTANCE );
}
/**
@ -181,93 +47,15 @@ public class BlobType extends AbstractType {
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);
}
}

View File

@ -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;
protected BooleanType(SqlTypeDescriptor sqlTypeDescriptor, BooleanTypeDescriptor javaTypeDescriptor) {
super( sqlTypeDescriptor, javaTypeDescriptor );
}
public String getName() {
return "boolean";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), boolean.class.getName(), Boolean.class.getName() };
}
public Class getPrimitiveClass() {
return boolean.class;
}
public Class getReturnedClass() {
return Boolean.class;
public Serializable getDefaultValue() {
return Boolean.FALSE;
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setBoolean( index, ( (Boolean) value ).booleanValue() );
public Boolean stringToObject(String string) {
return fromString( string );
}
public int sqlType() {
return Types.BIT;
@SuppressWarnings({ "UnnecessaryUnboxing" })
public String objectToSQLString(Boolean value, Dialect dialect) {
return dialect.toBooleanValueString( value.booleanValue() );
}
public String getName() { return "boolean"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return dialect.toBooleanValueString( ( (Boolean) value ).booleanValue() );
}
public Object stringToObject(String xml) throws Exception {
return fromStringValue(xml);
}
public Object fromStringValue(String xml) {
return Boolean.valueOf(xml);
}
}

View File

@ -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 ByteType() {
super( TinyIntTypeDescriptor.INSTANCE, ByteTypeDescriptor.INSTANCE );
}
public String getName() {
return "byte";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), byte.class.getName(), Byte.class.getName() };
}
public Serializable getDefaultValue() {
return ZERO;
}
public Object get(ResultSet rs, String name) throws SQLException {
return new Byte( rs.getByte(name) );
}
public Class getPrimitiveClass() {
return byte.class;
}
public Class getReturnedClass() {
return Byte.class;
public String objectToSQLString(Byte value, Dialect dialect) {
return toString( value );
}
public void set(PreparedStatement st, Object value, int index) throws SQLException {
st.setByte( index, ( (Byte) value ).byteValue() );
public Byte stringToObject(String xml) {
return fromString( xml );
}
public int sqlType() {
return Types.TINYINT;
public Byte fromStringValue(String xml) {
return fromString( xml );
}
public String getName() { return "byte"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return value.toString();
@SuppressWarnings({ "UnnecessaryUnboxing" })
public Byte next(Byte current, SessionImplementor session) {
return Byte.valueOf( (byte) ( current.byteValue() + 1 ) );
}
public Object stringToObject(String xml) throws Exception {
return new Byte(xml);
}
public Object fromStringValue(String xml) {
return new Byte(xml);
}
public Object next(Object current, SessionImplementor session) {
return new Byte( (byte) ( ( (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();
}
}

View File

@ -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,95 +20,25 @@
* 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 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 CalendarDateType() {
super( DateTypeDescriptor.INSTANCE, CalendarTypeDescriptor.INSTANCE );
}
public String getName() {

View File

@ -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 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 CalendarType() {
super( TimestampTypeDescriptor.INSTANCE, CalendarTypeDescriptor.INSTANCE );
}
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();
}
}

View File

@ -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"; }
}

View File

@ -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.HibernateException;
import org.hibernate.dialect.Dialect;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
/**
* 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;
}
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);
}
/**
* @deprecated Pass the true/false values into constructor instead.
*/
protected final String getFalseString() {
return stringValueFalse;
}
}

View File

@ -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();
public CharacterArrayType() {
super( VarcharTypeDescriptor.INSTANCE, CharacterArrayTypeDescriptor.INSTANCE );
}
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 String getName() {
return "wrapper-characters";
}
public Class getReturnedClass() {
return Character[].class;
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), Character[].class.getName(), "Character[]" };
}
public String getName() { return "wrapper-characters"; }
}

View File

@ -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 static final CharacterType INSTANCE = new CharacterType();
public CharacterType() {
super( CharTypeDescriptor.INSTANCE, CharacterTypeDescriptor.INSTANCE );
}
public String getName() {
return "character";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), char.class.getName(), Character.class.getName() };
}
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) );
}
throw new UnsupportedOperationException( "not a valid id type" );
}
public Class getPrimitiveClass() {
return char.class;
}
public Class getReturnedClass() {
return Character.class;
public String objectToSQLString(Character value, Dialect dialect) {
return '\'' + toString( value ) + '\'';
}
public void set(PreparedStatement st, Object value, int index) throws SQLException {
st.setString( index, (value).toString() );
}
public int sqlType() {
return Types.CHAR;
}
public String getName() { return "character"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return '\'' + value.toString() + '\'';
}
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 Object fromStringValue(String xml) {
return new Character( xml.charAt(0) );
public Character stringToObject(String xml) {
return fromString( xml );
}
}

View File

@ -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.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.util.ReflectHelper;
import org.hibernate.type.descriptor.java.ClassTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/**
* <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 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 ClassType() {
super( VarcharTypeDescriptor.INSTANCE, ClassTypeDescriptor.INSTANCE );
}
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;
}
}

View File

@ -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 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 ClobType() {
super( org.hibernate.type.descriptor.sql.ClobTypeDescriptor.INSTANCE, ClobTypeDescriptor.INSTANCE );
}
public String getName() {
return "clob";
}
public Serializable disassemble(Object value, SessionImplementor session, Object owner)
throws HibernateException {
throw new UnsupportedOperationException("Clobs are not cacheable");
@Override
protected boolean registerUnderJavaType() {
return true;
}
public Object deepCopy(Object value, EntityMode entityMode, SessionFactoryImplementor factory) {
return value;
}
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);
}
}

View File

@ -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 @@ public abstract class CollectionType extends AbstractType implements Association
this.foreignKeyPropertyName = foreignKeyPropertyName;
this.isEmbeddedInXML = isEmbeddedInXML;
}
public boolean isEmbeddedInXML() {
return isEmbeddedInXML;
}

View File

@ -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;

View File

@ -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 @@ import org.hibernate.usertype.CompositeUserType;
* 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) {

View File

@ -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 ) + "\'";
}
}

View File

@ -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;

View File

@ -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.sql.SQLException;
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.Mapping;
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 @@ public class CustomType extends AbstractType implements IdentifierType, Discrimi
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() {

View File

@ -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);
}
}
}

View File

@ -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.PreparedStatement;
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 @@ import org.slf4j.LoggerFactory;
*
* @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 @@ public class DbTimestampType extends TimestampType implements VersionType {
}
}
private Timestamp getCurrentTimestamp(SessionImplementor session) {
private Date getCurrentTimestamp(SessionImplementor session) {
Dialect dialect = session.getFactory().getDialect();
String timestampSelectString = dialect.getCurrentTimestampSelectString();
if ( dialect.isCurrentTimestampSelectStringCallable() ) {

View File

@ -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> {
}

View File

@ -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();
@SuppressWarnings({ "UnnecessaryBoxing" })
public static final Double ZERO = Double.valueOf( 0.0 );
public DoubleType() {
super( org.hibernate.type.descriptor.sql.DoubleTypeDescriptor.INSTANCE, DoubleTypeDescriptor.INSTANCE );
}
public String getName() {
return "double";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), double.class.getName(), Double.class.getName() };
}
public Serializable getDefaultValue() {
return new Double(0.0);
}
public Object get(ResultSet rs, String name) throws SQLException {
return new Double( rs.getDouble(name) );
return ZERO;
}
public Class getPrimitiveClass() {
return double.class;
}
public Class getReturnedClass() {
return Double.class;
public String objectToSQLString(Double value, Dialect dialect) throws Exception {
return toString( value );
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setDouble( index, ( (Double) value ).doubleValue() );
}
public int sqlType() {
return Types.DOUBLE;
}
public String getName() { return "double"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return value.toString();
}
public Object fromStringValue(String xml) {
return new Double(xml);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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();
@SuppressWarnings({ "UnnecessaryBoxing" })
public static final Float ZERO = Float.valueOf( 0.0f );
public FloatType() {
super( org.hibernate.type.descriptor.sql.FloatTypeDescriptor.INSTANCE, FloatTypeDescriptor.INSTANCE );
}
public String getName() {
return "float";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), float.class.getName(), Float.class.getName() };
}
public Serializable getDefaultValue() {
return new Float(0.0);
}
public Object get(ResultSet rs, String name) throws SQLException {
return new Float( rs.getFloat(name) );
return ZERO;
}
public Class getPrimitiveClass() {
return float.class;
}
public Class getReturnedClass() {
return Float.class;
public String objectToSQLString(Float value, Dialect dialect) throws Exception {
return toString( value );
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setFloat( index, ( (Float) value ).floatValue() );
}
public int sqlType() {
return Types.FLOAT;
}
public String getName() { return "float"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return value.toString();
}
public Object fromStringValue(String xml) {
return new Float(xml);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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() {

View File

@ -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 @@ import org.hibernate.engine.SessionImplementor;
/**
* Superclass of nullable immutable types.
* @author Gavin King
*
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class ImmutableType extends NullableType {

View File

@ -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();
@SuppressWarnings({ "UnnecessaryBoxing" })
public static final Integer ZERO = Integer.valueOf( 0 );
public IntegerType() {
super( org.hibernate.type.descriptor.sql.IntegerTypeDescriptor.INSTANCE, IntegerTypeDescriptor.INSTANCE );
}
public String getName() {
return "integer";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), int.class.getName(), Integer.class.getName() };
}
public Serializable getDefaultValue() {
return ZERO;
}
public Object get(ResultSet rs, String name) throws SQLException {
return new Integer( rs.getInt(name) );
}
public Class getPrimitiveClass() {
return int.class;
}
public Class getReturnedClass() {
return Integer.class;
public String objectToSQLString(Integer value, Dialect dialect) throws Exception {
return toString( value );
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setInt( index, ( (Integer) value ).intValue() );
public Integer stringToObject(String xml) {
return fromString( xml );
}
public int sqlType() {
return Types.INTEGER;
}
public String getName() { return "integer"; }
public String objectToSQLString(Object value, Dialect dialect) throws Exception {
return value.toString();
}
public Object stringToObject(String xml) throws Exception {
return new Integer(xml);
}
public Object next(Object current, SessionImplementor session) {
return new Integer( ( (Integer) current ).intValue() + 1 );
}
public Object seed(SessionImplementor session) {
public Integer seed(SessionImplementor session) {
return ZERO;
}
public Comparator getComparator() {
return ComparableComparator.INSTANCE;
}
public Object fromStringValue(String xml) {
return new Integer(xml);
@SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
public Integer next(Integer current, SessionImplementor session) {
return Integer.valueOf( current.intValue() + 1 );
}
public Comparator<Integer> getComparator() {
return getJavaTypeDescriptor().getComparator();
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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 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 LocaleType() {
super( VarcharTypeDescriptor.INSTANCE, LocaleTypeDescriptor.INSTANCE );
}
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 );
}
}

View File

@ -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();
@SuppressWarnings({ "UnnecessaryBoxing" })
private static final Long ZERO = Long.valueOf( 0 );
public LongType() {
super( BigIntTypeDescriptor.INSTANCE, LongTypeDescriptor.INSTANCE );
}
public String getName() {
return "long";
}
@Override
public String[] getRegistrationKeys() {
return new String[] { getName(), long.class.getName(), Long.class.getName() };
}
public Serializable getDefaultValue() {
return ZERO;
}
public Object get(ResultSet rs, String name) throws SQLException {
return new Long( rs.getLong(name) );
}
public Class getPrimitiveClass() {
return long.class;
}
public Class getReturnedClass() {
return Long.class;
}
public void set(PreparedStatement st, Object value, int index)
throws SQLException {
st.setLong( index, ( (Long) value ).longValue() );
}
public int sqlType() {
return Types.BIGINT;
}
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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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() {

View File

@ -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";
}
}

View File

@ -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 @@ import org.hibernate.engine.SessionImplementor;
* @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 class MetaType extends AbstractType {
}
}
public String[] getRegistrationKeys() {
return REGISTRATION_KEYS;
}
public int[] sqlTypes(Mapping mapping) throws MappingException {
return baseType.sqlTypes(mapping);
}

View File

@ -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 @@ import org.hibernate.engine.SessionImplementor;
/**
* Superclass for mutable nullable types
* @author Gavin King
*
* @deprecated Use the {@link AbstractStandardBasicType} approach instead
*/
public abstract class MutableType extends NullableType {

Some files were not shown because too many files have changed in this diff Show More