From 50ee956d4996df3325bcf6483170ac869ff56f65 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 8 Aug 2011 14:04:53 +0800 Subject: [PATCH] HHH-6262 Bind @EmbeddedId --- .../binding/BasicAttributeBinding.java | 2 +- .../binding/PluralAttributeBinding.java | 2 +- .../annotations/entity/EntityClass.java | 11 ++---- .../entity/RootEntitySourceImpl.java | 7 ++-- .../binder/ComponentIdentifierSource.java | 37 +++++++++++++++++++ .../source/binder/IdentifierSource.java | 11 +++++- .../source/binder/SimpleIdentifierSource.java | 6 --- 7 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentIdentifierSource.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/BasicAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/BasicAttributeBinding.java index 6fc2387646..c867c7b494 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/BasicAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/BasicAttributeBinding.java @@ -43,7 +43,7 @@ import org.hibernate.metamodel.source.MetaAttributeContext; */ public class BasicAttributeBinding extends AbstractSingularAttributeBinding - implements SingularAttributeBinding, KeyValueBinding { + implements KeyValueBinding { private String unsavedValue; private PropertyGeneration generation; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java index 0db73c2d28..d1b7e0357a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/binding/PluralAttributeBinding.java @@ -29,7 +29,7 @@ import org.hibernate.persister.collection.CollectionPersister; /** * @author Steve Ebersole */ -public interface PluralAttributeBinding extends AttributeBinding, AssociationAttributeBinding { +public interface PluralAttributeBinding extends AssociationAttributeBinding { // todo : really it is the element (and/or index) that can be associative not the collection itself... public CollectionKey getCollectionKey(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java index f61adfbd8c..00ed4cf75b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java @@ -295,24 +295,19 @@ public class EntityClass extends ConfiguredClass { } if ( !idAnnotations.isEmpty() ) { - if ( idAnnotations.size() == 1 ) { - return IdType.SIMPLE; - } - else { - return IdType.COMPOSED; - } + return idAnnotations.size() == 1 ? IdType.SIMPLE : IdType.COMPOSED; } return IdType.NONE; } private List findIdAnnotations(DotName idAnnotationType) { List idAnnotationList = new ArrayList(); - if ( getClassInfo().annotations().get( idAnnotationType ) != null ) { + if ( getClassInfo().annotations().containsKey( idAnnotationType ) ) { idAnnotationList.addAll( getClassInfo().annotations().get( idAnnotationType ) ); } ConfiguredClass parent = getParent(); while ( parent != null ) { - if ( parent.getClassInfo().annotations().get( idAnnotationType ) != null ) { + if ( parent.getClassInfo().annotations().containsKey( idAnnotationType ) ) { idAnnotationList.addAll( parent.getClassInfo().annotations().get( idAnnotationType ) ); } parent = parent.getParent(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/RootEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/RootEntitySourceImpl.java index 247733b4fc..808c0b0cd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/RootEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/RootEntitySourceImpl.java @@ -25,6 +25,7 @@ package org.hibernate.metamodel.source.annotations.entity; import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; +import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.engine.OptimisticLockStyle; import org.hibernate.metamodel.binding.Caching; import org.hibernate.metamodel.source.annotations.attribute.BasicAttribute; @@ -53,17 +54,15 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity return new SimpleIdentifierSourceImpl( attribute, getEntityClass().getAttributeOverrideMap() ); } case COMPOSED: { - break; + throw new NotYetImplementedException( "Composed ids must still be implemented." ); } case EMBEDDED: { - break; + throw new NotYetImplementedException( "Embedded ids must still be implemented." ); } default: { throw new AssertionFailure( "The root entity needs to specify an identifier" ); } } - - return null; //To change body of implemented methods use File | Settings | File Templates. } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentIdentifierSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentIdentifierSource.java new file mode 100644 index 0000000000..feb396751c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/ComponentIdentifierSource.java @@ -0,0 +1,37 @@ +/* + * 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.binder; + +/** + * @author Strong Liu + */ +public interface ComponentIdentifierSource extends IdentifierSource { + /** + * Obtain the source descriptor for the identifier attribute. + * + * @return The identifier attribute source. + */ + public ComponentAttributeSource getIdentifierAttributeSource(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/IdentifierSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/IdentifierSource.java index 9ede42fd5d..fe9a33d8e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/IdentifierSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/IdentifierSource.java @@ -23,13 +23,22 @@ */ package org.hibernate.metamodel.source.binder; +import org.hibernate.metamodel.binding.IdGenerator; + /** * Contract describing source of identifier information for the entity. * * @author Steve Ebersole */ public interface IdentifierSource { - public static enum Nature { + /** + * Obtain the identifier generator source. + * + * @return The generator source. + */ + IdGenerator getIdentifierGeneratorDescriptor(); + + public static enum Nature { /** * A single, simple identifier. Equivalent of an {@code } mapping or a single {@code @Id} * annotation. Indicates the {@link IdentifierSource} is castable to {@link SimpleIdentifierSource}. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/SimpleIdentifierSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/SimpleIdentifierSource.java index c543d997a2..8bb57c77e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/SimpleIdentifierSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/binder/SimpleIdentifierSource.java @@ -38,10 +38,4 @@ public interface SimpleIdentifierSource extends IdentifierSource { */ public SingularAttributeSource getIdentifierAttributeSource(); - /** - * Obtain the identifier generator source. - * - * @return The generator source. - */ - public IdGenerator getIdentifierGeneratorDescriptor(); }