HHH-7027 - Refine plural attribute binding information
This commit is contained in:
parent
780305d861
commit
eaf8c4816a
|
@ -115,7 +115,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
// Identity map of CollectionEntry instances, by the collection wrapper
|
||||
private IdentityMap<PersistentCollection, CollectionEntry> collectionEntries;
|
||||
|
||||
// Collection wrappers, by the CollectionKey
|
||||
// Collection wrappers, by the PluralAttributeKeyBinding
|
||||
private Map<CollectionKey, PersistentCollection> collectionsByKey;
|
||||
|
||||
// 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
|
||||
public PersistentCollection getCollection(CollectionKey collectionKey) {
|
||||
|
|
|
@ -100,7 +100,7 @@ public final class CollectionKey implements Serializable {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "CollectionKey" +
|
||||
return "PluralAttributeKeyBinding" +
|
||||
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 session The session being deserialized.
|
||||
* @return The deserialized CollectionKey
|
||||
* @return The deserialized PluralAttributeKeyBinding
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
|
|
|
@ -408,7 +408,7 @@ public interface PersistenceContext {
|
|||
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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -23,17 +23,11 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
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.relational.Table;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
|
@ -45,18 +39,13 @@ import org.hibernate.persister.collection.CollectionPersister;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBinding implements PluralAttributeBinding {
|
||||
private final CollectionKey collectionKey;
|
||||
private final AbstractCollectionElement collectionElement;
|
||||
private final PluralAttributeKeyBinding pluralAttributeKeyBinding;
|
||||
private final AbstractPluralAttributeElementBinding pluralAttributeElementBinding;
|
||||
|
||||
private Table collectionTable;
|
||||
|
||||
private FetchTiming fetchTiming;
|
||||
private FetchStyle fetchStyle;
|
||||
private int batchSize = -1;
|
||||
|
||||
private CascadeStyle cascadeStyle;
|
||||
private boolean orphanDelete;
|
||||
|
||||
private Caching caching;
|
||||
|
||||
private boolean inverse;
|
||||
|
@ -84,31 +73,31 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
|
|||
protected AbstractPluralAttributeBinding(
|
||||
AttributeBindingContainer container,
|
||||
PluralAttribute attribute,
|
||||
CollectionElementNature collectionElementNature) {
|
||||
PluralAttributeElementNature pluralAttributeElementNature) {
|
||||
super( container, attribute );
|
||||
this.collectionKey = new CollectionKey( this );
|
||||
this.collectionElement = interpretNature( collectionElementNature );
|
||||
this.pluralAttributeKeyBinding = new PluralAttributeKeyBinding( this );
|
||||
this.pluralAttributeElementBinding = interpretNature( pluralAttributeElementNature );
|
||||
}
|
||||
|
||||
private AbstractCollectionElement interpretNature(CollectionElementNature collectionElementNature) {
|
||||
switch ( collectionElementNature ) {
|
||||
private AbstractPluralAttributeElementBinding interpretNature(PluralAttributeElementNature pluralAttributeElementNature) {
|
||||
switch ( pluralAttributeElementNature ) {
|
||||
case BASIC: {
|
||||
return new BasicCollectionElement( this );
|
||||
return new BasicPluralAttributeElementBinding( this );
|
||||
}
|
||||
case COMPOSITE: {
|
||||
return new CompositeCollectionElement( this );
|
||||
return new CompositePluralAttributeElementBinding( this );
|
||||
}
|
||||
case ONE_TO_MANY: {
|
||||
return new OneToManyCollectionElement( this );
|
||||
return new OneToManyPluralAttributeElementBinding( this );
|
||||
}
|
||||
case MANY_TO_MANY: {
|
||||
return new ManyToManyCollectionElement( this );
|
||||
return new ManyToManyPluralAttributeElementBinding( this );
|
||||
}
|
||||
case MANY_TO_ANY: {
|
||||
return new ManyToAnyCollectionElement( this );
|
||||
return new ManyToAnyPluralAttributeElementBinding( this );
|
||||
}
|
||||
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 );
|
||||
// fetchMode = state.getFetchMode();
|
||||
// extraLazy = state.isExtraLazy();
|
||||
// collectionElement.setNodeName( state.getElementNodeName() );
|
||||
// collectionElement.setTypeName( state.getElementTypeName() );
|
||||
// pluralAttributeElementBinding.setNodeName( state.getElementNodeName() );
|
||||
// pluralAttributeElementBinding.setTypeName( state.getElementTypeName() );
|
||||
// inverse = state.isInverse();
|
||||
// mutable = state.isMutable();
|
||||
// subselectLoadable = state.isSubselectLoadable();
|
||||
|
@ -154,9 +143,7 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
|
|||
|
||||
@Override
|
||||
public boolean isAssociation() {
|
||||
return collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_ANY
|
||||
|| collectionElement.getCollectionElementNature() == CollectionElementNature.MANY_TO_MANY
|
||||
|| collectionElement.getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY;
|
||||
return pluralAttributeElementBinding.getPluralAttributeElementNature().isAssociation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,79 +156,13 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
|
|||
}
|
||||
|
||||
@Override
|
||||
public CollectionKey getCollectionKey() {
|
||||
return collectionKey;
|
||||
public PluralAttributeKeyBinding getPluralAttributeKeyBinding() {
|
||||
return pluralAttributeKeyBinding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractCollectionElement getCollectionElement() {
|
||||
return collectionElement;
|
||||
}
|
||||
|
||||
@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;
|
||||
public AbstractPluralAttributeElementBinding getPluralAttributeElementBinding() {
|
||||
return pluralAttributeElementBinding;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,22 +30,27 @@ import org.hibernate.metamodel.relational.Value;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractCollectionElement {
|
||||
private final AbstractPluralAttributeBinding collectionBinding;
|
||||
public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding {
|
||||
private final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private Value relationalValue;
|
||||
|
||||
private Value elementValue;
|
||||
|
||||
AbstractCollectionElement(AbstractPluralAttributeBinding collectionBinding) {
|
||||
this.collectionBinding = collectionBinding;
|
||||
AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
this.pluralAttributeBinding = pluralAttributeBinding;
|
||||
}
|
||||
|
||||
public abstract CollectionElementNature getCollectionElementNature();
|
||||
|
||||
public AbstractPluralAttributeBinding getCollectionBinding() {
|
||||
return collectionBinding;
|
||||
@Override
|
||||
public AbstractPluralAttributeBinding getPluralAttributeBinding() {
|
||||
return pluralAttributeBinding;
|
||||
}
|
||||
|
||||
public Value getElementValue() {
|
||||
return elementValue;
|
||||
@Override
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value getRelationalValue() {
|
||||
return relationalValue;
|
||||
}
|
||||
}
|
|
@ -100,7 +100,7 @@ public interface AttributeBindingContainer {
|
|||
*
|
||||
* @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.
|
||||
|
@ -110,7 +110,7 @@ public interface AttributeBindingContainer {
|
|||
*
|
||||
* @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.
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.metamodel.domain.PluralAttribute;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,17 +24,19 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
/**
|
||||
* Describes plural attributes of {@link PluralAttributeElementNature#BASIC} elements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class OneToManyCollectionElement extends AbstractCollectionElement {
|
||||
public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
|
||||
|
||||
OneToManyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
public BasicPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.ONE_TO_MANY;
|
||||
public PluralAttributeElementNature getPluralAttributeElementNature() {
|
||||
return PluralAttributeElementNature.BASIC;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -128,7 +128,7 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding
|
|||
}
|
||||
|
||||
@Override
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
|
||||
final BagBinding binding = new BagBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
|
@ -136,7 +136,7 @@ public class ComponentAttributeBinding extends AbstractSingularAttributeBinding
|
|||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
|
||||
final SetBinding binding = new SetBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
|
|
|
@ -24,16 +24,18 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
/**
|
||||
* Describes plural attributes of {@link PluralAttributeElementNature#COMPOSITE} elements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToAnyCollectionElement extends AbstractCollectionElement {
|
||||
ManyToAnyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
public class CompositePluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
|
||||
public CompositePluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.MANY_TO_ANY;
|
||||
public PluralAttributeElementNature getPluralAttributeElementNature() {
|
||||
return PluralAttributeElementNature.COMPOSITE;
|
||||
}
|
||||
}
|
|
@ -517,7 +517,7 @@ public class EntityBinding implements AttributeBindingContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.BAG );
|
||||
final BagBinding binding = new BagBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
|
@ -525,7 +525,7 @@ public class EntityBinding implements AttributeBindingContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
|
||||
public SetBinding makeSetAttributeBinding(PluralAttribute attribute, PluralAttributeElementNature nature) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.SET );
|
||||
final SetBinding binding = new SetBinding( this, attribute, nature );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -24,16 +24,18 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
/**
|
||||
* Describes plural attributes of {@link PluralAttributeElementNature#MANY_TO_ANY} elements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class CompositeCollectionElement extends AbstractCollectionElement {
|
||||
public CompositeCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
public class ManyToAnyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
|
||||
ManyToAnyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.COMPOSITE;
|
||||
public PluralAttributeElementNature getPluralAttributeElementNature() {
|
||||
return PluralAttributeElementNature.MANY_TO_ANY;
|
||||
}
|
||||
}
|
|
@ -28,44 +28,24 @@ import java.util.HashMap;
|
|||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* Describes plural attributes of {@link PluralAttributeElementNature#MANY_TO_MANY} elements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToManyCollectionElement extends AbstractCollectionElement {
|
||||
|
||||
public class ManyToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
|
||||
private final java.util.Map manyToManyFilters = new HashMap();
|
||||
private String manyToManyWhere;
|
||||
private String manyToManyOrderBy;
|
||||
|
||||
|
||||
ManyToManyCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
ManyToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.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 PluralAttributeElementNature getPluralAttributeElementNature() {
|
||||
return PluralAttributeElementNature.MANY_TO_MANY;
|
||||
}
|
||||
|
||||
public String getManyToManyWhere() {
|
|
@ -24,21 +24,18 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
/**
|
||||
* Describes plural attributes of {@link PluralAttributeElementNature#ONE_TO_MANY} elements
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class BasicCollectionElement extends AbstractCollectionElement {
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
|
||||
public BasicCollectionElement(AbstractPluralAttributeBinding binding) {
|
||||
public class OneToManyPluralAttributeElementBinding extends AbstractPluralAttributeAssociationElementBinding {
|
||||
OneToManyPluralAttributeElementBinding(AbstractPluralAttributeBinding binding) {
|
||||
super( binding );
|
||||
}
|
||||
|
||||
public CollectionElementNature getCollectionElementNature() {
|
||||
return CollectionElementNature.BASIC;
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
@Override
|
||||
public PluralAttributeElementNature getPluralAttributeElementNature() {
|
||||
return PluralAttributeElementNature.ONE_TO_MANY;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 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
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
|
@ -24,17 +24,11 @@
|
|||
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 Gail Badner
|
||||
*
|
||||
* @todo Merge with {@link org.hibernate.metamodel.source.binder.PluralAttributeNature} ? package separation kept me from doing that initially
|
||||
*/
|
||||
public enum CollectionElementNature {
|
||||
BASIC,
|
||||
COMPOSITE,
|
||||
ONE_TO_MANY,
|
||||
MANY_TO_MANY,
|
||||
MANY_TO_ANY
|
||||
public interface PluralAttributeAssociationElementBinding
|
||||
extends PluralAttributeElementBinding, Cascadeable, Fetchable {
|
||||
public boolean isOrphanDeleteEnabled();
|
||||
}
|
|
@ -30,17 +30,39 @@ import org.hibernate.metamodel.relational.TableSpecification;
|
|||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
|
||||
/**
|
||||
* Describes the binding of a plural attribute.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PluralAttributeBinding extends AssociationAttributeBinding {
|
||||
// todo : really it is the element (and/or index) that can be associative not the collection itself...
|
||||
|
||||
public interface PluralAttributeBinding extends AttributeBinding {
|
||||
/**
|
||||
* Retrieve the plural attribute being bound.
|
||||
*
|
||||
* @return The plural attribute descriptor
|
||||
*/
|
||||
@Override
|
||||
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();
|
||||
|
||||
|
@ -60,8 +82,6 @@ public interface PluralAttributeBinding extends AssociationAttributeBinding {
|
|||
|
||||
public CustomSQL getCustomSqlDeleteAll();
|
||||
|
||||
public boolean isOrphanDelete();
|
||||
|
||||
String getWhere();
|
||||
|
||||
boolean isSorted();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 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
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
|
@ -23,44 +23,40 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 FetchTiming getFetchTiming();
|
||||
public void setFetchTiming(FetchTiming fetchTiming);
|
||||
|
||||
public FetchStyle getFetchStyle();
|
||||
public void setFetchStyle(FetchStyle fetchStyle);
|
||||
|
||||
public Value getRelationalValue();
|
||||
|
||||
/**
|
||||
* Temporary. Needed for integration with legacy org.hibernate.mapping configuration of persisters.
|
||||
*
|
||||
* @deprecated
|
||||
* Retrieves an enumeration describing the mapping nature of the collection's elements.
|
||||
*
|
||||
* @return The nature enum.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings( {"JavaDoc"})
|
||||
public FetchMode getFetchMode();
|
||||
public PluralAttributeElementNature getPluralAttributeElementNature();
|
||||
|
||||
/**
|
||||
* Retrieve the Hibernate type descriptor describing the mapping-typing of the elements.
|
||||
*
|
||||
* @return The element type descriptor.
|
||||
*/
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -28,28 +28,63 @@ import org.hibernate.metamodel.relational.ForeignKey;
|
|||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
* Describes the binding information pertaining to the plural attribute foreign key.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CollectionKey {
|
||||
public class PluralAttributeKeyBinding {
|
||||
private final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
|
||||
private ForeignKey foreignKey;
|
||||
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;
|
||||
// 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.
|
||||
// private BasicAttributeBinding otherSide;
|
||||
|
||||
public CollectionKey(AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
|
||||
public PluralAttributeKeyBinding(AbstractPluralAttributeBinding 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() {
|
||||
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) {
|
||||
if ( foreignKey != null ) {
|
||||
throw new AssertionFailure( "Foreign key already initialized" );
|
||||
|
@ -68,7 +103,4 @@ public class CollectionKey {
|
|||
foreignKey = collectionTable.createForeignKey( targetTable, foreignKeyName );
|
||||
}
|
||||
|
||||
public ForeignKey getForeignKey() {
|
||||
return foreignKey;
|
||||
}
|
||||
}
|
|
@ -36,8 +36,8 @@ public class SetBinding extends AbstractPluralAttributeBinding {
|
|||
protected SetBinding(
|
||||
AttributeBindingContainer container,
|
||||
PluralAttribute attribute,
|
||||
CollectionElementNature collectionElementNature) {
|
||||
super( container, attribute, collectionElementNature );
|
||||
PluralAttributeElementNature pluralAttributeElementNature) {
|
||||
super( container, attribute, pluralAttributeElementNature );
|
||||
}
|
||||
|
||||
public Comparator getComparator() {
|
||||
|
|
|
@ -30,7 +30,8 @@ package org.hibernate.metamodel.binding;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
@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)?
|
||||
* <p/>
|
||||
|
|
|
@ -41,8 +41,10 @@ import org.hibernate.metamodel.binding.AbstractPluralAttributeBinding;
|
|||
import org.hibernate.metamodel.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.binding.AttributeBindingContainer;
|
||||
import org.hibernate.metamodel.binding.BasicAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.BasicCollectionElement;
|
||||
import org.hibernate.metamodel.binding.CollectionElementNature;
|
||||
import org.hibernate.metamodel.binding.BasicPluralAttributeElementBinding;
|
||||
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.ComponentAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
|
@ -497,9 +499,13 @@ public class Binder {
|
|||
}
|
||||
|
||||
private void doBasicPluralAttributeBinding(PluralAttributeSource source, AbstractPluralAttributeBinding binding) {
|
||||
binding.setFetchTiming( source.getFetchTiming() );
|
||||
binding.setFetchStyle( source.getFetchStyle() );
|
||||
binding.setCascadeStyles( source.getCascadeStyles() );
|
||||
if ( binding.isAssociation() ) {
|
||||
final Cascadeable cascadeable = (Cascadeable) binding.getPluralAttributeElementBinding();
|
||||
cascadeable.setCascadeStyles( source.getCascadeStyles() );
|
||||
final Fetchable fetchable = (Fetchable) binding.getPluralAttributeElementBinding();
|
||||
fetchable.setFetchTiming( source.getFetchTiming() );
|
||||
fetchable.setFetchStyle( source.getFetchStyle() );
|
||||
}
|
||||
|
||||
binding.setCaching( source.getCaching() );
|
||||
|
||||
|
@ -561,7 +567,7 @@ public class Binder {
|
|||
private void bindCollectionTable(
|
||||
PluralAttributeSource attributeSource,
|
||||
AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
if ( attributeSource.getElementSource().getNature() == PluralAttributeElementNature.ONE_TO_MANY ) {
|
||||
if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.source.binder.PluralAttributeElementNature.ONE_TO_MANY ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -620,11 +626,11 @@ public class Binder {
|
|||
private void bindCollectionKey(
|
||||
PluralAttributeSource attributeSource,
|
||||
AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
pluralAttributeBinding.getCollectionKey().prepareForeignKey(
|
||||
pluralAttributeBinding.getPluralAttributeKeyBinding().prepareForeignKey(
|
||||
attributeSource.getKeySource().getExplicitForeignKeyName(),
|
||||
null // todo : handle secondary table names
|
||||
);
|
||||
pluralAttributeBinding.getCollectionKey().getForeignKey().setDeleteRule(
|
||||
pluralAttributeBinding.getPluralAttributeKeyBinding().getForeignKey().setDeleteRule(
|
||||
attributeSource.getKeySource().getOnDeleteAction()
|
||||
);
|
||||
// todo : need to bind "relational values", account for property-ref
|
||||
|
@ -634,9 +640,9 @@ public class Binder {
|
|||
PluralAttributeSource attributeSource,
|
||||
AbstractPluralAttributeBinding pluralAttributeBinding) {
|
||||
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 BasicCollectionElement basicCollectionElement = (BasicCollectionElement) pluralAttributeBinding.getCollectionElement();
|
||||
final BasicPluralAttributeElementBinding basicCollectionElement = (BasicPluralAttributeElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding();
|
||||
resolveTypeInformation(
|
||||
basicElementSource.getExplicitHibernateTypeSource(),
|
||||
pluralAttributeBinding.getAttribute(),
|
||||
|
@ -692,8 +698,8 @@ public class Binder {
|
|||
attributeBinding.setIncludedInOptimisticLocking( attributeSource.isIncludedInOptimisticLocking() );
|
||||
}
|
||||
|
||||
private CollectionElementNature convert(PluralAttributeElementNature pluralAttributeElementNature) {
|
||||
return CollectionElementNature.valueOf( pluralAttributeElementNature.name() );
|
||||
private PluralAttributeElementNature convert(org.hibernate.metamodel.source.binder.PluralAttributeElementNature pluralAttributeElementNature) {
|
||||
return PluralAttributeElementNature.valueOf( pluralAttributeElementNature.name() );
|
||||
}
|
||||
|
||||
private BasicAttributeBinding doBasicSingularAttributeBindingCreation(
|
||||
|
@ -769,7 +775,7 @@ public class Binder {
|
|||
private void resolveTypeInformation(
|
||||
ExplicitHibernateTypeSource typeSource,
|
||||
PluralAttribute attribute,
|
||||
BasicCollectionElement collectionElement) {
|
||||
BasicPluralAttributeElementBinding collectionElement) {
|
||||
final Class<?> attributeJavaType = determineJavaType( attribute );
|
||||
resolveTypeInformation( typeSource, collectionElement.getHibernateTypeDescriptor(), attributeJavaType );
|
||||
}
|
||||
|
|
|
@ -26,11 +26,11 @@ package org.hibernate.metamodel.source.internal;
|
|||
import java.util.Properties;
|
||||
|
||||
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.AttributeBinding;
|
||||
import org.hibernate.metamodel.binding.BasicCollectionElement;
|
||||
import org.hibernate.metamodel.binding.CollectionElementNature;
|
||||
import org.hibernate.metamodel.binding.BasicPluralAttributeElementBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeElementNature;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
|
@ -160,8 +160,8 @@ class HibernateTypeResolver {
|
|||
getTypeParameters( attributeBinding.getHibernateTypeDescriptor() ),
|
||||
attributeBinding.getAttribute().getName(),
|
||||
attributeBinding.getReferencedPropertyName(),
|
||||
attributeBinding.getCollectionElement().getCollectionElementNature() ==
|
||||
CollectionElementNature.COMPOSITE
|
||||
attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() ==
|
||||
PluralAttributeElementNature.COMPOSITE
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -173,7 +173,7 @@ class HibernateTypeResolver {
|
|||
null,
|
||||
resolvedType );
|
||||
}
|
||||
resolveCollectionElementTypeInformation( attributeBinding.getCollectionElement() );
|
||||
resolveCollectionElementTypeInformation( attributeBinding.getPluralAttributeElementBinding() );
|
||||
}
|
||||
|
||||
private Type determineDefaultCollectionInformation(AbstractPluralAttributeBinding attributeBinding) {
|
||||
|
@ -183,15 +183,15 @@ class HibernateTypeResolver {
|
|||
return typeFactory.set(
|
||||
attributeBinding.getAttribute().getName(),
|
||||
attributeBinding.getReferencedPropertyName(),
|
||||
attributeBinding.getCollectionElement().getCollectionElementNature() == CollectionElementNature.COMPOSITE
|
||||
attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
|
||||
);
|
||||
}
|
||||
case BAG: {
|
||||
return typeFactory.bag(
|
||||
attributeBinding.getAttribute().getName(),
|
||||
attributeBinding.getReferencedPropertyName(),
|
||||
attributeBinding.getCollectionElement()
|
||||
.getCollectionElementNature() == CollectionElementNature.COMPOSITE
|
||||
attributeBinding.getPluralAttributeElementBinding()
|
||||
.getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE
|
||||
);
|
||||
}
|
||||
default: {
|
||||
|
@ -202,30 +202,33 @@ class HibernateTypeResolver {
|
|||
}
|
||||
}
|
||||
|
||||
private void resolveCollectionElementTypeInformation(AbstractCollectionElement collectionElement) {
|
||||
switch ( collectionElement.getCollectionElementNature() ) {
|
||||
private void resolveCollectionElementTypeInformation(AbstractPluralAttributeElementBinding pluralAttributeElementBinding) {
|
||||
switch ( pluralAttributeElementBinding.getPluralAttributeElementNature() ) {
|
||||
case BASIC: {
|
||||
resolveBasicCollectionElement( BasicCollectionElement.class.cast( collectionElement ) );
|
||||
resolveBasicCollectionElement( BasicPluralAttributeElementBinding.class.cast(
|
||||
pluralAttributeElementBinding
|
||||
) );
|
||||
break;
|
||||
}
|
||||
case COMPOSITE:
|
||||
case ONE_TO_MANY:
|
||||
case MANY_TO_MANY:
|
||||
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: {
|
||||
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() );
|
||||
if ( resolvedHibernateType != null ) {
|
||||
pushHibernateTypeInformationDownIfNeeded(
|
||||
basicCollectionElement.getHibernateTypeDescriptor(),
|
||||
basicCollectionElement.getElementValue(),
|
||||
basicCollectionElement.getRelationalValue(),
|
||||
resolvedHibernateType
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.mapping.SingleTableSubclass;
|
||||
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.PluralAttributeBinding;
|
||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||
|
@ -126,7 +126,7 @@ public class StandardPersisterClassResolver implements PersisterClassResolver {
|
|||
|
||||
@Override
|
||||
public Class<? extends CollectionPersister> getCollectionPersisterClass(PluralAttributeBinding metadata) {
|
||||
return metadata.getCollectionElement().getCollectionElementNature() == CollectionElementNature.ONE_TO_MANY
|
||||
return metadata.getPluralAttributeElementBinding().getCollectionElementNature() == PluralAttributeElementNature.ONE_TO_MANY
|
||||
? oneToManyPersister()
|
||||
: basicCollectionPersister();
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public interface SessionStatistics {
|
|||
*/
|
||||
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
|
||||
*/
|
||||
public Set getCollectionKeys();
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.hibernate.metamodel.binding.AssociationAttributeBinding;
|
|||
import org.hibernate.metamodel.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.binding.BasicAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeAssociationElementBinding;
|
||||
import org.hibernate.metamodel.binding.SimpleValueBinding;
|
||||
import org.hibernate.metamodel.binding.SingularAttributeBinding;
|
||||
import org.hibernate.property.Getter;
|
||||
|
@ -316,10 +317,10 @@ public class PropertyFactory {
|
|||
else {
|
||||
final AbstractPluralAttributeBinding pluralAttributeBinding = (AbstractPluralAttributeBinding) property;
|
||||
final CascadeStyle cascadeStyle = pluralAttributeBinding.isAssociation()
|
||||
? pluralAttributeBinding.getCascadeStyle()
|
||||
? ( (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getCascadeStyle()
|
||||
: CascadeStyle.NONE;
|
||||
final FetchMode fetchMode = pluralAttributeBinding.isAssociation()
|
||||
? pluralAttributeBinding.getFetchMode()
|
||||
? ( (PluralAttributeAssociationElementBinding) pluralAttributeBinding.getPluralAttributeElementBinding() ).getFetchMode()
|
||||
: FetchMode.DEFAULT;
|
||||
|
||||
return new StandardProperty(
|
||||
|
|
|
@ -77,14 +77,14 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
|
|||
assertNotNull( bagBinding );
|
||||
assertSame( bagBinding, entityBinding.locateAttributeBinding( "theBag" ) );
|
||||
assertNotNull( bagBinding.getCollectionTable() );
|
||||
assertEquals( CollectionElementNature.BASIC, bagBinding.getCollectionElement().getCollectionElementNature() );
|
||||
assertEquals( String.class.getName(), ( (BasicCollectionElement) bagBinding.getCollectionElement() ).getHibernateTypeDescriptor().getJavaTypeName() );
|
||||
assertEquals( PluralAttributeElementNature.BASIC, bagBinding.getPluralAttributeElementBinding().getCollectionElementNature() );
|
||||
assertEquals( String.class.getName(), ( (BasicPluralAttributeElementBinding) bagBinding.getPluralAttributeElementBinding() ).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(), ( (BasicCollectionElement) setBinding.getCollectionElement() ).getHibernateTypeDescriptor().getJavaTypeName() );
|
||||
assertEquals( PluralAttributeElementNature.BASIC, setBinding.getPluralAttributeElementBinding().getCollectionElementNature() );
|
||||
assertEquals( String.class.getName(), ( (BasicPluralAttributeElementBinding) setBinding.getPluralAttributeElementBinding() ).getHibernateTypeDescriptor().getJavaTypeName() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue