HHH-6503 - Develop Set-style plural attribute support for new metamodel

This commit is contained in:
Steve Ebersole 2011-07-29 00:27:43 -05:00
parent 425f41f5d6
commit 631286c77b
48 changed files with 1725 additions and 104 deletions

View File

@ -28,13 +28,11 @@ import java.util.Comparator;
import org.hibernate.cache.spi.CacheDataDescription; import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.type.VersionType; import org.hibernate.type.VersionType;
/** /**
* {@inheritDoc}
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CacheDataDescriptionImpl implements CacheDataDescription { public class CacheDataDescriptionImpl implements CacheDataDescription {
@ -84,7 +82,7 @@ public class CacheDataDescriptionImpl implements CacheDataDescription {
); );
} }
public static CacheDataDescriptionImpl decode(AbstractPluralAttributeBinding model) { public static CacheDataDescriptionImpl decode(PluralAttributeBinding model) {
return new CacheDataDescriptionImpl( return new CacheDataDescriptionImpl(
model.isMutable(), model.isMutable(),
model.getContainer().seekEntityBinding().isVersioned(), model.getContainer().seekEntityBinding().isVersioned(),

View File

@ -112,6 +112,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
@ -661,7 +662,7 @@ public final class SessionFactoryImpl
Map<String,Set<String>> tmpEntityToCollectionRoleMap = new HashMap<String,Set<String>>(); Map<String,Set<String>> tmpEntityToCollectionRoleMap = new HashMap<String,Set<String>>();
collectionPersisters = new HashMap(); collectionPersisters = new HashMap();
for ( AbstractPluralAttributeBinding model : metadata.getCollectionBindings() ) { for ( PluralAttributeBinding model : metadata.getCollectionBindings() ) {
if ( model.getAttribute() == null ) { if ( model.getAttribute() == null ) {
throw new IllegalStateException( "No attribute defined for a AbstractPluralAttributeBinding: " + model ); throw new IllegalStateException( "No attribute defined for a AbstractPluralAttributeBinding: " + model );
} }

View File

@ -37,7 +37,7 @@ import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.FetchProfile;
import org.hibernate.metamodel.binding.IdGenerator; import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.binding.TypeDef;
/** /**
@ -75,7 +75,7 @@ public interface Metadata {
*/ */
public EntityBinding getRootEntityBinding(String entityName); public EntityBinding getRootEntityBinding(String entityName);
public Iterable<AbstractPluralAttributeBinding> getCollectionBindings(); public Iterable<PluralAttributeBinding> getCollectionBindings();
public TypeDef getTypeDefinition(String name); public TypeDef getTypeDefinition(String name);

View File

@ -41,8 +41,8 @@ import org.hibernate.metamodel.relational.Table;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding { public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding {
private CollectionKey collectionKey; private final CollectionKey collectionKey;
private CollectionElement collectionElement; private final CollectionElement collectionElement;
private Table collectionTable; private Table collectionTable;
@ -81,6 +81,7 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
PluralAttribute attribute, PluralAttribute attribute,
CollectionElementNature collectionElementNature) { CollectionElementNature collectionElementNature) {
super( container, attribute ); super( container, attribute );
this.collectionKey = new CollectionKey( this );
this.collectionElement = interpretNature( collectionElementNature ); this.collectionElement = interpretNature( collectionElementNature );
} }
@ -160,10 +161,6 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
return collectionKey; return collectionKey;
} }
public void setCollectionKey(CollectionKey collectionKey) {
this.collectionKey = collectionKey;
}
public CollectionElement getCollectionElement() { public CollectionElement getCollectionElement() {
return collectionElement; return collectionElement;
} }

View File

@ -102,6 +102,16 @@ public interface AttributeBindingContainer {
*/ */
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature); public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature);
/**
* Factory method for bag attribute bindings.
*
* @param attribute The attribute for which to make a binding.
* @param nature The nature of the collection elements.
*
* @return The attribute binding instance.
*/
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature);
/** /**
* Seeks out the entity binding that is the root of this component path. * Seeks out the entity binding that is the root of this component path.
* *

View File

@ -30,6 +30,7 @@ import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.domain.AttributeContainer; import org.hibernate.metamodel.domain.AttributeContainer;
import org.hibernate.metamodel.domain.Component; import org.hibernate.metamodel.domain.Component;
import org.hibernate.metamodel.domain.PluralAttribute; import org.hibernate.metamodel.domain.PluralAttribute;
import org.hibernate.metamodel.domain.PluralAttributeNature;
import org.hibernate.metamodel.domain.SingularAttribute; import org.hibernate.metamodel.domain.SingularAttribute;
import org.hibernate.metamodel.source.MetaAttributeContext; import org.hibernate.metamodel.source.MetaAttributeContext;
@ -128,11 +129,20 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding
@Override @Override
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
final BagBinding binding = new BagBinding( this, attribute, nature ); final BagBinding binding = new BagBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding ); registerAttributeBinding( attribute.getName(), binding );
return binding; return binding;
} }
@Override
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
final SetBinding binding = new SetBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding );
return binding;
}
@Override @Override
public Class<?> getClassReference() { public Class<?> getClassReference() {
return getComponent().getClassReference(); return getComponent().getClassReference();

View File

@ -35,6 +35,7 @@ import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.domain.AttributeContainer; import org.hibernate.metamodel.domain.AttributeContainer;
import org.hibernate.metamodel.domain.Entity; import org.hibernate.metamodel.domain.Entity;
import org.hibernate.metamodel.domain.PluralAttribute; import org.hibernate.metamodel.domain.PluralAttribute;
import org.hibernate.metamodel.domain.PluralAttributeNature;
import org.hibernate.metamodel.domain.SingularAttribute; import org.hibernate.metamodel.domain.SingularAttribute;
import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.TableSpecification;
import org.hibernate.metamodel.source.MetaAttributeContext; import org.hibernate.metamodel.source.MetaAttributeContext;
@ -424,11 +425,20 @@ public class EntityBinding implements AttributeBindingContainer {
@Override @Override
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
final BagBinding binding = new BagBinding( this, attribute, nature ); final BagBinding binding = new BagBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding ); registerAttributeBinding( attribute.getName(), binding );
return binding; return binding;
} }
@Override
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
final SetBinding binding = new SetBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding );
return binding;
}
@Override @Override
public AttributeBinding locateAttributeBinding(String name) { public AttributeBinding locateAttributeBinding(String name) {
return attributeBindingMap.get( name ); return attributeBindingMap.get( name );

View File

@ -0,0 +1,47 @@
/*
* 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.binding;
import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.domain.PluralAttribute;
import org.hibernate.metamodel.domain.PluralAttributeNature;
/**
* Helper utilities specific to the binding package.
*
* @author Steve Ebersole
*/
public class Helper {
public static void checkPluralAttributeNature(PluralAttribute attribute, PluralAttributeNature expected) {
if ( attribute.getNature() != expected ) {
throw new AssertionFailure(
String.format(
"Mismatched collection natures; expecting %s, but found %s",
expected.getName(),
attribute.getNature().getName()
)
);
}
}
}

