HHH-7027 - Refine plural attribute binding information

This commit is contained in:
Steve Ebersole 2012-02-06 19:57:25 -06:00
parent 780305d861
commit eaf8c4816a
32 changed files with 558 additions and 262 deletions

View File

@ -115,7 +115,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
// Identity map of CollectionEntry instances, by the collection wrapper // Identity map of CollectionEntry instances, by the collection wrapper
private IdentityMap<PersistentCollection, CollectionEntry> collectionEntries; private IdentityMap<PersistentCollection, CollectionEntry> collectionEntries;
// Collection wrappers, by the CollectionKey // Collection wrappers, by the PluralAttributeKeyBinding
private Map<CollectionKey, PersistentCollection> collectionsByKey; private Map<CollectionKey, PersistentCollection> collectionsByKey;
// Set of EntityKeys of deleted objects // Set of EntityKeys of deleted objects
@ -905,7 +905,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
} }
/** /**
* Get the collection instance associated with the <tt>CollectionKey</tt> * Get the collection instance associated with the <tt>PluralAttributeKeyBinding</tt>
*/ */
@Override @Override
public PersistentCollection getCollection(CollectionKey collectionKey) { public PersistentCollection getCollection(CollectionKey collectionKey) {

View File

@ -100,7 +100,7 @@ public final class CollectionKey implements Serializable {
} }
public String toString() { public String toString() {
return "CollectionKey" + return "PluralAttributeKeyBinding" +
MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory ); MessageHelper.collectionInfoString( factory.getCollectionPersister(role), key, factory );
} }
@ -124,7 +124,7 @@ public final class CollectionKey implements Serializable {
* *
* @param ois The stream from which to read the entry. * @param ois The stream from which to read the entry.
* @param session The session being deserialized. * @param session The session being deserialized.
* @return The deserialized CollectionKey * @return The deserialized PluralAttributeKeyBinding
* @throws IOException * @throws IOException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */

View File

@ -408,7 +408,7 @@ public interface PersistenceContext {
PersistentCollection collection, Serializable id) throws HibernateException; PersistentCollection collection, Serializable id) throws HibernateException;
/** /**
* Get the collection instance associated with the <tt>CollectionKey</tt> * Get the collection instance associated with the <tt>PluralAttributeKeyBinding</tt>
*/ */
public PersistentCollection getCollection(CollectionKey collectionKey); public PersistentCollection getCollection(CollectionKey collectionKey);

View File

@ -0,0 +1,115 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated 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.ArrayList;
import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.CascadeStyle;
/**
* @author Steve Ebersole
*/
public abstract class AbstractPluralAttributeAssociationElementBinding
extends AbstractPluralAttributeElementBinding
implements PluralAttributeAssociationElementBinding {
private FetchTiming fetchTiming;
private FetchStyle fetchStyle;
private CascadeStyle cascadeStyle;
private boolean orphanDelete;
AbstractPluralAttributeAssociationElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
super( pluralAttributeBinding );
}
@Override
public CascadeStyle getCascadeStyle() {
return cascadeStyle;
}
@Override
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
for ( CascadeStyle style : cascadeStyles ) {
if ( style != CascadeStyle.NONE ) {
cascadeStyleList.add( style );
}
if ( style == CascadeStyle.DELETE_ORPHAN ||
style == CascadeStyle.ALL_DELETE_ORPHAN ) {
orphanDelete = true;
}
}
if ( cascadeStyleList.isEmpty() ) {
cascadeStyle = CascadeStyle.NONE;
}
else if ( cascadeStyleList.size() == 1 ) {
cascadeStyle = cascadeStyleList.get( 0 );
}
else {
cascadeStyle = new CascadeStyle.MultipleCascadeStyle(
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
);
}
}
@Override
public boolean isOrphanDeleteEnabled() {
return orphanDelete;
}
@Override
public FetchMode getFetchMode() {
if ( getFetchStyle() == FetchStyle.JOIN ) {
return FetchMode.JOIN;
}
else {
return FetchMode.SELECT;
}
}
@Override
public FetchTiming getFetchTiming() {
return fetchTiming;
}
@Override
public void setFetchTiming(FetchTiming fetchTiming) {
this.fetchTiming = fetchTiming;
}
@Override
public FetchStyle getFetchStyle() {
return fetchStyle;
}
@Override
public void setFetchStyle(FetchStyle fetchStyle) {
this.fetchStyle = fetchStyle;
}
}

View File

