From 37a8f83d2e475426027e044a33ff51168c958f04 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 1 Aug 2011 19:47:15 +0800 Subject: [PATCH] HHH-6490 Support @javax.persistence.Lob HHH-6492 Support @javax.persistence.Enumerated refact HHH-6489 Support @javax.persistence.Temporal refact test add license header --- ...ava => AbstractAttributeTypeResolver.java} | 27 +- .../annotations/attribute/BasicAttribute.java | 16 +- .../CompositeHibernateTypeResolver.java | 59 ---- .../attribute/DerivedValueSourceImpl.java | 24 ++ .../ExplicitHibernateTypeSourceImpl.java | 29 +- .../attribute/HibernateTypeResolver.java | 11 - .../attribute/MappedAttribute.java | 24 +- .../attribute/type/AttributeTypeResolver.java | 35 +++ .../type/CompositeAttributeTypeResolver.java | 83 ++++++ .../{ => type}/EnumeratedTypeResolver.java | 32 ++- .../ExplicitAttributeTypeResolver.java} | 32 ++- .../attribute/{ => type}/LobTypeResolver.java | 30 ++- .../{ => type}/TemporalTypeResolver.java | 37 ++- .../annotations/entity/EmbeddedIdTests.java | 24 ++ .../entity/EnumeratedBindingTests.java | 24 ++ .../entity/IdentifierGeneratorTest.java | 24 ++ .../annotations/entity/LobBindingTests.java | 252 +++++++++++++----- .../entity/QuotedIdentifierTest.java | 26 ++ 18 files changed, 602 insertions(+), 187 deletions(-) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/{AbstractHibernateTypeResolver.java => AbstractAttributeTypeResolver.java} (52%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/CompositeHibernateTypeResolver.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/HibernateTypeResolver.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/AttributeTypeResolver.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/CompositeAttributeTypeResolver.java rename hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/{ => type}/EnumeratedTypeResolver.java (74%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/{ExplicitHibernateTypeResolver.java => type/ExplicitAttributeTypeResolver.java} (57%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/{ => type}/LobTypeResolver.java (70%) rename hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/{ => type}/TemporalTypeResolver.java (62%) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractHibernateTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractAttributeTypeResolver.java similarity index 52% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractHibernateTypeResolver.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractAttributeTypeResolver.java index a79dc56fad..817c6af873 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractHibernateTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/AbstractAttributeTypeResolver.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute; import java.util.Collections; @@ -6,11 +30,12 @@ import java.util.Map; import org.jboss.jandex.AnnotationInstance; import org.hibernate.internal.util.StringHelper; +import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver; /** * @author Strong Liu */ -public abstract class AbstractHibernateTypeResolver implements HibernateTypeResolver { +public abstract class AbstractAttributeTypeResolver implements AttributeTypeResolver { protected abstract AnnotationInstance getAnnotationInstance(); protected abstract String resolveHibernateTypeName(AnnotationInstance annotationInstance); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/BasicAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/BasicAttribute.java index 1ca3f058ce..47d70c7670 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/BasicAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/BasicAttribute.java @@ -45,6 +45,12 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper; +import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.type.CompositeAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.type.EnumeratedTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.type.ExplicitAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.type.LobTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.type.TemporalTypeResolver; /** * Represent a mapped attribute (explicitly or implicitly mapped). @@ -99,7 +105,7 @@ public class BasicAttribute extends MappedAttribute { private final String customWriteFragment; private final String customReadFragment; private final String checkCondition; - private HibernateTypeResolver resolver; + private AttributeTypeResolver resolver; public static BasicAttribute createSimpleAttribute(String name, Class attributeType, @@ -351,17 +357,17 @@ public class BasicAttribute extends MappedAttribute { } @Override - public HibernateTypeResolver getHibernateTypeResolver() { + public AttributeTypeResolver getHibernateTypeResolver() { if ( resolver == null ) { resolver = getDefaultHibernateTypeResolver(); } return resolver; } - protected HibernateTypeResolver getDefaultHibernateTypeResolver() { + protected AttributeTypeResolver getDefaultHibernateTypeResolver() { - CompositeHibernateTypeResolver resolver = new CompositeHibernateTypeResolver( - new ExplicitHibernateTypeResolver( + CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( + new ExplicitAttributeTypeResolver( this ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/CompositeHibernateTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/CompositeHibernateTypeResolver.java deleted file mode 100644 index e8cdaf4b28..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/CompositeHibernateTypeResolver.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.hibernate.metamodel.source.annotations.attribute; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.hibernate.AssertionFailure; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; - -/** - * @author Strong Liu - */ -public class CompositeHibernateTypeResolver implements HibernateTypeResolver { - private List resolvers = new ArrayList(); - private final ExplicitHibernateTypeResolver explicitHibernateTypeResolver; - - public CompositeHibernateTypeResolver(ExplicitHibernateTypeResolver explicitHibernateTypeResolver) { - if ( explicitHibernateTypeResolver == null ) { - throw new AssertionFailure( "The Given HibernateTypeResolver is null." ); - } - this.explicitHibernateTypeResolver = explicitHibernateTypeResolver; - } - - public void addHibernateTypeResolver(HibernateTypeResolver resolver) { - if ( resolver == null ) { - throw new AssertionFailure( "The Given HibernateTypeResolver is null." ); - } - resolvers.add( resolver ); - } - - @Override - public String getExplicitHibernateTypeName() { - String type = explicitHibernateTypeResolver.getExplicitHibernateTypeName(); - if ( StringHelper.isEmpty( type ) ) { - for ( HibernateTypeResolver resolver : resolvers ) { - type = resolver.getExplicitHibernateTypeName(); - if ( StringHelper.isNotEmpty( type ) ) { - break; - } - } - } - return type; - } - - @Override - public Map getExplicitHibernateTypeParameters() { - Map parameters = explicitHibernateTypeResolver.getExplicitHibernateTypeParameters(); - if ( CollectionHelper.isEmpty( parameters ) ) { - for ( HibernateTypeResolver resolver : resolvers ) { - parameters = resolver.getExplicitHibernateTypeParameters(); - if ( CollectionHelper.isNotEmpty( parameters ) ) { - break; - } - } - } - return parameters; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/DerivedValueSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/DerivedValueSourceImpl.java index e92b86cb9c..c53002db96 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/DerivedValueSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/DerivedValueSourceImpl.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute; import org.hibernate.metamodel.source.binder.DerivedValueSource; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeSourceImpl.java index 2e1ff22348..6c4b1d7ce5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeSourceImpl.java @@ -1,16 +1,41 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute; import java.util.Map; +import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver; import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource; /** * @author Strong Liu */ public class ExplicitHibernateTypeSourceImpl implements ExplicitHibernateTypeSource { - private final HibernateTypeResolver typeResolver; + private final AttributeTypeResolver typeResolver; - public ExplicitHibernateTypeSourceImpl(HibernateTypeResolver typeResolver) { + public ExplicitHibernateTypeSourceImpl(AttributeTypeResolver typeResolver) { this.typeResolver = typeResolver; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/HibernateTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/HibernateTypeResolver.java deleted file mode 100644 index d8bef4014a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/HibernateTypeResolver.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.hibernate.metamodel.source.annotations.attribute; - -import java.util.Map; - -/** - * @author Strong Liu - */ -public interface HibernateTypeResolver { - String getExplicitHibernateTypeName(); - Map getExplicitHibernateTypeParameters(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/MappedAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/MappedAttribute.java index 41bbc55cb0..b19d544005 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/MappedAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/MappedAttribute.java @@ -23,32 +23,14 @@ */ package org.hibernate.metamodel.source.annotations.attribute; -import java.io.Serializable; -import java.sql.Blob; -import java.sql.Clob; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.persistence.TemporalType; import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.DotName; -import org.hibernate.AnnotationException; -import org.hibernate.AssertionFailure; -import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.source.annotations.AnnotationBindingContext; -import org.hibernate.metamodel.source.annotations.HibernateDotNames; -import org.hibernate.metamodel.source.annotations.JPADotNames; -import org.hibernate.metamodel.source.annotations.JandexHelper; -import org.hibernate.type.CharacterArrayClobType; -import org.hibernate.type.PrimitiveCharacterArrayClobType; -import org.hibernate.type.SerializableToBlobType; -import org.hibernate.type.StandardBasicTypes; -import org.hibernate.type.WrappedMaterializedBlobType; +import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver; /** * Base class for the different types of mapped attributes @@ -106,7 +88,7 @@ public abstract class MappedAttribute implements Comparable { return context; } - Map> annotations() { + public Map> annotations() { return annotations; } @@ -115,7 +97,7 @@ public abstract class MappedAttribute implements Comparable { return name.compareTo( mappedProperty.getName() ); } - public abstract HibernateTypeResolver getHibernateTypeResolver(); + public abstract AttributeTypeResolver getHibernateTypeResolver(); @Override public String toString() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/AttributeTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/AttributeTypeResolver.java new file mode 100644 index 0000000000..f1dc0e1254 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/AttributeTypeResolver.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; + +import java.util.Map; + +/** + * @author Strong Liu + */ +public interface AttributeTypeResolver { + String getExplicitHibernateTypeName(); + Map getExplicitHibernateTypeParameters(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/CompositeAttributeTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/CompositeAttributeTypeResolver.java new file mode 100644 index 0000000000..096a75f701 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/CompositeAttributeTypeResolver.java @@ -0,0 +1,83 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.hibernate.AssertionFailure; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; + +/** + * @author Strong Liu + */ +public class CompositeAttributeTypeResolver implements AttributeTypeResolver { + private List resolvers = new ArrayList(); + private final ExplicitAttributeTypeResolver explicitHibernateTypeResolver; + + public CompositeAttributeTypeResolver(ExplicitAttributeTypeResolver explicitHibernateTypeResolver) { + if ( explicitHibernateTypeResolver == null ) { + throw new AssertionFailure( "The Given AttributeTypeResolver is null." ); + } + this.explicitHibernateTypeResolver = explicitHibernateTypeResolver; + } + + public void addHibernateTypeResolver(AttributeTypeResolver resolver) { + if ( resolver == null ) { + throw new AssertionFailure( "The Given AttributeTypeResolver is null." ); + } + resolvers.add( resolver ); + } + + @Override + public String getExplicitHibernateTypeName() { + String type = explicitHibernateTypeResolver.getExplicitHibernateTypeName(); + if ( StringHelper.isEmpty( type ) ) { + for ( AttributeTypeResolver resolver : resolvers ) { + type = resolver.getExplicitHibernateTypeName(); + if ( StringHelper.isNotEmpty( type ) ) { + break; + } + } + } + return type; + } + + @Override + public Map getExplicitHibernateTypeParameters() { + Map parameters = explicitHibernateTypeResolver.getExplicitHibernateTypeParameters(); + if ( CollectionHelper.isEmpty( parameters ) ) { + for ( AttributeTypeResolver resolver : resolvers ) { + parameters = resolver.getExplicitHibernateTypeParameters(); + if ( CollectionHelper.isNotEmpty( parameters ) ) { + break; + } + } + } + return parameters; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/EnumeratedTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/EnumeratedTypeResolver.java similarity index 74% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/EnumeratedTypeResolver.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/EnumeratedTypeResolver.java index f7602f80b3..f386645b6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/EnumeratedTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/EnumeratedTypeResolver.java @@ -1,4 +1,28 @@ -package org.hibernate.metamodel.source.annotations.attribute; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; import java.sql.Types; import java.util.HashMap; @@ -8,16 +32,16 @@ import org.jboss.jandex.AnnotationInstance; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; -import org.hibernate.metamodel.relational.Identifier; -import org.hibernate.metamodel.relational.Schema; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; +import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute; import org.hibernate.type.EnumType; /** * @author Strong Liu */ -public class EnumeratedTypeResolver extends AbstractHibernateTypeResolver { +public class EnumeratedTypeResolver extends AbstractAttributeTypeResolver { private final MappedAttribute mappedAttribute; private final boolean isMapKey; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/ExplicitAttributeTypeResolver.java similarity index 57% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeResolver.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/ExplicitAttributeTypeResolver.java index b32c40cabe..ff2f8d4c4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/ExplicitHibernateTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/ExplicitAttributeTypeResolver.java @@ -1,4 +1,28 @@ -package org.hibernate.metamodel.source.annotations.attribute; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; import java.util.HashMap; import java.util.Map; @@ -8,15 +32,17 @@ import org.jboss.jandex.AnnotationValue; import org.hibernate.metamodel.source.annotations.HibernateDotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; +import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute; /** * @author Strong Liu */ -public class ExplicitHibernateTypeResolver extends AbstractHibernateTypeResolver { +public class ExplicitAttributeTypeResolver extends AbstractAttributeTypeResolver { private final MappedAttribute mappedAttribute; - public ExplicitHibernateTypeResolver(MappedAttribute mappedAttribute) { + public ExplicitAttributeTypeResolver(MappedAttribute mappedAttribute) { this.mappedAttribute = mappedAttribute; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/LobTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/LobTypeResolver.java similarity index 70% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/LobTypeResolver.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/LobTypeResolver.java index 5fbe53125e..99d048099b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/LobTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/LobTypeResolver.java @@ -1,4 +1,28 @@ -package org.hibernate.metamodel.source.annotations.attribute; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; import java.io.Serializable; import java.sql.Blob; @@ -11,6 +35,8 @@ import org.jboss.jandex.AnnotationInstance; import org.hibernate.AssertionFailure; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; +import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute; import org.hibernate.type.CharacterArrayClobType; import org.hibernate.type.PrimitiveCharacterArrayClobType; import org.hibernate.type.SerializableToBlobType; @@ -20,7 +46,7 @@ import org.hibernate.type.WrappedMaterializedBlobType; /** * @author Strong Liu */ -public class LobTypeResolver extends AbstractHibernateTypeResolver { +public class LobTypeResolver extends AbstractAttributeTypeResolver { private final MappedAttribute mappedAttribute; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/TemporalTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/TemporalTypeResolver.java similarity index 62% rename from hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/TemporalTypeResolver.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/TemporalTypeResolver.java index 72210be237..79f0ddcab8 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/TemporalTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/attribute/type/TemporalTypeResolver.java @@ -1,4 +1,28 @@ -package org.hibernate.metamodel.source.annotations.attribute; +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.attribute.type; import java.util.Calendar; import java.util.Date; @@ -11,11 +35,14 @@ import org.hibernate.AssertionFailure; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; +import org.hibernate.metamodel.source.annotations.attribute.AbstractAttributeTypeResolver; +import org.hibernate.metamodel.source.annotations.attribute.MappedAttribute; +import org.hibernate.type.StandardBasicTypes; /** * @author Strong Liu */ -public class TemporalTypeResolver extends AbstractHibernateTypeResolver { +public class TemporalTypeResolver extends AbstractAttributeTypeResolver { private final MappedAttribute mappedAttribute; private final boolean isMapKey; @@ -40,16 +67,16 @@ public class TemporalTypeResolver extends AbstractHibernateTypeResolver { String type = null; switch ( temporalType ) { case DATE: - type = isDate ? "date" : "calendar_date"; + type = isDate ? StandardBasicTypes.DATE.getName() : StandardBasicTypes.CALENDAR_DATE.getName(); break; case TIME: - type = "time"; + type = StandardBasicTypes.TIME.getName(); if ( !isDate ) { throw new NotYetImplementedException( "Calendar cannot persist TIME only" ); } break; case TIMESTAMP: - type = isDate ? "timestamp" : "calendar"; + type = isDate ? StandardBasicTypes.TIMESTAMP.getName() : StandardBasicTypes.CALENDAR.getName(); break; default: throw new AssertionFailure( "Unknown temporal type: " + temporalType ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedIdTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedIdTests.java index 45073a425a..91635135fa 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedIdTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EmbeddedIdTests.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.entity; import javax.persistence.Access; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EnumeratedBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EnumeratedBindingTests.java index 928260569e..7753fd8da4 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EnumeratedBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/EnumeratedBindingTests.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.entity; import java.sql.Types; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/IdentifierGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/IdentifierGeneratorTest.java index 014fa1ae4c..11c50418bf 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/IdentifierGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/IdentifierGeneratorTest.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.entity; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/LobBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/LobBindingTests.java index f56d6a6185..6069d63048 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/LobBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/LobBindingTests.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.entity; import java.io.Serializable; @@ -23,8 +47,6 @@ import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.WrappedMaterializedBlobType; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -55,92 +77,174 @@ public class LobBindingTests extends BaseAnnotationBindingTestCase { String noLob; } - class Thing implements Serializable{ + class Thing implements Serializable { int size; } + private HibernateTypeDescriptor getTypeDescriptor(String attributeName) { + EntityBinding binding = getEntityBinding( Item.class ); + AttributeBinding attributeBinding = binding.locateAttributeBinding( attributeName ); + return attributeBinding.getHibernateTypeDescriptor(); + } + + private class ExpectedValue { + String explicitTypeName; + String javaTypeName; + boolean isResolvedTypeMappingNull; + Class resolvedTypeMappingClass; + boolean isTypeParametersNull; + boolean isTypeParametersEmpty; + + private ExpectedValue(String explicitTypeName, + String javaTypeName, + boolean resolvedTypeMappingNull, + Class resolvedTypeMappingClass, + boolean typeParametersNull, + boolean typeParametersEmpty + ) { + this.explicitTypeName = explicitTypeName; + this.isResolvedTypeMappingNull = resolvedTypeMappingNull; + this.isTypeParametersEmpty = typeParametersEmpty; + this.isTypeParametersNull = typeParametersNull; + this.javaTypeName = javaTypeName; + this.resolvedTypeMappingClass = resolvedTypeMappingClass; + } + } + + private void checkHibernateTypeDescriptor(ExpectedValue expectedValue, String attributeName) { + HibernateTypeDescriptor descriptor = getTypeDescriptor( attributeName ); + assertEquals( expectedValue.explicitTypeName, descriptor.getExplicitTypeName() ); + assertEquals( expectedValue.javaTypeName, descriptor.getJavaTypeName() ); + assertEquals( expectedValue.isResolvedTypeMappingNull, descriptor.getResolvedTypeMapping() == null ); + assertEquals( expectedValue.resolvedTypeMappingClass, descriptor.getResolvedTypeMapping().getClass() ); + assertEquals( expectedValue.isTypeParametersNull, descriptor.getTypeParameters() == null ); + assertEquals( expectedValue.isTypeParametersEmpty, descriptor.getTypeParameters().isEmpty() ); + } + @Test @Resources(annotatedClasses = Item.class) - public void testLobTypeAttribute() { - EntityBinding binding = getEntityBinding( Item.class ); + public void testClobWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + "clob", + Clob.class.getName(), + false, + ClobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "clob" ); + } - AttributeBinding attributeBinding = binding.locateAttributeBinding( "clob" ); - HibernateTypeDescriptor descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( "clob", descriptor.getExplicitTypeName() ); - assertEquals( Clob.class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( ClobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testBlobWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + "blob", + Blob.class.getName(), + false, + BlobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "blob" ); + } - attributeBinding = binding.locateAttributeBinding( "blob" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( "blob", descriptor.getExplicitTypeName() ); - assertEquals( Blob.class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( BlobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testStringWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + "materialized_clob", + String.class.getName(), + false, + MaterializedClobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "str" ); + } - attributeBinding = binding.locateAttributeBinding( "str" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( "materialized_clob", descriptor.getExplicitTypeName() ); - assertEquals( String.class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( MaterializedClobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testCharacterArrayWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + CharacterArrayClobType.class.getName(), + Character[].class.getName(), + false, + CharacterArrayClobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "characters" ); + } - attributeBinding = binding.locateAttributeBinding( "characters" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( CharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() ); - assertEquals( Character[].class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( CharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testPrimitiveCharacterArrayWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + PrimitiveCharacterArrayClobType.class.getName(), + char[].class.getName(), + false, + PrimitiveCharacterArrayClobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "chars" ); + } - attributeBinding = binding.locateAttributeBinding( "chars" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( PrimitiveCharacterArrayClobType.class.getName(), descriptor.getExplicitTypeName() ); - assertEquals( char[].class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( PrimitiveCharacterArrayClobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testByteArrayWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + WrappedMaterializedBlobType.class.getName(), + Byte[].class.getName(), + false, + WrappedMaterializedBlobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "bytes" ); + } - attributeBinding = binding.locateAttributeBinding( "bytes" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( WrappedMaterializedBlobType.class.getName(), descriptor.getExplicitTypeName() ); - assertEquals( Byte[].class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( WrappedMaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testPrimitiveByteArrayWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + StandardBasicTypes.MATERIALIZED_BLOB.getName(), + byte[].class.getName(), + false, + MaterializedBlobType.class, + false, + true + ); + checkHibernateTypeDescriptor( expectedValue, "bytes2" ); + } - attributeBinding = binding.locateAttributeBinding( "bytes2" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( StandardBasicTypes.MATERIALIZED_BLOB.getName(), descriptor.getExplicitTypeName() ); - assertEquals( byte[].class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( MaterializedBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + @Test + @Resources(annotatedClasses = Item.class) + public void testSerializableWithLobAnnotation() { + ExpectedValue expectedValue = new ExpectedValue( + SerializableToBlobType.class.getName(), + Thing.class.getName(), + false, + SerializableToBlobType.class, + false, + false + ); + checkHibernateTypeDescriptor( expectedValue, "serializable" ); - attributeBinding = binding.locateAttributeBinding( "serializable" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertEquals( SerializableToBlobType.class.getName(), descriptor.getExplicitTypeName() ); - assertEquals( Thing.class.getName(), descriptor.getJavaTypeName() ); - assertNotNull( descriptor.getResolvedTypeMapping() ); - assertEquals( SerializableToBlobType.class, descriptor.getResolvedTypeMapping().getClass() ); - assertNotNull( descriptor.getTypeParameters() ); - assertEquals( 1,descriptor.getTypeParameters().size() ); - assertTrue( descriptor.getTypeParameters().get( SerializableToBlobType.CLASS_NAME ).equals( Thing.class.getName() ) ); + assertTrue( + getTypeDescriptor( "serializable" ).getTypeParameters() + .get( SerializableToBlobType.CLASS_NAME ) + .equals( Thing.class.getName() ) + ); + } - attributeBinding = binding.locateAttributeBinding( "noLob" ); - descriptor = attributeBinding.getHibernateTypeDescriptor(); - assertNull( descriptor.getExplicitTypeName() ); - assertTrue( descriptor.getTypeParameters().isEmpty() ); + + @Test + @Resources(annotatedClasses = Item.class) + public void testNoLobAttribute() { + assertNull( getTypeDescriptor( "noLob" ).getExplicitTypeName() ); + assertTrue( getTypeDescriptor( "noLob" ).getTypeParameters().isEmpty() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/QuotedIdentifierTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/QuotedIdentifierTest.java index 61ea86b750..c8b95b2afd 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/QuotedIdentifierTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/QuotedIdentifierTest.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. or third-party contributors as + * indicated 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.metamodel.source.annotations.entity; import javax.persistence.Entity; @@ -33,6 +57,8 @@ public class QuotedIdentifierTest extends BaseAnnotationBindingTestCase { assertIdentifierEquals( "`TABLE_ITEM4`", item ); } + //todo check if the column names are quoted + private void assertIdentifierEquals(String expected, EntityBinding realValue) { org.hibernate.metamodel.relational.Table table = (org.hibernate.metamodel.relational.Table) realValue.getPrimaryTable(); assertEquals( Identifier.toIdentifier( expected ), table.getTableName() );