View File

@ -24,6 +24,7 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
import org.hibernate.metamodel.relational.Table; import org.hibernate.metamodel.relational.Table;
import org.hibernate.persister.collection.CollectionPersister;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -37,4 +38,11 @@ public interface PluralAttributeBinding extends AttributeBinding, AssociationAtt
public Table getCollectionTable(); public Table getCollectionTable();
public boolean isMutable();
public String getCacheRegionName();
public String getCacheConcurrencyStrategy();
public Class<CollectionPersister> getCollectionPersisterClass();
} }

View File

@ -0,0 +1,50 @@
/*
* 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.binding;
import java.util.Comparator;
import org.hibernate.metamodel.domain.PluralAttribute;
/**
* @author Steve Ebersole
*/
public class SetBinding extends AbstractPluralAttributeBinding {
private Comparator comparator;
protected SetBinding(
AttributeBindingContainer container,
PluralAttribute attribute,
CollectionElementNature collectionElementNature) {
super( container, attribute, collectionElementNature );
}
public Comparator getComparator() {
return comparator;
}
public void setComparator(Comparator comparator) {
this.comparator = comparator;
}
}

View File

@ -35,6 +35,7 @@ import java.util.Set;
*/ */
public enum PluralAttributeNature { public enum PluralAttributeNature {
BAG( "bag", Collection.class ), BAG( "bag", Collection.class ),
IDBAG( "idbag", Collection.class ),
SET( "set", Set.class ), SET( "set", Set.class ),
LIST( "list", List.class ), LIST( "list", List.class ),
MAP( "map", Map.class ); MAP( "map", Map.class );

View File

@ -29,10 +29,10 @@ import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.NamedQueryDefinition; import org.hibernate.engine.spi.NamedQueryDefinition;
import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinition;
import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.Metadata;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.FetchProfile; import org.hibernate.metamodel.binding.FetchProfile;
import org.hibernate.metamodel.binding.IdGenerator; import org.hibernate.metamodel.binding.IdGenerator;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.binding.TypeDef;
import org.hibernate.metamodel.relational.Database; import org.hibernate.metamodel.relational.Database;
import org.hibernate.service.BasicServiceRegistry; import org.hibernate.service.BasicServiceRegistry;
@ -52,7 +52,7 @@ public interface MetadataImplementor extends Metadata, BindingContext, Mapping {
public void addEntity(EntityBinding entityBinding); public void addEntity(EntityBinding entityBinding);
public void addCollection(AbstractPluralAttributeBinding collectionBinding); public void addCollection(PluralAttributeBinding collectionBinding);
public void addFetchProfile(FetchProfile profile); public void addFetchProfile(FetchProfile profile);

View File

@ -44,6 +44,7 @@ import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type; import org.jboss.jandex.Type;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.service.classloading.spi.ClassLoaderService; import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -363,4 +364,25 @@ public class JandexHelper {
return type.cast( returnValue ); return type.cast( returnValue );
} }
public static AnnotationInstance locatePojoTuplizerAnnotation(ClassInfo classInfo) {
final AnnotationInstance tuplizersAnnotation = getSingleAnnotation(
classInfo, HibernateDotNames.TUPLIZERS
);
if ( tuplizersAnnotation == null ) {
return null;
}
AnnotationInstance[] annotations = getValue(
tuplizersAnnotation,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance tuplizerAnnotation : annotations ) {
if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) {
return tuplizerAnnotation;
}
}
return null;
}
} }

View File