@ -23,17 +23,11 @@
*/ */
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.metamodel.domain.PluralAttribute; import org.hibernate.metamodel.domain.PluralAttribute;
import org.hibernate.metamodel.relational.Table; import org.hibernate.metamodel.relational.Table;
import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.TableSpecification;
@ -45,18 +39,13 @@ import org.hibernate.persister.collection.CollectionPersister;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding { public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding {
private final CollectionKey collectionKey; private final PluralAttributeKeyBinding pluralAttributeKeyBinding;
private final AbstractCollectionElement collectionElement; private final AbstractPluralAttributeElementBinding pluralAttributeElementBinding;
private Table collectionTable; private Table collectionTable;
private FetchTiming fetchTiming;
private FetchStyle fetchStyle;
private int batchSize = -1; private int batchSize = -1;
private CascadeStyle cascadeStyle;
private boolean orphanDelete;
private Caching caching; private Caching caching;
private boolean inverse; private boolean inverse;
@ -84,31 +73,31 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
protected AbstractPluralAttributeBinding( protected AbstractPluralAttributeBinding(
AttributeBindingContainer container, AttributeBindingContainer container,
PluralAttribute attribute, PluralAttribute attribute,
CollectionElementNature collectionElementNature) { PluralAttributeElementNature pluralAttributeElementNature) {
super( container, attribute ); super( container, attribute );
this.collectionKey = new CollectionKey( this ); this.pluralAttributeKeyBinding = new PluralAttributeKeyBinding( this );
this.collectionElement = interpretNature( collectionElementNature ); this.pluralAttributeElementBinding = interpretNature( pluralAttributeElementNature );
} }
private AbstractCollectionElement interpretNature(CollectionElementNature collectionElementNature) { private AbstractPluralAttributeElementBinding interpretNature(PluralAttributeElementNature pluralAttributeElementNature) {
switch ( collectionElementNature ) { switch ( pluralAttributeElementNature ) {
case BASIC: { case BASIC: {
return new BasicCollectionElement( this ); return new BasicPluralAttributeElementBinding( this );
} }
case COMPOSITE: { case COMPOSITE: {
return new CompositeCollectionElement( this ); return new CompositePluralAttributeElementBinding( this );
} }
case ONE_TO_MANY: { case ONE_TO_MANY: {
return new OneToManyCollectionElement( this ); return new OneToManyPluralAttributeElementBinding( this );
} }
case MANY_TO_MANY: { case MANY_TO_MANY: {
return new ManyToManyCollectionElement( this ); return new ManyToManyPluralAttributeElementBinding( this );
} }
case MANY_TO_ANY: { case MANY_TO_ANY: {
return new ManyToAnyCollectionElement( this ); return new ManyToAnyPluralAttributeElementBinding( this );
} }
default: { default: {
throw new AssertionFailure( "Unknown collection element nature : " + collectionElementNature ); throw new AssertionFailure( "Unknown collection element nature : " + pluralAttributeElementNature );
} }
} }
} }
@ -117,8 +106,8 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
// super.initialize( state ); // super.initialize( state );
// fetchMode = state.getFetchMode(); // fetchMode = state.getFetchMode();
// extraLazy = state.isExtraLazy(); // extraLazy = state.isExtraLazy();
// collectionElement.setNodeName( state.getElementNodeName() ); // pluralAttributeElementBinding.setNodeName( state.getElementNodeName() );
// collectionElement.setTypeName( state.getElementTypeName() ); // pluralAttributeElementBinding.setTypeName( state.getElementTypeName() );
// inverse = state.isInverse(); // inverse = state.isInverse();
// mutable = state.isMutable(); // mutable = state.isMutable();
// subselectLoadable = state.isSubselectLoadable(); // subselectLoadable = state.isSubselectLoadable();
@ -154,9 +143,7 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
@Override @Override
public boolean isAssociation() { public boolean isAssociation() {
return collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_ANY return pluralAttributeElementBinding.getPluralAttributeElementNature().isAssociation();
|| collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_MANY
|| collectionElement.getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY;
} }
@Override @Override
@ -169,79 +156,13 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
} }
@Override @Override
public CollectionKey getCollectionKey() { public PluralAttributeKeyBinding getPluralAttributeKeyBinding() {
return collectionKey; return pluralAttributeKeyBinding;
} }
@Override @Override
public AbstractCollectionElement getCollectionElement() { public AbstractPluralAttributeElementBinding getPluralAttributeElementBinding() {
return collectionElement; return pluralAttributeElementBinding;
}
@Override
public CascadeStyle getCascadeStyle() {
return cascadeStyle;
}
@Override
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles) {
List<CascadeStyle> cascadeStyleList = new ArrayList<CascadeStyle>();
for ( CascadeStyle style : cascadeStyles ) {
if ( style != CascadeStyle.NONE ) {
cascadeStyleList.add( style );
}
if ( style == CascadeStyle.DELETE_ORPHAN ||
style == CascadeStyle.ALL_DELETE_ORPHAN ) {
orphanDelete = true;
}
}
if ( cascadeStyleList.isEmpty() ) {
cascadeStyle = CascadeStyle.NONE;
}
else if ( cascadeStyleList.size() == 1 ) {
cascadeStyle = cascadeStyleList.get( 0 );
}
else {
cascadeStyle = new CascadeStyle.MultipleCascadeStyle(
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
);
}
}
@Override
public boolean isOrphanDelete() {
return orphanDelete;
}
@Override
public FetchMode getFetchMode() {
if ( getFetchStyle() == FetchStyle.JOIN ) {
return FetchMode.JOIN;
}
else {
return FetchMode.SELECT;
}
}
@Override
public FetchTiming getFetchTiming() {
return fetchTiming;
}
@Override
public void setFetchTiming(FetchTiming fetchTiming) {
this.fetchTiming = fetchTiming;
}
@Override
public FetchStyle getFetchStyle() {
return fetchStyle;
}
@Override
public void setFetchStyle(FetchStyle fetchStyle) {
this.fetchStyle = fetchStyle;
} }
@Override @Override

View File

