Removing obsolete DomHelper. Removing dom4j methods from MappingHelper. Removing getClassValue, because ClassLoaderService should be used

This commit is contained in:
Hardy Ferentschik 2011-05-12 12:04:45 +02:00
parent 095e858f77
commit 0278966b2e
9 changed files with 204 additions and 258 deletions

View File

@ -44,18 +44,39 @@ import org.hibernate.metamodel.relational.Table;
import org.hibernate.metamodel.relational.TableSpecification; import org.hibernate.metamodel.relational.TableSpecification;
import org.hibernate.metamodel.relational.UniqueKey; import org.hibernate.metamodel.relational.UniqueKey;
import org.hibernate.metamodel.source.hbm.state.domain.HbmManyToOneAttributeDomainState; import org.hibernate.metamodel.source.hbm.state.domain.HbmManyToOneAttributeDomainState;
import org.hibernate.metamodel.source.hbm.state.relational.HbmManyToOneRelationalStateContainer;
import org.hibernate.metamodel.source.hbm.xml.mapping.*;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.metamodel.source.hbm.state.domain.HbmPluralAttributeDomainState; 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.domain.HbmSimpleAttributeDomainState;
import org.hibernate.metamodel.source.hbm.state.relational.HbmManyToOneRelationalStateContainer;
import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelationalStateContainer; import org.hibernate.metamodel.source.hbm.state.relational.HbmSimpleValueRelationalStateContainer;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLAnyElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLBagElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLComponentElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLDynamicComponentElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLFilterElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLIdbagElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLJoinedSubclassElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLListElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMapElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLOneToOneElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertiesElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLQueryElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLResultsetElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSetElement;
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.XMLTuplizerElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLUnionSubclassElement;
import org.hibernate.metamodel.source.internal.MetadataImpl;
/** /**
* TODO : javadoc * TODO : javadoc
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
abstract class AbstractEntityBinder { abstract class AbstractEntityBinder {
private final HibernateMappingBinder hibernateMappingBinder; private final HibernateMappingBinder hibernateMappingBinder;
private final Schema.Name schemaName; private final Schema.Name schemaName;
@ -88,6 +109,7 @@ abstract class AbstractEntityBinder {
protected Schema.Name getSchemaName() { protected Schema.Name getSchemaName() {
return schemaName; return schemaName;
} }
protected NamingStrategy getNamingStrategy() { protected NamingStrategy getNamingStrategy() {
return getMetadata().getNamingStrategy(); return getMetadata().getNamingStrategy();
} }
@ -151,7 +173,7 @@ abstract class AbstractEntityBinder {
if ( nodeName == null ) { if ( nodeName == null ) {
nodeName = StringHelper.unqualify( entityBinding.getEntity().getName() ); nodeName = StringHelper.unqualify( entityBinding.getEntity().getName() );
} }
entityBinding.getEntity().getDom4jEntitySpecifics().setNodeName(nodeName); entityBinding.getEntity().getDom4jEntitySpecifics().setNodeName( nodeName );
XMLTuplizerElement tuplizer = locateTuplizerDefinition( entityClazz, EntityMode.DOM4J ); XMLTuplizerElement tuplizer = locateTuplizerDefinition( entityClazz, EntityMode.DOM4J );
if ( tuplizer != null ) { if ( tuplizer != null ) {
@ -176,7 +198,7 @@ abstract class AbstractEntityBinder {
* @return The tuplizer element, or null. * @return The tuplizer element, or null.
*/ */
private static XMLTuplizerElement locateTuplizerDefinition(XMLHibernateMapping.XMLClass container, private static XMLTuplizerElement locateTuplizerDefinition(XMLHibernateMapping.XMLClass container,
EntityMode entityMode) { EntityMode entityMode) {
for ( XMLTuplizerElement tuplizer : container.getTuplizer() ) { for ( XMLTuplizerElement tuplizer : container.getTuplizer() ) {
if ( entityMode.toString().equals( tuplizer.getEntityMode() ) ) { if ( entityMode.toString().equals( tuplizer.getEntityMode() ) ) {
return tuplizer; return tuplizer;
@ -216,7 +238,9 @@ abstract class AbstractEntityBinder {
String physicalTableName; String physicalTableName;
if ( entityClazz.getTable() == null ) { if ( entityClazz.getTable() == null ) {
logicalTableName = StringHelper.unqualify( entityName ); logicalTableName = StringHelper.unqualify( entityName );
physicalTableName = getHibernateXmlBinder().getMetadata().getNamingStrategy().classToTableName( entityName ); physicalTableName = getHibernateXmlBinder().getMetadata()
.getNamingStrategy()
.classToTableName( entityName );
} }
else { else {
logicalTableName = entityClazz.getTable(); logicalTableName = entityClazz.getTable();
@ -296,7 +320,7 @@ abstract class AbstractEntityBinder {
//hibernateMappingBinder.getHibernateXmlBinder().getMetadata().addCollection( attributeBinding ); //hibernateMappingBinder.getHibernateXmlBinder().getMetadata().addCollection( attributeBinding );
} }
else if ( XMLManyToOneElement.class.isInstance( attribute ) ) { else if ( XMLManyToOneElement.class.isInstance( attribute ) ) {
XMLManyToOneElement manyToOne = XMLManyToOneElement.class.cast( attribute ); XMLManyToOneElement manyToOne = XMLManyToOneElement.class.cast( attribute );
ManyToOneAttributeBinding manyToOneBinding = entityBinding.makeManyToOneAttributeBinding( manyToOne.getName() ); ManyToOneAttributeBinding manyToOneBinding = entityBinding.makeManyToOneAttributeBinding( manyToOne.getName() );
bindManyToOne( manyToOne, manyToOneBinding, entityBinding ); bindManyToOne( manyToOne, manyToOneBinding, entityBinding );
attributeBinding = manyToOneBinding; attributeBinding = manyToOneBinding;
@ -424,6 +448,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmSimpleAttributeDomainState( new HbmSimpleAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ), entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -452,6 +477,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmSimpleAttributeDomainState( new HbmSimpleAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ), entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -480,6 +506,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmSimpleAttributeDomainState( new HbmSimpleAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ), entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -508,6 +535,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmSimpleAttributeDomainState( new HbmSimpleAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ), entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -535,6 +563,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmSimpleAttributeDomainState( new HbmSimpleAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( property.getName() ), entityBinding.getEntity().getOrCreateSingularAttribute( property.getName() ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -564,6 +593,7 @@ PrimitiveArray
// domain model has not been bound yet // domain model has not been bound yet
collectionBinding.initialize( collectionBinding.initialize(
new HbmPluralAttributeDomainState( new HbmPluralAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
collection, collection,
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -586,6 +616,7 @@ PrimitiveArray
if ( attributeBinding.getAttribute() == null ) { if ( attributeBinding.getAttribute() == null ) {
attributeBinding.initialize( attributeBinding.initialize(
new HbmManyToOneAttributeDomainState( new HbmManyToOneAttributeDomainState(
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
hibernateMappingBinder, hibernateMappingBinder,
entityBinding.getEntity().getOrCreateSingularAttribute( manyToOne.getName() ), entityBinding.getEntity().getOrCreateSingularAttribute( manyToOne.getName() ),
entityBinding.getMetaAttributes(), entityBinding.getMetaAttributes(),
@ -648,8 +679,8 @@ PrimitiveArray
// protected HbmRelationalState processValues(Element identifierElement, TableSpecification baseTable, String propertyPath, boolean isSimplePrimaryKey) { // protected HbmRelationalState processValues(Element identifierElement, TableSpecification baseTable, String propertyPath, boolean isSimplePrimaryKey) {
// first boolean (false here) indicates that by default columns are nullable // first boolean (false here) indicates that by default columns are nullable
// second boolean (true here) indicates that by default column names should be guessed // second boolean (true here) indicates that by default column names should be guessed
// todo : logical 1-1 handling // todo : logical 1-1 handling
// final Attribute uniqueAttribute = node.attribute( "unique" ); // final Attribute uniqueAttribute = node.attribute( "unique" );
// if ( uniqueAttribute != null // if ( uniqueAttribute != null
@ -657,8 +688,7 @@ PrimitiveArray
// && ManyToOne.class.isInstance( simpleValue ) ) { // && ManyToOne.class.isInstance( simpleValue ) ) {
// ( (ManyToOne) simpleValue ).markAsLogicalOneToOne(); // ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
// } // }
//return processValues( identifierElement, baseTable, false, true, propertyPath, isSimplePrimaryKey ); //return processValues( identifierElement, baseTable, false, true, propertyPath, isSimplePrimaryKey );
} }

View File

@ -36,7 +36,6 @@ import org.hibernate.metamodel.binding.CustomSQL;
import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement;
import org.hibernate.metamodel.source.util.DomHelper;
import org.hibernate.metamodel.source.util.MappingHelper; import org.hibernate.metamodel.source.util.MappingHelper;
/** /**
@ -76,7 +75,7 @@ public class HbmHelper {
public static final Map<String, MetaAttribute> extractMetas(List<XMLMetaElement> metaList, boolean onlyInheritable, Map<String, MetaAttribute> baseline) { public static final Map<String, MetaAttribute> extractMetas(List<XMLMetaElement> metaList, boolean onlyInheritable, Map<String, MetaAttribute> baseline) {
Map<String, MetaAttribute> extractedMetas = new HashMap<String, MetaAttribute>(); Map<String, MetaAttribute> extractedMetas = new HashMap<String, MetaAttribute>();
extractedMetas.putAll( baseline ); extractedMetas.putAll( baseline );
for ( XMLMetaElement meta : metaList) { for ( XMLMetaElement meta : metaList ) {
boolean inheritable = meta.isInherit(); boolean inheritable = meta.isInherit();
if ( onlyInheritable & !inheritable ) { if ( onlyInheritable & !inheritable ) {
continue; continue;
@ -94,16 +93,18 @@ public class HbmHelper {
return extractedMetas; return extractedMetas;
} }
public static String extractEntityName( XMLClass entityClazz, String unqualifiedPackageName) { public static String extractEntityName(XMLClass entityClazz, String unqualifiedPackageName) {
return extractEntityName( entityClazz.getEntityName(), entityClazz.getName(), unqualifiedPackageName ); return extractEntityName( entityClazz.getEntityName(), entityClazz.getName(), unqualifiedPackageName );
} }
public static String extractEntityName( String entityName, String entityClassName, String unqualifiedPackageName) { public static String extractEntityName(String entityName, String entityClassName, String unqualifiedPackageName) {
return entityName == null ? getClassName( entityClassName, unqualifiedPackageName ) : entityName; return entityName == null ? getClassName( entityClassName, unqualifiedPackageName ) : entityName;
} }
public static String getClassName(Attribute att, String unqualifiedPackageName) { public static String getClassName(Attribute att, String unqualifiedPackageName) {
if ( att == null ) return null; if ( att == null ) {
return null;
}
return getClassName( att.getValue(), unqualifiedPackageName ); return getClassName( att.getValue(), unqualifiedPackageName );
} }
@ -117,18 +118,10 @@ public class HbmHelper {
return unqualifiedName; return unqualifiedName;
} }
public static CustomSQL getCustomSql(String sql, boolean isCallable, String check ) { public static CustomSQL getCustomSql(String sql, boolean isCallable, String check) {
return new CustomSQL( sql.trim(), isCallable, getResultCheckStyle( check, isCallable ) ); return new CustomSQL( sql.trim(), isCallable, getResultCheckStyle( check, isCallable ) );
} }
public static String getPropertyAccessorName(Element element, boolean isEmbedded, String defaultAccess) {
return DomHelper.extractAttributeValue(
element,
"access",
isEmbedded ? "embedded" : defaultAccess
);
}
public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) { public static String getPropertyAccessorName(String access, boolean isEmbedded, String defaultAccess) {
return MappingHelper.getStringValue( return MappingHelper.getStringValue(
access, access,

View File

@ -51,7 +51,7 @@ import org.hibernate.metamodel.source.util.MappingHelper;
/** /**
* Responsible for performing binding of the {@code <hibernate-mapping/>} DOM element * Responsible for performing binding of the {@code <hibernate-mapping/>} DOM element
*/ */
class HibernateMappingBinder implements MappingDefaults { public class HibernateMappingBinder implements MappingDefaults {
private final HibernateXmlBinder hibernateXmlBinder; private final HibernateXmlBinder hibernateXmlBinder;
private final JaxbRoot<XMLHibernateMapping> jaxbRoot; private final JaxbRoot<XMLHibernateMapping> jaxbRoot;
private final XMLHibernateMapping hibernateMapping; private final XMLHibernateMapping hibernateMapping;

View File

@ -25,9 +25,11 @@ package org.hibernate.metamodel.source.hbm.state.domain;
import java.util.Map; import java.util.Map;
import org.hibernate.metamodel.Metadata;
import org.hibernate.metamodel.binding.MappingDefaults; import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.domain.Attribute; import org.hibernate.metamodel.domain.Attribute;
import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.metamodel.source.util.MappingHelper; import org.hibernate.metamodel.source.util.MappingHelper;
import org.hibernate.metamodel.state.domain.AttributeDomainState; import org.hibernate.metamodel.state.domain.AttributeDomainState;
@ -35,6 +37,7 @@ import org.hibernate.metamodel.state.domain.AttributeDomainState;
* @author Gail Badner * @author Gail Badner
*/ */
public abstract class AbstractHbmAttributeDomainState implements AttributeDomainState { public abstract class AbstractHbmAttributeDomainState implements AttributeDomainState {
private final MetadataImpl metadata;
private final MappingDefaults defaults; private final MappingDefaults defaults;
private final Attribute attribute; private final Attribute attribute;
private final String nodeName; private final String nodeName;
@ -42,12 +45,15 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
private final boolean isOptimisticLockable; private final boolean isOptimisticLockable;
private final Map<String, MetaAttribute> metaAttributes; private final Map<String, MetaAttribute> metaAttributes;
public AbstractHbmAttributeDomainState(MappingDefaults defaults, public AbstractHbmAttributeDomainState(
Attribute attribute, MetadataImpl metadata,
String nodeName, MappingDefaults defaults,
Map<String, MetaAttribute> metaAttributes, Attribute attribute,
String accessorName, String nodeName,
boolean isOptimisticLockable) { Map<String, MetaAttribute> metaAttributes,
String accessorName,
boolean isOptimisticLockable) {
this.metadata = metadata;
this.defaults = defaults; this.defaults = defaults;
this.attribute = attribute; this.attribute = attribute;
this.nodeName = MappingHelper.getStringValue( nodeName, attribute.getName() ); this.nodeName = MappingHelper.getStringValue( nodeName, attribute.getName() );
@ -56,12 +62,18 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
this.isOptimisticLockable = isOptimisticLockable; this.isOptimisticLockable = isOptimisticLockable;
} }
public MetadataImpl getMetadata() {
return metadata;
}
protected final MappingDefaults getDefaults() { protected final MappingDefaults getDefaults() {
return defaults; return defaults;
} }
public final Attribute getAttribute() { public final Attribute getAttribute() {
return attribute; return attribute;
} }
public final String getPropertyAccessorName() { public final String getPropertyAccessorName() {
return accessorName; return accessorName;
} }
@ -70,9 +82,11 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
//TODO: implement //TODO: implement
return false; return false;
} }
public final boolean isOptimisticLockable() { public final boolean isOptimisticLockable() {
return isOptimisticLockable; return isOptimisticLockable;
} }
public final String getNodeName() { public final String getNodeName() {
return nodeName; return nodeName;
} }

View File

@ -27,11 +27,11 @@ import java.util.Map;
import org.hibernate.FetchMode; import org.hibernate.FetchMode;
import org.hibernate.metamodel.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
import org.hibernate.metamodel.binding.MappingDefaults; import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.domain.MetaAttribute; import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.hbm.HbmHelper; import org.hibernate.metamodel.source.hbm.HbmHelper;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLManyToOneElement; 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.source.util.MappingHelper;
import org.hibernate.metamodel.state.domain.ManyToOneAttributeDomainState; import org.hibernate.metamodel.state.domain.ManyToOneAttributeDomainState;
@ -54,22 +54,27 @@ public class HbmManyToOneAttributeDomainState
private final boolean isInsertable; private final boolean isInsertable;
private final boolean isUpdateable; private final boolean isUpdateable;
public HbmManyToOneAttributeDomainState(MappingDefaults defaults, public HbmManyToOneAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLManyToOneElement manyToOne) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLManyToOneElement manyToOne) {
super( super(
metadata,
defaults, defaults,
attribute, attribute,
manyToOne.getNode(), manyToOne.getNode(),
HbmHelper.extractMetas( manyToOne.getMeta(), entityMetaAttributes ), HbmHelper.extractMetas( manyToOne.getMeta(), entityMetaAttributes ),
HbmHelper.getPropertyAccessorName( manyToOne.getAccess(), manyToOne.isEmbedXml(), defaults.getDefaultAccess() ), HbmHelper.getPropertyAccessorName(
manyToOne.getAccess(), manyToOne.isEmbedXml(), defaults.getDefaultAccess()
),
manyToOne.isOptimisticLock() manyToOne.isOptimisticLock()
); );
fetchMode = getFetchMode( manyToOne ); fetchMode = getFetchMode( manyToOne );
isUnwrapProxy = manyToOne.getLazy() != null && "no-proxy".equals( manyToOne.getLazy().value() ); isUnwrapProxy = manyToOne.getLazy() != null && "no-proxy".equals( manyToOne.getLazy().value() );
//TODO: better to degrade to lazy="false" if uninstrumented //TODO: better to degrade to lazy="false" if uninstrumented
isLazy = manyToOne.getLazy() == null || isLazy = manyToOne.getLazy() == null ||
isUnwrapProxy || isUnwrapProxy ||
"proxy".equals( manyToOne.getLazy().value() ); "proxy".equals( manyToOne.getLazy().value() );
cascade = MappingHelper.getStringValue( manyToOne.getCascade(), defaults.getDefaultCascade() ); cascade = MappingHelper.getStringValue( manyToOne.getCascade(), defaults.getDefaultCascade() );
@ -78,8 +83,8 @@ public class HbmManyToOneAttributeDomainState
referencedPropertyName = manyToOne.getPropertyRef(); referencedPropertyName = manyToOne.getPropertyRef();
referencedEntityName = ( referencedEntityName = (
manyToOne.getEntityName() == null ? manyToOne.getEntityName() == null ?
HbmHelper.getClassName( manyToOne.getClazz(), getDefaults().getPackageName() ) : HbmHelper.getClassName( manyToOne.getClazz(), getDefaults().getPackageName() ) :
manyToOne.getEntityName().intern() manyToOne.getEntityName().intern()
); );
ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() ); ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() );
isInsertable = manyToOne.isInsert(); isInsertable = manyToOne.isInsert();
@ -156,6 +161,7 @@ public class HbmManyToOneAttributeDomainState
//TODO: implement //TODO: implement
return false; return false;
} }
public String getUnsavedValue() { public String getUnsavedValue() {
//TODO: implement //TODO: implement
return null; return null;

View File

@ -24,14 +24,13 @@
package org.hibernate.metamodel.source.hbm.state.domain; package org.hibernate.metamodel.source.hbm.state.domain;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import org.hibernate.FetchMode; import org.hibernate.FetchMode;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.metamodel.binding.CustomSQL; import org.hibernate.metamodel.binding.CustomSQL;
import org.hibernate.metamodel.binding.ElementCollectionElement;
import org.hibernate.metamodel.binding.HibernateTypeDescriptor; import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.binding.MappingDefaults; import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.domain.Attribute; import org.hibernate.metamodel.domain.Attribute;
@ -43,50 +42,58 @@ 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.XMLSqlInsertElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement; import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSqlUpdateElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLSynchronizeElement; 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.source.util.MappingHelper;
import org.hibernate.metamodel.state.domain.CollectionElementDomainState; import org.hibernate.metamodel.state.domain.CollectionElementDomainState;
import org.hibernate.metamodel.state.domain.PluralAttributeDomainState; import org.hibernate.metamodel.state.domain.PluralAttributeDomainState;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.classloading.spi.ClassLoadingException;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainState implements PluralAttributeDomainState { public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainState
implements PluralAttributeDomainState {
private final XMLBagElement collection; private final XMLBagElement collection;
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private final String cascade; private final String cascade;
public HbmPluralAttributeDomainState(MappingDefaults defaults, public HbmPluralAttributeDomainState(
XMLBagElement collection, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults mappingDefaults,
Attribute attribute) { XMLBagElement collection,
Map<String, MetaAttribute> entityMetaAttributes,
Attribute attribute) {
super( super(
defaults, metadata,
mappingDefaults,
attribute, attribute,
collection.getNode(), collection.getNode(),
HbmHelper.extractMetas( collection.getMeta(), entityMetaAttributes ), HbmHelper.extractMetas( collection.getMeta(), entityMetaAttributes ),
HbmHelper.getPropertyAccessorName( collection.getAccess(), collection.isEmbedXml(), defaults.getDefaultAccess() ), HbmHelper.getPropertyAccessorName(
collection.getAccess(), collection.isEmbedXml(), mappingDefaults.getDefaultAccess()
),
collection.isOptimisticLock() collection.isOptimisticLock()
); );
this.collection = collection; this.collection = collection;
// TODO: is collection.getCollectionType() correct here? // TODO: is collection.getCollectionType() correct here?
this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() ); this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() );
this.cascade = MappingHelper.getStringValue( collection.getCascade(), defaults.getDefaultCascade() ); this.cascade = MappingHelper.getStringValue( collection.getCascade(), mappingDefaults.getDefaultCascade() );
//Attribute typeNode = collectionElement.attribute( "collection-type" ); //Attribute typeNode = collectionElement.attribute( "collection-type" );
//if ( typeNode != null ) { //if ( typeNode != null ) {
// TODO: implement when typedef binding is implemented // TODO: implement when typedef binding is implemented
/* /*
String typeName = typeNode.getValue(); String typeName = typeNode.getValue();
TypeDef typeDef = mappings.getTypeDef( typeName ); TypeDef typeDef = mappings.getTypeDef( typeName );
if ( typeDef != null ) { if ( typeDef != null ) {
collectionBinding.setTypeName( typeDef.getTypeClass() ); collectionBinding.setTypeName( typeDef.getTypeClass() );
collectionBinding.setTypeParameters( typeDef.getParameters() ); collectionBinding.setTypeParameters( typeDef.getParameters() );
} }
else { else {
collectionBinding.setTypeName( typeName ); collectionBinding.setTypeName( typeName );
} }
*/ */
//} //}
//TODO: fix this!!! //TODO: fix this!!!
this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() ); this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() );
@ -98,7 +105,8 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
fetchMode = "join".equals( collection.getFetch() ) ? FetchMode.JOIN : FetchMode.SELECT; fetchMode = "join".equals( collection.getFetch() ) ? FetchMode.JOIN : FetchMode.SELECT;
} }
else { else {
String jfNodeValue = ( collection.getOuterJoin().value() == null ? "auto" : collection.getOuterJoin().value() ); String jfNodeValue = ( collection.getOuterJoin().value() == null ? "auto" : collection.getOuterJoin()
.value() );
if ( "auto".equals( jfNodeValue ) ) { if ( "auto".equals( jfNodeValue ) ) {
fetchMode = FetchMode.DEFAULT; fetchMode = FetchMode.DEFAULT;
} }
@ -114,11 +122,11 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
public boolean isLazy() { public boolean isLazy() {
return isExtraLazy() || return isExtraLazy() ||
MappingHelper.getBooleanValue( collection.getLazy().value(), getDefaults().isDefaultLazy()); MappingHelper.getBooleanValue( collection.getLazy().value(), getDefaults().isDefaultLazy() );
} }
public boolean isExtraLazy() { public boolean isExtraLazy() {
return ( "extra".equals( collection.getLazy() ) ); return ( "extra".equals( collection.getLazy() ) );
} }
public CollectionElementDomainState getCollectionElementDomainState() { public CollectionElementDomainState getCollectionElementDomainState() {
@ -136,30 +144,37 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
public boolean isSubselectLoadable() { public boolean isSubselectLoadable() {
return "subselect".equals( collection.getFetch() ); return "subselect".equals( collection.getFetch() );
} }
public String getCacheConcurrencyStrategy() { public String getCacheConcurrencyStrategy() {
return collection.getCache() == null ? return collection.getCache() == null ?
null : null :
collection.getCache().getUsage(); collection.getCache().getUsage();
} }
public String getCacheRegionName() { public String getCacheRegionName() {
return collection.getCache() == null ? return collection.getCache() == null ?
null : null :
collection.getCache().getRegion(); collection.getCache().getRegion();
} }
public String getOrderBy() { public String getOrderBy() {
return collection.getOrderBy(); return collection.getOrderBy();
} }
public String getWhere() { public String getWhere() {
return collection.getWhere(); return collection.getWhere();
} }
public String getReferencedPropertyName() { public String getReferencedPropertyName() {
return collection.getKey().getPropertyRef(); return collection.getKey().getPropertyRef();
} }
public boolean isSorted() { public boolean isSorted() {
// SORT // SORT
// unsorted, natural, comparator.class.name // unsorted, natural, comparator.class.name
return ( ! "unsorted".equals( getSortString() ) ); return ( !"unsorted".equals( getSortString() ) );
} }
public Comparator getComparator() { public Comparator getComparator() {
return null; return null;
} }
@ -167,7 +182,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
public String getComparatorClassName() { public String getComparatorClassName() {
String sortString = getSortString(); String sortString = getSortString();
return ( return (
isSorted() && ! "natural".equals( sortString ) ? isSorted() && !"natural".equals( sortString ) ?
sortString : sortString :
null null
); );
@ -178,28 +193,37 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
// collection.getSort() == null ? "unsorted" : collection.getSort(); // collection.getSort() == null ? "unsorted" : collection.getSort();
return "unsorted"; return "unsorted";
} }
public boolean isOrphanDelete() { public boolean isOrphanDelete() {
// ORPHAN DELETE (used for programmer error detection) // ORPHAN DELETE (used for programmer error detection)
return ( getCascade().indexOf( "delete-orphan" ) >= 0 ); return ( getCascade().indexOf( "delete-orphan" ) >= 0 );
} }
public int getBatchSize() { public int getBatchSize() {
return MappingHelper.getIntValue( collection.getBatchSize(), 0 ); return MappingHelper.getIntValue( collection.getBatchSize(), 0 );
} }
@Override @Override
public boolean isEmbedded() { public boolean isEmbedded() {
return collection.isEmbedXml(); return collection.isEmbedXml();
} }
public boolean isOptimisticLocked() { public boolean isOptimisticLocked() {
return collection.isOptimisticLock(); return collection.isOptimisticLock();
} }
public Class getCollectionPersisterClass() { public Class getCollectionPersisterClass() {
String className = collection.getPersister();
ClassLoaderService classLoaderService = getMetadata().getServiceRegistry()
.getService( ClassLoaderService.class );
try { try {
return MappingHelper.getClassValue( collection.getPersister() ); return classLoaderService.classForName( className );
} }
catch (ClassNotFoundException cnfe) { catch ( ClassLoadingException e ) {
throw new MappingException( "Could not find collection persister class: " throw new MappingException(
+ collection.getPersister() ); "Could not find collection persister class: "
+ collection.getPersister()
);
} }
} }
@ -216,6 +240,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
//} //}
return new HashMap(); return new HashMap();
} }
public java.util.Set getSynchronizedTables() { public java.util.Set getSynchronizedTables() {
java.util.Set<String> synchronizedTables = new HashSet<String>(); java.util.Set<String> synchronizedTables = new HashSet<String>();
for ( XMLSynchronizeElement sync : collection.getSynchronize() ) { for ( XMLSynchronizeElement sync : collection.getSynchronize() ) {
@ -234,6 +259,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
collection.getSqlInsert().getCheck().value() collection.getSqlInsert().getCheck().value()
); );
} }
public CustomSQL getCustomSQLUpdate() { public CustomSQL getCustomSQLUpdate() {
XMLSqlUpdateElement sqlUpdate = collection.getSqlUpdate(); XMLSqlUpdateElement sqlUpdate = collection.getSqlUpdate();
return sqlUpdate == null ? return sqlUpdate == null ?
@ -244,6 +270,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
collection.getSqlUpdate().getCheck().value() collection.getSqlUpdate().getCheck().value()
); );
} }
public CustomSQL getCustomSQLDelete() { public CustomSQL getCustomSQLDelete() {
XMLSqlDeleteElement sqlDelete = collection.getSqlDelete(); XMLSqlDeleteElement sqlDelete = collection.getSqlDelete();
return sqlDelete == null ? return sqlDelete == null ?
@ -254,6 +281,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
collection.getSqlDelete().getCheck().value() collection.getSqlDelete().getCheck().value()
); );
} }
public CustomSQL getCustomSQLDeleteAll() { public CustomSQL getCustomSQLDeleteAll() {
XMLSqlDeleteAllElement sqlDeleteAll = collection.getSqlDeleteAll(); XMLSqlDeleteAllElement sqlDeleteAll = collection.getSqlDeleteAll();
return sqlDeleteAll == null ? return sqlDeleteAll == null ?
@ -264,6 +292,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
collection.getSqlDeleteAll().getCheck().value() collection.getSqlDeleteAll().getCheck().value()
); );
} }
public String getLoaderName() { public String getLoaderName() {
return collection.getLoader() == null ? return collection.getLoader() == null ?
null : null :
@ -278,6 +307,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
//TODO: implement //TODO: implement
return false; return false;
} }
public String getUnsavedValue() { public String getUnsavedValue() {
//TODO: implement //TODO: implement
return null; return null;

View File

@ -36,29 +36,34 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLCla
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLTimestamp; 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.XMLHibernateMapping.XMLClass.XMLVersion;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement; 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.source.util.MappingHelper;
import org.hibernate.metamodel.state.domain.SimpleAttributeDomainState; import org.hibernate.metamodel.state.domain.SimpleAttributeDomainState;
/** /**
* @author Gail Badner * @author Gail Badner
*/ */
public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainState implements SimpleAttributeDomainState { public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainState
implements SimpleAttributeDomainState {
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private final boolean isLazy; private final boolean isLazy;
private final PropertyGeneration propertyGeneration; private final PropertyGeneration propertyGeneration;
private final boolean isInsertable; private final boolean isInsertable;
private final boolean isUpdateable; private final boolean isUpdateable;
public HbmSimpleAttributeDomainState(MappingDefaults defaults, public HbmSimpleAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLId id) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLId id) {
super( super(
metadata,
defaults, defaults,
attribute, attribute,
id.getNode(), id.getNode(),
HbmHelper.extractMetas( id.getMeta(), entityMetaAttributes ), HbmHelper.extractMetas( id.getMeta(), entityMetaAttributes ),
HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ) , HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ),
true true
); );
@ -74,14 +79,17 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
this.isUpdateable = false; this.isUpdateable = false;
} }
public HbmSimpleAttributeDomainState(MappingDefaults defaults, public HbmSimpleAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLDiscriminator discriminator) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLDiscriminator discriminator) {
super( super(
defaults, attribute, null, null, null, true metadata, defaults, attribute, null, null, null, true
); );
this.hibernateTypeDescriptor.setTypeName( discriminator.getType() == null ? "string" : discriminator.getType() ); this.hibernateTypeDescriptor
.setTypeName( discriminator.getType() == null ? "string" : discriminator.getType() );
this.isLazy = false; this.isLazy = false;
this.propertyGeneration = PropertyGeneration.NEVER; this.propertyGeneration = PropertyGeneration.NEVER;
@ -89,17 +97,20 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
this.isUpdateable = false; this.isUpdateable = false;
} }
public HbmSimpleAttributeDomainState(MappingDefaults defaults, public HbmSimpleAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLVersion version) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLVersion version) {
super( super(
metadata,
defaults, defaults,
attribute, attribute,
version.getNode(), version.getNode(),
HbmHelper.extractMetas( version.getMeta(), entityMetaAttributes ), HbmHelper.extractMetas( version.getMeta(), entityMetaAttributes ),
HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ) , HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ),
true true
); );
this.hibernateTypeDescriptor.setTypeName( version.getType() == null ? "integer" : version.getType() ); this.hibernateTypeDescriptor.setTypeName( version.getType() == null ? "integer" : version.getType() );
@ -108,7 +119,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
// for version properties marked as being generated, make sure they are "always" // for version properties marked as being generated, make sure they are "always"
// generated; aka, "insert" is invalid; this is dis-allowed by the DTD, // generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
// but just to make sure. // but just to make sure.
this.propertyGeneration = PropertyGeneration.parse( version.getGenerated().value() ); this.propertyGeneration = PropertyGeneration.parse( version.getGenerated().value() );
if ( propertyGeneration == PropertyGeneration.INSERT ) { if ( propertyGeneration == PropertyGeneration.INSERT ) {
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" ); throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
} }
@ -116,12 +127,15 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
this.isUpdateable = true; this.isUpdateable = true;
} }
public HbmSimpleAttributeDomainState(MappingDefaults defaults, public HbmSimpleAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLTimestamp timestamp) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLTimestamp timestamp) {
super( super(
metadata,
defaults, defaults,
attribute, attribute,
timestamp.getNode(), timestamp.getNode(),
@ -136,7 +150,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
// for version properties marked as being generated, make sure they are "always" // for version properties marked as being generated, make sure they are "always"
// generated; aka, "insert" is invalid; this is dis-allowed by the DTD, // generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
// but just to make sure. // but just to make sure.
this.propertyGeneration = PropertyGeneration.parse( timestamp.getGenerated().value() ); this.propertyGeneration = PropertyGeneration.parse( timestamp.getGenerated().value() );
if ( propertyGeneration == PropertyGeneration.INSERT ) { if ( propertyGeneration == PropertyGeneration.INSERT ) {
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" ); throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
} }
@ -144,11 +158,14 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
this.isUpdateable = true; this.isUpdateable = true;
} }
public HbmSimpleAttributeDomainState(MappingDefaults defaults, public HbmSimpleAttributeDomainState(
org.hibernate.metamodel.domain.Attribute attribute, MetadataImpl metadata,
Map<String, MetaAttribute> entityMetaAttributes, MappingDefaults defaults,
XMLPropertyElement property) { org.hibernate.metamodel.domain.Attribute attribute,
Map<String, MetaAttribute> entityMetaAttributes,
XMLPropertyElement property) {
super( super(
metadata,
defaults, defaults,
attribute, attribute,
property.getNode(), property.getNode(),
@ -161,12 +178,12 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
if ( propertyGeneration == PropertyGeneration.ALWAYS || propertyGeneration == PropertyGeneration.INSERT ) { if ( propertyGeneration == PropertyGeneration.ALWAYS || propertyGeneration == PropertyGeneration.INSERT ) {
// generated properties can *never* be insertable. // generated properties can *never* be insertable.
if (property.isInsert() != null && property.isInsert()) { if ( property.isInsert() != null && property.isInsert() ) {
// the user specifically supplied insert="true", which constitutes an illegal combo // the user specifically supplied insert="true", which constitutes an illegal combo
throw new MappingException( throw new MappingException(
"cannot specify both insert=\"true\" and generated=\"" + propertyGeneration.getName() + "cannot specify both insert=\"true\" and generated=\"" + propertyGeneration.getName() +
"\" for property: " + "\" for property: " +
getAttribute().getName() getAttribute().getName()
); );
} }
isInsertable = false; isInsertable = false;
@ -175,13 +192,13 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
isInsertable = MappingHelper.getBooleanValue( property.isInsert(), true ); isInsertable = MappingHelper.getBooleanValue( property.isInsert(), true );
} }
if ( propertyGeneration == PropertyGeneration.ALWAYS ) { if ( propertyGeneration == PropertyGeneration.ALWAYS ) {
if (property.isUpdate() != null && property.isUpdate()) { if ( property.isUpdate() != null && property.isUpdate() ) {
// the user specifically supplied update="true", // the user specifically supplied update="true",
// which constitutes an illegal combo // which constitutes an illegal combo
throw new MappingException( throw new MappingException(
"cannot specify both update=\"true\" and generated=\"" + propertyGeneration.getName() + "cannot specify both update=\"true\" and generated=\"" + propertyGeneration.getName() +
"\" for property: " + "\" for property: " +
getAttribute().getName() getAttribute().getName()
); );
} }
isUpdateable = false; isUpdateable = false;
@ -206,9 +223,11 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
public PropertyGeneration getPropertyGeneration() { public PropertyGeneration getPropertyGeneration() {
return propertyGeneration; return propertyGeneration;
} }
public boolean isInsertable() { public boolean isInsertable() {
return isInsertable; return isInsertable;
} }
public boolean isUpdateable() { public boolean isUpdateable() {
return isUpdateable; return isUpdateable;
} }
@ -221,6 +240,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
//TODO: implement //TODO: implement
return false; return false;
} }
public String getUnsavedValue() { public String getUnsavedValue() {
//TODO: implement //TODO: implement
return null; return null;

View File

@ -1,97 +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.source.util;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.hibernate.internal.util.ReflectHelper;
/**
* Helper class for working with DOM documents.
*
* @author Steve Ebersole
*/
public class DomHelper {
private DomHelper() {
}
public static String extractAttributeValue(Element element, String attributeName) {
return extractAttributeValue( element, attributeName, null );
}
public static String extractAttributeValue(Element element, String attributeName, String defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : attributeValue;
}
public static int extractIntAttributeValue(Element element, String attributeName) {
return extractIntAttributeValue( element, attributeName, -1 );
}
public static int extractIntAttributeValue(Element element, String attributeName, int defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : Integer.valueOf( attributeValue );
}
public static boolean extractBooleanAttributeValue(Element element, String attributeName) {
return extractBooleanAttributeValue( element, attributeName, false );
}
public static boolean extractBooleanAttributeValue(Element element, String attributeName, boolean defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : Boolean.valueOf( attributeValue );
}
public static Class extractClassAttributeValue(Element element, String attributeName)
throws ClassNotFoundException {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return (
attributeValue == null ?
null :
ReflectHelper.classForName( attributeValue )
);
}
public static Set<String> extractUniqueAttributeValueTokens(Element element, String attributeName, String delimiters) {
String attributeValue = element.attributeValue( attributeName );
if ( attributeValue == null ) {
return Collections.emptySet();
}
else {
StringTokenizer tokenizer = new StringTokenizer( attributeValue, delimiters );
Set<String> tokens = new HashSet<String>();
while ( tokenizer.hasMoreTokens() ) {
tokens.add( tokenizer.nextToken() );
}
return tokens;
}
}
}

View File

@ -28,12 +28,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.dom4j.Element;
import org.hibernate.internal.util.ReflectHelper;
/** /**
* Helper class for working with DOM documents. * Helper class.
* *
* @author Gail Badner * @author Gail Badner
*/ */
@ -41,41 +37,14 @@ public class MappingHelper {
private MappingHelper() { private MappingHelper() {
} }
public static String extractAttributeValue(Element element, String attributeName) {
return extractAttributeValue( element, attributeName, null );
}
public static String extractAttributeValue(Element element, String attributeName, String defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : attributeValue;
}
public static String getStringValue(String value, String defaultValue) { public static String getStringValue(String value, String defaultValue) {
return value == null ? defaultValue : value; return value == null ? defaultValue : value;
} }
public static int extractIntAttributeValue(Element element, String attributeName) {
return extractIntAttributeValue( element, attributeName, -1 );
}
public static int extractIntAttributeValue(Element element, String attributeName, int defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : Integer.valueOf( attributeValue );
}
public static int getIntValue(String value, int defaultValue) { public static int getIntValue(String value, int defaultValue) {
return value == null ? defaultValue : Integer.parseInt( value ); return value == null ? defaultValue : Integer.parseInt( value );
} }
public static boolean extractBooleanAttributeValue(Element element, String attributeName) {
return extractBooleanAttributeValue( element, attributeName, false );
}
public static boolean extractBooleanAttributeValue(Element element, String attributeName, boolean defaultValue) {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return attributeValue == null ? defaultValue : Boolean.valueOf( attributeValue );
}
public static boolean getBooleanValue(String value, boolean defaultValue) { public static boolean getBooleanValue(String value, boolean defaultValue) {
return value == null ? defaultValue : Boolean.valueOf( value ); return value == null ? defaultValue : Boolean.valueOf( value );
} }
@ -84,25 +53,6 @@ public class MappingHelper {
return value == null ? defaultValue : value; return value == null ? defaultValue : value;
} }
public static Class extractClassAttributeValue(Element element, String attributeName)
throws ClassNotFoundException {
String attributeValue = ( element == null ? null : element.attributeValue( attributeName ) );
return (
attributeValue == null ?
null :
ReflectHelper.classForName( attributeValue )
);
}
public static Class getClassValue(String className)
throws ClassNotFoundException {
return (
className == null ?
null :
ReflectHelper.classForName( className )
);
}
public static Set<String> getStringValueTokens(String str, String delimiters) { public static Set<String> getStringValueTokens(String str, String delimiters) {
if ( str == null ) { if ( str == null ) {
return Collections.emptySet(); return Collections.emptySet();