HHH-6230 : Rework attribute binding using attribute states
This commit is contained in:
parent
006c96b952
commit
755e6fcd25
|
@ -232,6 +232,18 @@ public final class ReflectHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to resolve the specified property type through reflection.
|
||||
*
|
||||
* @param clazz The class owning the property.
|
||||
* @param name The name of the property.
|
||||
* @return The type of the property.
|
||||
* @throws MappingException Indicates we were unable to locate the property.
|
||||
*/
|
||||
public static Class reflectedPropertyClass(Class clazz, String name) throws MappingException {
|
||||
return getter( clazz, name ).getReturnType();
|
||||
}
|
||||
|
||||
private static Getter getter(Class clazz, String name) throws MappingException {
|
||||
try {
|
||||
return BASIC_PROPERTY_ACCESSOR.getGetter( clazz, name );
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
|
@ -38,8 +39,9 @@ import org.hibernate.metamodel.relational.SimpleValue;
|
|||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.relational.Tuple;
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
import org.hibernate.metamodel.relational.ValueFactory;
|
||||
import org.hibernate.metamodel.state.domain.AttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.AttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ValueCreator;
|
||||
import org.hibernate.metamodel.state.relational.SimpleValueRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.TupleRelationalState;
|
||||
|
||||
|
@ -73,15 +75,15 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
|||
this.entityBinding = entityBinding;
|
||||
}
|
||||
|
||||
protected void initialize(AttributeDomainState state) {
|
||||
hibernateTypeDescriptor.initialize( state.getHibernateTypeDescriptor() );
|
||||
attribute = state.getAttribute();
|
||||
protected void initialize(AttributeBindingState state) {
|
||||
hibernateTypeDescriptor.setTypeName( state.getTypeName() );
|
||||
hibernateTypeDescriptor.setTypeParameters( state.getTypeParameters() );
|
||||
isLazy = state.isLazy();
|
||||
propertyAccessorName = state.getPropertyAccessorName();
|
||||
isAlternateUniqueKey = state.isAlternateUniqueKey();
|
||||
cascade = state.getCascade();
|
||||
optimisticLockable = state.isOptimisticLockable();
|
||||
nodeName = state.getNodeName();
|
||||
nodeName = state.getNodeName() ;
|
||||
metaAttributes = state.getMetaAttributes();
|
||||
}
|
||||
|
||||
|
@ -107,24 +109,36 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected void initializeValue(ValueRelationalState state) {
|
||||
value = ValueFactory.createValue( getEntityBinding().getBaseTable(),
|
||||
protected final boolean isPrimaryKey() {
|
||||
return this == getEntityBinding().getEntityIdentifier().getValueBinding();
|
||||
}
|
||||
|
||||
protected void initializeValueRelationalState(ValueRelationalState state) {
|
||||
// TODO: change to have ValueRelationalState generate the value
|
||||
value = ValueCreator.createValue(
|
||||
getEntityBinding().getBaseTable(),
|
||||
getAttribute().getName(),
|
||||
convertToSimpleRelationalStateIfPossible( state ),
|
||||
state,
|
||||
forceNonNullable(),
|
||||
forceUnique()
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: should a single-valued tuple always be converted???
|
||||
protected ValueRelationalState convertToSimpleRelationalStateIfPossible(ValueRelationalState state) {
|
||||
if ( !TupleRelationalState.class.isInstance( state ) ) {
|
||||
return state;
|
||||
// TODO: not sure I like this here...
|
||||
if ( isPrimaryKey() ) {
|
||||
if ( SimpleValue.class.isInstance( value ) ) {
|
||||
if ( ! Column.class.isInstance( value ) ) {
|
||||
// this should never ever happen..
|
||||
throw new MappingException( "Simple ID is not a column." );
|
||||
}
|
||||
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( value ) );
|
||||
}
|
||||
else {
|
||||
for ( SimpleValueRelationalState val : TupleRelationalState.class.cast( state ).getRelationalStates() ) {
|
||||
if ( Column.class.isInstance( val ) ) {
|
||||
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TupleRelationalState tupleRelationalState = TupleRelationalState.class.cast( state );
|
||||
return tupleRelationalState.getRelationalStates().size() == 1 ?
|
||||
tupleRelationalState.getRelationalStates().get( 0 ) :
|
||||
state;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,10 +159,6 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
|||
return optimisticLockable;
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MetaAttribute> getMetaAttributes() {
|
||||
return metaAttributes;
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.metamodel.state.binding.PluralAttributeBindingState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
|
@ -32,4 +34,9 @@ public class BagBinding extends PluralAttributeBinding {
|
|||
protected BagBinding(EntityBinding entityBinding) {
|
||||
super( entityBinding );
|
||||
}
|
||||
|
||||
public BagBinding initialize(PluralAttributeBindingState bindingState) {
|
||||
super.initialize( bindingState );
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
import org.hibernate.metamodel.state.domain.CollectionElementDomainState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -44,8 +43,13 @@ public class CollectionElement {
|
|||
this.collectionBinding = collectionBinding;
|
||||
}
|
||||
|
||||
public void initialize(CollectionElementDomainState state) {
|
||||
hibernateTypeDescriptor.initialize( state.getHibernateTypeDescriptor() );
|
||||
nodeName = state.getNodeName();
|
||||
/* package-protected */
|
||||
void setTypeName(String typeName) {
|
||||
hibernateTypeDescriptor.setTypeName( typeName );
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.engine.internal.Versioning;
|
|||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.domain.PluralAttributeNature;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||
|
@ -45,6 +46,11 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.state.binding.ManyToOneAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.binding.PluralAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ColumnRelationalState;
|
||||
|
||||
/**
|
||||
* Provides the link between the domain and the relational model for an entity.
|
||||
|
@ -207,16 +213,6 @@ public class EntityBinding {
|
|||
return entityDiscriminator;
|
||||
}
|
||||
|
||||
public void bindEntityDiscriminator(SimpleAttributeBinding attributeBinding) {
|
||||
if ( !Column.class.isInstance( attributeBinding.getValue() ) ) {
|
||||
throw new MappingException(
|
||||
"Identifier value must be a Column; instead it is: " + attributeBinding.getValue().getClass()
|
||||
);
|
||||
}
|
||||
entityDiscriminator.setValueBinding( attributeBinding );
|
||||
baseTable.getPrimaryKey().addColumn( Column.class.cast( attributeBinding.getValue() ) );
|
||||
}
|
||||
|
||||
public void setInheritanceType(InheritanceType entityInheritanceType) {
|
||||
this.entityInheritanceType = entityInheritanceType;
|
||||
}
|
||||
|
@ -241,27 +237,26 @@ public class EntityBinding {
|
|||
return entityReferencingAttributeBindings;
|
||||
}
|
||||
|
||||
public SimpleAttributeBinding makeSimplePrimaryKeyAttributeBinding(String name) {
|
||||
public SimpleAttributeBinding makeSimpleIdAttributeBinding(String name) {
|
||||
final SimpleAttributeBinding binding = makeSimpleAttributeBinding( name, true, true );
|
||||
getEntityIdentifier().setValueBinding( binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
public SimpleAttributeBinding makeEntityDiscriminatorBinding(String name) {
|
||||
public EntityDiscriminator makeEntityDiscriminator(String attributeName) {
|
||||
if ( entityDiscriminator != null ) {
|
||||
throw new AssertionFailure( "Creation of entity discriminator was called more than once" );
|
||||
}
|
||||
entityDiscriminator = new EntityDiscriminator();
|
||||
entityDiscriminator.setValueBinding( makeSimpleAttributeBinding( name, true, false ) );
|
||||
return entityDiscriminator.getValueBinding();
|
||||
entityDiscriminator.setValueBinding( makeSimpleAttributeBinding( attributeName, true, false ) );
|
||||
return entityDiscriminator;
|
||||
}
|
||||
|
||||
public SimpleAttributeBinding makeVersionBinding(String name) {
|
||||
versionBinding = makeSimpleAttributeBinding( name, true, false );
|
||||
public SimpleAttributeBinding makeVersionBinding(String attributeName) {
|
||||
versionBinding = makeSimpleAttributeBinding( attributeName, true, false );
|
||||
return versionBinding;
|
||||
}
|
||||
|
||||
|
||||
public SimpleAttributeBinding makeSimpleAttributeBinding(String name) {
|
||||
return makeSimpleAttributeBinding( name, false, false );
|
||||
}
|
||||
|
@ -273,17 +268,17 @@ public class EntityBinding {
|
|||
return binding;
|
||||
}
|
||||
|
||||
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(String name) {
|
||||
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(String attributeName) {
|
||||
final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( this );
|
||||
registerAttributeBinding( name, binding );
|
||||
binding.setAttribute( entity.getAttribute( name ) );
|
||||
registerAttributeBinding( attributeName, binding );
|
||||
binding.setAttribute( entity.getAttribute( attributeName ) );
|
||||
return binding;
|
||||
}
|
||||
|
||||
public BagBinding makeBagAttributeBinding(String name) {
|
||||
public BagBinding makeBagAttributeBinding(String attributeName) {
|
||||
final BagBinding binding = new BagBinding( this );
|
||||
registerAttributeBinding( name, binding );
|
||||
binding.setAttribute( entity.getAttribute( name ) );
|
||||
registerAttributeBinding( attributeName, binding );
|
||||
binding.setAttribute( entity.getAttribute( attributeName ) );
|
||||
return binding;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
|
||||
/**
|
||||
* Binding of the discriminator in a entity hierarchy
|
||||
*
|
||||
|
@ -40,10 +43,26 @@ public class EntityDiscriminator {
|
|||
return valueBinding;
|
||||
}
|
||||
|
||||
public void setValueBinding(SimpleAttributeBinding valueBinding) {
|
||||
/* package-protected */
|
||||
void setValueBinding(SimpleAttributeBinding valueBinding) {
|
||||
this.valueBinding = valueBinding;
|
||||
}
|
||||
|
||||
public EntityDiscriminator initialize(DiscriminatorBindingState state) {
|
||||
if ( valueBinding == null ) {
|
||||
throw new IllegalStateException( "Cannot bind state because the value binding has not been initialized." );
|
||||
}
|
||||
this.valueBinding.initialize( state );
|
||||
this.forced = state.isForced();
|
||||
this.inserted = state.isInsertable();
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityDiscriminator initialize(ValueRelationalState state) {
|
||||
valueBinding.initialize( state );
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return forced;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class HibernateTypeDescriptor {
|
|||
return typeName;
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
@ -49,13 +50,17 @@ public class HibernateTypeDescriptor {
|
|||
return explicitType;
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
public void setExplicitType(Type explicitType) {
|
||||
this.explicitType = explicitType;
|
||||
}
|
||||
|
||||
public void initialize(HibernateTypeDescriptor hibernateTypeDescriptor) {
|
||||
typeName = hibernateTypeDescriptor.typeName;
|
||||
explicitType = hibernateTypeDescriptor.explicitType;
|
||||
typeParameters = hibernateTypeDescriptor.typeParameters;
|
||||
public Properties getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
/* package-protected */
|
||||
void setTypeParameters(Properties typeParameters) {
|
||||
this.typeParameters = typeParameters;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.hibernate.internal.util.ReflectHelper;
|
|||
import org.hibernate.metamodel.relational.ForeignKey;
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.state.domain.ManyToOneAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.ManyToOneAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ManyToOneRelationalState;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ import org.hibernate.metamodel.state.relational.ManyToOneRelationalState;
|
|||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ManyToOneAttributeBinding extends SingularAttributeBinding implements EntityReferencingAttributeBinding {
|
||||
public class ManyToOneAttributeBinding extends SimpleAttributeBinding implements EntityReferencingAttributeBinding {
|
||||
private boolean isLogicalOneToOne;
|
||||
private boolean isPropertyReference;
|
||||
private String foreignKeyName;
|
||||
|
@ -51,7 +51,7 @@ public class ManyToOneAttributeBinding extends SingularAttributeBinding implemen
|
|||
super( entityBinding, false, false );
|
||||
}
|
||||
|
||||
public final void initialize(ManyToOneAttributeDomainState state) {
|
||||
public final ManyToOneAttributeBinding initialize(ManyToOneAttributeBindingState state) {
|
||||
super.initialize( state );
|
||||
isPropertyReference = state.getReferencedAttributeName() != null;
|
||||
referencedAttributeName = state.getReferencedAttributeName();
|
||||
|
@ -60,15 +60,17 @@ public class ManyToOneAttributeBinding extends SingularAttributeBinding implemen
|
|||
referencedEntityName =
|
||||
ReflectHelper.reflectedPropertyClass(
|
||||
getEntityBinding().getEntity().getName(),
|
||||
state.getAttribute().getName()
|
||||
state.getAttributeName()
|
||||
).getName();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public final void initialize(ManyToOneRelationalState state) {
|
||||
super.initializeValue( state );
|
||||
public final ManyToOneAttributeBinding initialize(ManyToOneRelationalState state) {
|
||||
super.initializeValueRelationalState( state );
|
||||
isLogicalOneToOne = state.isLogicalOneToOne();
|
||||
foreignKeyName = state.getForeignKeyName();
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isPropertyReference() {
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
|
@ -36,8 +37,11 @@ public interface MappingDefaults {
|
|||
String getPackageName();
|
||||
String getDefaultSchemaName();
|
||||
String getDefaultCatalogName();
|
||||
String getDefaultIdColumnName();
|
||||
String getDefaultDescriminatorColumnName();
|
||||
String getDefaultCascade();
|
||||
String getDefaultAccess();
|
||||
boolean isDefaultLazy();
|
||||
ServiceRegistry getServiceRegistry();
|
||||
NamingStrategy getNamingStrategy();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jboss.logging.Logger;
|
|||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.relational.Table;
|
||||
import org.hibernate.metamodel.state.domain.PluralAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.PluralAttributeBindingState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -84,12 +84,13 @@ public abstract class PluralAttributeBinding extends AbstractAttributeBinding {
|
|||
collectionElement = new CollectionElement( this );
|
||||
}
|
||||
|
||||
public void initialize(PluralAttributeDomainState state) {
|
||||
protected void initializeBinding(PluralAttributeBindingState state) {
|
||||
super.initialize( state );
|
||||
fetchMode = state.getFetchMode();
|
||||
extraLazy = state.isExtraLazy();
|
||||
collectionElement = new ElementCollectionElement( this );
|
||||
collectionElement.initialize( state.getCollectionElementDomainState() );
|
||||
collectionElement.setNodeName( state.getElementNodeName() );
|
||||
collectionElement.setTypeName( state.getElementTypeName() );
|
||||
inverse = state.isInverse();
|
||||
mutable = state.isMutable();
|
||||
subselectLoadable = state.isSubselectLoadable();
|
||||
|
|
|
@ -24,38 +24,43 @@
|
|||
package org.hibernate.metamodel.binding;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.state.domain.SimpleAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ColumnRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.DerivedValueRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.TupleRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SimpleAttributeBinding extends SingularAttributeBinding {
|
||||
public class SimpleAttributeBinding extends AbstractAttributeBinding implements KeyValueBinding {
|
||||
private final boolean forceNonNullable;
|
||||
private final boolean forceUnique;
|
||||
private boolean insertable;
|
||||
private boolean updateable;
|
||||
private boolean keyCasadeDeleteEnabled;
|
||||
private String unsavedValue;
|
||||
private PropertyGeneration generation;
|
||||
|
||||
SimpleAttributeBinding(EntityBinding entityBinding, boolean forceNonNullable, boolean forceUnique) {
|
||||
super( entityBinding, forceNonNullable, forceUnique );
|
||||
super( entityBinding );
|
||||
this.forceNonNullable = forceNonNullable;
|
||||
this.forceUnique = forceUnique;
|
||||
}
|
||||
|
||||
public final void initialize(SimpleAttributeDomainState state) {
|
||||
public final SimpleAttributeBinding initialize(SimpleAttributeBindingState state) {
|
||||
super.initialize( state );
|
||||
generation = state.getPropertyGeneration();
|
||||
insertable = state.isInsertable();
|
||||
updateable = state.isUpdateable();
|
||||
keyCasadeDeleteEnabled = state.isKeyCasadeDeleteEnabled();
|
||||
unsavedValue = state.getUnsavedValue();
|
||||
generation = state.getPropertyGeneration() == null ? PropertyGeneration.NEVER : state.getPropertyGeneration();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void initializeColumnValue(ColumnRelationalState state) {
|
||||
super.initializeValue( state );
|
||||
}
|
||||
|
||||
public void initializeDerivedValue(DerivedValueRelationalState state) {
|
||||
super.initializeValue( state );
|
||||
}
|
||||
|
||||
public void initializeTupleValue(TupleRelationalState state) {
|
||||
super.initializeValue( state );
|
||||
public SimpleAttributeBinding initialize(ValueRelationalState state) {
|
||||
super.initializeValueRelationalState( state );
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isUnique(ColumnRelationalState state) {
|
||||
|
@ -67,8 +72,46 @@ public class SimpleAttributeBinding extends SingularAttributeBinding {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean isPrimaryKey() {
|
||||
return this == getEntityBinding().getEntityIdentifier().getValueBinding();
|
||||
public boolean isInsertable() {
|
||||
return insertable;
|
||||
}
|
||||
|
||||
protected void setInsertable(boolean insertable) {
|
||||
this.insertable = insertable;
|
||||
}
|
||||
|
||||
public boolean isUpdateable() {
|
||||
return updateable;
|
||||
}
|
||||
|
||||
protected void setUpdateable(boolean updateable) {
|
||||
this.updateable = updateable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeyCasadeDeleteEnabled() {
|
||||
return keyCasadeDeleteEnabled;
|
||||
}
|
||||
|
||||
public void setKeyCasadeDeleteEnabled(boolean keyCasadeDeleteEnabled) {
|
||||
this.keyCasadeDeleteEnabled = keyCasadeDeleteEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnsavedValue() {
|
||||
return unsavedValue;
|
||||
}
|
||||
|
||||
public void setUnsavedValue(String unsaveValue) {
|
||||
this.unsavedValue = unsaveValue;
|
||||
}
|
||||
|
||||
public boolean forceNonNullable() {
|
||||
return forceNonNullable;
|
||||
}
|
||||
|
||||
public boolean forceUnique() {
|
||||
return forceUnique;
|
||||
}
|
||||
|
||||
public PropertyGeneration getGeneration() {
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, 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.state.domain.SingularAttributeDomainState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public abstract class SingularAttributeBinding extends AbstractAttributeBinding implements KeyValueBinding {
|
||||
private final boolean forceNonNullable;
|
||||
private final boolean forceUnique;
|
||||
private boolean insertable;
|
||||
private boolean updateable;
|
||||
private boolean keyCasadeDeleteEnabled;
|
||||
private String unsavedValue;
|
||||
|
||||
SingularAttributeBinding(EntityBinding entityBinding, boolean forceNonNullable, boolean forceUnique) {
|
||||
super( entityBinding );
|
||||
this.forceNonNullable = forceNonNullable;
|
||||
this.forceUnique = forceUnique;
|
||||
}
|
||||
|
||||
public final void initialize(SingularAttributeDomainState state) {
|
||||
super.initialize( state );
|
||||
insertable = state.isInsertable();
|
||||
updateable = state.isUpdateable();
|
||||
keyCasadeDeleteEnabled = state.isKeyCasadeDeleteEnabled();
|
||||
unsavedValue = state.getUnsavedValue();
|
||||
}
|
||||
|
||||
public boolean isInsertable() {
|
||||
return insertable;
|
||||
}
|
||||
|
||||
protected void setInsertable(boolean insertable) {
|
||||
this.insertable = insertable;
|
||||
}
|
||||
|
||||
public boolean isUpdateable() {
|
||||
return updateable;
|
||||
}
|
||||
|
||||
protected void setUpdateable(boolean updateable) {
|
||||
this.updateable = updateable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeyCasadeDeleteEnabled() {
|
||||
return keyCasadeDeleteEnabled;
|
||||
}
|
||||
|
||||
public void setKeyCasadeDeleteEnabled(boolean keyCasadeDeleteEnabled) {
|
||||
this.keyCasadeDeleteEnabled = keyCasadeDeleteEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnsavedValue() {
|
||||
return unsavedValue;
|
||||
}
|
||||
|
||||
public void setUnsavedValue(String unsaveValue) {
|
||||
this.unsavedValue = unsaveValue;
|
||||
}
|
||||
|
||||
public boolean forceNonNullable() {
|
||||
return forceNonNullable;
|
||||
}
|
||||
|
||||
public boolean forceUnique() {
|
||||
return forceUnique;
|
||||
}
|
||||
}
|
|
@ -121,15 +121,27 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
|
|||
public static class SingularAttributeImpl implements SingularAttribute {
|
||||
private final AttributeContainer attributeContainer;
|
||||
private final String name;
|
||||
private Type type;
|
||||
|
||||
public SingularAttributeImpl(String name, AttributeContainer attributeContainer) {
|
||||
this.name = name;
|
||||
this.attributeContainer = attributeContainer;
|
||||
}
|
||||
|
||||
boolean isTypeResolved() {
|
||||
return type != null;
|
||||
}
|
||||
|
||||
void resolveType(Type type) {
|
||||
if ( type == null ) {
|
||||
throw new IllegalArgumentException( "Attempt to resolve with null type" );
|
||||
}
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getSingularAttributeType() {
|
||||
return null;
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,6 +164,7 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
|
|||
private final AttributeContainer attributeContainer;
|
||||
private final PluralAttributeNature nature;
|
||||
private final String name;
|
||||
private String nodeName;
|
||||
|
||||
private Type elementType;
|
||||
|
||||
|
|
|
@ -42,5 +42,4 @@ public interface Type {
|
|||
* @return persistence type
|
||||
*/
|
||||
public TypeNature getNature();
|
||||
|
||||
}
|
||||
|
|
|
@ -36,16 +36,19 @@ import org.hibernate.cache.spi.access.AccessType;
|
|||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.Hierarchical;
|
||||
import org.hibernate.metamodel.relational.Identifier;
|
||||
import org.hibernate.metamodel.relational.Schema;
|
||||
import org.hibernate.metamodel.source.annotations.state.domain.AttributeDomainState;
|
||||
import org.hibernate.metamodel.source.annotations.state.binding.AnnotationsAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.annotations.state.binding.AnnotationsDiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.source.annotations.state.relational.AttributeColumnRelationalState;
|
||||
import org.hibernate.metamodel.source.annotations.state.relational.AttributeTupleRelationalState;
|
||||
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
|
||||
/**
|
||||
|
@ -119,9 +122,9 @@ public class EntityBinder {
|
|||
if ( !( discriminatorAttribute.getColumnValues() instanceof DiscriminatorColumnValues ) ) {
|
||||
throw new AssertionFailure( "Expected discriminator column values" );
|
||||
}
|
||||
|
||||
// TODO: move this into DiscriminatorBindingState
|
||||
DiscriminatorColumnValues discriminatorColumnvalues = (DiscriminatorColumnValues) discriminatorAttribute.getColumnValues();
|
||||
entityBinding.getEntityDiscriminator().setForced( discriminatorColumnvalues.isForced() );
|
||||
entityBinding.getEntityDiscriminator().setInserted( discriminatorColumnvalues.isIncludedInSql() );
|
||||
entityBinding.setDiscriminatorValue( discriminatorColumnvalues.getDiscriminatorValue() );
|
||||
}
|
||||
|
||||
|
@ -294,18 +297,12 @@ public class EntityBinder {
|
|||
);
|
||||
|
||||
String idName = JandexHelper.getPropertyName( idAnnotation.target() );
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( idName );
|
||||
SimpleAttributeBinding idBinding = entityBinding.makeSimplePrimaryKeyAttributeBinding( idName );
|
||||
|
||||
MappedAttribute idAttribute = configuredClass.getMappedProperty( idName );
|
||||
|
||||
AttributeDomainState domainState = new AttributeDomainState( entityBinding, idAttribute );
|
||||
idBinding.initialize( domainState );
|
||||
|
||||
AttributeColumnRelationalState columnRelationsState = new AttributeColumnRelationalState( idAttribute, meta );
|
||||
AttributeTupleRelationalState relationalState = new AttributeTupleRelationalState();
|
||||
relationalState.addValueState( columnRelationsState );
|
||||
idBinding.initializeTupleValue( relationalState );
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( idName );
|
||||
entityBinding.makeSimpleIdAttributeBinding( idName )
|
||||
.initialize( new AnnotationsAttributeBindingState( idAttribute ) )
|
||||
.initialize( new AttributeColumnRelationalState( idAttribute, meta ) );
|
||||
}
|
||||
|
||||
private void bindAttributes(EntityBinding entityBinding) {
|
||||
|
@ -323,26 +320,27 @@ public class EntityBinder {
|
|||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName );
|
||||
SimpleAttributeBinding attributeBinding;
|
||||
|
||||
if ( mappedAttribute.isVersioned() ) {
|
||||
attributeBinding = entityBinding.makeVersionBinding( attributeName );
|
||||
}
|
||||
else if ( mappedAttribute.isDiscriminator() ) {
|
||||
attributeBinding = entityBinding.makeEntityDiscriminatorBinding( attributeName );
|
||||
if ( mappedAttribute.isDiscriminator() ) {
|
||||
attributeBinding = entityBinding.makeEntityDiscriminator( attributeName )
|
||||
.initialize( new AnnotationsDiscriminatorBindingState( mappedAttribute ) )
|
||||
.getValueBinding();
|
||||
}
|
||||
else {
|
||||
attributeBinding = entityBinding.makeSimpleAttributeBinding( attributeName );
|
||||
attributeBinding = mappedAttribute.isVersioned() ?
|
||||
entityBinding.makeVersionBinding( attributeName ) :
|
||||
entityBinding.makeSimpleAttributeBinding( attributeName );
|
||||
attributeBinding.initialize( new AnnotationsAttributeBindingState( mappedAttribute ) );
|
||||
}
|
||||
|
||||
AttributeDomainState domainState = new AttributeDomainState( entityBinding, mappedAttribute );
|
||||
attributeBinding.initialize( domainState );
|
||||
|
||||
if ( configuredClass.hasOwnTable() ) {
|
||||
AttributeColumnRelationalState columnRelationsState = new AttributeColumnRelationalState(
|
||||
mappedAttribute, meta
|
||||
);
|
||||
AttributeTupleRelationalState relationalState = new AttributeTupleRelationalState();
|
||||
relationalState.addValueState( columnRelationsState );
|
||||
attributeBinding.initializeTupleValue( relationalState );
|
||||
// TODO: if this really just binds a column, then it can be changed to
|
||||
// attributeBinding.initialize( columnRelationsState );
|
||||
attributeBinding.initialize( relationalState );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +1,55 @@
|
|||
package org.hibernate.metamodel.source.annotations.state.domain;
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.annotations.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.state.domain.SimpleAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.annotations.MappedAttribute;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class AttributeDomainState implements SimpleAttributeDomainState {
|
||||
public class AnnotationsAttributeBindingState implements SimpleAttributeBindingState {
|
||||
private final MappedAttribute mappedAttribute;
|
||||
private final PropertyGeneration propertyGeneration = null;
|
||||
private final HibernateTypeDescriptor typeDescriptor;
|
||||
private final Attribute attribute;
|
||||
private final String typeName;
|
||||
private final Properties typeParameters;
|
||||
|
||||
public AttributeDomainState(EntityBinding entityBinding, MappedAttribute mappedAttribute) {
|
||||
typeDescriptor = new HibernateTypeDescriptor();
|
||||
typeDescriptor.setTypeName( mappedAttribute.getType().getName() );
|
||||
public AnnotationsAttributeBindingState(MappedAttribute mappedAttribute) {
|
||||
this.mappedAttribute = mappedAttribute;
|
||||
typeName = mappedAttribute.getType().getName();
|
||||
// TODO: implement....
|
||||
typeParameters = null;
|
||||
}
|
||||
|
||||
Entity entity = entityBinding.getEntity();
|
||||
attribute = entity.getOrCreateSingularAttribute( mappedAttribute.getName() );
|
||||
@Override
|
||||
public String getAttributeName() {
|
||||
return mappedAttribute.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,13 +86,13 @@ public class AttributeDomainState implements SimpleAttributeDomainState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return typeDescriptor;
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute getAttribute() {
|
||||
return attribute;
|
||||
public Properties getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -21,30 +21,36 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
package org.hibernate.metamodel.source.annotations.state.binding;
|
||||
|
||||
import org.hibernate.metamodel.binding.CollectionElement;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLElementElement;
|
||||
import org.hibernate.metamodel.state.domain.CollectionElementDomainState;
|
||||
import org.hibernate.metamodel.source.annotations.ColumnValues;
|
||||
import org.hibernate.metamodel.source.annotations.DiscriminatorColumnValues;
|
||||
import org.hibernate.metamodel.source.annotations.MappedAttribute;
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*
|
||||
* TODO: extract a superclass that sets defaults for other stuff
|
||||
*/
|
||||
public class HbmCollectionElementDomainState implements CollectionElementDomainState {
|
||||
private final XMLElementElement element;
|
||||
|
||||
HbmCollectionElementDomainState(XMLElementElement element) {
|
||||
this.element = element;
|
||||
public class AnnotationsDiscriminatorBindingState
|
||||
extends AnnotationsAttributeBindingState implements DiscriminatorBindingState {
|
||||
private final boolean isForced;
|
||||
private final boolean isInserted;
|
||||
public AnnotationsDiscriminatorBindingState(MappedAttribute mappedAttribute) {
|
||||
super( mappedAttribute );
|
||||
DiscriminatorColumnValues columnValues = DiscriminatorColumnValues.class.cast( mappedAttribute.getColumnValues() );
|
||||
isForced = columnValues.isForced();
|
||||
isInserted = columnValues.isIncludedInSql();
|
||||
}
|
||||
|
||||
public final HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
hibernateTypeDescriptor.setTypeName( element.getTypeAttribute() );
|
||||
return hibernateTypeDescriptor;
|
||||
@Override
|
||||
public boolean isForced() {
|
||||
return isForced;
|
||||
}
|
||||
|
||||
public final String getNodeName() {
|
||||
return element.getNode();
|
||||
@Override
|
||||
public boolean isInsertable() {
|
||||
return isInserted;
|
||||
}
|
||||
}
|
|
@ -34,18 +34,16 @@ import org.hibernate.metamodel.binding.AttributeBinding;
|
|||
import org.hibernate.metamodel.binding.BagBinding;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.Hierarchical;
|
||||
import org.hibernate.metamodel.domain.PluralAttributeNature;
|
||||
import org.hibernate.metamodel.relational.Schema;
|
||||
import org.hibernate.metamodel.relational.Table;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.relational.UniqueKey;
|
||||
import org.hibernate.metamodel.source.hbm.state.domain.HbmManyToOneAttributeDomainState;
|
||||
import org.hibernate.metamodel.source.hbm.state.domain.HbmPluralAttributeDomainState;
|
||||
import org.hibernate.metamodel.source.hbm.state.domain.HbmSimpleAttributeDomainState;
|
||||
import org.hibernate.metamodel.source.hbm.state.binding.HbmManyToOneAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.state.binding.HbmPluralAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.state.binding.HbmSimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.state.relational.HbmManyToOneRelationalStateContainer;
|
||||
import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelationalStateContainer;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLAnyElement;
|
||||
|
@ -71,6 +69,12 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLTuplizerElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.state.binding.ManyToOneAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.binding.PluralAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ManyToOneRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.TupleRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -284,8 +288,7 @@ abstract class AbstractEntityBinder {
|
|||
for ( Object attribute : entityClazz.getPropertyOrManyToOneOrOneToOne() ) {
|
||||
if ( XMLBagElement.class.isInstance( attribute ) ) {
|
||||
XMLBagElement collection = XMLBagElement.class.cast( attribute );
|
||||
BagBinding collectionBinding = entityBinding.makeBagAttributeBinding( collection.getName() );
|
||||
bindBag( collection, collectionBinding, entityBinding );
|
||||
BagBinding collectionBinding = makeBagAttributeBinding( collection, entityBinding );
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata().addCollection( collectionBinding );
|
||||
attributeBinding = collectionBinding;
|
||||
}
|
||||
|
@ -321,12 +324,7 @@ abstract class AbstractEntityBinder {
|
|||
}
|
||||
else if ( XMLManyToOneElement.class.isInstance( attribute ) ) {
|
||||
XMLManyToOneElement manyToOne = XMLManyToOneElement.class.cast( attribute );
|
||||
ManyToOneAttributeBinding manyToOneBinding = entityBinding.makeManyToOneAttributeBinding( manyToOne.getName() );
|
||||
bindManyToOne( manyToOne, manyToOneBinding, entityBinding );
|
||||
attributeBinding = manyToOneBinding;
|
||||
// todo : implement
|
||||
// value = new ManyToOne( mappings, table );
|
||||
// bindManyToOne( subElement, (ManyToOne) value, propertyName, nullable, mappings );
|
||||
attributeBinding = makeManyToOneAttributeBinding( manyToOne, entityBinding );
|
||||
}
|
||||
else if ( XMLAnyElement.class.isInstance( attribute ) ) {
|
||||
// todo : implement
|
||||
|
@ -340,9 +338,7 @@ abstract class AbstractEntityBinder {
|
|||
}
|
||||
else if ( XMLPropertyElement.class.isInstance( attribute ) ) {
|
||||
XMLPropertyElement property = XMLPropertyElement.class.cast( attribute );
|
||||
SimpleAttributeBinding binding = entityBinding.makeSimpleAttributeBinding( property.getName() );
|
||||
bindSimpleAttribute( property, binding, entityBinding );
|
||||
attributeBinding = binding;
|
||||
attributeBinding = bindProperty( property, entityBinding );
|
||||
}
|
||||
else if ( XMLComponentElement.class.isInstance( attribute )
|
||||
|| XMLDynamicComponentElement.class.isInstance( attribute )
|
||||
|
@ -441,200 +437,86 @@ PrimitiveArray
|
|||
|
||||
}
|
||||
|
||||
protected void bindSimpleAttribute(XMLHibernateMapping.XMLClass.XMLId id,
|
||||
SimpleAttributeBinding attributeBinding,
|
||||
EntityBinding entityBinding,
|
||||
String attributeName) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
id
|
||||
)
|
||||
);
|
||||
}
|
||||
protected SimpleAttributeBinding bindProperty(XMLPropertyElement property,
|
||||
EntityBinding entityBinding) {
|
||||
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
property
|
||||
);
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initializeTupleValue(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
id
|
||||
)
|
||||
);
|
||||
}
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ValueRelationalState relationalState =
|
||||
convertToSimpleValueRelationalStateIfPossible(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
property
|
||||
)
|
||||
);
|
||||
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( bindingState.getAttributeName() );
|
||||
return entityBinding.makeSimpleAttributeBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
}
|
||||
|
||||
protected void bindSimpleAttribute(XMLHibernateMapping.XMLClass.XMLDiscriminator discriminator,
|
||||
SimpleAttributeBinding attributeBinding,
|
||||
EntityBinding entityBinding,
|
||||
String attributeName) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
discriminator
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initializeTupleValue(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
discriminator
|
||||
)
|
||||
);
|
||||
protected static ValueRelationalState convertToSimpleValueRelationalStateIfPossible(ValueRelationalState state) {
|
||||
// TODO: should a single-valued tuple always be converted???
|
||||
if ( !TupleRelationalState.class.isInstance( state ) ) {
|
||||
return state;
|
||||
}
|
||||
TupleRelationalState tupleRelationalState = TupleRelationalState.class.cast( state );
|
||||
return tupleRelationalState.getRelationalStates().size() == 1 ?
|
||||
tupleRelationalState.getRelationalStates().get( 0 ) :
|
||||
state;
|
||||
}
|
||||
|
||||
protected void bindSimpleAttribute(XMLHibernateMapping.XMLClass.XMLVersion version,
|
||||
SimpleAttributeBinding attributeBinding,
|
||||
EntityBinding entityBinding,
|
||||
String attributeName) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
version
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initializeTupleValue(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
version
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void bindSimpleAttribute(XMLHibernateMapping.XMLClass.XMLTimestamp timestamp,
|
||||
SimpleAttributeBinding attributeBinding,
|
||||
EntityBinding entityBinding,
|
||||
String attributeName) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
timestamp
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initializeTupleValue(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
timestamp
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void bindSimpleAttribute(XMLPropertyElement property,
|
||||
SimpleAttributeBinding attributeBinding,
|
||||
EntityBinding entityBinding) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( property.getName() ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
property
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initializeTupleValue(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
property
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void bindBag(
|
||||
protected BagBinding makeBagAttributeBinding(
|
||||
XMLBagElement collection,
|
||||
PluralAttributeBinding collectionBinding,
|
||||
EntityBinding entityBinding) {
|
||||
if ( collectionBinding.getAttribute() == null ) {
|
||||
// domain model has not been bound yet
|
||||
collectionBinding.initialize(
|
||||
new HbmPluralAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
collection,
|
||||
entityBinding.getMetaAttributes(),
|
||||
entityBinding.getEntity().getOrCreatePluralAttribute(
|
||||
collection.getName(),
|
||||
PluralAttributeNature.BAG
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( collectionBinding.getValue() == null ) {
|
||||
PluralAttributeBindingState bindingState =
|
||||
new HbmPluralAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
hibernateMappingBinder,
|
||||
collection,
|
||||
entityBinding.getMetaAttributes()
|
||||
);
|
||||
|
||||
BagBinding collectionBinding = entityBinding.makeBagAttributeBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState );
|
||||
|
||||
// todo : relational model binding
|
||||
}
|
||||
return collectionBinding;
|
||||
}
|
||||
|
||||
private void bindManyToOne(XMLManyToOneElement manyToOne,
|
||||
ManyToOneAttributeBinding attributeBinding,
|
||||
private ManyToOneAttributeBinding makeManyToOneAttributeBinding(XMLManyToOneElement manyToOne,
|
||||
EntityBinding entityBinding) {
|
||||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmManyToOneAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( manyToOne.getName() ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
manyToOne
|
||||
)
|
||||
);
|
||||
}
|
||||
ManyToOneAttributeBindingState bindingState =
|
||||
new HbmManyToOneAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getMetaAttributes(),
|
||||
manyToOne
|
||||
);
|
||||
|
||||
if ( attributeBinding.getValue() == null ) {
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
attributeBinding.initialize(
|
||||
new HbmManyToOneRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
manyToOne
|
||||
)
|
||||
);
|
||||
}
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ManyToOneRelationalState relationalState =
|
||||
new HbmManyToOneRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
manyToOne
|
||||
);
|
||||
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( bindingState.getAttributeName() );
|
||||
ManyToOneAttributeBinding manyToOneAttributeBinding =
|
||||
entityBinding.makeManyToOneAttributeBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
|
||||
return manyToOneAttributeBinding;
|
||||
}
|
||||
|
||||
// private static Property createProperty(
|
||||
|
|
|
@ -47,11 +47,15 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlQueryElement;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSubclassElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Responsible for performing binding of the {@code <hibernate-mapping/>} DOM element
|
||||
*/
|
||||
public class HibernateMappingBinder implements MappingDefaults {
|
||||
private static final String DEFAULT_IDENTIFIER_COLUMN_NAME = "id";
|
||||
private static final String DEFAULT_DISCRIMINATOR_COLUMN_NAME = "class";
|
||||
|
||||
private final HibernateXmlBinder hibernateXmlBinder;
|
||||
private final JaxbRoot<XMLHibernateMapping> jaxbRoot;
|
||||
private final XMLHibernateMapping hibernateMapping;
|
||||
|
@ -103,6 +107,15 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
return defaultCatalogName;
|
||||
}
|
||||
|
||||
public String getDefaultIdColumnName() {
|
||||
return DEFAULT_IDENTIFIER_COLUMN_NAME;
|
||||
|
||||
|
||||
}
|
||||
public String getDefaultDescriminatorColumnName() {
|
||||
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
||||
}
|
||||
|
||||
public String getDefaultCascade() {
|
||||
return defaultCascade;
|
||||
}
|
||||
|
@ -115,6 +128,11 @@ public class HibernateMappingBinder implements MappingDefaults {
|
|||
return defaultLazy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceRegistry getServiceRegistry() {
|
||||
return hibernateXmlBinder.getMetadata().getServiceRegistry();
|
||||
}
|
||||
|
||||
public NamingStrategy getNamingStrategy() {
|
||||
return hibernateXmlBinder.getMetadata().getNamingStrategy();
|
||||
}
|
||||
|
|
|
@ -26,18 +26,22 @@ package org.hibernate.metamodel.source.hbm;
|
|||
import org.hibernate.InvalidMappingException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.Identifier;
|
||||
import org.hibernate.metamodel.relational.InLineView;
|
||||
import org.hibernate.metamodel.relational.Schema;
|
||||
import org.hibernate.metamodel.source.hbm.state.binding.HbmDiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.state.binding.HbmSimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelationalStateContainer;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLCacheElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLCompositeId;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
|
@ -76,7 +80,7 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
|
||||
bindIdentifier( xmlClazz, entityBinding );
|
||||
bindDiscriminator( xmlClazz, entityBinding );
|
||||
bindVersion( xmlClazz, entityBinding );
|
||||
bindVersionOrTimestamp( xmlClazz, entityBinding );
|
||||
bindCaching( xmlClazz, entityBinding );
|
||||
|
||||
// called createClassProperties in HBMBinder...
|
||||
|
@ -135,18 +139,25 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
}
|
||||
|
||||
private void bindSimpleId(XMLId id, EntityBinding entityBinding) {
|
||||
// Handle the domain portion of the binding...
|
||||
final String explicitName = id.getName();
|
||||
final String attributeName = explicitName == null ? RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME : explicitName;
|
||||
SimpleAttributeBinding idBinding = entityBinding.makeSimplePrimaryKeyAttributeBinding( attributeName );
|
||||
bindSimpleAttribute( id, idBinding, entityBinding, attributeName );
|
||||
|
||||
if ( !Column.class.isInstance( idBinding.getValue() ) ) {
|
||||
// this should never ever happen..
|
||||
throw new MappingException( "Unanticipated situation" );
|
||||
SimpleAttributeBindingState bindingState = new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
id
|
||||
);
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
HbmSimpleValueRelationalStateContainer relationalStateContainer = new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(), true, id
|
||||
);
|
||||
if ( relationalStateContainer.getRelationalStates().size() > 1 ) {
|
||||
throw new MappingException( "ID is expected to be a single column, but has more than 1 value" );
|
||||
}
|
||||
|
||||
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( idBinding.getValue() ) );
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( bindingState.getAttributeName() );
|
||||
entityBinding.makeSimpleIdAttributeBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalStateContainer.getRelationalStates().get( 0 ) );
|
||||
|
||||
// if ( propertyName == null || entity.getPojoRepresentation() == null ) {
|
||||
// bindSimpleValue( idNode, id, false, RootClass.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings );
|
||||
// if ( !id.isTypeSpecified() ) {
|
||||
|
@ -233,53 +244,97 @@ class RootEntityBinder extends AbstractEntityBinder {
|
|||
return;
|
||||
}
|
||||
|
||||
// Discriminator.getName() is not defined, so the attribute will always be RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME
|
||||
SimpleAttributeBinding discriminatorBinding = entityBinding.makeEntityDiscriminatorBinding( RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME );
|
||||
|
||||
// Handle the relational portion of the binding...
|
||||
bindSimpleAttribute(
|
||||
xmlEntityClazz.getDiscriminator(),
|
||||
discriminatorBinding,
|
||||
entityBinding,
|
||||
RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME
|
||||
DiscriminatorBindingState bindingState = new HbmDiscriminatorBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
xmlEntityClazz.getDiscriminator()
|
||||
);
|
||||
|
||||
entityBinding.getEntityDiscriminator().setForced( xmlEntityClazz.getDiscriminator().isForce() );
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ValueRelationalState relationalState = convertToSimpleValueRelationalStateIfPossible(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
xmlEntityClazz.getDiscriminator()
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( bindingState.getAttributeName() );
|
||||
entityBinding.makeEntityDiscriminator( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
}
|
||||
|
||||
private void bindVersion(XMLClass xmlEntityClazz,
|
||||
EntityBinding entityBinding) {
|
||||
if ( xmlEntityClazz.getVersion() == null && xmlEntityClazz.getTimestamp() == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isVersion = xmlEntityClazz.getVersion() != null;
|
||||
String explicitName = isVersion ? xmlEntityClazz.getVersion().getName() : xmlEntityClazz.getTimestamp()
|
||||
.getName();
|
||||
if ( explicitName == null ) {
|
||||
throw new MappingException(
|
||||
"Missing property name for version/timestamp mapping [" + entityBinding.getEntity().getName() + "]"
|
||||
);
|
||||
}
|
||||
SimpleAttributeBinding versionBinding = entityBinding.makeVersionBinding( explicitName );
|
||||
if ( isVersion ) {
|
||||
bindSimpleAttribute(
|
||||
private void bindVersionOrTimestamp(XMLClass xmlEntityClazz,
|
||||
EntityBinding entityBinding) {
|
||||
if ( xmlEntityClazz.getVersion() != null ) {
|
||||
bindVersion(
|
||||
xmlEntityClazz.getVersion(),
|
||||
versionBinding,
|
||||
entityBinding,
|
||||
explicitName
|
||||
entityBinding
|
||||
);
|
||||
}
|
||||
else {
|
||||
bindSimpleAttribute(
|
||||
else if ( xmlEntityClazz.getTimestamp() != null ) {
|
||||
bindTimestamp(
|
||||
xmlEntityClazz.getTimestamp(),
|
||||
versionBinding,
|
||||
entityBinding,
|
||||
explicitName
|
||||
entityBinding
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected void bindVersion(XMLHibernateMapping.XMLClass.XMLVersion version,
|
||||
EntityBinding entityBinding) {
|
||||
SimpleAttributeBindingState bindingState =
|
||||
new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
version
|
||||
);
|
||||
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ValueRelationalState relationalState =
|
||||
convertToSimpleValueRelationalStateIfPossible(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
version
|
||||
)
|
||||
);
|
||||
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( bindingState.getAttributeName() );
|
||||
entityBinding.makeVersionBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
}
|
||||
|
||||
protected void bindTimestamp(XMLHibernateMapping.XMLClass.XMLTimestamp timestamp,
|
||||
EntityBinding entityBinding) {
|
||||
|
||||
SimpleAttributeBindingState bindingState =
|
||||
new HbmSimpleAttributeBindingState(
|
||||
entityBinding.getEntity().getPojoEntitySpecifics().getClassName(),
|
||||
getHibernateMappingBinder(),
|
||||
entityBinding.getMetaAttributes(),
|
||||
timestamp
|
||||
);
|
||||
|
||||
// relational model has not been bound yet
|
||||
// boolean (true here) indicates that by default column names should be guessed
|
||||
ValueRelationalState relationalState =
|
||||
convertToSimpleValueRelationalStateIfPossible(
|
||||
new HbmSimpleValueRelationalStateContainer(
|
||||
getHibernateMappingBinder(),
|
||||
true,
|
||||
timestamp
|
||||
)
|
||||
);
|
||||
|
||||
entityBinding.makeVersionBinding( bindingState.getAttributeName() )
|
||||
.initialize( bindingState )
|
||||
.initialize( relationalState );
|
||||
}
|
||||
|
||||
private void bindCaching(XMLClass xmlClazz,
|
||||
EntityBinding entityBinding) {
|
||||
XMLCacheElement cache = xmlClazz.getCache();
|
||||
|
|
|
@ -21,59 +21,72 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.metamodel.Metadata;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.metamodel.state.domain.AttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.AttributeBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public abstract class AbstractHbmAttributeDomainState implements AttributeDomainState {
|
||||
private final MetadataImpl metadata;
|
||||
public abstract class AbstractHbmAttributeBindingState implements AttributeBindingState {
|
||||
private final String ownerClassName;
|
||||
private final String attributeName;
|
||||
private final MappingDefaults defaults;
|
||||
private final Attribute attribute;
|
||||
private final String nodeName;
|
||||
private final String accessorName;
|
||||
private final boolean isOptimisticLockable;
|
||||
private final Map<String, MetaAttribute> metaAttributes;
|
||||
|
||||
public AbstractHbmAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public AbstractHbmAttributeBindingState(
|
||||
String ownerClassName,
|
||||
String attributeName,
|
||||
MappingDefaults defaults,
|
||||
Attribute attribute,
|
||||
String nodeName,
|
||||
Map<String, MetaAttribute> metaAttributes,
|
||||
String accessorName,
|
||||
boolean isOptimisticLockable) {
|
||||
this.metadata = metadata;
|
||||
if ( attributeName == null ) {
|
||||
throw new MappingException(
|
||||
"Attribute name cannot be null."
|
||||
);
|
||||
}
|
||||
|
||||
this.ownerClassName = ownerClassName;
|
||||
this.attributeName = attributeName;
|
||||
this.defaults = defaults;
|
||||
this.attribute = attribute;
|
||||
this.nodeName = MappingHelper.getStringValue( nodeName, attribute.getName() );
|
||||
this.nodeName = nodeName;
|
||||
this.metaAttributes = metaAttributes;
|
||||
this.accessorName = accessorName;
|
||||
this.isOptimisticLockable = isOptimisticLockable;
|
||||
}
|
||||
|
||||
public MetadataImpl getMetadata() {
|
||||
return metadata;
|
||||
// TODO: really don't like this here...
|
||||
protected String getOwnerClassName() {
|
||||
return ownerClassName;
|
||||
}
|
||||
|
||||
protected final String getTypeNameByReflection() {
|
||||
Class ownerClass = MappingHelper.classForName( ownerClassName, defaults.getServiceRegistry() );
|
||||
return ReflectHelper.reflectedPropertyClass( ownerClass, attributeName ).getName();
|
||||
}
|
||||
|
||||
public String getAttributeName() {
|
||||
return attributeName;
|
||||
}
|
||||
|
||||
protected final MappingDefaults getDefaults() {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public final Attribute getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
public final String getPropertyAccessorName() {
|
||||
return accessorName;
|
||||
}
|
||||
|
@ -88,10 +101,27 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
|
|||
}
|
||||
|
||||
public final String getNodeName() {
|
||||
return nodeName;
|
||||
return nodeName == null ? getAttributeName() : nodeName;
|
||||
}
|
||||
|
||||
public final Map<String, MetaAttribute> getMetaAttributes() {
|
||||
return metaAttributes;
|
||||
}
|
||||
|
||||
public PropertyGeneration getPropertyGeneration() {
|
||||
return PropertyGeneration.NEVER;
|
||||
}
|
||||
|
||||
public boolean isKeyCasadeDeleteEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getUnsavedValue() {
|
||||
//TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
public Properties getTypeParameters() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
||||
import org.hibernate.metamodel.state.binding.DiscriminatorBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingState implements DiscriminatorBindingState {
|
||||
private final XMLDiscriminator discriminator;
|
||||
public HbmDiscriminatorBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
XMLDiscriminator discriminator) {
|
||||
// Discriminator.getName() is not defined, so the attribute will always be
|
||||
// defaults.getDefaultDescriminatorColumnName()
|
||||
super(
|
||||
ownerClassName, defaults.getDefaultDescriminatorColumnName(), defaults, null, null, null, true
|
||||
);
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
public String getCascade() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isEmbedded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return discriminator.getType() == null ? "string" : discriminator.getType();
|
||||
}
|
||||
|
||||
public boolean isLazy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInsertable() {
|
||||
return discriminator.isInsert();
|
||||
}
|
||||
|
||||
public boolean isUpdateable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isForced() {
|
||||
return discriminator.isForce();
|
||||
}
|
||||
}
|
|
@ -21,28 +21,26 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.metamodel.state.domain.ManyToOneAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.ManyToOneAttributeBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class HbmManyToOneAttributeDomainState
|
||||
extends AbstractHbmAttributeDomainState
|
||||
implements ManyToOneAttributeDomainState {
|
||||
public class HbmManyToOneAttributeBindingState
|
||||
extends AbstractHbmAttributeBindingState
|
||||
implements ManyToOneAttributeBindingState {
|
||||
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private final FetchMode fetchMode;
|
||||
private final boolean isUnwrapProxy;
|
||||
private final boolean isLazy;
|
||||
|
@ -54,16 +52,15 @@ public class HbmManyToOneAttributeDomainState
|
|||
private final boolean isInsertable;
|
||||
private final boolean isUpdateable;
|
||||
|
||||
public HbmManyToOneAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmManyToOneAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLManyToOneElement manyToOne) {
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
manyToOne.getName(),
|
||||
defaults,
|
||||
attribute,
|
||||
manyToOne.getNode(),
|
||||
HbmHelper.extractMetas( manyToOne.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName(
|
||||
|
@ -79,13 +76,8 @@ public class HbmManyToOneAttributeDomainState
|
|||
"proxy".equals( manyToOne.getLazy().value() );
|
||||
cascade = MappingHelper.getStringValue( manyToOne.getCascade(), defaults.getDefaultCascade() );
|
||||
isEmbedded = manyToOne.isEmbedXml();
|
||||
hibernateTypeDescriptor.setTypeName( getReferencedEntityName() );
|
||||
referencedEntityName = getReferencedEntityName( ownerClassName, manyToOne, defaults );
|
||||
referencedPropertyName = manyToOne.getPropertyRef();
|
||||
referencedEntityName = (
|
||||
manyToOne.getEntityName() == null ?
|
||||
HbmHelper.getClassName( manyToOne.getClazz(), getDefaults().getPackageName() ) :
|
||||
manyToOne.getEntityName().intern()
|
||||
);
|
||||
ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() );
|
||||
isInsertable = manyToOne.isInsert();
|
||||
isUpdateable = manyToOne.isUpdate();
|
||||
|
@ -96,8 +88,19 @@ public class HbmManyToOneAttributeDomainState
|
|||
return isEmbedded;
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
private static String getReferencedEntityName(String ownerClassName, XMLManyToOneElement manyToOne, MappingDefaults defaults) {
|
||||
String referencedEntityName = null;
|
||||
if ( manyToOne.getEntityName() != null ) {
|
||||
referencedEntityName = manyToOne.getEntityName();
|
||||
}
|
||||
else if ( manyToOne.getClazz() != null ) {
|
||||
referencedEntityName = HbmHelper.getClassName( manyToOne.getClazz(), defaults.getPackageName() );
|
||||
}
|
||||
else {
|
||||
Class ownerClazz = MappingHelper.classForName( ownerClassName, defaults.getServiceRegistry() );
|
||||
referencedEntityName = ReflectHelper.reflectedPropertyClass( ownerClazz, manyToOne.getName() ).getName();
|
||||
}
|
||||
return referencedEntityName;
|
||||
}
|
||||
|
||||
// same as for plural attributes...
|
||||
|
@ -121,6 +124,10 @@ public class HbmManyToOneAttributeDomainState
|
|||
return fetchMode;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return referencedEntityName;
|
||||
}
|
||||
|
||||
public FetchMode getFetchMode() {
|
||||
return fetchMode;
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
@ -29,11 +29,8 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.metamodel.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLBagElement;
|
||||
|
@ -42,33 +39,28 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlDeleteElement;
|
|||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlInsertElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.metamodel.state.domain.CollectionElementDomainState;
|
||||
import org.hibernate.metamodel.state.domain.PluralAttributeDomainState;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.service.classloading.spi.ClassLoadingException;
|
||||
|
||||
import org.hibernate.metamodel.state.binding.PluralAttributeBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainState
|
||||
implements PluralAttributeDomainState {
|
||||
public class HbmPluralAttributeBindingState extends AbstractHbmAttributeBindingState
|
||||
implements PluralAttributeBindingState {
|
||||
private final XMLBagElement collection;
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private final Class collectionPersisterClass;
|
||||
private final String typeName;
|
||||
private final String cascade;
|
||||
|
||||
public HbmPluralAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmPluralAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults mappingDefaults,
|
||||
XMLBagElement collection,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
Attribute attribute) {
|
||||
Map<String, MetaAttribute> entityMetaAttributes) {
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
collection.getName(),
|
||||
mappingDefaults,
|
||||
attribute,
|
||||
collection.getNode(),
|
||||
HbmHelper.extractMetas( collection.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName(
|
||||
|
@ -77,9 +69,9 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
collection.isOptimisticLock()
|
||||
);
|
||||
this.collection = collection;
|
||||
// TODO: is collection.getCollectionType() correct here?
|
||||
this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() );
|
||||
this.collectionPersisterClass = MappingHelper.classForName( collection.getPersister(), getDefaults().getServiceRegistry() );
|
||||
this.cascade = MappingHelper.getStringValue( collection.getCascade(), mappingDefaults.getDefaultCascade() );
|
||||
|
||||
//Attribute typeNode = collectionElement.attribute( "collection-type" );
|
||||
//if ( typeNode != null ) {
|
||||
// TODO: implement when typedef binding is implemented
|
||||
|
@ -95,8 +87,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
}
|
||||
*/
|
||||
//}
|
||||
//TODO: fix this!!!
|
||||
this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() );
|
||||
typeName = collection.getCollectionType();
|
||||
}
|
||||
|
||||
public FetchMode getFetchMode() {
|
||||
|
@ -129,10 +120,14 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
return ( "extra".equals( collection.getLazy() ) );
|
||||
}
|
||||
|
||||
public CollectionElementDomainState getCollectionElementDomainState() {
|
||||
return new HbmCollectionElementDomainState( collection.getElement() );
|
||||
public String getElementTypeName() {
|
||||
return collection.getElement().getTypeAttribute();
|
||||
|
||||
}
|
||||
|
||||
public String getElementNodeName() {
|
||||
return collection.getElement().getNode();
|
||||
}
|
||||
public boolean isInverse() {
|
||||
return collection.isInverse();
|
||||
}
|
||||
|
@ -213,22 +208,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
}
|
||||
|
||||
public Class getCollectionPersisterClass() {
|
||||
String className = collection.getPersister();
|
||||
ClassLoaderService classLoaderService = getMetadata().getServiceRegistry()
|
||||
.getService( ClassLoaderService.class );
|
||||
try {
|
||||
return classLoaderService.classForName( className );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
throw new MappingException(
|
||||
"Could not find collection persister class: "
|
||||
+ collection.getPersister()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
return collectionPersisterClass;
|
||||
}
|
||||
|
||||
public java.util.Map getFilters() {
|
||||
|
@ -312,4 +292,8 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
//TODO: implement
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
}
|
|
@ -21,46 +21,46 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLTimestamp;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLVersion;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLParamElement;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||
import org.hibernate.metamodel.state.domain.SimpleAttributeDomainState;
|
||||
import org.hibernate.metamodel.state.binding.SimpleAttributeBindingState;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainState
|
||||
implements SimpleAttributeDomainState {
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingState
|
||||
implements SimpleAttributeBindingState {
|
||||
private final String typeName;
|
||||
private final Properties typeParameters = new Properties();
|
||||
|
||||
private final boolean isLazy;
|
||||
private final PropertyGeneration propertyGeneration;
|
||||
private final boolean isInsertable;
|
||||
private final boolean isUpdateable;
|
||||
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmSimpleAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLId id) {
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
id.getName() != null ? id.getName() : defaults.getDefaultIdColumnName(),
|
||||
defaults,
|
||||
attribute,
|
||||
id.getNode(),
|
||||
HbmHelper.extractMetas( id.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
|
@ -68,8 +68,14 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
);
|
||||
|
||||
this.isLazy = false;
|
||||
if ( id.getType() != null ) {
|
||||
this.hibernateTypeDescriptor.setTypeName( id.getType().getName() );
|
||||
if ( id.getTypeAttribute() != null ) {
|
||||
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
|
||||
}
|
||||
else if ( id.getType() != null ) {
|
||||
typeName = maybeConvertToTypeDefName( id.getType().getName(), defaults );
|
||||
}
|
||||
else {
|
||||
typeName = getTypeNameByReflection();
|
||||
}
|
||||
|
||||
// TODO: how should these be set???
|
||||
|
@ -79,40 +85,32 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = false;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
XMLDiscriminator discriminator) {
|
||||
super(
|
||||
metadata, defaults, attribute, null, null, null, true
|
||||
);
|
||||
this.hibernateTypeDescriptor
|
||||
.setTypeName( discriminator.getType() == null ? "string" : discriminator.getType() );
|
||||
this.isLazy = false;
|
||||
|
||||
this.propertyGeneration = PropertyGeneration.NEVER;
|
||||
this.isInsertable = discriminator.isInsert();
|
||||
this.isUpdateable = false;
|
||||
private static String maybeConvertToTypeDefName(String typeName, MappingDefaults defaults) {
|
||||
String actualTypeName = typeName;
|
||||
if ( typeName != null ) {
|
||||
// TODO: tweak for typedef...
|
||||
}
|
||||
else {
|
||||
}
|
||||
return actualTypeName;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmSimpleAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLVersion version) {
|
||||
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
version.getName(),
|
||||
defaults,
|
||||
attribute,
|
||||
version.getNode(),
|
||||
HbmHelper.extractMetas( version.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
true
|
||||
);
|
||||
this.hibernateTypeDescriptor.setTypeName( version.getType() == null ? "integer" : version.getType() );
|
||||
this.typeName = version.getType() == null ? "integer" : version.getType();
|
||||
|
||||
this.isLazy = false;
|
||||
|
||||
// for version properties marked as being generated, make sure they are "always"
|
||||
|
@ -126,24 +124,24 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = true;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmSimpleAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLTimestamp timestamp) {
|
||||
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
timestamp.getName(),
|
||||
defaults,
|
||||
attribute,
|
||||
timestamp.getNode(),
|
||||
HbmHelper.extractMetas( timestamp.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( timestamp.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
true
|
||||
);
|
||||
|
||||
// Timestamp.getType() is not defined
|
||||
this.hibernateTypeDescriptor.setTypeName( "db".equals( timestamp.getSource() ) ? "dbtimestamp" : "timestamp" );
|
||||
this.typeName = "db".equals( timestamp.getSource() ) ? "dbtimestamp" : "timestamp";
|
||||
this.isLazy = false;
|
||||
|
||||
// for version properties marked as being generated, make sure they are "always"
|
||||
|
@ -157,16 +155,15 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = true;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
public HbmSimpleAttributeBindingState(
|
||||
String ownerClassName,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLPropertyElement property) {
|
||||
super(
|
||||
metadata,
|
||||
ownerClassName,
|
||||
property.getName(),
|
||||
defaults,
|
||||
attribute,
|
||||
property.getNode(),
|
||||
HbmHelper.extractMetas( property.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( property.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
|
@ -182,7 +179,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
throw new MappingException(
|
||||
"cannot specify both insert=\"true\" and generated=\"" + propertyGeneration.getName() +
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
property.getName()
|
||||
);
|
||||
}
|
||||
isInsertable = false;
|
||||
|
@ -197,7 +194,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
throw new MappingException(
|
||||
"cannot specify both update=\"true\" and generated=\"" + propertyGeneration.getName() +
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
property.getName()
|
||||
);
|
||||
}
|
||||
isUpdateable = false;
|
||||
|
@ -205,14 +202,47 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
else {
|
||||
isUpdateable = MappingHelper.getBooleanValue( property.isUpdate(), true );
|
||||
}
|
||||
|
||||
if ( property.getTypeAttribute() != null ) {
|
||||
typeName = maybeConvertToTypeDefName( property.getTypeAttribute(), defaults );
|
||||
}
|
||||
else if ( property.getType() != null ) {
|
||||
typeName = maybeConvertToTypeDefName( property.getType().getName(), defaults );
|
||||
for ( XMLParamElement typeParameter : property.getType().getParam() ) {
|
||||
//TODO: add parameters from typedef
|
||||
typeParameters.put( typeParameter.getName(), typeParameter.getValue().trim() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
typeName = getTypeNameByReflection();
|
||||
}
|
||||
|
||||
|
||||
// TODO: check for typedef first
|
||||
/*
|
||||
TypeDef typeDef = mappings.getTypeDef( typeName );
|
||||
if ( typeDef != null ) {
|
||||
typeName = typeDef.getTypeClass();
|
||||
// parameters on the property mapping should
|
||||
// override parameters in the typedef
|
||||
Properties allParameters = new Properties();
|
||||
allParameters.putAll( typeDef.getParameters() );
|
||||
allParameters.putAll( parameters );
|
||||
parameters = allParameters;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
protected boolean isEmbedded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public Properties getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
public boolean isLazy() {
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.source.internal;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
import org.hibernate.metamodel.domain.Entity;
|
||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class JavaClassNameResolver {
|
||||
private final MetadataImplementor metadata;
|
||||
|
||||
JavaClassNameResolver(MetadataImplementor metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public void resolve(EntityBinding entityBinding) {
|
||||
// TODO: this only deals w/ POJO...
|
||||
Entity entity = entityBinding.getEntity();
|
||||
if ( entity == null ) {
|
||||
throw new MappingException(
|
||||
"Cannot resolve Java type names because the domain model has not been bound to EntityBinding." );
|
||||
}
|
||||
String entityClassName =
|
||||
entity.getPojoEntitySpecifics().getClassName() != null ?
|
||||
entity.getPojoEntitySpecifics().getClassName() :
|
||||
entity.getPojoEntitySpecifics().getProxyInterfaceName();
|
||||
if ( entityClassName == null ) {
|
||||
throw new MappingException( "No Java class or interface defined for: " + entityBinding.getEntity().getName() );
|
||||
}
|
||||
|
||||
for ( Attribute attribute : entity.getAttributes() ) {
|
||||
if ( attribute.isSingular() ) {
|
||||
SingularAttribute singularAttribute = SingularAttribute.class.cast( attribute );
|
||||
if ( singularAttribute.getSingularAttributeType().getName() == null ) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,6 +28,12 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.metamodel.source.spi.MetadataImplementor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.service.classloading.spi.ClassLoadingException;
|
||||
|
||||
/**
|
||||
* Helper class.
|
||||
*
|
||||
|
@ -66,4 +72,17 @@ public class MappingHelper {
|
|||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class classForName(String className, ServiceRegistry serviceRegistry) {
|
||||
ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||
try {
|
||||
return classLoaderService.classForName( className );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
throw new MappingException(
|
||||
"Could not find class: "
|
||||
+ className
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.state.domain;
|
||||
package org.hibernate.metamodel.state.binding;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.domain.Attribute;
|
||||
|
@ -32,9 +33,10 @@ import org.hibernate.metamodel.domain.MetaAttribute;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface AttributeDomainState {
|
||||
HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
Attribute getAttribute();
|
||||
public interface AttributeBindingState {
|
||||
String getAttributeName();
|
||||
String getTypeName();
|
||||
Properties getTypeParameters();
|
||||
boolean isLazy();
|
||||
String getPropertyAccessorName();
|
||||
boolean isAlternateUniqueKey();
|
|
@ -21,14 +21,13 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.state.domain;
|
||||
package org.hibernate.metamodel.state.binding;
|
||||
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.AttributeBinding;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface CollectionElementDomainState {
|
||||
HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
String getNodeName();
|
||||
public interface DiscriminatorBindingState extends SimpleAttributeBindingState {
|
||||
boolean isForced();
|
||||
}
|
|
@ -21,12 +21,12 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.state.domain;
|
||||
package org.hibernate.metamodel.state.binding;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface ManyToOneAttributeDomainState extends SingularAttributeDomainState {
|
||||
public interface ManyToOneAttributeBindingState extends SimpleAttributeBindingState {
|
||||
boolean isUnwrapProxy();
|
||||
String getReferencedAttributeName();
|
||||
String getReferencedEntityName();
|
|
@ -21,15 +21,12 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.state.domain;
|
||||
package org.hibernate.metamodel.state.binding;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.metamodel.binding.AbstractAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.CollectionElement;
|
||||
import org.hibernate.metamodel.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
|
@ -38,10 +35,11 @@ import org.hibernate.metamodel.binding.PluralAttributeBinding;
|
|||
* Time: 4:49 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public interface PluralAttributeDomainState extends AttributeDomainState {
|
||||
public interface PluralAttributeBindingState extends AttributeBindingState {
|
||||
FetchMode getFetchMode();
|
||||
boolean isExtraLazy();
|
||||
CollectionElementDomainState getCollectionElementDomainState();
|
||||
String getElementTypeName();
|
||||
String getElementNodeName();
|
||||
boolean isInverse();
|
||||
boolean isMutable();
|
||||
boolean isSubselectLoadable();
|
|
@ -21,14 +21,17 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.state.domain;
|
||||
package org.hibernate.metamodel.state.binding;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface SingularAttributeDomainState extends AttributeDomainState{
|
||||
public interface SimpleAttributeBindingState extends AttributeBindingState {
|
||||
boolean isInsertable();
|
||||
boolean isUpdateable();
|
||||
boolean isKeyCasadeDeleteEnabled();
|
||||
String getUnsavedValue();
|
||||
public PropertyGeneration getPropertyGeneration();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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.state.domain;
|
||||
|
||||
import org.hibernate.mapping.PropertyGeneration;
|
||||
import org.hibernate.metamodel.binding.SingularAttributeBinding;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public interface SimpleAttributeDomainState extends SingularAttributeDomainState {
|
||||
public PropertyGeneration getPropertyGeneration();
|
||||
}
|
|
@ -21,9 +21,15 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.metamodel.relational;
|
||||
package org.hibernate.metamodel.state.relational;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.metamodel.relational.Column;
|
||||
import org.hibernate.metamodel.relational.DerivedValue;
|
||||
import org.hibernate.metamodel.relational.SimpleValue;
|
||||
import org.hibernate.metamodel.relational.TableSpecification;
|
||||
import org.hibernate.metamodel.relational.Tuple;
|
||||
import org.hibernate.metamodel.relational.Value;
|
||||
import org.hibernate.metamodel.state.relational.ColumnRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.DerivedValueRelationalState;
|
||||
import org.hibernate.metamodel.state.relational.ValueRelationalState;
|
||||
|
@ -33,7 +39,7 @@ import org.hibernate.metamodel.state.relational.TupleRelationalState;
|
|||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class ValueFactory {
|
||||
public class ValueCreator {
|
||||
|
||||
public static Column createColumn(TableSpecification table,
|
||||
String attributeName,
|
Loading…
Reference in New Issue