@ -27,9 +27,12 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.internal.util.Value; import org.hibernate.internal.util.Value;
import org.hibernate.mapping.PropertyGeneration; import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.source.LocalBindingContext; import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute; import org.hibernate.metamodel.source.annotations.attribute.AssociationAttribute;
import org.hibernate.metamodel.source.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.source.annotations.attribute.BasicAttribute;
import org.hibernate.metamodel.source.annotations.attribute.SingularAttributeSourceImpl; import org.hibernate.metamodel.source.annotations.attribute.SingularAttributeSourceImpl;
@ -93,6 +96,16 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
return embeddableClass.getEmbeddedAttributeName(); return embeddableClass.getEmbeddedAttributeName();
} }
@Override
public String getExplicitTuplizerClassName() {
String customTuplizer = null;
final AnnotationInstance pojoTuplizerAnnotation = JandexHelper.locatePojoTuplizerAnnotation( embeddableClass.getClassInfo() );
if ( pojoTuplizerAnnotation != null ) {
customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString();
}
return customTuplizer;
}
@Override @Override
public String getPropertyAccessorName() { public String getPropertyAccessorName() {
return embeddableClass.getClassAccessType().toString().toLowerCase(); return embeddableClass.getClassAccessType().toString().toLowerCase();

View File

@ -23,14 +23,14 @@
*/ */
package org.hibernate.metamodel.source.annotations.entity; package org.hibernate.metamodel.source.annotations.entity;
import javax.persistence.AccessType;
import javax.persistence.DiscriminatorType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.persistence.AccessType;
import javax.persistence.DiscriminatorType;
import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.AnnotationValue;
@ -38,7 +38,6 @@ import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName; import org.jboss.jandex.DotName;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.EntityMode;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.OptimisticLockType;
@ -54,10 +53,8 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.attribute.ColumnValues; import org.hibernate.metamodel.source.annotations.attribute.ColumnValues;
import org.hibernate.metamodel.source.annotations.attribute.DerivedValueSourceImpl;
import org.hibernate.metamodel.source.annotations.attribute.FormulaValue; import org.hibernate.metamodel.source.annotations.attribute.FormulaValue;
import org.hibernate.metamodel.source.binder.ConstraintSource; import org.hibernate.metamodel.source.binder.ConstraintSource;
import org.hibernate.metamodel.source.binder.DerivedValueSource;
import org.hibernate.metamodel.source.binder.TableSource; import org.hibernate.metamodel.source.binder.TableSource;
/** /**
@ -722,34 +719,13 @@ public class EntityClass extends ConfiguredClass {
private String determineCustomTuplizer() { private String determineCustomTuplizer() {
// Custom tuplizer // Custom tuplizer
String customTuplizer = null; String customTuplizer = null;
final AnnotationInstance pojoTuplizerAnnotation = locatePojoTuplizerAnnotation(); final AnnotationInstance pojoTuplizerAnnotation = JandexHelper.locatePojoTuplizerAnnotation( getClassInfo() );
if ( pojoTuplizerAnnotation != null ) { if ( pojoTuplizerAnnotation != null ) {
customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString(); customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString();
} }
return customTuplizer; return customTuplizer;
} }
private AnnotationInstance locatePojoTuplizerAnnotation() {
final AnnotationInstance tuplizersAnnotation = JandexHelper.getSingleAnnotation(
getClassInfo(), HibernateDotNames.TUPLIZERS
);
if ( tuplizersAnnotation == null ) {
return null;
}
AnnotationInstance[] annotations = JandexHelper.getValue(
tuplizersAnnotation,
"value",
AnnotationInstance[].class
);
for ( AnnotationInstance tuplizerAnnotation : annotations ) {
if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) {
return tuplizerAnnotation;
}
}
return null;
}
private void processProxyGeneration() { private void processProxyGeneration() {
// Proxy generation // Proxy generation
final AnnotationInstance hibernateProxyAnnotation = JandexHelper.getSingleAnnotation( final AnnotationInstance hibernateProxyAnnotation = JandexHelper.getSingleAnnotation(

View File

@ -0,0 +1,34 @@
/*
* 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;
import java.util.List;
/**
* @author Steve Ebersole
*/
public interface BasicPluralAttributeElementSource extends PluralAttributeElementSource {
public List<RelationalValueSource> getValueSources();
public ExplicitHibernateTypeSource getExplicitHibernateTypeSource();
}

View File

@ -450,15 +450,77 @@ public class Binder {
: attributeBindingContainer.getAttributeContainer().createBag( attributeSource.getName() ); : attributeBindingContainer.getAttributeContainer().createBag( attributeSource.getName() );
pluralAttributeBinding = attributeBindingContainer.makeBagAttributeBinding( pluralAttributeBinding = attributeBindingContainer.makeBagAttributeBinding(
attribute, attribute,
convert( attributeSource.getPluralAttributeElementNature() ) convert( attributeSource.getElementSource().getNature() )
);
}
else if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.SET ) {
final PluralAttribute attribute = existingAttribute != null
? existingAttribute
: attributeBindingContainer.getAttributeContainer().createSet( attributeSource.getName() );
pluralAttributeBinding = attributeBindingContainer.makeSetAttributeBinding(
attribute,
convert( attributeSource.getElementSource().getNature() )
); );
} }
else { else {
// todo : implement other collection types // todo : implement other collection types
throw new NotYetImplementedException( "Collections other than bag not yet implmented :(" ); throw new NotYetImplementedException( "Collections other than bag not yet implemented :(" );
} }
doBasicAttributeBinding( attributeSource, pluralAttributeBinding ); doBasicAttributeBinding( attributeSource, pluralAttributeBinding );
bindCollectionTable( attributeSource, pluralAttributeBinding );
bindCollectionKey( attributeSource, pluralAttributeBinding );
bindSortingAndOrdering( attributeSource, pluralAttributeBinding );
metadata.addCollection( pluralAttributeBinding );
}
private void bindCollectionTable(
PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) {
if ( attributeSource.getElementSource().getNature() == PluralAttributeElementNature.ONE_TO_MANY ) {
return;
}
if ( StringHelper.isNotEmpty( attributeSource.getExplicitCollectionTableName() ) ) {
final Identifier tableIdentifier = Identifier.toIdentifier( attributeSource.getExplicitCollectionTableName() );
Table collectionTable = metadata.getDatabase().getDefaultSchema().locateTable( tableIdentifier );
if ( collectionTable == null ) {
collectionTable = metadata.getDatabase().getDefaultSchema().createTable( tableIdentifier );
}
pluralAttributeBinding.setCollectionTable( collectionTable );
}
else {
// todo : we need to infer the name, but that requires possibly knowing the other side
}
}
private void bindCollectionKey(
PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) {
// todo : implement
}
private void bindSortingAndOrdering(
PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) {
if ( Sortable.class.isInstance( attributeSource ) ) {
final Sortable sortable = Sortable.class.cast( attributeSource );
if ( sortable.isSorted() ) {
// todo : handle setting comparator
// and then return because sorting and ordering are mutually exclusive
return;
}
}
if ( Orderable.class.isInstance( attributeSource ) ) {
final Orderable orderable = Orderable.class.cast( attributeSource );
if ( orderable.isOrdered() ) {
// todo : handle setting ordering
}
}
} }
private void doBasicAttributeBinding(AttributeSource attributeSource, AttributeBinding attributeBinding) { private void doBasicAttributeBinding(AttributeSource attributeSource, AttributeBinding attributeBinding) {

View File

@ -34,4 +34,6 @@ public interface ComponentAttributeSource extends SingularAttributeSource, Attri
public Value<Class<?>> getClassReference(); public Value<Class<?>> getClassReference();
public String getParentReferenceAttributeName(); public String getParentReferenceAttributeName();
public String getExplicitTuplizerClassName();
} }

View File

@ -0,0 +1,39 @@
/*
* 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;
import org.hibernate.internal.util.Value;
/**
* @author Steve Ebersole
*/
public interface CompositePluralAttributeElementSource extends PluralAttributeElementSource, AttributeSourceContainer {
public String getClassName();
public Value<Class<?>> getClassReference();
public String getParentReferenceAttributeName();
public String getExplicitTuplizerClassName();
}

View File

@ -0,0 +1,30 @@
/*
* 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 Steve Ebersole
*/
public interface ManyToAnyPluralAttributeElementSource extends PluralAttributeElementSource {
}

View File

@ -0,0 +1,48 @@
/*
* 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;
import java.util.List;
import org.hibernate.FetchMode;
/**
* @author Steve Ebersole
*/
public interface ManyToManyPluralAttributeElementSource extends PluralAttributeElementSource {
public String getReferencedEntityName();
public String getReferencedEntityAttributeName();
public List<RelationalValueSource> getValueSources(); // these describe the "outgoing" link
public boolean isNotFoundAnException();
public String getExplicitForeignKeyName();
public boolean isUnique();
public String getOrderBy();
public String getWhere();
public FetchMode getFetchMode();
public boolean fetchImmediately();
}

View File

@ -0,0 +1,32 @@
/*
* 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 Steve Ebersole
*/
public interface OneToManyPluralAttributeElementSource extends PluralAttributeElementSource {
public String getReferencedEntityName();
public boolean isNotFoundAnException();
}

View File

@ -0,0 +1,32 @@
/*
* 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 Steve Ebersole
*/
public interface Orderable {
public boolean isOrdered();
public String getOrder();
}

View File

@ -0,0 +1,32 @@
/*
* 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 Steve Ebersole
*/
public interface PluralAttributeElementSource {
public PluralAttributeElementNature getNature();
}

