Removing obsolete DomHelper. Removing dom4j methods from MappingHelper. Removing getClassValue, because ClassLoaderService should be used
This commit is contained in:
parent
095e858f77
commit
0278966b2e
|
@ -44,18 +44,39 @@ 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.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.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.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
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
abstract class AbstractEntityBinder {
|
||||
private final HibernateMappingBinder hibernateMappingBinder;
|
||||
private final Schema.Name schemaName;
|
||||
|
@ -88,6 +109,7 @@ abstract class AbstractEntityBinder {
|
|||
protected Schema.Name getSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
|
||||
protected NamingStrategy getNamingStrategy() {
|
||||
return getMetadata().getNamingStrategy();
|
||||
}
|
||||
|
@ -151,7 +173,7 @@ abstract class AbstractEntityBinder {
|
|||
if ( nodeName == null ) {
|
||||
nodeName = StringHelper.unqualify( entityBinding.getEntity().getName() );
|
||||
}
|
||||
entityBinding.getEntity().getDom4jEntitySpecifics().setNodeName(nodeName);
|
||||
entityBinding.getEntity().getDom4jEntitySpecifics().setNodeName( nodeName );
|
||||
|
||||
XMLTuplizerElement tuplizer = locateTuplizerDefinition( entityClazz, EntityMode.DOM4J );
|
||||
if ( tuplizer != null ) {
|
||||
|
@ -176,7 +198,7 @@ abstract class AbstractEntityBinder {
|
|||
* @return The tuplizer element, or null.
|
||||
*/
|
||||
private static XMLTuplizerElement locateTuplizerDefinition(XMLHibernateMapping.XMLClass container,
|
||||
EntityMode entityMode) {
|
||||
EntityMode entityMode) {
|
||||
for ( XMLTuplizerElement tuplizer : container.getTuplizer() ) {
|
||||
if ( entityMode.toString().equals( tuplizer.getEntityMode() ) ) {
|
||||
return tuplizer;
|
||||
|
@ -216,7 +238,9 @@ abstract class AbstractEntityBinder {
|
|||
String physicalTableName;
|
||||
if ( entityClazz.getTable() == null ) {
|
||||
logicalTableName = StringHelper.unqualify( entityName );
|
||||
physicalTableName = getHibernateXmlBinder().getMetadata().getNamingStrategy().classToTableName( entityName );
|
||||
physicalTableName = getHibernateXmlBinder().getMetadata()
|
||||
.getNamingStrategy()
|
||||
.classToTableName( entityName );
|
||||
}
|
||||
else {
|
||||
logicalTableName = entityClazz.getTable();
|
||||
|
@ -296,7 +320,7 @@ abstract class AbstractEntityBinder {
|
|||
//hibernateMappingBinder.getHibernateXmlBinder().getMetadata().addCollection( attributeBinding );
|
||||
}
|
||||
else if ( XMLManyToOneElement.class.isInstance( attribute ) ) {
|
||||
XMLManyToOneElement manyToOne = XMLManyToOneElement.class.cast( attribute );
|
||||
XMLManyToOneElement manyToOne = XMLManyToOneElement.class.cast( attribute );
|
||||
ManyToOneAttributeBinding manyToOneBinding = entityBinding.makeManyToOneAttributeBinding( manyToOne.getName() );
|
||||
bindManyToOne( manyToOne, manyToOneBinding, entityBinding );
|
||||
attributeBinding = manyToOneBinding;
|
||||
|
@ -424,6 +448,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -452,6 +477,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -480,6 +506,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -508,6 +535,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( attributeName ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -535,6 +563,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmSimpleAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( property.getName() ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -564,6 +593,7 @@ PrimitiveArray
|
|||
// domain model has not been bound yet
|
||||
collectionBinding.initialize(
|
||||
new HbmPluralAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
collection,
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -586,6 +616,7 @@ PrimitiveArray
|
|||
if ( attributeBinding.getAttribute() == null ) {
|
||||
attributeBinding.initialize(
|
||||
new HbmManyToOneAttributeDomainState(
|
||||
hibernateMappingBinder.getHibernateXmlBinder().getMetadata(),
|
||||
hibernateMappingBinder,
|
||||
entityBinding.getEntity().getOrCreateSingularAttribute( manyToOne.getName() ),
|
||||
entityBinding.getMetaAttributes(),
|
||||
|
@ -648,8 +679,8 @@ PrimitiveArray
|
|||
|
||||
|
||||
// protected HbmRelationalState processValues(Element identifierElement, TableSpecification baseTable, String propertyPath, boolean isSimplePrimaryKey) {
|
||||
// first boolean (false here) indicates that by default columns are nullable
|
||||
// second boolean (true here) indicates that by default column names should be guessed
|
||||
// first boolean (false here) indicates that by default columns are nullable
|
||||
// second boolean (true here) indicates that by default column names should be guessed
|
||||
// todo : logical 1-1 handling
|
||||
// final Attribute uniqueAttribute = node.attribute( "unique" );
|
||||
// if ( uniqueAttribute != null
|
||||
|
@ -657,8 +688,7 @@ PrimitiveArray
|
|||
// && ManyToOne.class.isInstance( simpleValue ) ) {
|
||||
// ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
|
||||
// }
|
||||
//return processValues( identifierElement, baseTable, false, true, propertyPath, isSimplePrimaryKey );
|
||||
|
||||
//return processValues( identifierElement, baseTable, false, true, propertyPath, isSimplePrimaryKey );
|
||||
|
||||
|
||||
}
|
|
@ -36,7 +36,6 @@ import org.hibernate.metamodel.binding.CustomSQL;
|
|||
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass;
|
||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLMetaElement;
|
||||
import org.hibernate.metamodel.source.util.DomHelper;
|
||||
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) {
|
||||
Map<String, MetaAttribute> extractedMetas = new HashMap<String, MetaAttribute>();
|
||||
extractedMetas.putAll( baseline );
|
||||
for ( XMLMetaElement meta : metaList) {
|
||||
for ( XMLMetaElement meta : metaList ) {
|
||||
boolean inheritable = meta.isInherit();
|
||||
if ( onlyInheritable & !inheritable ) {
|
||||
continue;
|
||||
|
@ -94,16 +93,18 @@ public class HbmHelper {
|
|||
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 );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static String getClassName(Attribute att, String unqualifiedPackageName) {
|
||||
if ( att == null ) return null;
|
||||
if ( att == null ) {
|
||||
return null;
|
||||
}
|
||||
return getClassName( att.getValue(), unqualifiedPackageName );
|
||||
}
|
||||
|
||||
|
@ -117,18 +118,10 @@ public class HbmHelper {
|
|||
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 ) );
|
||||
}
|
||||
|
||||
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) {
|
||||
return MappingHelper.getStringValue(
|
||||
access,
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.hibernate.metamodel.source.util.MappingHelper;
|
|||
/**
|
||||
* 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 JaxbRoot<XMLHibernateMapping> jaxbRoot;
|
||||
private final XMLHibernateMapping hibernateMapping;
|
||||
|
|
|
@ -25,9 +25,11 @@ package org.hibernate.metamodel.source.hbm.state.domain;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.Metadata;
|
||||
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;
|
||||
|
||||
|
@ -35,6 +37,7 @@ import org.hibernate.metamodel.state.domain.AttributeDomainState;
|
|||
* @author Gail Badner
|
||||
*/
|
||||
public abstract class AbstractHbmAttributeDomainState implements AttributeDomainState {
|
||||
private final MetadataImpl metadata;
|
||||
private final MappingDefaults defaults;
|
||||
private final Attribute attribute;
|
||||
private final String nodeName;
|
||||
|
@ -42,12 +45,15 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
|
|||
private final boolean isOptimisticLockable;
|
||||
private final Map<String, MetaAttribute> metaAttributes;
|
||||
|
||||
public AbstractHbmAttributeDomainState(MappingDefaults defaults,
|
||||
Attribute attribute,
|
||||
String nodeName,
|
||||
Map<String, MetaAttribute> metaAttributes,
|
||||
String accessorName,
|
||||
boolean isOptimisticLockable) {
|
||||
public AbstractHbmAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
Attribute attribute,
|
||||
String nodeName,
|
||||
Map<String, MetaAttribute> metaAttributes,
|
||||
String accessorName,
|
||||
boolean isOptimisticLockable) {
|
||||
this.metadata = metadata;
|
||||
this.defaults = defaults;
|
||||
this.attribute = attribute;
|
||||
this.nodeName = MappingHelper.getStringValue( nodeName, attribute.getName() );
|
||||
|
@ -56,12 +62,18 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
|
|||
this.isOptimisticLockable = isOptimisticLockable;
|
||||
}
|
||||
|
||||
public MetadataImpl getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
protected final MappingDefaults getDefaults() {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public final Attribute getAttribute() {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
public final String getPropertyAccessorName() {
|
||||
return accessorName;
|
||||
}
|
||||
|
@ -70,9 +82,11 @@ public abstract class AbstractHbmAttributeDomainState implements AttributeDomain
|
|||
//TODO: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isOptimisticLockable() {
|
||||
return isOptimisticLockable;
|
||||
}
|
||||
|
||||
public final String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.FetchMode;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
|
||||
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;
|
||||
|
||||
|
@ -54,22 +54,27 @@ public class HbmManyToOneAttributeDomainState
|
|||
private final boolean isInsertable;
|
||||
private final boolean isUpdateable;
|
||||
|
||||
public HbmManyToOneAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLManyToOneElement manyToOne) {
|
||||
public HbmManyToOneAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLManyToOneElement manyToOne) {
|
||||
super(
|
||||
metadata,
|
||||
defaults,
|
||||
attribute,
|
||||
manyToOne.getNode(),
|
||||
HbmHelper.extractMetas( manyToOne.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( manyToOne.getAccess(), manyToOne.isEmbedXml(), defaults.getDefaultAccess() ),
|
||||
HbmHelper.getPropertyAccessorName(
|
||||
manyToOne.getAccess(), manyToOne.isEmbedXml(), defaults.getDefaultAccess()
|
||||
),
|
||||
manyToOne.isOptimisticLock()
|
||||
);
|
||||
fetchMode = getFetchMode( manyToOne );
|
||||
isUnwrapProxy = manyToOne.getLazy() != null && "no-proxy".equals( manyToOne.getLazy().value() );
|
||||
//TODO: better to degrade to lazy="false" if uninstrumented
|
||||
isLazy = manyToOne.getLazy() == null ||
|
||||
isLazy = manyToOne.getLazy() == null ||
|
||||
isUnwrapProxy ||
|
||||
"proxy".equals( manyToOne.getLazy().value() );
|
||||
cascade = MappingHelper.getStringValue( manyToOne.getCascade(), defaults.getDefaultCascade() );
|
||||
|
@ -78,8 +83,8 @@ public class HbmManyToOneAttributeDomainState
|
|||
referencedPropertyName = manyToOne.getPropertyRef();
|
||||
referencedEntityName = (
|
||||
manyToOne.getEntityName() == null ?
|
||||
HbmHelper.getClassName( manyToOne.getClazz(), getDefaults().getPackageName() ) :
|
||||
manyToOne.getEntityName().intern()
|
||||
HbmHelper.getClassName( manyToOne.getClazz(), getDefaults().getPackageName() ) :
|
||||
manyToOne.getEntityName().intern()
|
||||
);
|
||||
ignoreNotFound = "ignore".equals( manyToOne.getNotFound().value() );
|
||||
isInsertable = manyToOne.isInsert();
|
||||
|
@ -156,6 +161,7 @@ public class HbmManyToOneAttributeDomainState
|
|||
//TODO: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getUnsavedValue() {
|
||||
//TODO: implement
|
||||
return null;
|
||||
|
|
|
@ -24,14 +24,13 @@
|
|||
package org.hibernate.metamodel.source.hbm.state.domain;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
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.ElementCollectionElement;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||
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.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;
|
||||
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainState implements PluralAttributeDomainState {
|
||||
public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainState
|
||||
implements PluralAttributeDomainState {
|
||||
private final XMLBagElement collection;
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private final String cascade;
|
||||
|
||||
public HbmPluralAttributeDomainState(MappingDefaults defaults,
|
||||
XMLBagElement collection,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
Attribute attribute) {
|
||||
public HbmPluralAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults mappingDefaults,
|
||||
XMLBagElement collection,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
Attribute attribute) {
|
||||
super(
|
||||
defaults,
|
||||
metadata,
|
||||
mappingDefaults,
|
||||
attribute,
|
||||
collection.getNode(),
|
||||
HbmHelper.extractMetas( collection.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( collection.getAccess(), collection.isEmbedXml(), defaults.getDefaultAccess() ),
|
||||
HbmHelper.getPropertyAccessorName(
|
||||
collection.getAccess(), collection.isEmbedXml(), mappingDefaults.getDefaultAccess()
|
||||
),
|
||||
collection.isOptimisticLock()
|
||||
);
|
||||
this.collection = collection;
|
||||
// TODO: is collection.getCollectionType() correct here?
|
||||
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" );
|
||||
//if ( typeNode != null ) {
|
||||
// TODO: implement when typedef binding is implemented
|
||||
/*
|
||||
String typeName = typeNode.getValue();
|
||||
TypeDef typeDef = mappings.getTypeDef( typeName );
|
||||
if ( typeDef != null ) {
|
||||
collectionBinding.setTypeName( typeDef.getTypeClass() );
|
||||
collectionBinding.setTypeParameters( typeDef.getParameters() );
|
||||
}
|
||||
else {
|
||||
collectionBinding.setTypeName( typeName );
|
||||
}
|
||||
*/
|
||||
// TODO: implement when typedef binding is implemented
|
||||
/*
|
||||
String typeName = typeNode.getValue();
|
||||
TypeDef typeDef = mappings.getTypeDef( typeName );
|
||||
if ( typeDef != null ) {
|
||||
collectionBinding.setTypeName( typeDef.getTypeClass() );
|
||||
collectionBinding.setTypeParameters( typeDef.getParameters() );
|
||||
}
|
||||
else {
|
||||
collectionBinding.setTypeName( typeName );
|
||||
}
|
||||
*/
|
||||
//}
|
||||
//TODO: fix this!!!
|
||||
this.hibernateTypeDescriptor.setTypeName( collection.getCollectionType() );
|
||||
|
@ -98,7 +105,8 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
fetchMode = "join".equals( collection.getFetch() ) ? FetchMode.JOIN : FetchMode.SELECT;
|
||||
}
|
||||
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 ) ) {
|
||||
fetchMode = FetchMode.DEFAULT;
|
||||
}
|
||||
|
@ -114,11 +122,11 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
|
||||
public boolean isLazy() {
|
||||
return isExtraLazy() ||
|
||||
MappingHelper.getBooleanValue( collection.getLazy().value(), getDefaults().isDefaultLazy());
|
||||
MappingHelper.getBooleanValue( collection.getLazy().value(), getDefaults().isDefaultLazy() );
|
||||
}
|
||||
|
||||
public boolean isExtraLazy() {
|
||||
return ( "extra".equals( collection.getLazy() ) );
|
||||
return ( "extra".equals( collection.getLazy() ) );
|
||||
}
|
||||
|
||||
public CollectionElementDomainState getCollectionElementDomainState() {
|
||||
|
@ -136,30 +144,37 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
public boolean isSubselectLoadable() {
|
||||
return "subselect".equals( collection.getFetch() );
|
||||
}
|
||||
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return collection.getCache() == null ?
|
||||
null :
|
||||
collection.getCache().getUsage();
|
||||
}
|
||||
|
||||
public String getCacheRegionName() {
|
||||
return collection.getCache() == null ?
|
||||
null :
|
||||
collection.getCache().getRegion();
|
||||
}
|
||||
|
||||
public String getOrderBy() {
|
||||
return collection.getOrderBy();
|
||||
}
|
||||
|
||||
public String getWhere() {
|
||||
return collection.getWhere();
|
||||
}
|
||||
|
||||
public String getReferencedPropertyName() {
|
||||
return collection.getKey().getPropertyRef();
|
||||
}
|
||||
|
||||
public boolean isSorted() {
|
||||
// SORT
|
||||
// unsorted, natural, comparator.class.name
|
||||
return ( ! "unsorted".equals( getSortString() ) );
|
||||
return ( !"unsorted".equals( getSortString() ) );
|
||||
}
|
||||
|
||||
public Comparator getComparator() {
|
||||
return null;
|
||||
}
|
||||
|
@ -167,7 +182,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
public String getComparatorClassName() {
|
||||
String sortString = getSortString();
|
||||
return (
|
||||
isSorted() && ! "natural".equals( sortString ) ?
|
||||
isSorted() && !"natural".equals( sortString ) ?
|
||||
sortString :
|
||||
null
|
||||
);
|
||||
|
@ -178,28 +193,37 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
// collection.getSort() == null ? "unsorted" : collection.getSort();
|
||||
return "unsorted";
|
||||
}
|
||||
|
||||
public boolean isOrphanDelete() {
|
||||
// ORPHAN DELETE (used for programmer error detection)
|
||||
return ( getCascade().indexOf( "delete-orphan" ) >= 0 );
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return MappingHelper.getIntValue( collection.getBatchSize(), 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmbedded() {
|
||||
return collection.isEmbedXml();
|
||||
}
|
||||
|
||||
public boolean isOptimisticLocked() {
|
||||
return collection.isOptimisticLock();
|
||||
}
|
||||
|
||||
public Class getCollectionPersisterClass() {
|
||||
String className = collection.getPersister();
|
||||
ClassLoaderService classLoaderService = getMetadata().getServiceRegistry()
|
||||
.getService( ClassLoaderService.class );
|
||||
try {
|
||||
return MappingHelper.getClassValue( collection.getPersister() );
|
||||
return classLoaderService.classForName( className );
|
||||
}
|
||||
catch (ClassNotFoundException cnfe) {
|
||||
throw new MappingException( "Could not find collection persister class: "
|
||||
+ collection.getPersister() );
|
||||
catch ( ClassLoadingException e ) {
|
||||
throw new MappingException(
|
||||
"Could not find collection persister class: "
|
||||
+ collection.getPersister()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,6 +240,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
//}
|
||||
return new HashMap();
|
||||
}
|
||||
|
||||
public java.util.Set getSynchronizedTables() {
|
||||
java.util.Set<String> synchronizedTables = new HashSet<String>();
|
||||
for ( XMLSynchronizeElement sync : collection.getSynchronize() ) {
|
||||
|
@ -234,6 +259,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
collection.getSqlInsert().getCheck().value()
|
||||
);
|
||||
}
|
||||
|
||||
public CustomSQL getCustomSQLUpdate() {
|
||||
XMLSqlUpdateElement sqlUpdate = collection.getSqlUpdate();
|
||||
return sqlUpdate == null ?
|
||||
|
@ -244,6 +270,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
collection.getSqlUpdate().getCheck().value()
|
||||
);
|
||||
}
|
||||
|
||||
public CustomSQL getCustomSQLDelete() {
|
||||
XMLSqlDeleteElement sqlDelete = collection.getSqlDelete();
|
||||
return sqlDelete == null ?
|
||||
|
@ -254,6 +281,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
collection.getSqlDelete().getCheck().value()
|
||||
);
|
||||
}
|
||||
|
||||
public CustomSQL getCustomSQLDeleteAll() {
|
||||
XMLSqlDeleteAllElement sqlDeleteAll = collection.getSqlDeleteAll();
|
||||
return sqlDeleteAll == null ?
|
||||
|
@ -264,6 +292,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
collection.getSqlDeleteAll().getCheck().value()
|
||||
);
|
||||
}
|
||||
|
||||
public String getLoaderName() {
|
||||
return collection.getLoader() == null ?
|
||||
null :
|
||||
|
@ -278,6 +307,7 @@ public class HbmPluralAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
//TODO: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getUnsavedValue() {
|
||||
//TODO: implement
|
||||
return null;
|
||||
|
|
|
@ -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.XMLVersion;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @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 boolean isLazy;
|
||||
private final PropertyGeneration propertyGeneration;
|
||||
private final boolean isInsertable;
|
||||
private final boolean isUpdateable;
|
||||
|
||||
public HbmSimpleAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLId id) {
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLId id) {
|
||||
super(
|
||||
metadata,
|
||||
defaults,
|
||||
attribute,
|
||||
id.getNode(),
|
||||
HbmHelper.extractMetas( id.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ) ,
|
||||
HbmHelper.getPropertyAccessorName( id.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
true
|
||||
);
|
||||
|
||||
|
@ -74,14 +79,17 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = false;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLDiscriminator discriminator) {
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLDiscriminator discriminator) {
|
||||
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.propertyGeneration = PropertyGeneration.NEVER;
|
||||
|
@ -89,17 +97,20 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = false;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLVersion version) {
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLVersion version) {
|
||||
|
||||
super(
|
||||
metadata,
|
||||
defaults,
|
||||
attribute,
|
||||
version.getNode(),
|
||||
HbmHelper.extractMetas( version.getMeta(), entityMetaAttributes ),
|
||||
HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ) ,
|
||||
HbmHelper.getPropertyAccessorName( version.getAccess(), false, defaults.getDefaultAccess() ),
|
||||
true
|
||||
);
|
||||
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"
|
||||
// generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
|
||||
// but just to make sure.
|
||||
this.propertyGeneration = PropertyGeneration.parse( version.getGenerated().value() );
|
||||
this.propertyGeneration = PropertyGeneration.parse( version.getGenerated().value() );
|
||||
if ( propertyGeneration == PropertyGeneration.INSERT ) {
|
||||
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
|
||||
}
|
||||
|
@ -116,12 +127,15 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = true;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLTimestamp timestamp) {
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLTimestamp timestamp) {
|
||||
|
||||
super(
|
||||
metadata,
|
||||
defaults,
|
||||
attribute,
|
||||
timestamp.getNode(),
|
||||
|
@ -136,7 +150,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
// for version properties marked as being generated, make sure they are "always"
|
||||
// generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
|
||||
// but just to make sure.
|
||||
this.propertyGeneration = PropertyGeneration.parse( timestamp.getGenerated().value() );
|
||||
this.propertyGeneration = PropertyGeneration.parse( timestamp.getGenerated().value() );
|
||||
if ( propertyGeneration == PropertyGeneration.INSERT ) {
|
||||
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
|
||||
}
|
||||
|
@ -144,11 +158,14 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
this.isUpdateable = true;
|
||||
}
|
||||
|
||||
public HbmSimpleAttributeDomainState(MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLPropertyElement property) {
|
||||
public HbmSimpleAttributeDomainState(
|
||||
MetadataImpl metadata,
|
||||
MappingDefaults defaults,
|
||||
org.hibernate.metamodel.domain.Attribute attribute,
|
||||
Map<String, MetaAttribute> entityMetaAttributes,
|
||||
XMLPropertyElement property) {
|
||||
super(
|
||||
metadata,
|
||||
defaults,
|
||||
attribute,
|
||||
property.getNode(),
|
||||
|
@ -161,12 +178,12 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
|
||||
if ( propertyGeneration == PropertyGeneration.ALWAYS || propertyGeneration == PropertyGeneration.INSERT ) {
|
||||
// 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
|
||||
throw new MappingException(
|
||||
"cannot specify both insert=\"true\" and generated=\"" + propertyGeneration.getName() +
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
);
|
||||
}
|
||||
isInsertable = false;
|
||||
|
@ -175,13 +192,13 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
isInsertable = MappingHelper.getBooleanValue( property.isInsert(), true );
|
||||
}
|
||||
if ( propertyGeneration == PropertyGeneration.ALWAYS ) {
|
||||
if (property.isUpdate() != null && property.isUpdate()) {
|
||||
if ( property.isUpdate() != null && property.isUpdate() ) {
|
||||
// the user specifically supplied update="true",
|
||||
// which constitutes an illegal combo
|
||||
throw new MappingException(
|
||||
"cannot specify both update=\"true\" and generated=\"" + propertyGeneration.getName() +
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
"\" for property: " +
|
||||
getAttribute().getName()
|
||||
);
|
||||
}
|
||||
isUpdateable = false;
|
||||
|
@ -206,9 +223,11 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
public PropertyGeneration getPropertyGeneration() {
|
||||
return propertyGeneration;
|
||||
}
|
||||
|
||||
public boolean isInsertable() {
|
||||
return isInsertable;
|
||||
}
|
||||
|
||||
public boolean isUpdateable() {
|
||||
return isUpdateable;
|
||||
}
|
||||
|
@ -221,6 +240,7 @@ public class HbmSimpleAttributeDomainState extends AbstractHbmAttributeDomainSta
|
|||
//TODO: implement
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getUnsavedValue() {
|
||||
//TODO: implement
|
||||
return null;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,12 +28,8 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
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
|
||||
*/
|
||||
|
@ -41,41 +37,14 @@ public class 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) {
|
||||
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) {
|
||||
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) {
|
||||
return value == null ? defaultValue : Boolean.valueOf( value );
|
||||
}
|
||||
|
@ -84,25 +53,6 @@ public class MappingHelper {
|
|||
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) {
|
||||
if ( str == null ) {
|
||||
return Collections.emptySet();
|
||||
|
|
Loading…
Reference in New Issue