@ -30,22 +30,27 @@ import org.hibernate.metamodel.relational.Value;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class AbstractCollectionElement { public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding {
private final AbstractPluralAttributeBinding collectionBinding; private final AbstractPluralAttributeBinding pluralAttributeBinding;
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private Value relationalValue;
private Value elementValue; AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
this.pluralAttributeBinding = pluralAttributeBinding;
AbstractCollectionElement(AbstractPluralAttributeBinding collectionBinding) {
this.collectionBinding = collectionBinding;
} }
public abstract CollectionElementNature getCollectionElementNature(); @Override
public AbstractPluralAttributeBinding getPluralAttributeBinding() {
public AbstractPluralAttributeBinding getCollectionBinding() { return pluralAttributeBinding;
return collectionBinding;
} }
public Value getElementValue() { @Override
return elementValue; public HibernateTypeDescriptor getHibernateTypeDescriptor() {
return hibernateTypeDescriptor;
}
@Override
public Value getRelationalValue() {
return relationalValue;
} }
} }

View File

@ -100,7 +100,7 @@ public interface AttributeBindingContainer {
* *
* @return The attribute binding instance. * @return The attribute binding instance.
*/ */
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature); public BagBinding makeBagAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature);
/** /**
* Factory method for bag attribute bindings. * Factory method for bag attribute bindings.
@ -110,7 +110,7 @@ public interface AttributeBindingContainer {
* *
* @return The attribute binding instance. * @return The attribute binding instance.
*/ */
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature); public SetBinding makeSetAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature 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

@ -31,7 +31,7 @@ import org.hibernate.metamodel.domain.PluralAttribute;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class BagBinding extends AbstractPluralAttributeBinding { public class BagBinding extends AbstractPluralAttributeBinding {
protected BagBinding(AttributeBindingContainer container, PluralAttribute attribute, CollectionElementNature nature) { protected BagBinding(AttributeBindingContainer container, PluralAttribute attribute, PluralAttributeElementNature nature) {
super( container, attribute, nature ); super( container, attribute, nature );
} }
} }

View File

@ -24,17 +24,19 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
/** /**
* Describes plural attributes of {@link PluralAttributeElementNature#BASIC} elements
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner * @author Gail Badner
*/ */
public class OneToManyCollectionElement extends AbstractCollectionElement { public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
OneToManyCollectionElement(AbstractPluralAttributeBinding binding) { public BasicPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
super( binding ); super( binding );
} }
@Override @Override
public CollectionElementNature getCollectionElementNature() { public PluralAttributeElementNature getPluralAttributeElementNature() {
return CollectionElementNature.ONE_TO_MANY; return PluralAttributeElementNature.BASIC;
} }
} }

View File

@ -0,0 +1,35 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated 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.engine.spi.CascadeStyle;
/**
* @author Steve Ebersole
*/
public interface Cascadeable {
public CascadeStyle getCascadeStyle();
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles);
}

View File

@ -128,7 +128,7 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding
} }
@Override @Override
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public BagBinding makeBagAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG ); 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 );
@ -136,7 +136,7 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding
} }
@Override @Override
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public SetBinding makeSetAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET ); Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
final SetBinding binding = new SetBinding( this, attribute, nature ); final SetBinding binding = new SetBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding ); registerAttributeBinding( attribute.getName(), binding );

View File

@ -24,16 +24,18 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
/** /**
* Describes plural attributes of {@link PluralAttributeElementNature#COMPOSITE} elements
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner * @author Gail Badner
*/ */
public class ManyToAnyCollectionElement extends AbstractCollectionElement { public class CompositePluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
ManyToAnyCollectionElement(AbstractPluralAttributeBinding binding) { public CompositePluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
super( binding ); super( binding );
} }
@Override @Override
public CollectionElementNature getCollectionElementNature() { public PluralAttributeElementNature getPluralAttributeElementNature() {
return CollectionElementNature.MANY_TO_ANY; return PluralAttributeElementNature.COMPOSITE;
} }
} }

View File

@ -517,7 +517,7 @@ public class EntityBinding implements AttributeBindingContainer {
} }
@Override @Override
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public BagBinding makeBagAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG ); 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 );
@ -525,7 +525,7 @@ public class EntityBinding implements AttributeBindingContainer {
} }
@Override @Override
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) { public SetBinding makeSetAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET ); Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
final SetBinding binding = new SetBinding( this, attribute, nature ); final SetBinding binding = new SetBinding( this, attribute, nature );
registerAttributeBinding( attribute.getName(), binding ); registerAttributeBinding( attribute.getName(), binding );

View File

@ -0,0 +1,43 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated 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.FetchMode;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
/**
* @author Steve Ebersole
*/
public interface Fetchable {
public FetchMode getFetchMode();
public FetchTiming getFetchTiming();
public void setFetchTiming(FetchTiming fetchTiming);
public FetchStyle getFetchStyle();
public void setFetchStyle(FetchStyle fetchStyle);
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated 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;
/**
* Specialization of plural attribute binding for indexed collections (maps and lists).
*
* @author Steve Ebersole
*/
public interface IndexedPluralAttributeBinding extends PluralAttributeBinding {
/**
* Retrieve the binding descriptor pertaining to the plural attribute's index value.
*
* @return The index binding descriptor
*/
public PluralAttributeIndexBinding getPluralAttributeIndexBinding();
}

View File

@ -24,16 +24,18 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
/** /**
* Describes plural attributes of {@link PluralAttributeElementNature#MANY_TO_ANY} elements
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner * @author Gail Badner
*/ */
public class CompositeCollectionElement extends AbstractCollectionElement { public class ManyToAnyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
public CompositeCollectionElement(AbstractPluralAttributeBinding binding) { ManyToAnyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
super( binding ); super( binding );
} }
@Override @Override
public CollectionElementNature getCollectionElementNature() { public PluralAttributeElementNature getPluralAttributeElementNature() {
return CollectionElementNature.COMPOSITE; return PluralAttributeElementNature.MANY_TO_ANY;
} }
} }