View File

@ -0,0 +1,38 @@
/*
* 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;
import java.util.List;
import org.hibernate.metamodel.relational.ForeignKey;
/**
* @author Steve Ebersole
*/
public interface PluralAttributeKeySource {
public List<RelationalValueSource> getValueSources();
public String getExplicitForeignKeyName();
public ForeignKey.ReferentialAction getOnDeleteAction();
public String getReferencedEntityAttributeName();
}

View File

@ -26,8 +26,14 @@ package org.hibernate.metamodel.source.binder;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface PluralAttributeSource extends AttributeSource { public interface PluralAttributeSource extends AssociationAttributeSource {
public PluralAttributeNature getPluralAttributeNature(); public PluralAttributeNature getPluralAttributeNature();
public PluralAttributeElementNature getPluralAttributeElementNature(); public PluralAttributeKeySource getKeySource();
public PluralAttributeElementSource getElementSource();
public String getExplicitCollectionTableName();
public boolean isInverse();
} }

View File

@ -0,0 +1,33 @@
/*
* 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 Steve Ebersole
*/
public interface Sortable {
public boolean isSorted();
public String getComparatorName();
}

View File

@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.binding.CustomSQL; import org.hibernate.metamodel.binding.CustomSQL;
@ -41,12 +42,17 @@ import org.hibernate.metamodel.source.binder.SubclassEntitySource;
import org.hibernate.metamodel.source.binder.TableSource; import org.hibernate.metamodel.source.binder.TableSource;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.EntityElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.EntityElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLAnyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLAnyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLBagElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLComponentElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLComponentElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLIdbagElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLListElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToManyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToOneElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLMapElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSetElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSynchronizeElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSynchronizeElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement;
@ -232,12 +238,34 @@ public abstract class AbstractEntitySourceImpl implements EntitySource {
else if ( XMLAnyElement.class.isInstance( attributeElement ) ) { else if ( XMLAnyElement.class.isInstance( attributeElement ) ) {
// todo : implement // todo : implement
} }
else if ( XMLOneToManyElement.class.isInstance( attributeElement ) ) { else if ( XMLBagElement.class.isInstance( attributeElement ) ) {
attributeSources.add(
new BagAttributeSourceImpl(
XMLBagElement.class.cast( attributeElement ),
this
)
);
}
else if ( XMLIdbagElement.class.isInstance( attributeElement ) ) {
// todo : implement // todo : implement
} }
else if ( XMLManyToManyElement.class.isInstance( attributeElement ) ) { else if ( XMLSetElement.class.isInstance( attributeElement ) ) {
attributeSources.add(
new SetAttributeSourceImpl(
XMLSetElement.class.cast( attributeElement ),
this
)
);
}
else if ( XMLListElement.class.isInstance( attributeElement ) ) {
// todo : implement // todo : implement
} }
else if ( XMLMapElement.class.isInstance( attributeElement ) ) {
// todo : implement
}
else {
throw new AssertionFailure( "Unexpected attribute element type encountered : " + attributeElement.getClass() );
}
} }
return attributeSources; return attributeSources;
} }

View File

@ -0,0 +1,52 @@
/*
* 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.hbm;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.binder.AttributeSourceContainer;
import org.hibernate.metamodel.source.binder.PluralAttributeSource;
/**
* @author Steve Ebersole
*/
public abstract class AbstractPluralAttributeSourceImpl implements PluralAttributeSource {
private final AttributeSourceContainer container;
protected AbstractPluralAttributeSourceImpl(AttributeSourceContainer container) {
this.container = container;
}
protected AttributeSourceContainer container() {
return container;
}
protected LocalBindingContext bindingContext() {
return container().getLocalBindingContext();
}
@Override
public boolean isSingular() {
return false;
}
}

View File

@ -0,0 +1,149 @@
/*
* 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.hbm;
import org.hibernate.FetchMode;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.MappingException;
import org.hibernate.metamodel.source.binder.AttributeSourceContainer;
import org.hibernate.metamodel.source.binder.MetaAttributeSource;
import org.hibernate.metamodel.source.binder.PluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.PluralAttributeKeySource;
import org.hibernate.metamodel.source.binder.PluralAttributeNature;
import org.hibernate.metamodel.source.binder.PluralAttributeSource;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLBagElement;
/**
* @author Steve Ebersole
*/
public class BagAttributeSourceImpl implements PluralAttributeSource {
private final XMLBagElement bagElement;
private final AttributeSourceContainer container;
// todo : a lot of this could be consolidated with common JAXB interface for collection mappings and moved to a base class
private final PluralAttributeKeySource keySource;
private final PluralAttributeElementSource elementSource;
public BagAttributeSourceImpl(XMLBagElement bagElement, AttributeSourceContainer container) {
this.bagElement = bagElement;
this.container = container;
this.keySource = new PluralAttributeKeySourceImpl( bagElement.getKey(), container );
this.elementSource = interpretElementType( bagElement );
}
private PluralAttributeElementSource interpretElementType(XMLBagElement bagElement) {
if ( bagElement.getElement() != null ) {
return new BasicPluralAttributeElementSourceImpl( bagElement.getElement(), container.getLocalBindingContext() );
}
else if ( bagElement.getCompositeElement() != null ) {
return new CompositePluralAttributeElementSourceImpl( bagElement.getCompositeElement(), container.getLocalBindingContext() );
}
else if ( bagElement.getOneToMany() != null ) {
return new OneToManyPluralAttributeElementSourceImpl( bagElement.getOneToMany(), container.getLocalBindingContext() );
}
else if ( bagElement.getManyToMany() != null ) {
return new ManyToManyPluralAttributeElementSourceImpl( bagElement.getManyToMany(), container.getLocalBindingContext() );
}
else if ( bagElement.getManyToAny() != null ) {
throw new NotYetImplementedException( "Support for many-to-any not yet implemented" );
// return PluralAttributeElementNature.MANY_TO_ANY;
}
else {
throw new MappingException(
"Unexpected collection element type : " + bagElement.getName(),
bindingContext().getOrigin()
);
}
}
@Override
public PluralAttributeNature getPluralAttributeNature() {
return PluralAttributeNature.BAG;
}
@Override
public PluralAttributeKeySource getKeySource() {
return keySource;
}
@Override
public PluralAttributeElementSource getElementSource() {
return elementSource;
}
@Override
public String getExplicitCollectionTableName() {
return bagElement.getTable();
}
private LocalBindingContext bindingContext() {
return container.getLocalBindingContext();
}
@Override
public String getName() {
return bagElement.getName();
}
@Override
public boolean isSingular() {
return false;
}
@Override
public String getPropertyAccessorName() {
return bagElement.getAccess();
}
@Override
public boolean isIncludedInOptimisticLocking() {
return bagElement.isOptimisticLock();
}
@Override
public boolean isInverse() {
return bagElement.isInverse();
}
@Override
public Iterable<MetaAttributeSource> metaAttributes() {
return Helper.buildMetaAttributeSources( bagElement.getMeta() );
}
@Override
public Iterable<CascadeStyle> getCascadeStyles() {
return Helper.interpretCascadeStyles( bagElement.getCascade(), bindingContext() );
}
@Override
public FetchMode getFetchMode() {
return bagElement.getFetch() == null
? FetchMode.DEFAULT
: FetchMode.valueOf( bagElement.getFetch().value() );
}
}

