Walks an XML mapping document and produces the Hibernate configuration-time metamodel (the
classes in the
| Method from org.hibernate.cfg.HbmBinder Detail: |
public static void bindAny(Element node,
Any any,
boolean isNullable,
Mappings mappings) throws MappingException {
any.setIdentifierType( getTypeFromXML( node ) );
Attribute metaAttribute = node.attribute( "meta-type" );
if ( metaAttribute != null ) {
any.setMetaType( metaAttribute.getValue() );
Iterator iter = node.elementIterator( "meta-value" );
if ( iter.hasNext() ) {
HashMap values = new HashMap();
org.hibernate.type.Type metaType = TypeFactory.heuristicType( any.getMetaType() );
while ( iter.hasNext() ) {
Element metaValue = (Element) iter.next();
try {
Object value = ( (DiscriminatorType) metaType ).stringToObject( metaValue
.attributeValue( "value" ) );
String entityName = getClassName( metaValue.attribute( "class" ), mappings );
values.put( value, entityName );
}
catch (ClassCastException cce) {
throw new MappingException( "meta-type was not a DiscriminatorType: "
+ metaType.getName() );
}
catch (Exception e) {
throw new MappingException( "could not interpret meta-value", e );
}
}
any.setMetaValues( values );
}
}
bindColumns( node, any, isNullable, false, null, mappings );
}
|
public static void bindArray(Element node,
Array array,
String prefix,
String path,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindCollection( node, array, prefix, path, mappings, inheritedMetas );
Attribute att = node.attribute( "element-class" );
if ( att != null ) array.setElementClassName( getClassName( att, mappings ) );
}
Called for arrays and primitive arrays |
public static void bindClass(Element node,
PersistentClass persistentClass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
// transfer an explicitly defined entity name
// handle the lazy attribute
Attribute lazyNode = node.attribute( "lazy" );
boolean lazy = lazyNode == null ?
mappings.isDefaultLazy() :
"true".equals( lazyNode.getValue() );
// go ahead and set the lazy here, since pojo.proxy can override it.
persistentClass.setLazy( lazy );
String entityName = node.attributeValue( "entity-name" );
if ( entityName == null ) entityName = getClassName( node.attribute("name"), mappings );
if ( entityName==null ) {
throw new MappingException( "Unable to determine entity name" );
}
persistentClass.setEntityName( entityName );
bindPojoRepresentation( node, persistentClass, mappings, inheritedMetas );
bindDom4jRepresentation( node, persistentClass, mappings, inheritedMetas );
bindMapRepresentation( node, persistentClass, mappings, inheritedMetas );
bindPersistentClassCommonValues( node, persistentClass, mappings, inheritedMetas );
}
|
public static void bindCollection(Element node,
Collection collection,
String className,
String path,
Mappings mappings,
Map inheritedMetas) throws MappingException {
// ROLENAME
collection.setRole(path);
Attribute inverseNode = node.attribute( "inverse" );
if ( inverseNode != null ) {
collection.setInverse( "true".equals( inverseNode.getValue() ) );
}
Attribute mutableNode = node.attribute( "mutable" );
if ( mutableNode != null ) {
collection.setMutable( !"false".equals( mutableNode.getValue() ) );
}
Attribute olNode = node.attribute( "optimistic-lock" );
collection.setOptimisticLocked( olNode == null || "true".equals( olNode.getValue() ) );
Attribute orderNode = node.attribute( "order-by" );
if ( orderNode != null ) {
if ( Environment.jvmSupportsLinkedHashCollections() || ( collection instanceof Bag ) ) {
collection.setOrderBy( orderNode.getValue() );
}
else {
log.warn( "Attribute \"order-by\" ignored in JDK1.3 or less" );
}
}
Attribute whereNode = node.attribute( "where" );
if ( whereNode != null ) {
collection.setWhere( whereNode.getValue() );
}
Attribute batchNode = node.attribute( "batch-size" );
if ( batchNode != null ) {
collection.setBatchSize( Integer.parseInt( batchNode.getValue() ) );
}
String nodeName = node.attributeValue( "node" );
if ( nodeName == null ) nodeName = node.attributeValue( "name" );
collection.setNodeName( nodeName );
String embed = node.attributeValue( "embed-xml" );
collection.setEmbedded( embed==null || "true".equals(embed) );
// PERSISTER
Attribute persisterNode = node.attribute( "persister" );
if ( persisterNode != null ) {
try {
collection.setCollectionPersisterClass( ReflectHelper.classForName( persisterNode
.getValue() ) );
}
catch (ClassNotFoundException cnfe) {
throw new MappingException( "Could not find collection persister class: "
+ persisterNode.getValue() );
}
}
Attribute typeNode = node.attribute( "collection-type" );
if ( typeNode != null ) {
String typeName = typeNode.getValue();
TypeDef typeDef = mappings.getTypeDef( typeName );
if ( typeDef != null ) {
collection.setTypeName( typeDef.getTypeClass() );
collection.setTypeParameters( typeDef.getParameters() );
}
else {
collection.setTypeName( typeName );
}
}
// FETCH STRATEGY
initOuterJoinFetchSetting( node, collection );
if ( "subselect".equals( node.attributeValue("fetch") ) ) {
collection.setSubselectLoadable(true);
collection.getOwner().setSubselectLoadableCollections(true);
}
initLaziness( node, collection, mappings, "true", mappings.isDefaultLazy() );
//TODO: suck this into initLaziness!
if ( "extra".equals( node.attributeValue("lazy") ) ) {
collection.setLazy(true);
collection.setExtraLazy(true);
}
Element oneToManyNode = node.element( "one-to-many" );
if ( oneToManyNode != null ) {
OneToMany oneToMany = new OneToMany( collection.getOwner() );
collection.setElement( oneToMany );
bindOneToMany( oneToManyNode, oneToMany, mappings );
// we have to set up the table later!! yuck
}
else {
// TABLE
Attribute tableNode = node.attribute( "table" );
String tableName;
if ( tableNode != null ) {
tableName = mappings.getNamingStrategy().tableName( tableNode.getValue() );
}
else {
//tableName = mappings.getNamingStrategy().propertyToTableName( className, path );
Table ownerTable = collection.getOwner().getTable();
//TODO mappings.getLogicalTableName(ownerTable)
String logicalOwnerTableName = ownerTable.getName();
//FIXME we don't have the associated entity table name here, has to be done in a second pass
tableName = mappings.getNamingStrategy().collectionTableName(
collection.getOwner().getEntityName(),
logicalOwnerTableName ,
null,
null,
path
);
}
Attribute schemaNode = node.attribute( "schema" );
String schema = schemaNode == null ?
mappings.getSchemaName() : schemaNode.getValue();
Attribute catalogNode = node.attribute( "catalog" );
String catalog = catalogNode == null ?
mappings.getCatalogName() : catalogNode.getValue();
Table table = mappings.addTable(
schema,
catalog,
tableName,
getSubselect( node ),
false
);
collection.setCollectionTable( table );
bindComment(table, node);
log.info(
"Mapping collection: " + collection.getRole() +
" - > " + collection.getCollectionTable().getName()
);
}
// SORT
Attribute sortedAtt = node.attribute( "sort" );
// unsorted, natural, comparator.class.name
if ( sortedAtt == null || sortedAtt.getValue().equals( "unsorted" ) ) {
collection.setSorted( false );
}
else {
collection.setSorted( true );
String comparatorClassName = sortedAtt.getValue();
if ( !comparatorClassName.equals( "natural" ) ) {
collection.setComparatorClassName(comparatorClassName);
}
}
// ORPHAN DELETE (used for programmer error detection)
Attribute cascadeAtt = node.attribute( "cascade" );
if ( cascadeAtt != null && cascadeAtt.getValue().indexOf( "delete-orphan" ) >= 0 ) {
collection.setOrphanDelete( true );
}
// CUSTOM SQL
handleCustomSQL( node, collection );
// set up second pass
if ( collection instanceof List ) {
mappings.addSecondPass( new ListSecondPass( node, mappings, (List) collection, inheritedMetas ) );
}
else if ( collection instanceof Map ) {
mappings.addSecondPass( new MapSecondPass( node, mappings, (Map) collection, inheritedMetas ) );
}
else if ( collection instanceof IdentifierCollection ) {
mappings.addSecondPass( new IdentifierCollectionSecondPass(
node,
mappings,
collection,
inheritedMetas
) );
}
else {
mappings.addSecondPass( new CollectionSecondPass( node, mappings, collection, inheritedMetas ) );
}
Iterator iter = node.elementIterator( "filter" );
while ( iter.hasNext() ) {
final Element filter = (Element) iter.next();
parseFilter( filter, collection, mappings );
}
Iterator tables = node.elementIterator( "synchronize" );
while ( tables.hasNext() ) {
collection.getSynchronizedTables().add(
( (Element) tables.next() ).attributeValue( "table" ) );
}
Element element = node.element( "loader" );
if ( element != null ) {
collection.setLoaderName( element.attributeValue( "query-ref" ) );
}
collection.setReferencedPropertyName( node.element( "key" ).attributeValue( "property-ref" ) );
}
Called for all collections |
public static void bindCollectionSecondPass(Element node,
Collection collection,
Map persistentClasses,
Mappings mappings,
Map inheritedMetas) throws MappingException {
if ( collection.isOneToMany() ) {
OneToMany oneToMany = (OneToMany) collection.getElement();
String assocClass = oneToMany.getReferencedEntityName();
PersistentClass persistentClass = (PersistentClass) persistentClasses.get( assocClass );
if ( persistentClass == null ) {
throw new MappingException( "Association references unmapped class: " + assocClass );
}
oneToMany.setAssociatedClass( persistentClass );
collection.setCollectionTable( persistentClass.getTable() );
log.info(
"Mapping collection: " + collection.getRole() +
" - > " + collection.getCollectionTable().getName()
);
}
// CHECK
Attribute chNode = node.attribute( "check" );
if ( chNode != null ) {
collection.getCollectionTable().addCheckConstraint( chNode.getValue() );
}
// contained elements:
Iterator iter = node.elementIterator();
while ( iter.hasNext() ) {
Element subnode = (Element) iter.next();
String name = subnode.getName();
if ( "key".equals( name ) ) {
KeyValue keyVal;
String propRef = collection.getReferencedPropertyName();
if ( propRef == null ) {
keyVal = collection.getOwner().getIdentifier();
}
else {
keyVal = (KeyValue) collection.getOwner().getRecursiveProperty( propRef ).getValue();
}
SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal );
key.setCascadeDeleteEnabled( "cascade"
.equals( subnode.attributeValue( "on-delete" ) ) );
bindSimpleValue(
subnode,
key,
collection.isOneToMany(),
Collection.DEFAULT_KEY_COLUMN_NAME,
mappings
);
collection.setKey( key );
Attribute notNull = subnode.attribute( "not-null" );
( (DependantValue) key ).setNullable( notNull == null
|| notNull.getValue().equals( "false" ) );
Attribute updateable = subnode.attribute( "update" );
( (DependantValue) key ).setUpdateable( updateable == null
|| updateable.getValue().equals( "true" ) );
}
else if ( "element".equals( name ) ) {
SimpleValue elt = new SimpleValue( collection.getCollectionTable() );
collection.setElement( elt );
bindSimpleValue(
subnode,
elt,
true,
Collection.DEFAULT_ELEMENT_COLUMN_NAME,
mappings
);
}
else if ( "many-to-many".equals( name ) ) {
ManyToOne element = new ManyToOne( collection.getCollectionTable() );
collection.setElement( element );
bindManyToOne(
subnode,
element,
Collection.DEFAULT_ELEMENT_COLUMN_NAME,
false,
mappings
);
bindManyToManySubelements( collection, subnode, mappings );
}
else if ( "composite-element".equals( name ) ) {
Component element = new Component( collection );
collection.setElement( element );
bindComposite(
subnode,
element,
collection.getRole() + ".element",
true,
mappings,
inheritedMetas
);
}
else if ( "many-to-any".equals( name ) ) {
Any element = new Any( collection.getCollectionTable() );
collection.setElement( element );
bindAny( subnode, element, true, mappings );
}
else if ( "cache".equals( name ) ) {
collection.setCacheConcurrencyStrategy( subnode.attributeValue( "usage" ) );
collection.setCacheRegionName( subnode.attributeValue( "region" ) );
}
String nodeName = subnode.attributeValue( "node" );
if ( nodeName != null ) collection.setElementNodeName( nodeName );
}
if ( collection.isOneToMany()
&& !collection.isInverse()
&& !collection.getKey().isNullable() ) {
// for non-inverse one-to-many, with a not-null fk, add a backref!
String entityName = ( (OneToMany) collection.getElement() ).getReferencedEntityName();
PersistentClass referenced = mappings.getClass( entityName );
Backref prop = new Backref();
prop.setName( '_" + collection.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "Backref" );
prop.setUpdateable( false );
prop.setSelectable( false );
prop.setCollectionRole( collection.getRole() );
prop.setEntityName( collection.getOwner().getEntityName() );
prop.setValue( collection.getKey() );
referenced.addProperty( prop );
}
}
Called for all collections |
public static void bindColumn(Element node,
Column column,
boolean isNullable) {
Attribute lengthNode = node.attribute( "length" );
if ( lengthNode != null ) column.setLength( Integer.parseInt( lengthNode.getValue() ) );
Attribute scalNode = node.attribute( "scale" );
if ( scalNode != null ) column.setScale( Integer.parseInt( scalNode.getValue() ) );
Attribute precNode = node.attribute( "precision" );
if ( precNode != null ) column.setPrecision( Integer.parseInt( precNode.getValue() ) );
Attribute nullNode = node.attribute( "not-null" );
column.setNullable( nullNode == null ? isNullable : nullNode.getValue().equals( "false" ) );
Attribute unqNode = node.attribute( "unique" );
if ( unqNode != null ) column.setUnique( unqNode.getValue().equals( "true" ) );
column.setCheckConstraint( node.attributeValue( "check" ) );
column.setDefaultValue( node.attributeValue( "default" ) );
Attribute typeNode = node.attribute( "sql-type" );
if ( typeNode != null ) column.setSqlType( typeNode.getValue() );
Element comment = node.element("comment");
if (comment!=null) column.setComment( comment.getTextTrim() );
}
|
public static void bindColumns(Element node,
SimpleValue simpleValue,
boolean isNullable,
boolean autoColumn,
String propertyPath,
Mappings mappings) throws MappingException {
Table table = simpleValue.getTable();
// COLUMN(S)
Attribute columnAttribute = node.attribute( "column" );
if ( columnAttribute == null ) {
Iterator iter = node.elementIterator();
int count = 0;
while ( iter.hasNext() ) {
Element columnElement = (Element) iter.next();
if ( columnElement.getName().equals( "column" ) ) {
Column column = new Column();
column.setValue( simpleValue );
column.setTypeIndex( count++ );
bindColumn( columnElement, column, isNullable );
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
columnElement.attributeValue( "name" ), propertyPath
);
column.setName( mappings.getNamingStrategy().columnName(
logicalColumnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null - > an association
// - fill it in later
//TODO fill in the mappings for table == null
mappings.addColumnBinding( logicalColumnName, column, table );
}
simpleValue.addColumn( column );
// column index
bindIndex( columnElement.attribute( "index" ), table, column, mappings );
bindIndex( node.attribute( "index" ), table, column, mappings );
//column unique-key
bindUniqueKey( columnElement.attribute( "unique-key" ), table, column, mappings );
bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
}
else if ( columnElement.getName().equals( "formula" ) ) {
Formula formula = new Formula();
formula.setFormula( columnElement.getText() );
simpleValue.addFormula( formula );
}
}
}
else {
if ( node.elementIterator( "column" ).hasNext() ) {
throw new MappingException(
"column attribute may not be used together with < column > subelement" );
}
if ( node.elementIterator( "formula" ).hasNext() ) {
throw new MappingException(
"column attribute may not be used together with < formula > subelement" );
}
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
columnAttribute.getValue(), propertyPath
);
column.setName( mappings.getNamingStrategy().columnName( logicalColumnName ) );
if ( table != null ) {
table.addColumn( column ); // table=null - > an association - fill
// it in later
//TODO fill in the mappings for table == null
mappings.addColumnBinding( logicalColumnName, column, table );
}
simpleValue.addColumn( column );
bindIndex( node.attribute( "index" ), table, column, mappings );
bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
}
if ( autoColumn && simpleValue.getColumnSpan() == 0 ) {
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
column.setName( mappings.getNamingStrategy().propertyToColumnName( propertyPath ) );
String logicalName = mappings.getNamingStrategy().logicalColumnName( null, propertyPath );
mappings.addColumnBinding( logicalName, column, table );
/* TODO: joinKeyColumnName & foreignKeyColumnName should be called either here or at a
* slightly higer level in the stack (to get all the information we need)
* Right now HbmBinder does not support the
*/
simpleValue.getTable().addColumn( column );
simpleValue.addColumn( column );
bindIndex( node.attribute( "index" ), table, column, mappings );
bindUniqueKey( node.attribute( "unique-key" ), table, column, mappings );
}
}
|
public static void bindComponent(Element node,
Component component,
String ownerClassName,
String parentProperty,
String path,
boolean isNullable,
boolean isEmbedded,
Mappings mappings,
Map inheritedMetas,
boolean isIdentifierMapper) throws MappingException {
component.setEmbedded( isEmbedded );
component.setRoleName( path );
inheritedMetas = getMetas( node, inheritedMetas );
component.setMetaAttributes( inheritedMetas );
Attribute classNode = isIdentifierMapper ? null : node.attribute( "class" );
if ( classNode != null ) {
component.setComponentClassName( getClassName( classNode, mappings ) );
}
else if ( "dynamic-component".equals( node.getName() ) ) {
component.setDynamic( true );
}
else if ( isEmbedded ) {
// an "embedded" component (composite ids and unique)
// note that this does not handle nested components
if ( component.getOwner().hasPojoRepresentation() ) {
component.setComponentClassName( component.getOwner().getClassName() );
}
else {
component.setDynamic(true);
}
}
else {
// todo : again, how *should* this work for non-pojo entities?
if ( component.getOwner().hasPojoRepresentation() ) {
Class reflectedClass = reflectedPropertyClass( ownerClassName, parentProperty );
if ( reflectedClass != null ) {
component.setComponentClassName( reflectedClass.getName() );
}
}
else {
component.setDynamic(true);
}
}
String nodeName = node.attributeValue( "node" );
if ( nodeName == null ) nodeName = node.attributeValue( "name" );
if ( nodeName == null ) nodeName = component.getOwner().getNodeName();
component.setNodeName( nodeName );
Iterator iter = node.elementIterator();
while ( iter.hasNext() ) {
Element subnode = (Element) iter.next();
String name = subnode.getName();
String propertyName = getPropertyName( subnode );
String subpath = propertyName == null ? null : StringHelper
.qualify( path, propertyName );
CollectionType collectType = CollectionType.collectionTypeFromString( name );
Value value = null;
if ( collectType != null ) {
Collection collection = collectType.create(
subnode,
subpath,
component.getOwner(),
mappings, inheritedMetas
);
mappings.addCollection( collection );
value = collection;
}
else if ( "many-to-one".equals( name ) || "key-many-to-one".equals( name ) ) {
value = new ManyToOne( component.getTable() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
}
else {
relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
}
bindManyToOne( subnode, (ManyToOne) value, relativePath, isNullable, mappings );
}
else if ( "one-to-one".equals( name ) ) {
value = new OneToOne( component.getTable(), component.getOwner() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
}
else {
relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
}
bindOneToOne( subnode, (OneToOne) value, relativePath, isNullable, mappings );
}
else if ( "any".equals( name ) ) {
value = new Any( component.getTable() );
bindAny( subnode, (Any) value, isNullable, mappings );
}
else if ( "property".equals( name ) || "key-property".equals( name ) ) {
value = new SimpleValue( component.getTable() );
String relativePath;
if (isEmbedded) {
relativePath = propertyName;
}
else {
relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
}
bindSimpleValue( subnode, (SimpleValue) value, isNullable, relativePath, mappings );
}
else if ( "component".equals( name )
|| "dynamic-component".equals( name )
|| "nested-composite-element".equals( name ) ) {
value = new Component( component ); // a nested composite element
bindComponent(
subnode,
(Component) value,
component.getComponentClassName(),
propertyName,
subpath,
isNullable,
isEmbedded,
mappings,
inheritedMetas,
isIdentifierMapper
);
}
else if ( "parent".equals( name ) ) {
component.setParentProperty( propertyName );
}
if ( value != null ) {
Property property = createProperty( value, propertyName, component
.getComponentClassName(), subnode, mappings, inheritedMetas );
if (isIdentifierMapper) {
property.setInsertable(false);
property.setUpdateable(false);
}
component.addProperty( property );
}
}
if ( "true".equals( node.attributeValue( "unique" ) ) ) {
iter = component.getColumnIterator();
ArrayList cols = new ArrayList();
while ( iter.hasNext() ) {
cols.add( iter.next() );
}
component.getOwner().getTable().createUniqueKey( cols );
}
iter = node.elementIterator( "tuplizer" );
while ( iter.hasNext() ) {
final Element tuplizerElem = ( Element ) iter.next();
EntityMode mode = EntityMode.parse( tuplizerElem.attributeValue( "entity-mode" ) );
component.addTuplizer( mode, tuplizerElem.attributeValue( "class" ) );
}
}
|
public static void bindComposite(Element node,
Component component,
String path,
boolean isNullable,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindComponent(
node,
component,
null,
null,
path,
isNullable,
false,
mappings,
inheritedMetas,
false
);
}
|
public static void bindCompositeId(Element node,
Component component,
PersistentClass persistentClass,
String propertyName,
Mappings mappings,
Map inheritedMetas) throws MappingException {
component.setKey( true );
String path = StringHelper.qualify(
persistentClass.getEntityName(),
propertyName == null ? "id" : propertyName );
bindComponent(
node,
component,
persistentClass.getClassName(),
propertyName,
path,
false,
node.attribute( "class" ) == null
&& propertyName == null,
mappings,
inheritedMetas,
false
);
if ( "true".equals( node.attributeValue("mapped") ) ) {
if ( propertyName!=null ) {
throw new MappingException("cannot combine mapped=\"true\" with specified name");
}
Component mapper = new Component(persistentClass);
bindComponent(
node,
mapper,
persistentClass.getClassName(),
null,
path,
false,
true,
mappings,
inheritedMetas,
true
);
persistentClass.setIdentifierMapper(mapper);
Property property = new Property();
property.setName("_identifierMapper");
property.setNodeName("id");
property.setUpdateable(false);
property.setInsertable(false);
property.setValue(mapper);
property.setPropertyAccessorName( "embedded" );
persistentClass.addProperty(property);
}
}
|
public static void bindIdentifierCollectionSecondPass(Element node,
IdentifierCollection collection,
Map persistentClasses,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindCollectionSecondPass( node, collection, persistentClasses, mappings, inheritedMetas );
Element subnode = node.element( "collection-id" );
SimpleValue id = new SimpleValue( collection.getCollectionTable() );
bindSimpleValue(
subnode,
id,
false,
IdentifierCollection.DEFAULT_IDENTIFIER_COLUMN_NAME,
mappings
);
collection.setIdentifier( id );
makeIdentifier( subnode, id, mappings );
}
|
public static void bindJoinedSubclass(Element node,
JoinedSubclass joinedSubclass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindClass( node, joinedSubclass, mappings, inheritedMetas );
inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from
// < joined-subclass >
// joined subclasses
if ( joinedSubclass.getEntityPersisterClass() == null ) {
joinedSubclass.getRootClass()
.setEntityPersisterClass( JoinedSubclassEntityPersister.class );
}
Attribute schemaNode = node.attribute( "schema" );
String schema = schemaNode == null ?
mappings.getSchemaName() : schemaNode.getValue();
Attribute catalogNode = node.attribute( "catalog" );
String catalog = catalogNode == null ?
mappings.getCatalogName() : catalogNode.getValue();
Table mytable = mappings.addTable(
schema,
catalog,
getClassTableName( joinedSubclass, node, schema, catalog, null, mappings ),
getSubselect( node ),
false
);
joinedSubclass.setTable( mytable );
bindComment(mytable, node);
log.info(
"Mapping joined-subclass: " + joinedSubclass.getEntityName() +
" - > " + joinedSubclass.getTable().getName()
);
// KEY
Element keyNode = node.element( "key" );
SimpleValue key = new DependantValue( mytable, joinedSubclass.getIdentifier() );
joinedSubclass.setKey( key );
key.setCascadeDeleteEnabled( "cascade".equals( keyNode.attributeValue( "on-delete" ) ) );
bindSimpleValue( keyNode, key, false, joinedSubclass.getEntityName(), mappings );
// model.getKey().setType( new Type( model.getIdentifier() ) );
joinedSubclass.createPrimaryKey();
joinedSubclass.createForeignKey();
// CHECK
Attribute chNode = node.attribute( "check" );
if ( chNode != null ) mytable.addCheckConstraint( chNode.getValue() );
// properties
createClassProperties( node, joinedSubclass, mappings, inheritedMetas );
}
|
public static void bindListSecondPass(Element node,
List list,
Map classes,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas );
Element subnode = node.element( "list-index" );
if ( subnode == null ) subnode = node.element( "index" );
SimpleValue iv = new SimpleValue( list.getCollectionTable() );
bindSimpleValue(
subnode,
iv,
list.isOneToMany(),
IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
mappings
);
iv.setTypeName( "integer" );
list.setIndex( iv );
String baseIndex = subnode.attributeValue( "base" );
if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) );
list.setIndexNodeName( subnode.attributeValue("node") );
if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {
String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();
PersistentClass referenced = mappings.getClass( entityName );
IndexBackref ib = new IndexBackref();
ib.setName( '_" + list.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
ib.setUpdateable( false );
ib.setSelectable( false );
ib.setCollectionRole( list.getRole() );
ib.setEntityName( list.getOwner().getEntityName() );
ib.setValue( list.getIndex() );
// ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
// ).setNullable(false);
referenced.addProperty( ib );
}
}
Called for Lists, arrays, primitive arrays |
public static void bindManyToOne(Element node,
ManyToOne manyToOne,
String path,
boolean isNullable,
Mappings mappings) throws MappingException {
bindColumnsOrFormula( node, manyToOne, path, isNullable, mappings );
initOuterJoinFetchSetting( node, manyToOne );
initLaziness( node, manyToOne, mappings, true );
Attribute ukName = node.attribute( "property-ref" );
if ( ukName != null ) {
manyToOne.setReferencedPropertyName( ukName.getValue() );
}
manyToOne.setReferencedEntityName( getEntityName( node, mappings ) );
String embed = node.attributeValue( "embed-xml" );
manyToOne.setEmbedded( embed == null || "true".equals( embed ) );
String notFound = node.attributeValue( "not-found" );
manyToOne.setIgnoreNotFound( "ignore".equals( notFound ) );
if( ukName != null && !manyToOne.isIgnoreNotFound() ) {
if ( !node.getName().equals("many-to-many") ) { //TODO: really bad, evil hack to fix!!!
mappings.addSecondPass( new ManyToOneSecondPass(manyToOne) );
}
}
Attribute fkNode = node.attribute( "foreign-key" );
if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() );
validateCascade( node, path );
}
|
public static void bindMapSecondPass(Element node,
Map map,
Map classes,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindCollectionSecondPass( node, map, classes, mappings, inheritedMetas );
Iterator iter = node.elementIterator();
while ( iter.hasNext() ) {
Element subnode = (Element) iter.next();
String name = subnode.getName();
if ( "index".equals( name ) || "map-key".equals( name ) ) {
SimpleValue value = new SimpleValue( map.getCollectionTable() );
bindSimpleValue(
subnode,
value,
map.isOneToMany(),
IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
mappings
);
if ( !value.isTypeSpecified() ) {
throw new MappingException( "map index element must specify a type: "
+ map.getRole() );
}
map.setIndex( value );
map.setIndexNodeName( subnode.attributeValue("node") );
}
else if ( "index-many-to-many".equals( name ) || "map-key-many-to-many".equals( name ) ) {
ManyToOne mto = new ManyToOne( map.getCollectionTable() );
bindManyToOne(
subnode,
mto,
IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
map.isOneToMany(),
mappings
);
map.setIndex( mto );
}
else if ( "composite-index".equals( name ) || "composite-map-key".equals( name ) ) {
Component component = new Component( map );
bindComposite(
subnode,
component,
map.getRole() + ".index",
map.isOneToMany(),
mappings,
inheritedMetas
);
map.setIndex( component );
}
else if ( "index-many-to-any".equals( name ) ) {
Any any = new Any( map.getCollectionTable() );
bindAny( subnode, any, map.isOneToMany(), mappings );
map.setIndex( any );
}
}
// TODO: this is a bit of copy/paste from IndexedCollection.createPrimaryKey()
boolean indexIsFormula = false;
Iterator colIter = map.getIndex().getColumnIterator();
while ( colIter.hasNext() ) {
if ( ( (Selectable) colIter.next() ).isFormula() ) indexIsFormula = true;
}
if ( map.isOneToMany() && !map.getKey().isNullable() && !map.isInverse() && !indexIsFormula ) {
String entityName = ( (OneToMany) map.getElement() ).getReferencedEntityName();
PersistentClass referenced = mappings.getClass( entityName );
IndexBackref ib = new IndexBackref();
ib.setName( '_" + map.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
ib.setUpdateable( false );
ib.setSelectable( false );
ib.setCollectionRole( map.getRole() );
ib.setEntityName( map.getOwner().getEntityName() );
ib.setValue( map.getIndex() );
// ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
// ).setNullable(false);
referenced.addProperty( ib );
}
}
|
public static void bindOneToMany(Element node,
OneToMany oneToMany,
Mappings mappings) throws MappingException {
oneToMany.setReferencedEntityName( getEntityName( node, mappings ) );
String embed = node.attributeValue( "embed-xml" );
oneToMany.setEmbedded( embed == null || "true".equals( embed ) );
String notFound = node.attributeValue( "not-found" );
oneToMany.setIgnoreNotFound( "ignore".equals( notFound ) );
}
|
public static void bindOneToOne(Element node,
OneToOne oneToOne,
String path,
boolean isNullable,
Mappings mappings) throws MappingException {
bindColumns( node, oneToOne, isNullable, false, null, mappings );
Attribute constrNode = node.attribute( "constrained" );
boolean constrained = constrNode != null && constrNode.getValue().equals( "true" );
oneToOne.setConstrained( constrained );
oneToOne.setForeignKeyType( constrained ?
ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT :
ForeignKeyDirection.FOREIGN_KEY_TO_PARENT );
initOuterJoinFetchSetting( node, oneToOne );
initLaziness( node, oneToOne, mappings, true );
oneToOne.setEmbedded( "true".equals( node.attributeValue( "embed-xml" ) ) );
Attribute fkNode = node.attribute( "foreign-key" );
if ( fkNode != null ) oneToOne.setForeignKeyName( fkNode.getValue() );
Attribute ukName = node.attribute( "property-ref" );
if ( ukName != null ) oneToOne.setReferencedPropertyName( ukName.getValue() );
oneToOne.setPropertyName( node.attributeValue( "name" ) );
oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );
validateCascade( node, path );
}
|
public static void bindProperty(Element node,
Property property,
Mappings mappings,
Map inheritedMetas) throws MappingException {
String propName = node.attributeValue( "name" );
property.setName( propName );
String nodeName = node.attributeValue( "node" );
if (nodeName==null) nodeName = propName;
property.setNodeName( nodeName );
// TODO:
//Type type = model.getValue().getType();
//if (type==null) throw new MappingException(
//"Could not determine a property type for: " + model.getName() );
Attribute accessNode = node.attribute( "access" );
if ( accessNode != null ) {
property.setPropertyAccessorName( accessNode.getValue() );
}
else if ( node.getName().equals( "properties" ) ) {
property.setPropertyAccessorName( "embedded" );
}
else {
property.setPropertyAccessorName( mappings.getDefaultAccess() );
}
Attribute cascadeNode = node.attribute( "cascade" );
property.setCascade( cascadeNode == null ? mappings.getDefaultCascade() : cascadeNode
.getValue() );
Attribute updateNode = node.attribute( "update" );
property.setUpdateable( updateNode == null || "true".equals( updateNode.getValue() ) );
Attribute insertNode = node.attribute( "insert" );
property.setInsertable( insertNode == null || "true".equals( insertNode.getValue() ) );
Attribute lockNode = node.attribute( "optimistic-lock" );
property.setOptimisticLocked( lockNode == null || "true".equals( lockNode.getValue() ) );
Attribute generatedNode = node.attribute( "generated" );
String generationName = generatedNode == null ? null : generatedNode.getValue();
PropertyGeneration generation = PropertyGeneration.parse( generationName );
property.setGeneration( generation );
if ( generation == PropertyGeneration.ALWAYS || generation == PropertyGeneration.INSERT ) {
// generated properties can *never* be insertable...
if ( property.isInsertable() ) {
if ( insertNode == null ) {
// insertable simply because that is the user did not specify
// anything; just override it
property.setInsertable( false );
}
else {
// the user specifically supplied insert="true",
// which constitutes an illegal combo
throw new MappingException(
"cannot specify both insert=\"true\" and generated=\"" + generation.getName() +
"\" for property: " +
propName
);
}
}
// properties generated on update can never be updateable...
if ( property.isUpdateable() && generation == PropertyGeneration.ALWAYS ) {
if ( updateNode == null ) {
// updateable only because the user did not specify
// anything; just override it
property.setUpdateable( false );
}
else {
// the user specifically supplied update="true",
// which constitutes an illegal combo
throw new MappingException(
"cannot specify both update=\"true\" and generated=\"" + generation.getName() +
"\" for property: " +
propName
);
}
}
}
boolean isLazyable = "property".equals( node.getName() ) ||
"component".equals( node.getName() ) ||
"many-to-one".equals( node.getName() ) ||
"one-to-one".equals( node.getName() ) ||
"any".equals( node.getName() );
if ( isLazyable ) {
Attribute lazyNode = node.attribute( "lazy" );
property.setLazy( lazyNode != null && "true".equals( lazyNode.getValue() ) );
}
if ( log.isDebugEnabled() ) {
String msg = "Mapped property: " + property.getName();
String columns = columns( property.getValue() );
if ( columns.length() > 0 ) msg += " - > " + columns;
// TODO: this fails if we run with debug on!
// if ( model.getType()!=null ) msg += ", type: " + model.getType().getName();
log.debug( msg );
}
property.setMetaAttributes( getMetas( node, inheritedMetas ) );
}
|
public static void bindRoot(Document doc,
Mappings mappings,
Map inheritedMetas) throws MappingException {
java.util.List names = HbmBinder.getExtendsNeeded( doc, mappings );
if ( !names.isEmpty() ) {
// classes mentioned in extends not available - so put it in queue
Element hmNode = doc.getRootElement();
Attribute packNode = hmNode.attribute( "package" );
String packageName = null;
if ( packNode != null ) {
packageName = packNode.getValue();
}
Iterator itr = names.iterator();
while ( itr.hasNext() ) {
String extendsName = (String) itr.next();
mappings.addToExtendsQueue( new ExtendsQueueEntry( extendsName, packageName, doc ) );
}
return;
}
Element hmNode = doc.getRootElement();
// get meta's from < hibernate-mapping >
inheritedMetas = getMetas( hmNode, inheritedMetas, true );
extractRootAttributes( hmNode, mappings );
Iterator rootChildren = hmNode.elementIterator();
while ( rootChildren.hasNext() ) {
final Element element = (Element) rootChildren.next();
final String elementName = element.getName();
if ( "filter-def".equals( elementName ) ) {
parseFilterDef( element, mappings );
}
else if ( "typedef".equals( elementName ) ) {
bindTypeDef( element, mappings );
}
else if ( "class".equals( elementName ) ) {
RootClass rootclass = new RootClass();
bindRootClass( element, rootclass, mappings, inheritedMetas );
mappings.addClass( rootclass );
}
else if ( "subclass".equals( elementName ) ) {
PersistentClass superModel = getSuperclass( mappings, element );
handleSubclass( superModel, mappings, element, inheritedMetas );
}
else if ( "joined-subclass".equals( elementName ) ) {
PersistentClass superModel = getSuperclass( mappings, element );
handleJoinedSubclass( superModel, mappings, element, inheritedMetas );
}
else if ( "union-subclass".equals( elementName ) ) {
PersistentClass superModel = getSuperclass( mappings, element );
handleUnionSubclass( superModel, mappings, element, inheritedMetas );
}
else if ( "query".equals( elementName ) ) {
bindNamedQuery( element, null, mappings );
}
else if ( "sql-query".equals( elementName ) ) {
bindNamedSQLQuery( element, null, mappings );
}
else if ( "resultset".equals( elementName ) ) {
bindResultSetMappingDefinition( element, null, mappings );
}
else if ( "import".equals( elementName ) ) {
bindImport( element, mappings );
}
else if ( "database-object".equals( elementName ) ) {
bindAuxiliaryDatabaseObject( element, mappings );
}
}
}
The main contract into the hbm.xml-based binder. Performs necessary binding operations
represented by the given DOM. |
public static void bindRootClass(Element node,
RootClass rootClass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindClass( node, rootClass, mappings, inheritedMetas );
inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from < class >
bindRootPersistentClassCommonValues( node, inheritedMetas, mappings, rootClass );
}
Responsible for perfoming the bind operation related to an <class/> mapping element. |
public static void bindSimpleValue(Element node,
SimpleValue simpleValue,
boolean isNullable,
String path,
Mappings mappings) throws MappingException {
bindSimpleValueType( node, simpleValue, mappings );
bindColumnsOrFormula( node, simpleValue, path, isNullable, mappings );
Attribute fkNode = node.attribute( "foreign-key" );
if ( fkNode != null ) simpleValue.setForeignKeyName( fkNode.getValue() );
}
|
public static void bindSubclass(Element node,
Subclass subclass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindClass( node, subclass, mappings, inheritedMetas );
inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from < subclass >
if ( subclass.getEntityPersisterClass() == null ) {
subclass.getRootClass()
.setEntityPersisterClass( SingleTableEntityPersister.class );
}
log.info(
"Mapping subclass: " + subclass.getEntityName() +
" - > " + subclass.getTable().getName()
);
// properties
createClassProperties( node, subclass, mappings, inheritedMetas );
}
|
public static void bindUnionSubclass(Element node,
UnionSubclass unionSubclass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
bindClass( node, unionSubclass, mappings, inheritedMetas );
inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from < subclass >
if ( unionSubclass.getEntityPersisterClass() == null ) {
unionSubclass.getRootClass().setEntityPersisterClass(
UnionSubclassEntityPersister.class );
}
Attribute schemaNode = node.attribute( "schema" );
String schema = schemaNode == null ?
mappings.getSchemaName() : schemaNode.getValue();
Attribute catalogNode = node.attribute( "catalog" );
String catalog = catalogNode == null ?
mappings.getCatalogName() : catalogNode.getValue();
Table denormalizedSuperTable = unionSubclass.getSuperclass().getTable();
Table mytable = mappings.addDenormalizedTable(
schema,
catalog,
getClassTableName(unionSubclass, node, schema, catalog, denormalizedSuperTable, mappings ),
unionSubclass.isAbstract() != null && unionSubclass.isAbstract().booleanValue(),
getSubselect( node ),
denormalizedSuperTable
);
unionSubclass.setTable( mytable );
log.info(
"Mapping union-subclass: " + unionSubclass.getEntityName() +
" - > " + unionSubclass.getTable().getName()
);
createClassProperties( node, unionSubclass, mappings, inheritedMetas );
}
|
protected static void createClassProperties(Element node,
PersistentClass persistentClass,
Mappings mappings,
Map inheritedMetas) throws MappingException {
createClassProperties(node, persistentClass, mappings, inheritedMetas, null, true, true, false);
}
|
protected static void createClassProperties(Element node,
PersistentClass persistentClass,
Mappings mappings,
Map inheritedMetas,
UniqueKey uniqueKey,
boolean mutable,
boolean nullable,
boolean naturalId) throws MappingException {
String entityName = persistentClass.getEntityName();
Table table = persistentClass.getTable();
Iterator iter = node.elementIterator();
while ( iter.hasNext() ) {
Element subnode = (Element) iter.next();
String name = subnode.getName();
String propertyName = subnode.attributeValue( "name" );
CollectionType collectType = CollectionType.collectionTypeFromString( name );
Value value = null;
if ( collectType != null ) {
Collection collection = collectType.create(
subnode,
StringHelper.qualify( entityName, propertyName ),
persistentClass,
mappings, inheritedMetas
);
mappings.addCollection( collection );
value = collection;
}
else if ( "many-to-one".equals( name ) ) {
value = new ManyToOne( table );
bindManyToOne( subnode, (ManyToOne) value, propertyName, nullable, mappings );
}
else if ( "any".equals( name ) ) {
value = new Any( table );
bindAny( subnode, (Any) value, nullable, mappings );
}
else if ( "one-to-one".equals( name ) ) {
value = new OneToOne( table, persistentClass );
bindOneToOne( subnode, (OneToOne) value, propertyName, true, mappings );
}
else if ( "property".equals( name ) ) {
value = new SimpleValue( table );
bindSimpleValue( subnode, (SimpleValue) value, nullable, propertyName, mappings );
}
else if ( "component".equals( name )
|| "dynamic-component".equals( name )
|| "properties".equals( name ) ) {
String subpath = StringHelper.qualify( entityName, propertyName );
value = new Component( persistentClass );
bindComponent(
subnode,
(Component) value,
persistentClass.getClassName(),
propertyName,
subpath,
true,
"properties".equals( name ),
mappings,
inheritedMetas,
false
);
}
else if ( "join".equals( name ) ) {
Join join = new Join();
join.setPersistentClass( persistentClass );
bindJoin( subnode, join, mappings, inheritedMetas );
persistentClass.addJoin( join );
}
else if ( "subclass".equals( name ) ) {
handleSubclass( persistentClass, mappings, subnode, inheritedMetas );
}
else if ( "joined-subclass".equals( name ) ) {
handleJoinedSubclass( persistentClass, mappings, subnode, inheritedMetas );
}
else if ( "union-subclass".equals( name ) ) {
handleUnionSubclass( persistentClass, mappings, subnode, inheritedMetas );
}
else if ( "filter".equals( name ) ) {
parseFilter( subnode, persistentClass, mappings );
}
else if ( "natural-id".equals( name ) ) {
UniqueKey uk = new UniqueKey();
uk.setName("_UniqueKey");
uk.setTable(table);
//by default, natural-ids are "immutable" (constant)
boolean mutableId = "true".equals( subnode.attributeValue("mutable") );
createClassProperties(
subnode,
persistentClass,
mappings,
inheritedMetas,
uk,
mutableId,
false,
true
);
table.addUniqueKey(uk);
}
else if ( "query".equals(name) ) {
bindNamedQuery(subnode, persistentClass.getEntityName(), mappings);
}
else if ( "sql-query".equals(name) ) {
bindNamedSQLQuery(subnode, persistentClass.getEntityName(), mappings);
}
else if ( "resultset".equals(name) ) {
bindResultSetMappingDefinition( subnode, persistentClass.getEntityName(), mappings );
}
if ( value != null ) {
Property property = createProperty( value, propertyName, persistentClass
.getClassName(), subnode, mappings, inheritedMetas );
if ( !mutable ) property.setUpdateable(false);
if ( naturalId ) property.setNaturalIdentifier(true);
persistentClass.addProperty( property );
if ( uniqueKey!=null ) uniqueKey.addColumns( property.getColumnIterator() );
}
}
}
|
public static CacheMode getCacheMode(String cacheMode) {
if (cacheMode == null) return null;
if ( "get".equals( cacheMode ) ) return CacheMode.GET;
if ( "ignore".equals( cacheMode ) ) return CacheMode.IGNORE;
if ( "normal".equals( cacheMode ) ) return CacheMode.NORMAL;
if ( "put".equals( cacheMode ) ) return CacheMode.PUT;
if ( "refresh".equals( cacheMode ) ) return CacheMode.REFRESH;
throw new MappingException("Unknown Cache Mode: " + cacheMode);
}
|
public static String getClassName(String unqualifiedName,
Mappings model) {
return getClassName( unqualifiedName, model.getDefaultPackage() );
}
|
public static String getClassName(String unqualifiedName,
String defaultPackage) {
if ( unqualifiedName == null ) return null;
if ( unqualifiedName.indexOf( '." ) < 0 && defaultPackage != null ) {
return defaultPackage + '." + unqualifiedName;
}
return unqualifiedName;
}
|
public static String getEntityName(Element elem,
Mappings model) {
String entityName = elem.attributeValue( "entity-name" );
return entityName == null ? getClassName( elem.attribute( "class" ), model ) : entityName;
}
|
public static List getExtendsNeeded(Document doc,
Mappings mappings) {
java.util.List extendz = new ArrayList();
Iterator[] subclasses = new Iterator[3];
final Element hmNode = doc.getRootElement();
Attribute packNode = hmNode.attribute( "package" );
final String packageName = packNode == null ? null : packNode.getValue();
if ( packageName != null ) {
mappings.setDefaultPackage( packageName );
}
// first, iterate over all elements capable of defining an extends attribute
// collecting all found extends references if they cannot be resolved
// against the already processed mappings.
subclasses[0] = hmNode.elementIterator( "subclass" );
subclasses[1] = hmNode.elementIterator( "joined-subclass" );
subclasses[2] = hmNode.elementIterator( "union-subclass" );
Iterator iterator = new JoinedIterator( subclasses );
while ( iterator.hasNext() ) {
final Element element = (Element) iterator.next();
final String extendsName = element.attributeValue( "extends" );
// mappings might contain either the "raw" extends name (in the case of
// an entity-name mapping) or a FQN (in the case of a POJO mapping).
if ( mappings.getClass( extendsName ) == null && mappings.getClass( getClassName( extendsName, mappings ) ) == null ) {
extendz.add( extendsName );
}
}
if ( !extendz.isEmpty() ) {
// we found some extends attributes referencing entities which were
// not already processed. here we need to locate all entity-names
// and class-names contained in this document itself, making sure
// that these get removed from the extendz list such that only
// extends names which require us to delay processing (i.e.
// external to this document and not yet processed) are contained
// in the returned result
final java.util.Set set = new HashSet( extendz );
EntityElementHandler handler = new EntityElementHandler() {
public void handleEntity(String entityName, String className, Mappings mappings) {
if ( entityName != null ) {
set.remove( entityName );
}
else {
String fqn = getClassName( className, packageName );
set.remove( fqn );
if ( packageName != null ) {
set.remove( StringHelper.unqualify( fqn ) );
}
}
}
};
recognizeEntities( mappings, hmNode, handler );
extendz.clear();
extendz.addAll( set );
}
return extendz;
}
For the given document, locate all extends attributes which refer to
entities (entity-name or class-name) not defined within said document. |
public static final FlushMode getFlushMode(String flushMode) {
if ( flushMode == null ) {
return null;
}
else if ( "auto".equals( flushMode ) ) {
return FlushMode.AUTO;
}
else if ( "commit".equals( flushMode ) ) {
return FlushMode.COMMIT;
}
else if ( "never".equals( flushMode ) ) {
return FlushMode.NEVER;
}
else if ( "manual".equals( flushMode ) ) {
return FlushMode.MANUAL;
}
else if ( "always".equals( flushMode ) ) {
return FlushMode.ALWAYS;
}
else {
throw new MappingException( "unknown flushmode" );
}
}
|
public static final Map getMetas(Element node,
Map inheritedMeta,
boolean onlyInheritable) {
java.util.Map map = new HashMap();
map.putAll( inheritedMeta );
Iterator iter = node.elementIterator( "meta" );
while ( iter.hasNext() ) {
Element metaNode = (Element) iter.next();
boolean inheritable = Boolean
.valueOf( metaNode.attributeValue( "inherit" ) )
.booleanValue();
if ( onlyInheritable & !inheritable ) {
continue;
}
String name = metaNode.attributeValue( "attribute" );
MetaAttribute meta = (MetaAttribute) map.get( name );
MetaAttribute inheritedAttribute = (MetaAttribute) inheritedMeta.get( name );
if ( meta == null ) {
meta = new MetaAttribute( name );
map.put( name, meta );
} else if (meta == inheritedAttribute) { // overriding inherited meta attribute. HBX-621 & HBX-793
meta = new MetaAttribute( name );
map.put( name, meta );
}
meta.addValue( metaNode.getText() );
}
return map;
}
|
public static Map getParameterTypes(Element queryElem) {
java.util.Map result = new java.util.LinkedHashMap();
Iterator iter = queryElem.elementIterator("query-param");
while ( iter.hasNext() ) {
Element element = (Element) iter.next();
result.put( element.attributeValue("name"), element.attributeValue("type") );
}
return result;
}
|
public static String getTypeFromXML(Element node) throws MappingException {
// TODO: handle TypeDefs
Attribute typeNode = node.attribute( "type" );
if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any
if ( typeNode == null ) return null; // we will have to use reflection
return typeNode.getValue();
}
|