View File

@ -28,44 +28,24 @@ import java.util.HashMap;
import org.dom4j.Element; import org.dom4j.Element;
/** /**
* Describes plural attributes of {@link PluralAttributeElementNature#MANY_TO_MANY} elements
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner * @author Gail Badner
*/ */
public class ManyToManyCollectionElement extends AbstractCollectionElement { public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
private final java.util.Map manyToManyFilters = new HashMap(); private final java.util.Map manyToManyFilters = new HashMap();
private String manyToManyWhere; private String manyToManyWhere;
private String manyToManyOrderBy; private String manyToManyOrderBy;
ManyToManyCollectionElement(AbstractPluralAttributeBinding binding) { ManyToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
super( binding ); super( binding );
} }
@Override @Override
public CollectionElementNature getCollectionElementNature() { public PluralAttributeElementNature getPluralAttributeElementNature() {
return CollectionElementNature.MANY_TO_MANY; return PluralAttributeElementNature.MANY_TO_MANY;
}
public void fromHbmXml(Element node){
/*
<!ELEMENT many-to-many (meta*,(column|formula)*,filter*)>
<!ATTLIST many-to-many class CDATA #IMPLIED>
<!ATTLIST many-to-many node CDATA #IMPLIED>
<!ATTLIST many-to-many embed-xml (true|false) "true">
<!ATTLIST many-to-many entity-name CDATA #IMPLIED>
<!ATTLIST many-to-many column CDATA #IMPLIED>
<!ATTLIST many-to-many formula CDATA #IMPLIED>
<!ATTLIST many-to-many not-found (exception|ignore) "exception">
<!ATTLIST many-to-many outer-join (true|false|auto) #IMPLIED>
<!ATTLIST many-to-many fetch (join|select) #IMPLIED>
<!ATTLIST many-to-many lazy (false|proxy) #IMPLIED>
<!ATTLIST many-to-many foreign-key CDATA #IMPLIED>
<!ATTLIST many-to-many unique (true|false) "false">
<!ATTLIST many-to-many where CDATA #IMPLIED>
<!ATTLIST many-to-many order-by CDATA #IMPLIED>
<!ATTLIST many-to-many property-ref CDATA #IMPLIED>
*/
} }
public String getManyToManyWhere() { public String getManyToManyWhere() {

View File

@ -24,21 +24,18 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
/** /**
* Describes plural attributes of {@link PluralAttributeElementNature#ONE_TO_MANY} elements
*
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner * @author Gail Badner
*/ */
public class BasicCollectionElement extends AbstractCollectionElement { public class OneToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); OneToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
public BasicCollectionElement(AbstractPluralAttributeBinding binding) {
super( binding ); super( binding );
} }
public CollectionElementNature getCollectionElementNature() { @Override
return CollectionElementNature.BASIC; public PluralAttributeElementNature getPluralAttributeElementNature() {
} return PluralAttributeElementNature.ONE_TO_MANY;
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
return hibernateTypeDescriptor;
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
@ -24,17 +24,11 @@
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
/** /**
* Describes the nature of persistent collection elements. * Specialization of PluralAttributeElementBinding for elements which are association (entity) values.
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Gail Badner
*
* @todo Merge with {@link org.hibernate.metamodel.source.binder.PluralAttributeNature} ? package separation kept me from doing that initially
*/ */
public enum CollectionElementNature { public interface PluralAttributeAssociationElementBinding
BASIC, extends PluralAttributeElementBinding, Cascadeable, Fetchable {
COMPOSITE, public boolean isOrphanDeleteEnabled();
ONE_TO_MANY,
MANY_TO_MANY,
MANY_TO_ANY
} }

View File

@ -30,17 +30,39 @@ import org.hibernate.metamodel.relational.TableSpecification;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
/** /**
* Describes the binding of a plural attribute.
*
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface PluralAttributeBinding extends AssociationAttributeBinding { public interface PluralAttributeBinding extends AttributeBinding {
// todo : really it is the element (and/or index) that can be associative not the collection itself... /**
* Retrieve the plural attribute being bound.
*
* @return The plural attribute descriptor
*/
@Override @Override
public PluralAttribute getAttribute(); public PluralAttribute getAttribute();
public CollectionKey getCollectionKey(); /**
* Retrieve the binding information pertaining to the collection (foreign) key.
*
* @return The key binding descriptor
*/
public PluralAttributeKeyBinding getPluralAttributeKeyBinding();
/**
* Retrieve the binding information pertaining to the collection elements.
*
* @return The element binding descriptor
*/
public PluralAttributeElementBinding getPluralAttributeElementBinding();
public AbstractCollectionElement getCollectionElement();
public TableSpecification getCollectionTable(); public TableSpecification getCollectionTable();
@ -60,8 +82,6 @@ public interface PluralAttributeBinding extends AssociationAttributeBinding {
public CustomSQL getCustomSqlDeleteAll(); public CustomSQL getCustomSqlDeleteAll();
public boolean isOrphanDelete();
String getWhere(); String getWhere();
boolean isSorted(); boolean isSorted();

View File

@ -1,7 +1,7 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
@ -23,44 +23,40 @@
*/ */
package org.hibernate.metamodel.binding; package org.hibernate.metamodel.binding;
import org.hibernate.FetchMode; import org.hibernate.metamodel.relational.Value;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.CascadeStyle;
/** /**
* Contract describing a binding for attributes which model associations. * Common information pertaining to the binding of the various plural attribute natures (one-to-many, basic, etc).
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public interface AssociationAttributeBinding extends AttributeBinding { public interface PluralAttributeElementBinding {
/** /**
* Obtain the cascade style in effect for this association. * Retrieves the plural attribute binding descriptor whose element binding is described here.
* *
* @return The (potentially aggregated) cascade style. * @return The plural attribute binding descriptor.
*/ */
public CascadeStyle getCascadeStyle(); public PluralAttributeBinding getPluralAttributeBinding();
/** /**
* Set the cascade styles in effect for this association. * Retrieve the relational aspect of the element binding. Essentially describes the column(s) to which the
* binding maps the elements
* *
* @param cascadeStyles The cascade styles. * @return The relation information.
*/ */
public void setCascadeStyles(Iterable<CascadeStyle> cascadeStyles); public Value getRelationalValue();
public FetchTiming getFetchTiming();
public void setFetchTiming(FetchTiming fetchTiming);
public FetchStyle getFetchStyle();
public void setFetchStyle(FetchStyle fetchStyle);
/** /**
* Temporary. Needed for integration with legacy org.hibernate.mapping configuration of persisters. * Retrieves an enumeration describing the mapping nature of the collection's elements.
* *
* @deprecated * @return The nature enum.
*/ */
@Deprecated public PluralAttributeElementNature getPluralAttributeElementNature();
@SuppressWarnings( {"JavaDoc"})
public FetchMode getFetchMode(); /**
* Retrieve the Hibernate type descriptor describing the mapping-typing of the elements.
*
* @return The element type descriptor.
*/
public HibernateTypeDescriptor getHibernateTypeDescriptor();
} }

View File

@ -0,0 +1,67 @@
/*
* 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;
/**
* Describes the nature of plural attribute elements in terms of relational implications.
*
* @author Steve Ebersole
* @author Gail Badner
*/
public enum PluralAttributeElementNature {
/**
* The collection elements are basic, simple values.
*/
BASIC( false ),
/**
* The collection elements are compositions.
*/
COMPOSITE( false ),
/**
* The collection elements represent entity's in a one-to-many association.
*/
ONE_TO_MANY,
/**
* The collection elements represent entity's in a many-to-many association.
*/
MANY_TO_MANY,
/**
* The collection elements represent entity's in a multi-valued ANY mapping.
*/
MANY_TO_ANY;
private final boolean isAssociation;
private PluralAttributeElementNature() {
this( true );
}
private PluralAttributeElementNature(boolean association) {
this.isAssociation = association;
}
public boolean isAssociation() {
return isAssociation;
}
}

View File

@ -0,0 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated 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.relational.Value;
/**
* De
* @author Steve Ebersole
*/
public interface PluralAttributeIndexBinding {
public PluralAttributeBinding getPluralAttributeBinding();
public Value getIndexRelationalValue();
public HibernateTypeDescriptor getHibernateTypeDescriptor();
}

View File

@ -28,28 +28,63 @@ import org.hibernate.metamodel.relational.ForeignKey;
import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.TableSpecification;
/** /**
* TODO : javadoc * Describes the binding information pertaining to the plural attribute foreign key.
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class CollectionKey { public class PluralAttributeKeyBinding {
private final AbstractPluralAttributeBinding pluralAttributeBinding; private final AbstractPluralAttributeBinding pluralAttributeBinding;
private ForeignKey foreignKey; private ForeignKey foreignKey;
private boolean inverse; private boolean inverse;
// may need notion of "boolean updatable"
// this knowledge can be implicitly resolved based on the typing information on the referenced owner attribute
private HibernateTypeDescriptor hibernateTypeDescriptor; private HibernateTypeDescriptor hibernateTypeDescriptor;
// in which case add this...
// SingularAttributeBinding referencedAttributeBinding;
// todo : this would be nice to have but we do not always know it, especially in HBM case. // todo : this would be nice to have but we do not always know it, especially in HBM case.
// private BasicAttributeBinding otherSide; // private BasicAttributeBinding otherSide;
public CollectionKey(AbstractPluralAttributeBinding pluralAttributeBinding) {
public PluralAttributeKeyBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
this.pluralAttributeBinding = pluralAttributeBinding; this.pluralAttributeBinding = pluralAttributeBinding;
} }
/**
* Identifies the plural attribute binding whose foreign key this class is describing.
*
* @return The plural attribute whose foreign key is being described
*/
public AbstractPluralAttributeBinding getPluralAttributeBinding() { public AbstractPluralAttributeBinding getPluralAttributeBinding() {
return pluralAttributeBinding; return pluralAttributeBinding;
} }
/**
* The foreign key that defines the scope of this relationship.
*
* @return The foreign key being bound to.
*/
public ForeignKey getForeignKey() {
return foreignKey;
}
/**
* Is the plural attribute considered inverse?
* <p/>
* NOTE: The "inverse-ness" of a plural attribute logically applies to it key.
*
* @return {@code true} indicates the plural attribute is inverse; {@code false} indicates is not.
*/
public boolean isInverse() {
return inverse;
}
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
return hibernateTypeDescriptor;
}
public void prepareForeignKey(String foreignKeyName, String targetTableName) { public void prepareForeignKey(String foreignKeyName, String targetTableName) {
if ( foreignKey != null ) { if ( foreignKey != null ) {
throw new AssertionFailure( "Foreign key already initialized" ); throw new AssertionFailure( "Foreign key already initialized" );
@ -68,7 +103,4 @@ public class CollectionKey {
foreignKey = collectionTable.createForeignKey( targetTable, foreignKeyName ); foreignKey = collectionTable.createForeignKey( targetTable, foreignKeyName );
} }
public ForeignKey getForeignKey() {
return foreignKey;
}
} }

View File

@ -36,8 +36,8 @@ public class SetBinding extends AbstractPluralAttributeBinding {
protected SetBinding( protected SetBinding(
AttributeBindingContainer container, AttributeBindingContainer container,
PluralAttribute attribute, PluralAttribute attribute,
CollectionElementNature collectionElementNature) { PluralAttributeElementNature pluralAttributeElementNature) {
super( container, attribute, collectionElementNature ); super( container, attribute, pluralAttributeElementNature );
} }
public Comparator getComparator() { public Comparator getComparator() {

View File

@ -30,7 +30,8 @@ package org.hibernate.metamodel.binding;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings( {"JavaDoc", "UnusedDeclaration"}) @SuppressWarnings( {"JavaDoc", "UnusedDeclaration"})
public interface SingularAssociationAttributeBinding extends SingularAttributeBinding, AssociationAttributeBinding { public interface SingularAssociationAttributeBinding
extends SingularAttributeBinding, Cascadeable, Fetchable {
/** /**
* Is this association based on a property reference (non PK column(s) as target of FK)? * Is this association based on a property reference (non PK column(s) as target of FK)?
* <p/> * <p/>

View File

@ -41,8 +41,10 @@ import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.AttributeBindingContainer; import org.hibernate.metamodel.binding.AttributeBindingContainer;
import org.hibernate.metamodel.binding.BasicAttributeBinding; import org.hibernate.metamodel.binding.BasicAttributeBinding;
import org.hibernate.metamodel.binding.BasicCollectionElement; import org.hibernate.metamodel.binding.BasicPluralAttributeElementBinding;
import org.hibernate.metamodel.binding.CollectionElementNature; import org.hibernate.metamodel.binding.Cascadeable;
import org.hibernate.metamodel.binding.Fetchable;
import org.hibernate.metamodel.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.binding.CollectionLaziness; import org.hibernate.metamodel.binding.CollectionLaziness;
import org.hibernate.metamodel.binding.ComponentAttributeBinding; import org.hibernate.metamodel.binding.ComponentAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
@ -497,9 +499,13 @@ public class Binder {
} }
private void doBasicPluralAttributeBinding(PluralAttributeSource source, AbstractPluralAttributeBinding binding) { private void doBasicPluralAttributeBinding(PluralAttributeSource source, AbstractPluralAttributeBinding binding) {
binding.setFetchTiming( source.getFetchTiming() ); if ( binding.isAssociation() ) {
binding.setFetchStyle( source.getFetchStyle() ); final Cascadeable cascadeable = (Cascadeable) binding.getPluralAttributeElementBinding();
binding.setCascadeStyles( source.getCascadeStyles() ); cascadeable.setCascadeStyles( source.getCascadeStyles() );
final Fetchable fetchable = (Fetchable) binding.getPluralAttributeElementBinding();
fetchable.setFetchTiming( source.getFetchTiming() );
fetchable.setFetchStyle( source.getFetchStyle() );
}
binding.setCaching( source.getCaching() ); binding.setCaching( source.getCaching() );
@ -561,7 +567,7 @@ public class Binder {
private void bindCollectionTable( private void bindCollectionTable(
PluralAttributeSource attributeSource, PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) { AbstractPluralAttributeBinding pluralAttributeBinding) {
if ( attributeSource.getElementSource().getNature() == PluralAttributeElementNature.ONE_TO_MANY ) { if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.source.binder.PluralAttributeElementNature.ONE_TO_MANY ) {
return; return;
} }
@ -620,11 +626,11 @@ public class Binder {
private void bindCollectionKey( private void bindCollectionKey(
PluralAttributeSource attributeSource, PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) { AbstractPluralAttributeBinding pluralAttributeBinding) {
pluralAttributeBinding.getCollectionKey().prepareForeignKey( pluralAttributeBinding.getPluralAttributeKeyBinding().prepareForeignKey(
attributeSource.getKeySource().getExplicitForeignKeyName(), attributeSource.getKeySource().getExplicitForeignKeyName(),
null // todo : handle secondary table names null // todo : handle secondary table names
); );
pluralAttributeBinding.getCollectionKey().getForeignKey().setDeleteRule( pluralAttributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule(
attributeSource.getKeySource().getOnDeleteAction() attributeSource.getKeySource().getOnDeleteAction()
); );
// todo : need to bind "relational values", account for property-ref // todo : need to bind "relational values", account for property-ref
@ -634,9 +640,9 @@ public class Binder {
PluralAttributeSource attributeSource, PluralAttributeSource attributeSource,
AbstractPluralAttributeBinding pluralAttributeBinding) { AbstractPluralAttributeBinding pluralAttributeBinding) {
final PluralAttributeElementSource elementSource = attributeSource.getElementSource(); final PluralAttributeElementSource elementSource = attributeSource.getElementSource();
if ( elementSource.getNature() == PluralAttributeElementNature.BASIC ) { if ( elementSource.getNature() == org.hibernate.metamodel.source.binder.PluralAttributeElementNature.BASIC ) {
final BasicPluralAttributeElementSource basicElementSource = (BasicPluralAttributeElementSource) elementSource; final BasicPluralAttributeElementSource basicElementSource = (BasicPluralAttributeElementSource) elementSource;
final BasicCollectionElement basicCollectionElement = (BasicCollectionElement) pluralAttributeBinding.getCollectionElement(); final BasicPluralAttributeElementBinding basicCollectionElement = (BasicPluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding();
resolveTypeInformation( resolveTypeInformation(
basicElementSource.getExplicitHibernateTypeSource(), basicElementSource.getExplicitHibernateTypeSource(),
pluralAttributeBinding.getAttribute(), pluralAttributeBinding.getAttribute(),
@ -692,8 +698,8 @@ public class Binder {
attributeBinding.setIncludedInOptimisticLocking( attributeSource.isIncludedInOptimisticLocking() ); attributeBinding.setIncludedInOptimisticLocking( attributeSource.isIncludedInOptimisticLocking() );
} }
private CollectionElementNature convert(PluralAttributeElementNature pluralAttributeElementNature) { private PluralAttributeElementNature convert(org.hibernate.metamodel.source.binder.PluralAttributeElementNature pluralAttributeElementNature) {
return CollectionElementNature.valueOf( pluralAttributeElementNature.name() ); return PluralAttributeElementNature.valueOf( pluralAttributeElementNature.name() );
} }
private BasicAttributeBinding doBasicSingularAttributeBindingCreation( private BasicAttributeBinding doBasicSingularAttributeBindingCreation(
@ -769,7 +775,7 @@ public class Binder {
private void resolveTypeInformation( private void resolveTypeInformation(
ExplicitHibernateTypeSource typeSource, ExplicitHibernateTypeSource typeSource,
PluralAttribute attribute, PluralAttribute attribute,
BasicCollectionElement collectionElement) { BasicPluralAttributeElementBinding collectionElement) {
final Class<?> attributeJavaType = determineJavaType( attribute ); final Class<?> attributeJavaType = determineJavaType( attribute );
resolveTypeInformation( typeSource, collectionElement.getHibernateTypeDescriptor(), attributeJavaType ); resolveTypeInformation( typeSource, collectionElement.getHibernateTypeDescriptor(), attributeJavaType );
} }

View File

@ -26,11 +26,11 @@ package org.hibernate.metamodel.source.internal;
import java.util.Properties; import java.util.Properties;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.binding.AbstractCollectionElement; import org.hibernate.metamodel.binding.AbstractPluralAttributeElementBinding;
import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.BasicCollectionElement; import org.hibernate.metamodel.binding.BasicPluralAttributeElementBinding;
import org.hibernate.metamodel.binding.CollectionElementNature; import org.hibernate.metamodel.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.EntityDiscriminator; import org.hibernate.metamodel.binding.EntityDiscriminator;
import org.hibernate.metamodel.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
@ -160,8 +160,8 @@ class HibernateTypeResolver {
getTypeParameters( attributeBinding.getHibernateTypeDescriptor() ), getTypeParameters( attributeBinding.getHibernateTypeDescriptor() ),
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
attributeBinding.getReferencedPropertyName(), attributeBinding.getReferencedPropertyName(),
attributeBinding.getCollectionElement().getCollectionElementNature() == attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ==
CollectionElementNature.COMPOSITE PluralAttributeElementNature.COMPOSITE
); );
} }
else { else {
@ -173,7 +173,7 @@ class HibernateTypeResolver {
null, null,
resolvedType ); resolvedType );
} }
resolveCollectionElementTypeInformation( attributeBinding.getCollectionElement() ); resolveCollectionElementTypeInformation( attributeBinding.getPluralAttributeElementBinding() );
} }
private Type determineDefaultCollectionInformation(AbstractPluralAttributeBinding attributeBinding) { private Type determineDefaultCollectionInformation(AbstractPluralAttributeBinding attributeBinding) {
@ -183,15 +183,15 @@ class HibernateTypeResolver {
return typeFactory.set( return typeFactory.set(
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
attributeBinding.getReferencedPropertyName(), attributeBinding.getReferencedPropertyName(),
attributeBinding.getCollectionElement().getCollectionElementNature() == CollectionElementNature.COMPOSITE attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
); );
} }
case BAG: { case BAG: {
return typeFactory.bag( return typeFactory.bag(
attributeBinding.getAttribute().getName(), attributeBinding.getAttribute().getName(),
attributeBinding.getReferencedPropertyName(), attributeBinding.getReferencedPropertyName(),
attributeBinding.getCollectionElement() attributeBinding.getPluralAttributeElementBinding()
.getCollectionElementNature() == CollectionElementNature.COMPOSITE .getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
); );
} }
default: { default: {
@ -202,30 +202,33 @@ class HibernateTypeResolver {
} }
} }
private void resolveCollectionElementTypeInformation(AbstractCollectionElement collectionElement) { private void resolveCollectionElementTypeInformation(AbstractPluralAttributeElementBinding pluralAttributeElementBinding) {
switch ( collectionElement.getCollectionElementNature() ) { switch ( pluralAttributeElementBinding.getPluralAttributeElementNature() ) {
case BASIC: { case BASIC: {
resolveBasicCollectionElement( BasicCollectionElement.class.cast( collectionElement ) ); resolveBasicCollectionElement( BasicPluralAttributeElementBinding.class.cast(
pluralAttributeElementBinding
) );
break; break;
} }
case COMPOSITE: case COMPOSITE:
case ONE_TO_MANY: case ONE_TO_MANY:
case MANY_TO_MANY: case MANY_TO_MANY:
case MANY_TO_ANY: { case MANY_TO_ANY: {
throw new UnsupportedOperationException( "Collection element nature not supported yet: " + collectionElement.getCollectionElementNature() ); throw new UnsupportedOperationException( "Collection element nature not supported yet: " + pluralAttributeElementBinding
.getPluralAttributeElementNature() );
} }
default: { default: {
throw new AssertionFailure( "Unknown collection element nature : " + collectionElement.getCollectionElementNature() ); throw new AssertionFailure( "Unknown collection element nature : " + pluralAttributeElementBinding.getPluralAttributeElementNature() );
} }
} }
} }
private void resolveBasicCollectionElement(BasicCollectionElement basicCollectionElement) { private void resolveBasicCollectionElement(BasicPluralAttributeElementBinding basicCollectionElement) {
Type resolvedHibernateType = determineSingularTypeFromDescriptor( basicCollectionElement.getHibernateTypeDescriptor() ); Type resolvedHibernateType = determineSingularTypeFromDescriptor( basicCollectionElement.getHibernateTypeDescriptor() );
if ( resolvedHibernateType != null ) { if ( resolvedHibernateType != null ) {
pushHibernateTypeInformationDownIfNeeded( pushHibernateTypeInformationDownIfNeeded(
basicCollectionElement.getHibernateTypeDescriptor(), basicCollectionElement.getHibernateTypeDescriptor(),
basicCollectionElement.getElementValue(), basicCollectionElement.getRelationalValue(),
resolvedHibernateType resolvedHibernateType
); );
} }

View File

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

View File

@ -46,7 +46,7 @@ public interface SessionStatistics {
*/ */
public Set getEntityKeys(); public Set getEntityKeys();
/** /**
* Get the set of all <tt>CollectionKey</tt>s * Get the set of all <tt>PluralAttributeKeyBinding</tt>s
* @see org.hibernate.engine.spi.CollectionKey * @see org.hibernate.engine.spi.CollectionKey
*/ */
public Set getCollectionKeys(); public Set getCollectionKeys();

View File

@ -42,6 +42,7 @@ import org.hibernate.metamodel.binding.AssociationAttributeBinding;
import org.hibernate.metamodel.binding.AttributeBinding; import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.BasicAttributeBinding; import org.hibernate.metamodel.binding.BasicAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.PluralAttributeAssociationElementBinding;
import org.hibernate.metamodel.binding.SimpleValueBinding; import org.hibernate.metamodel.binding.SimpleValueBinding;
import org.hibernate.metamodel.binding.SingularAttributeBinding; import org.hibernate.metamodel.binding.SingularAttributeBinding;
import org.hibernate.property.Getter; import org.hibernate.property.Getter;
@ -316,10 +317,10 @@ public class PropertyFactory {
else { else {
final AbstractPluralAttributeBinding pluralAttributeBinding = (AbstractPluralAttributeBinding) property; final AbstractPluralAttributeBinding pluralAttributeBinding = (AbstractPluralAttributeBinding) property;
final CascadeStyle cascadeStyle = pluralAttributeBinding.isAssociation() final CascadeStyle cascadeStyle = pluralAttributeBinding.isAssociation()
? pluralAttributeBinding.getCascadeStyle() ? ( (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getCascadeStyle()
: CascadeStyle.NONE; : CascadeStyle.NONE;
final FetchMode fetchMode = pluralAttributeBinding.isAssociation() final FetchMode fetchMode = pluralAttributeBinding.isAssociation()
? pluralAttributeBinding.getFetchMode() ? ( (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getFetchMode()
: FetchMode.DEFAULT; : FetchMode.DEFAULT;
return new StandardProperty( return new StandardProperty(

View File

@ -77,14 +77,14 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
assertNotNull( bagBinding ); assertNotNull( bagBinding );
assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) ); assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) );
assertNotNull( bagBinding.getCollectionTable() ); assertNotNull( bagBinding.getCollectionTable() );
assertEquals( CollectionElementNature.BASIC, bagBinding.getCollectionElement().getCollectionElementNature() ); assertEquals( PluralAttributeElementNature.BASIC, bagBinding.getPluralAttributeElementBinding().getCollectionElementNature() );
assertEquals( String.class.getName(), ( (BasicCollectionElement) bagBinding.getCollectionElement() ).getHibernateTypeDescriptor().getJavaTypeName() ); assertEquals( String.class.getName(), ( (BasicPluralAttributeElementBinding) bagBinding.getPluralAttributeElementBinding() ).getHibernateTypeDescriptor().getJavaTypeName() );
PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" ); PluralAttributeBinding setBinding = metadata.getCollection( EntityWithBasicCollections.class.getName() + ".theSet" );
assertNotNull( setBinding ); assertNotNull( setBinding );
assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) ); assertSame( setBinding, entityBinding.locateAttributeBinding( "theSet" ) );
assertNotNull( setBinding.getCollectionTable() ); assertNotNull( setBinding.getCollectionTable() );
assertEquals( CollectionElementNature.BASIC, setBinding.getCollectionElement().getCollectionElementNature() ); assertEquals( PluralAttributeElementNature.BASIC, setBinding.getPluralAttributeElementBinding().getCollectionElementNature() );
assertEquals( String.class.getName(), ( (BasicCollectionElement) setBinding.getCollectionElement() ).getHibernateTypeDescriptor().getJavaTypeName() ); assertEquals( String.class.getName(), ( (BasicPluralAttributeElementBinding) setBinding.getPluralAttributeElementBinding() ).getHibernateTypeDescriptor().getJavaTypeName() );
} }
} }