View File

@ -0,0 +1,118 @@
/*
* 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.hbm;
import java.util.List;
import java.util.Map;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.binder.BasicPluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.source.binder.PluralAttributeElementNature;
import org.hibernate.metamodel.source.binder.RelationalValueSource;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLElementElement;
/**
* @author Steve Ebersole
*/
public class BasicPluralAttributeElementSourceImpl implements BasicPluralAttributeElementSource {
private final List<RelationalValueSource> valueSources;
private final ExplicitHibernateTypeSource typeSource;
public BasicPluralAttributeElementSourceImpl(
final XMLElementElement elementElement,
LocalBindingContext bindingContext) {
this.valueSources = Helper.buildValueSources(
new Helper.ValueSourcesAdapter() {
@Override
public String getContainingTableName() {
return null;
}
@Override
public boolean isIncludedInInsertByDefault() {
return true;
}
@Override
public boolean isIncludedInUpdateByDefault() {
return true;
}
@Override
public String getColumnAttribute() {
return elementElement.getColumn();
}
@Override
public String getFormulaAttribute() {
return elementElement.getFormula();
}
@Override
public List getColumnOrFormulaElements() {
return elementElement.getColumnOrFormula();
}
},
bindingContext
);
this.typeSource = new ExplicitHibernateTypeSource() {
@Override
public String getName() {
if ( elementElement.getTypeAttribute() != null ) {
return elementElement.getTypeAttribute();
}
else if ( elementElement.getType() != null ) {
return elementElement.getType().getName();
}
else {
return null;
}
}
@Override
public Map<String, String> getParameters() {
return elementElement.getType() != null
? Helper.extractParameters( elementElement.getType().getParam() )
: java.util.Collections.<String, String>emptyMap();
}
};
}
@Override
public PluralAttributeElementNature getNature() {
return PluralAttributeElementNature.BASIC;
}
@Override
public List<RelationalValueSource> getValueSources() {
return valueSources;
}
@Override
public ExplicitHibernateTypeSource getExplicitHibernateTypeSource() {
return typeSource;
}
}

View File

@ -26,6 +26,8 @@ package org.hibernate.metamodel.source.hbm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.EntityMode;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.Value; import org.hibernate.internal.util.Value;
import org.hibernate.mapping.PropertyGeneration; import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.source.LocalBindingContext; import org.hibernate.metamodel.source.LocalBindingContext;
@ -43,6 +45,7 @@ import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToOneElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToOneElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement; import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLPropertyElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -61,7 +64,9 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
this.componentElement = componentElement; this.componentElement = componentElement;
this.parentContainer = parentContainer; this.parentContainer = parentContainer;
this.componentClassReference = bindingContext.makeClassReference( componentElement.getClazz() ); this.componentClassReference = bindingContext.makeClassReference(
bindingContext.qualifyClassName( componentElement.getClazz() )
);
this.path = parentContainer.getPath() + '.' + componentElement.getName(); this.path = parentContainer.getPath() + '.' + componentElement.getName();
} }
@ -90,6 +95,20 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
return componentElement.getParent() == null ? null : componentElement.getParent().getName(); return componentElement.getParent() == null ? null : componentElement.getParent().getName();
} }
@Override
public String getExplicitTuplizerClassName() {
if ( componentElement.getTuplizer() == null ) {
return null;
}
final EntityMode entityMode = StringHelper.isEmpty( componentElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO;
for ( XMLTuplizerElement tuplizerElement : componentElement.getTuplizer() ) {
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) {
return tuplizerElement.getClazz();
}
}
return null;
}
@Override @Override
public Iterable<AttributeSource> attributeSources() { public Iterable<AttributeSource> attributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>(); List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();

View File

@ -0,0 +1,108 @@
/*
* 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.hbm;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.EntityMode;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.Value;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.binder.AttributeSource;
import org.hibernate.metamodel.source.binder.CompositePluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.PluralAttributeElementNature;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLCompositeElementElement;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLTuplizerElement;
/**
* @author Steve Ebersole
*/
public class CompositePluralAttributeElementSourceImpl implements CompositePluralAttributeElementSource {
private final XMLCompositeElementElement compositeElement;
private final LocalBindingContext bindingContext;
public CompositePluralAttributeElementSourceImpl(
XMLCompositeElementElement compositeElement,
LocalBindingContext bindingContext) {
this.compositeElement = compositeElement;
this.bindingContext = bindingContext;
}
@Override
public PluralAttributeElementNature getNature() {
return PluralAttributeElementNature.COMPONENT;
}
@Override
public String getClassName() {
return bindingContext.qualifyClassName( compositeElement.getClazz() );
}
@Override
public Value<Class<?>> getClassReference() {
return bindingContext.makeClassReference( getClassName() );
}
@Override
public String getParentReferenceAttributeName() {
return compositeElement.getParent() != null
? compositeElement.getParent().getName()
: null;
}
@Override
public String getExplicitTuplizerClassName() {
if ( compositeElement.getTuplizer() == null ) {
return null;
}
final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO;
for ( XMLTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) {
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode() ) ) {
return tuplizerElement.getClazz();
}
}
return null;
}
@Override
public String getPath() {
// todo : implementing this requires passing in the collection source and being able to resolve the collection's role
return null;
}
@Override
public Iterable<AttributeSource> attributeSources() {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
for ( Object attribute : compositeElement.getPropertyOrManyToOneOrAny() ) {
}
return attributeSources;
}
@Override
public LocalBindingContext getLocalBindingContext() {
return bindingContext;
}
}

View File

@ -0,0 +1,159 @@
/*
* 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.hbm;
import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.binder.ManyToManyPluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.PluralAttributeElementNature;
import org.hibernate.metamodel.source.binder.RelationalValueSource;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLManyToManyElement;
/**
* @author Steve Ebersole
*/
public class ManyToManyPluralAttributeElementSourceImpl implements ManyToManyPluralAttributeElementSource {
private final XMLManyToManyElement manyToManyElement;
private final LocalBindingContext bindingContext;
private final List<RelationalValueSource> valueSources;
public ManyToManyPluralAttributeElementSourceImpl(
final XMLManyToManyElement manyToManyElement,
final LocalBindingContext bindingContext) {
this.manyToManyElement = manyToManyElement;
this.bindingContext = bindingContext;
this.valueSources = Helper.buildValueSources(
new Helper.ValueSourcesAdapter() {
@Override
public String getContainingTableName() {
return null;
}
@Override
public boolean isIncludedInInsertByDefault() {
return true;
}
@Override
public boolean isIncludedInUpdateByDefault() {
return true;
}
@Override
public String getColumnAttribute() {
return manyToManyElement.getColumn();
}
@Override
public String getFormulaAttribute() {
return manyToManyElement.getFormula();
}
@Override
public List getColumnOrFormulaElements() {
return manyToManyElement.getColumnOrFormula();
}
},
bindingContext
);
}
@Override
public PluralAttributeElementNature getNature() {
return PluralAttributeElementNature.MANY_TO_MANY;
}
@Override
public String getReferencedEntityName() {
return StringHelper.isNotEmpty( manyToManyElement.getEntityName() )
? manyToManyElement.getEntityName()
: bindingContext.qualifyClassName( manyToManyElement.getClazz() );
}
@Override
public String getReferencedEntityAttributeName() {
return manyToManyElement.getPropertyRef();
}
@Override
public List<RelationalValueSource> getValueSources() {
return valueSources;
}
@Override
public boolean isNotFoundAnException() {
return manyToManyElement.getNotFound() == null
|| ! "ignore".equals( manyToManyElement.getNotFound().value() );
}
@Override
public String getExplicitForeignKeyName() {
return manyToManyElement.getForeignKey();
}
@Override
public boolean isUnique() {
return manyToManyElement.isUnique();
}
@Override
public String getOrderBy() {
return manyToManyElement.getOrderBy();
}
@Override
public String getWhere() {
return manyToManyElement.getWhere();
}
@Override
public FetchMode getFetchMode() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean fetchImmediately() {
if ( manyToManyElement.getLazy() != null ) {
if ( "false".equals( manyToManyElement.getLazy().value() ) ) {
return true;
}
}
if ( manyToManyElement.getOuterJoin() == null ) {
return ! bindingContext.getMappingDefaults().areAssociationsLazy();
}
else {
final String value = manyToManyElement.getOuterJoin().value();
if ( "auto".equals( value ) ) {
return ! bindingContext.getMappingDefaults().areAssociationsLazy();
}
return "true".equals( value );
}
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.hbm;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.binder.OneToManyPluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.PluralAttributeElementNature;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLOneToManyElement;
/**
* @author Steve Ebersole
*/
public class OneToManyPluralAttributeElementSourceImpl implements OneToManyPluralAttributeElementSource {
private final XMLOneToManyElement oneToManyElement;
private final LocalBindingContext bindingContext;
public OneToManyPluralAttributeElementSourceImpl(
XMLOneToManyElement oneToManyElement,
LocalBindingContext bindingContext) {
this.oneToManyElement = oneToManyElement;
this.bindingContext = bindingContext;
}
@Override
public PluralAttributeElementNature getNature() {
return PluralAttributeElementNature.ONE_TO_MANY;
}
@Override
public String getReferencedEntityName() {
return StringHelper.isNotEmpty( oneToManyElement.getEntityName() )
? oneToManyElement.getEntityName()
: bindingContext.qualifyClassName( oneToManyElement.getClazz() );
}
@Override
public boolean isNotFoundAnException() {
return oneToManyElement.getNotFound() == null
|| ! "ignore".equals( oneToManyElement.getNotFound().value() );
}
}

View File

@ -0,0 +1,104 @@
/*
* 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.hbm;
import java.util.List;
import org.hibernate.metamodel.relational.ForeignKey;
import org.hibernate.metamodel.source.binder.AttributeSourceContainer;
import org.hibernate.metamodel.source.binder.PluralAttributeKeySource;
import org.hibernate.metamodel.source.binder.RelationalValueSource;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLKeyElement;
/**
* @author Steve Ebersole
*/
public class PluralAttributeKeySourceImpl implements PluralAttributeKeySource {
private final XMLKeyElement keyElement;
private final List<RelationalValueSource> valueSources;
public PluralAttributeKeySourceImpl(
final XMLKeyElement keyElement,
final AttributeSourceContainer container) {
this.keyElement = keyElement;
this.valueSources = Helper.buildValueSources(
new Helper.ValueSourcesAdapter() {
@Override
public String getContainingTableName() {
return null;
}
@Override
public boolean isIncludedInInsertByDefault() {
return true;
}
@Override
public boolean isIncludedInUpdateByDefault() {
return Helper.getBooleanValue( keyElement.isUpdate(), true );
}
@Override
public String getColumnAttribute() {
return keyElement.getColumnAttribute();
}
@Override
public String getFormulaAttribute() {
return null;
}
@Override
public List getColumnOrFormulaElements() {
return keyElement.getColumn();
}
},
container.getLocalBindingContext()
);
}
@Override
public List<RelationalValueSource> getValueSources() {
return valueSources;
}
@Override
public String getExplicitForeignKeyName() {
return keyElement.getForeignKey();
}
@Override
public ForeignKey.ReferentialAction getOnDeleteAction() {
return "cascade".equals( keyElement.getOnDelete() )
? ForeignKey.ReferentialAction.CASCADE
: ForeignKey.ReferentialAction.NO_ACTION;
}
@Override
public String getReferencedEntityAttributeName() {
return keyElement.getPropertyRef();
}
}

View File

@ -0,0 +1,172 @@
/*
* 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.hbm;
import org.hibernate.FetchMode;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.source.LocalBindingContext;
import org.hibernate.metamodel.source.MappingException;
import org.hibernate.metamodel.source.binder.AttributeSourceContainer;
import org.hibernate.metamodel.source.binder.MetaAttributeSource;
import org.hibernate.metamodel.source.binder.Orderable;
import org.hibernate.metamodel.source.binder.PluralAttributeElementSource;
import org.hibernate.metamodel.source.binder.PluralAttributeKeySource;
import org.hibernate.metamodel.source.binder.PluralAttributeNature;
import org.hibernate.metamodel.source.binder.PluralAttributeSource;
import org.hibernate.metamodel.source.binder.Sortable;
import org.hibernate.metamodel.source.hbm.jaxb.mapping.XMLSetElement;
/**
* @author Steve Ebersole
*/
public class SetAttributeSourceImpl implements PluralAttributeSource, Sortable, Orderable {
private XMLSetElement setElement;
private AttributeSourceContainer container;
// todo : a lot of this could be consolidated with common JAXB interface for collection mappings and moved to a base class
private final PluralAttributeKeySource keySource;
private final PluralAttributeElementSource elementSource;
public SetAttributeSourceImpl(XMLSetElement setElement, AttributeSourceContainer container) {
this.setElement = setElement;
this.container = container;
this.keySource = new PluralAttributeKeySourceImpl( setElement.getKey(), container );
this.elementSource = interpretElementType( setElement );
}
private PluralAttributeElementSource interpretElementType(XMLSetElement setElement) {
if ( setElement.getElement() != null ) {
return new BasicPluralAttributeElementSourceImpl( setElement.getElement(), container.getLocalBindingContext() );
}
else if ( setElement.getCompositeElement() != null ) {
return new CompositePluralAttributeElementSourceImpl( setElement.getCompositeElement(), container.getLocalBindingContext() );
}
else if ( setElement.getOneToMany() != null ) {
return new OneToManyPluralAttributeElementSourceImpl( setElement.getOneToMany(), container.getLocalBindingContext() );
}
else if ( setElement.getManyToMany() != null ) {
return new ManyToManyPluralAttributeElementSourceImpl( setElement.getManyToMany(), container.getLocalBindingContext() );
}
else if ( setElement.getManyToAny() != null ) {
throw new NotYetImplementedException( "Support for many-to-any not yet implemented" );
// return PluralAttributeElementNature.MANY_TO_ANY;
}
else {
throw new MappingException(
"Unexpected collection element type : " + setElement.getName(),
bindingContext().getOrigin()
);
}
}
private LocalBindingContext bindingContext() {
return container.getLocalBindingContext();
}
@Override
public PluralAttributeNature getPluralAttributeNature() {
return PluralAttributeNature.BAG;
}
@Override
public PluralAttributeKeySource getKeySource() {
return keySource;
}
@Override
public PluralAttributeElementSource getElementSource() {
return elementSource;
}
@Override
public String getExplicitCollectionTableName() {
return setElement.getTable();
}
@Override
public boolean isInverse() {
return setElement.isInverse();
}
@Override
public String getName() {
return setElement.getName();
}
@Override
public boolean isSingular() {
return false;
}
@Override
public String getPropertyAccessorName() {
return setElement.getAccess();
}
@Override
public boolean isIncludedInOptimisticLocking() {
return setElement.isOptimisticLock();
}
@Override
public Iterable<MetaAttributeSource> metaAttributes() {
return Helper.buildMetaAttributeSources( setElement.getMeta() );
}
@Override
public Iterable<CascadeStyle> getCascadeStyles() {
return Helper.interpretCascadeStyles( setElement.getCascade(), bindingContext() );
}
@Override
public FetchMode getFetchMode() {
return setElement.getFetch() == null
? FetchMode.DEFAULT
: FetchMode.valueOf( setElement.getFetch().value() );
}
@Override
public boolean isSorted() {
return StringHelper.isNotEmpty( setElement.getSort() );
}
@Override
public String getComparatorName() {
return setElement.getSort();
}
@Override
public boolean isOrdered() {
return StringHelper.isNotEmpty( setElement.getOrderBy() );
}
@Override
public String getOrder() {
return setElement.getOrderBy();
}
}

View File

@ -52,6 +52,7 @@ import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources; import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.SessionFactoryBuilder; import org.hibernate.metamodel.SessionFactoryBuilder;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.MappingDefaults; import org.hibernate.metamodel.source.MappingDefaults;
import org.hibernate.metamodel.source.MetaAttributeContext; import org.hibernate.metamodel.source.MetaAttributeContext;
import org.hibernate.metamodel.source.MetadataImplementor; import org.hibernate.metamodel.source.MetadataImplementor;
@ -106,7 +107,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
*/ */
private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>(); private Map<String, EntityBinding> entityBindingMap = new HashMap<String, EntityBinding>();
private Map<String, AbstractPluralAttributeBinding> collectionBindingMap = new HashMap<String, AbstractPluralAttributeBinding>(); private Map<String, PluralAttributeBinding> collectionBindingMap = new HashMap<String, PluralAttributeBinding>();
private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>(); private Map<String, FetchProfile> fetchProfiles = new HashMap<String, FetchProfile>();
private Map<String, String> imports = new HashMap<String, String>(); private Map<String, String> imports = new HashMap<String, String>();
private Map<String, TypeDef> typeDefs = new HashMap<String, TypeDef>(); private Map<String, TypeDef> typeDefs = new HashMap<String, TypeDef>();
@ -414,16 +415,16 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
entityBindingMap.put( entityName, entityBinding ); entityBindingMap.put( entityName, entityBinding );
} }
public AbstractPluralAttributeBinding getCollection(String collectionRole) { public PluralAttributeBinding getCollection(String collectionRole) {
return collectionBindingMap.get( collectionRole ); return collectionBindingMap.get( collectionRole );
} }
@Override @Override
public Iterable<AbstractPluralAttributeBinding> getCollectionBindings() { public Iterable<PluralAttributeBinding> getCollectionBindings() {
return collectionBindingMap.values(); return collectionBindingMap.values();
} }
public void addCollection(AbstractPluralAttributeBinding pluralAttributeBinding) { public void addCollection(PluralAttributeBinding pluralAttributeBinding) {
final String owningEntityName = pluralAttributeBinding.getContainer().getPathBase(); final String owningEntityName = pluralAttributeBinding.getContainer().getPathBase();
final String attributeName = pluralAttributeBinding.getAttribute().getName(); final String attributeName = pluralAttributeBinding.getAttribute().getName();
final String collectionRole = owningEntityName + '.' + attributeName; final String collectionRole = owningEntityName + '.' + attributeName;

View File

@ -23,6 +23,9 @@
*/ */
package org.hibernate.persister.internal; package org.hibernate.persister.internal;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
@ -32,9 +35,10 @@ import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.persister.spi.PersisterClassResolver;
@ -42,9 +46,6 @@ import org.hibernate.persister.spi.PersisterFactory;
import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/** /**
* The standard Hibernate {@link PersisterFactory} implementation * The standard Hibernate {@link PersisterFactory} implementation
* *
@ -197,8 +198,9 @@ public final class PersisterFactoryImpl implements PersisterFactory, ServiceRegi
@Override @Override
@SuppressWarnings( {"unchecked"}) @SuppressWarnings( {"unchecked"})
public CollectionPersister createCollectionPersister(MetadataImplementor metadata, public CollectionPersister createCollectionPersister(
AbstractPluralAttributeBinding collectionMetadata, MetadataImplementor metadata,
PluralAttributeBinding collectionMetadata,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException { SessionFactoryImplementor factory) throws HibernateException {
Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass(); Class<? extends CollectionPersister> persisterClass = collectionMetadata.getCollectionPersisterClass();

View File

@ -28,9 +28,9 @@ import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.UnionSubclass; import org.hibernate.mapping.UnionSubclass;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.CollectionElementNature; import org.hibernate.metamodel.binding.CollectionElementNature;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.persister.collection.BasicCollectionPersister; import org.hibernate.persister.collection.BasicCollectionPersister;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.OneToManyPersister; import org.hibernate.persister.collection.OneToManyPersister;
@ -106,7 +106,7 @@ public class StandardPersisterClassResolver implements PersisterClassResolver {
} }
@Override @Override
public Class<? extends CollectionPersister> getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { public Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata) {
return metadata.getCollectionElement().getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY return metadata.getCollectionElement().getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY
? oneToManyPersister() ? oneToManyPersister()
: basicCollectionPersister(); : basicCollectionPersister();

View File

@ -25,8 +25,8 @@ package org.hibernate.persister.spi;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.Service; import org.hibernate.service.Service;
@ -80,5 +80,5 @@ public interface PersisterClassResolver extends Service {
* *
* @return The collection persister class to use * @return The collection persister class to use
*/ */
Class<? extends CollectionPersister> getCollectionPersisterClass(AbstractPluralAttributeBinding metadata); Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata);
} }

View File

@ -31,9 +31,9 @@ import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.metamodel.source.MetadataImplementor;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.Service; import org.hibernate.service.Service;
@ -122,7 +122,7 @@ public interface PersisterFactory extends Service {
*/ */
public CollectionPersister createCollectionPersister( public CollectionPersister createCollectionPersister(
MetadataImplementor metadata, MetadataImplementor metadata,
AbstractPluralAttributeBinding model, PluralAttributeBinding model,
CollectionRegionAccessStrategy cacheAccessStrategy, CollectionRegionAccessStrategy cacheAccessStrategy,
SessionFactoryImplementor factory) throws HibernateException; SessionFactoryImplementor factory) throws HibernateException;

View File

@ -0,0 +1,91 @@
/*
* 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.binding;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
/**
* @author Steve Ebersole
*/
public class BasicCollectionBindingTests extends BaseUnitTestCase {
private BasicServiceRegistryImpl serviceRegistry;
@Before
public void setUp() {
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
}
@After
public void tearDown() {
serviceRegistry.destroy();
}
// @Test
// public void testAnnotations() {
// doTest( MetadataSourceProcessingOrder.ANNOTATIONS_FIRST );
// }
@Test
public void testHbm() {
doTest( MetadataSourceProcessingOrder.HBM_FIRST );
}
private void doTest(MetadataSourceProcessingOrder processingOrder) {
MetadataSources sources = new MetadataSources( serviceRegistry );
// sources.addAnnotatedClass( EntityWithBasicCollections.class );
sources.addResource( "org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml" );
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithBasicCollections.class.getName() );
assertNotNull( entityBinding );
PluralAttributeBinding bagBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theBag" );
assertNotNull( bagBinding );
assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) );
assertNotNull( bagBinding.getCollectionTable() );
assertEquals( CollectionElementNature.BASIC, bagBinding.getCollectionElement().getCollectionElementNature() );
assertEquals( String.class.getName(), bagBinding.getCollectionElement().getHibernateTypeDescriptor().getJavaTypeName() );
PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" );
assertNotNull( setBinding );
assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) );
assertNotNull( setBinding.getCollectionTable() );
assertEquals( CollectionElementNature.BASIC, setBinding.getCollectionElement().getCollectionElementNature() );
assertEquals( String.class.getName(), setBinding.getCollectionElement().getHibernateTypeDescriptor().getJavaTypeName() );
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<hibernate-mapping
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
package="org.hibernate.metamodel.binding" >
<class name="EntityWithBasicCollections">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<bag name="theBag">
<key column="owner_id"/>
<element column="bag_stuff" type="string"/>
</bag>
<set name="theSet">
<key column="pid"/>
<element column="set_stuff" type="string"/>
</set>
</class>
</hibernate-mapping>

View File

@ -23,24 +23,33 @@
*/ */
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* @author Gail Badner * @author Gail Badner
* @author Steve Ebersole
*/ */
public class EntityWithCollection { @Entity
public class EntityWithBasicCollections {
private Long id; private Long id;
private String name; private String name;
Set<String> otherNames = new HashSet<String>(); private Collection<String> theBag = new ArrayList<String>();
private Set<String> theSet = new HashSet<String>();
public EntityWithCollection() { public EntityWithBasicCollections() {
} }
public EntityWithCollection(String name) { public EntityWithBasicCollections(String name) {
this.name = name; this.name = name;
} }
@Id
public Long getId() { public Long getId() {
return id; return id;
} }
@ -57,11 +66,21 @@ public class EntityWithCollection {
this.name = name; this.name = name;
} }
public Set<String> getOtherNames() { @ElementCollection
return otherNames; public Collection<String> getTheBag() {
return theBag;
} }
public void setOtherNames(Set<String> otherNames) { public void setTheBag(Collection<String> theBag) {
this.otherNames = otherNames; this.theBag = theBag;
}
@ElementCollection
public Set<String> getTheSet() {
return theSet;
}
public void setTheSet(Set<String> theSet) {
this.theSet = theSet;
} }
} }

View File

@ -1,18 +0,0 @@
<?xml version="1.0"?>
<hibernate-mapping package="org.hibernate.metamodel.binding" xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="EntityWithCollection">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<set name="otherNames">
<key column="pid"/>
<element column="otherNames" type="string"/>
</set>
</class>
</hibernate-mapping>

View File

@ -45,8 +45,8 @@ import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata; import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.persister.spi.PersisterClassResolver; import org.hibernate.persister.spi.PersisterClassResolver;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
@ -76,7 +76,7 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver {
} }
@Override @Override
public Class<? extends CollectionPersister> getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { public Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata) {
return NoopCollectionPersister.class; return NoopCollectionPersister.class;
} }

View File

@ -20,13 +20,12 @@
*/ */
package org.hibernate.ejb.test.ejb3configuration; package org.hibernate.ejb.test.ejb3configuration;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import org.hibernate.EntityMode; import org.hibernate.EntityMode;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.LockMode; import org.hibernate.LockMode;
@ -45,11 +44,11 @@ import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata; import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.PluralAttributeBinding;
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.spi.PersisterClassResolver;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.spi.PersisterClassResolver;
import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.tuple.entity.EntityTuplizer;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -92,7 +91,7 @@ public class PersisterClassProviderTest extends junit.framework.TestCase {
} }
@Override @Override
public Class<? extends CollectionPersister> getCollectionPersisterClass(AbstractPluralAttributeBinding metadata) { public Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata) {
return null; return null;
} }
} }