Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping
In directory sc8-pr-cvs1:/tmp/cvs-serv24927/hibernate/mapping
Modified Files:
Array.java Association.java Bag.java Collection.java
Column.java Component.java Index.java IndexedCollection.java
IntegerValue.java List.java ManyToOne.java Map.java
OneToMany.java OneToOne.java PersistentClass.java
PrimitiveArray.java Property.java Root.java RootClass.java
Set.java Subclass.java Value.java
Log Message:
massive refactoring of XML mapping parsing code
Index: Array.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Array.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Array.java 19 Jan 2003 11:47:07 -0000 1.5
--- Array.java 27 Jan 2003 07:12:03 -0000 1.6
***************
*** 2,54 ****
package net.sf.hibernate.mapping;
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.PersistentCollectionType;
- import net.sf.hibernate.type.PrimitiveType;
- import net.sf.hibernate.type.Type;
import net.sf.hibernate.type.TypeFactory;
- import net.sf.hibernate.util.ReflectHelper;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
public class Array extends List {
private Class elementClass;
! public Array(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! super(node, prefix, owner, root);
! Node att = node.getAttributes().getNamedItem("element-class");
! if ( att!=null ) {
! try {
! elementClass = ReflectHelper.classForName( att.getNodeValue() );
! }
! catch (ClassNotFoundException cnfe) {
! throw new MappingException(cnfe);
! }
! }
! else {
!
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
! Node subnode = list.item(i);
! String name = subnode.getNodeName();
!
! if ( "element".equals(name) ) {
! Type type = Value.getTypeFromXML(subnode);
! elementClass = isPrimitiveArray() ? ( (PrimitiveType) type ).primitiveClass() : type.getReturnedClass();
! }
! else if ( "one-to-many".equals(name) || "many-to-many".equals(name) || "composite-element".equals(name) ) {
! try {
! elementClass = ReflectHelper.classForName( subnode.getAttributes().getNamedItem("class").getNodeValue() );
! }
! catch (ClassNotFoundException cnfe) {
! throw new MappingException(cnfe);
! }
! }
!
! }
! }
!
}
!
public Class getElementClass() {
return elementClass;
--- 2,20 ----
package net.sf.hibernate.mapping;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
public class Array extends List {
private Class elementClass;
! /**
! * Constructor for Array.
! * @param owner
! */
! public Array(PersistentClass owner) {
! super(owner);
}
!
public Class getElementClass() {
return elementClass;
***************
*** 67,70 ****
--- 33,44 ----
}
+ /**
+ * Sets the elementClass.
+ * @param elementClass The elementClass to set
+ */
+ public void setElementClass(Class elementClass) {
+ this.elementClass = elementClass;
+ }
+
}
Index: Association.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Association.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Association.java 19 Jan 2003 11:47:07 -0000 1.6
--- Association.java 27 Jan 2003 07:12:03 -0000 1.7
***************
*** 3,46 ****
import net.sf.hibernate.MappingException;
- import net.sf.hibernate.loader.OuterJoinLoader;
- import net.sf.hibernate.type.Type;
-
- import org.w3c.dom.Node;
public abstract class Association extends Value {
! private final int joinedFetch;
! private int initJoinedFetch(Node node) {
! Node jfNode = node.getAttributes().getNamedItem("outer-join");
! if ( jfNode==null ) {
! return OuterJoinLoader.AUTO;
! }
! else {
! String eoj = jfNode.getNodeValue().toLowerCase();
! if ( "auto".equals(eoj) ) return OuterJoinLoader.AUTO;
! return "true".equals(eoj) ? OuterJoinLoader.EAGER : OuterJoinLoader.LAZY;
! }
}
!
! // A one-to-one association
! protected Association(Node node, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, isNullable, table, root);
! joinedFetch = initJoinedFetch(node);
}
! // A many-to-one association
! protected Association(Node node, String path, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, isNullable, table, root, defaultColumnName);
! joinedFetch = initJoinedFetch(node);
}
- protected abstract Type typeFromXML(Node node) throws MappingException;
-
public abstract void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException;
!
! public int enableJoinedFetch() { return joinedFetch; }
!
! public abstract void createForeignKeys(Root root, Table table);
}
--- 3,25 ----
import net.sf.hibernate.MappingException;
public abstract class Association extends Value {
! private int joinedFetch;
! protected Association(Table table) {
! super(table);
}
!
! public int getOuterJoinFetchSetting() {
! return joinedFetch;
}
! public void setOuterJoinFetchSetting(int joinedFetch) {
! this.joinedFetch=joinedFetch;
}
public abstract void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException;
! public abstract void createForeignKey();
}
Index: Bag.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Bag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Bag.java 5 Jan 2003 02:11:22 -0000 1.3
--- Bag.java 27 Jan 2003 07:12:03 -0000 1.4
***************
*** 2,8 ****
package net.sf.hibernate.mapping;
- import org.w3c.dom.Node;
-
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
--- 2,5 ----
***************
*** 10,18 ****
public class Bag extends Collection {
! public Bag(Node node, String prefix, PersistentClass owner, Root root)
! throws MappingException {
! super(node, prefix, owner, root);
}
!
public PersistentCollectionType getType() {
return TypeFactory.bag( getRole() );
--- 7,18 ----
public class Bag extends Collection {
! /**
! * Constructor for Bag.
! * @param owner
! */
! public Bag(PersistentClass owner) {
! super(owner);
}
!
public PersistentCollectionType getType() {
return TypeFactory.bag( getRole() );
***************
*** 23,26 ****
--- 23,30 ----
}
+ public void createPrimaryKey() {
+ //do nothing .. bags have no PK
+ }
+
}
Index: Collection.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Collection.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Collection.java 26 Jan 2003 01:33:35 -0000 1.9
--- Collection.java 27 Jan 2003 07:12:03 -0000 1.10
***************
*** 2,31 ****
package net.sf.hibernate.mapping;
import java.util.Iterator;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.cache.CacheConcurrencyStrategy;
- import net.sf.hibernate.cfg.Environment;
- import net.sf.hibernate.util.StringHelper;
import net.sf.hibernate.type.PersistentCollectionType;
public abstract class Collection {
! private static final String DEFAULT_ELEMENT_COLUMN_NAME = "elt";
! private static final String DEFAULT_KEY_COLUMN_NAME = "id";
!
! private static final Log log = LogFactory.getLog(Collection.class);
- // All can be made final except table
private Value key;
private Value element;
private Table table;
! private final String role;
private boolean lazy;
private boolean isOneToMany;
--- 2,22 ----
package net.sf.hibernate.mapping;
+ import java.util.Comparator;
import java.util.Iterator;
import org.w3c.dom.Node;
import net.sf.hibernate.cache.CacheConcurrencyStrategy;
import net.sf.hibernate.type.PersistentCollectionType;
public abstract class Collection {
! public static final String DEFAULT_ELEMENT_COLUMN_NAME = "elt";
! public static final String DEFAULT_KEY_COLUMN_NAME = "id";
private Value key;
private Value element;
private Table table;
! private String role;
private boolean lazy;
private boolean isOneToMany;
***************
*** 34,41 ****
private CacheConcurrencyStrategy cache;
private String orderBy;
- protected Node node;
private PersistentClass owner;
! protected Root root;
! private boolean doneSecondPass;
public boolean isSet() {
--- 25,41 ----
private CacheConcurrencyStrategy cache;
private String orderBy;
private PersistentClass owner;
!
! //TODO: remove these ugly instance vars
! public Node node;
! public Root root;
! public boolean doneSecondPass;
!
! private boolean sorted;
! private Comparator comparator;
!
! protected Collection(PersistentClass owner) {
! this.owner = owner;
! }
public boolean isSet() {
***************
*** 62,173 ****
this.table = table;
}
! public Collection(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! this.node = node;
! this.owner = owner;
! this.root = root;
! NamedNodeMap atts = node.getAttributes();
! //ROLENAME
! Node roleAtt = atts.getNamedItem("name");
! if (roleAtt==null) roleAtt = atts.getNamedItem("role");
! String barerole = roleAtt.getNodeValue();
! role = prefix + Root.ROLE_SEPERATOR + barerole;
!
! Node inverseNode = atts.getNamedItem("inverse");
! if ( inverseNode==null) inverseNode = atts.getNamedItem("readonly");
! if ( inverseNode!=null) inverse = StringHelper.booleanValue( inverseNode.getNodeValue() );
!
! Node orderNode = atts.getNamedItem("order-by");
! if ( orderNode!=null) {
! if ( Environment.jvmSupportsLinkedHashCollections() || ( this instanceof Bag ) ) {
! orderBy = orderNode.getNodeValue();
! }
! else {
! log.warn("Attribute \"order-by\" ignored in JDK1.3 or less");
! }
! }
!
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
! String name = list.item(i).getNodeName();
! if ( "one-to-many".equals(name) ) {
! isOneToMany = true;
! oneToMany = new OneToMany( list.item(i), owner );
! }
! }
! if (isOneToMany) {
! //we have to set up the table later!! yuck
! }
! else {
! //TABLE
! Node tableNode = atts.getNamedItem("table");
! String tableName;
! if (tableNode!=null) {
! tableName = tableNode.getNodeValue();
! }
! else {
! tableName = barerole;
! }
! Node schemaNode = atts.getNamedItem("schema");
! String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue();
! table = root.addTable(schema, tableName);
! }
! //LAZINESS
! Node lazyNode = atts.getNamedItem("lazy");
! if (lazyNode!=null) {
! lazy = StringHelper.booleanValue( lazyNode.getNodeValue() );
! }
!
}
!
! public void secondPassCompile(java.util.Map persistentClasses) throws MappingException {
! if (doneSecondPass) return;
!
! if (isOneToMany) {
! Class assocClass = getOneToMany().getType().getPersistentClass();
! PersistentClass persistentClass = (PersistentClass) persistentClasses.get(assocClass);
! if (persistentClass==null) throw new MappingException(
! "Association references unmapped class: " + assocClass.getName()
! );
! table = persistentClass.getTable();
! }
!
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
! Node subnode = list.item(i);
! String name = subnode.getNodeName();
!
! if ( "key".equals(name) || "generated-key".equals(name) ) {
! key = new Value(subnode, isOneToMany, table, root, DEFAULT_KEY_COLUMN_NAME);
! key.setType( owner.getIdentifier().getType() );
! if ( key.getType().getReturnedClass().isArray() ) throw new MappingException(
! "illegal use of an array as an identifier (arrays don't reimplement equals)"
! );
! }
! else if ( "element".equals(name) ) {
! element = new Value(subnode, true, table, root, DEFAULT_ELEMENT_COLUMN_NAME);
! }
! else if ( "many-to-many".equals(name) ) {
! element = new ManyToOne(subnode, Root.ROOT_ROLE_NAME, DEFAULT_ELEMENT_COLUMN_NAME, true, table, root);
! }
! else if ( "composite-element".equals(name) ) {
! element = new Component(subnode, null, Root.ROOT_ROLE_NAME, null, true, table, root);
! }
! else if ( "jcs-cache".equals(name) ) {
! cache = root.createJCSCache(subnode, role, owner);
! }
! }
!
! if (!inverse) {
! if (!isOneToMany) element.createForeignKeys(root, table);
! // no foreign key for a one-to-many
!
! key.createForeignKeyOfClass( root, table, owner.getPersistentClass() );
! }
!
! if ( !isIndexed() ) createIndex();
!
! doneSecondPass=true;
}
-
public boolean isLazy() {
return lazy;
--- 62,71 ----
this.table = table;
}
! public boolean isSorted() {
! return sorted;
}
! public Comparator getComparator() {
! return comparator;
}
public boolean isLazy() {
return lazy;
***************
*** 207,213 ****
return index;
}
! public void createPrimaryKey() {
! // do nothing
! }
public CacheConcurrencyStrategy getCache() {
--- 105,109 ----
return index;
}
! public abstract void createPrimaryKey();
public CacheConcurrencyStrategy getCache() {
***************
*** 223,226 ****
--- 119,226 ----
}
+ /**
+ * Returns the orderBy.
+ * @return String
+ */
+ public String getOrderBy() {
+ return orderBy;
+ }
+
+ /**
+ * Sets the cache.
+ * @param cache The cache to set
+ */
+ public void setCache(CacheConcurrencyStrategy cache) {
+ this.cache = cache;
+ }
+
+ /**
+ * Sets the comparator.
+ * @param comparator The comparator to set
+ */
+ public void setComparator(Comparator comparator) {
+ this.comparator = comparator;
+ }
+
+ /**
+ * Sets the element.
+ * @param element The element to set
+ */
+ public void setElement(Value element) {
+ this.element = element;
+ }
+
+ /**
+ * Sets the isOneToMany.
+ * @param isOneToMany The isOneToMany to set
+ */
+ public void setIsOneToMany(boolean isOneToMany) {
+ this.isOneToMany = isOneToMany;
+ }
+
+ /**
+ * Sets the key.
+ * @param key The key to set
+ */
+ public void setKey(Value key) {
+ this.key = key;
+ }
+
+ /**
+ * Sets the oneToMany.
+ * @param oneToMany The oneToMany to set
+ */
+ public void setOneToMany(OneToMany oneToMany) {
+ this.oneToMany = oneToMany;
+ }
+
+ /**
+ * Sets the orderBy.
+ * @param orderBy The orderBy to set
+ */
+ public void setOrderBy(String orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ /**
+ * Sets the role.
+ * @param role The role to set
+ */
+ public void setRole(String role) {
+ this.role = role;
+ }
+
+ /**
+ * Sets the sorted.
+ * @param sorted The sorted to set
+ */
+ public void setSorted(boolean sorted) {
+ this.sorted = sorted;
+ }
+
+ /**
+ * Sets the inverse.
+ * @param inverse The inverse to set
+ */
+ public void setInverse(boolean inverse) {
+ this.inverse = inverse;
+ }
+
+ /**
+ * Returns the owner.
+ * @return PersistentClass
+ */
+ public PersistentClass getOwner() {
+ return owner;
+ }
+
+ /**
+ * Sets the owner.
+ * @param owner The owner to set
+ */
+ public void setOwner(PersistentClass owner) {
+ this.owner = owner;
+ }
+
}
Index: Column.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Column.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Column.java 19 Jan 2003 11:47:07 -0000 1.4
--- Column.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 7,13 ****
import net.sf.hibernate.engine.Mapping;
import net.sf.hibernate.type.Type;
- import net.sf.hibernate.util.StringHelper;
-
- import org.w3c.dom.Node;
public class Column {
--- 7,10 ----
***************
*** 55,70 ****
}
- public Column(Node node, boolean isNullable, Type type, int typeIndex) {
- this(type, typeIndex);
- Node lengthNode = node.getAttributes().getNamedItem("length");
- if (lengthNode!=null) length = Integer.parseInt( lengthNode.getNodeValue() );
- Node nullNode = node.getAttributes().getNamedItem("not-null");
- nullable = (nullNode!=null) ? !StringHelper.booleanValue( nullNode.getNodeValue() ) : isNullable;
- Node unqNode = node.getAttributes().getNamedItem("unique");
- unique = unqNode!=null && StringHelper.booleanValue( unqNode.getNodeValue() );
- Node typeNode = node.getAttributes().getNamedItem("sql-type");
- sqlType = (typeNode==null) ? null : typeNode.getNodeValue();
- }
-
public int getTypeIndex() {
return typeIndex;
--- 52,55 ----
***************
*** 109,112 ****
--- 94,121 ----
return name.hashCode();
}
+ /**
+ * Returns the sqlType.
+ * @return String
+ */
+ public String getSqlType() {
+ return sqlType;
+ }
+
+ /**
+ * Sets the sqlType.
+ * @param sqlType The sqlType to set
+ */
+ public void setSqlType(String sqlType) {
+ this.sqlType = sqlType;
+ }
+
+ /**
+ * Sets the unique.
+ * @param unique The unique to set
+ */
+ public void setUnique(boolean unique) {
+ this.unique = unique;
+ }
+
}
Index: Component.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Component.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Component.java 19 Jan 2003 11:47:07 -0000 1.6
--- Component.java 27 Jan 2003 07:12:03 -0000 1.7
***************
*** 6,22 ****
import net.sf.hibernate.MappingException;
- import net.sf.hibernate.engine.Cascades;
- import net.sf.hibernate.type.Type;
import net.sf.hibernate.util.JoinedIterator;
- import net.sf.hibernate.util.ReflectHelper;
- import net.sf.hibernate.util.StringHelper;
- import net.sf.hibernate.type.ComponentType;
- import net.sf.hibernate.type.DynaBeanType;
import org.apache.commons.beanutils.BasicDynaClass;
- import org.apache.commons.beanutils.BasicDynaBean;
- import org.apache.commons.beanutils.DynaProperty;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
public class Component extends Value {
--- 6,12 ----
***************
*** 25,30 ****
private Class componentClass;
private BasicDynaClass dynaClass;
! private final boolean embedded;
private String parentProperty;
public int getPropertySpan() {
--- 15,21 ----
private Class componentClass;
private BasicDynaClass dynaClass;
! private boolean embedded;
private String parentProperty;
+ private PersistentClass owner;
public int getPropertySpan() {
***************
*** 59,166 ****
}
! public Component(Node node, Class reflectedClass, String path, PersistentClass owner, boolean isNullable, Table table, Root root) throws MappingException {
! super();
! setTable(table);
! Node classNode = node.getAttributes().getNamedItem("class");
! Node dynaclassNode = node.getAttributes().getNamedItem("dynaclass");
! String className;
! if (dynaclassNode!=null) {
! className = dynaclassNode.getNodeValue();
! embedded = false;
! }
! else if (classNode!=null) {
! className = classNode.getNodeValue();
! try {
! componentClass = ReflectHelper.classForName(className);
! }
! catch (ClassNotFoundException cnfe) {
! throw new MappingException( "component class not found", cnfe );
! }
! embedded = false;
! }
! else if (reflectedClass!=null) {
! componentClass = reflectedClass;
! className = componentClass.getName();
! embedded = false;
! }
! else {
! // an "embedded" component (ids only)
! componentClass = owner.getPersistentClass();
! className = owner.getName();
! embedded = true;
! }
!
! //component path
! path += Root.ROLE_SEPERATOR + StringHelper.unqualify(className);
!
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
!
! Node subnode = list.item(i);
! String name = subnode.getNodeName();
! String propertyName = Property.getPropertyName(subnode);
!
! Root.CollectionType collectType = Root.CollectionType.collectionTypeFromString(name);
! Value value = null;
! if (collectType!=null) {
! Collection collection = collectType.create( list.item(i), path, owner, root );
! root.addCollection(collection);
! value = new Value(subnode, isNullable, table, root);
! value.setType( collection.getType() );
! }
! else if ( "many-to-one".equals(name) || "key-many-to-one".equals(name) ) {
! value = new ManyToOne(subnode, path, propertyName, isNullable, table, root);
! }
! else if ( "one-to-one".equals(name) ) {
! value = new OneToOne(subnode, owner.getIdentifier(), path, isNullable, table, root);
! }
! else if ( "property".equals(name) || "key-property".equals(name) ) {
! value = new Value(subnode, isNullable, table, root, propertyName);
! }
! else if ( "collection".equals(name) ) {
! value = new Value(subnode, isNullable, table, root, propertyName);
! }
! else if ( "component".equals(name) || "dynabean".equals(name) || "nested-composite-element".equals(name) ) {
! Class subreflectedClass = (componentClass==null) ?
! null :
! ReflectHelper.getGetter( componentClass, propertyName ).getReturnType();
! value = new Component(subnode, subreflectedClass, path, owner, isNullable, table, root);
! }
! else if ( "parent".equals(name) ) {
! parentProperty = propertyName;
! }
! if ( value!=null) {
! if (componentClass!=null) value.setTypeByReflection(componentClass, propertyName);
! value.createForeignKeys(root, table);
! addProperty( new Property(subnode, value, root) );
! }
! }
!
! int span = getPropertySpan();
! String[] names = new String[span];
! Type[] types = new Type[span];
! Cascades.CascadeStyle[] cascade = new Cascades.CascadeStyle[span];
! int[] joinedFetch = new int[span];
! DynaProperty[] dynaprops = new DynaProperty[span];
! Iterator iter = getPropertyIterator();
! int i=0;
! while ( iter.hasNext() ) {
! Property prop = (Property) iter.next();
! names[i] = prop.getName();
! types[i] = prop.getType();
! cascade[i] = prop.cascade();
! joinedFetch[i] = prop.getValue().enableJoinedFetch();
! if (componentClass==null) dynaprops[i] = new DynaProperty( names[i], types[i].getReturnedClass() );
! i++;
! }
! if (componentClass==null) dynaClass = new BasicDynaClass(className, BasicDynaBean.class, dynaprops);
!
! setType(
! (componentClass==null) ?
! (Type) new DynaBeanType(dynaClass, names, types, joinedFetch, cascade) :
! (Type) new ComponentType(componentClass, names, types, joinedFetch, cascade, parentProperty, embedded)
! );
}
!
public void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException {
}
--- 50,63 ----
}
! public Component(PersistentClass owner) throws MappingException {
! super( owner.getTable() );
! this.owner = owner;
}
!
! public Component(Table table) throws MappingException {
! super(table);
! this.owner = null;
! }
!
public void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException {
}
***************
*** 174,177 ****
--- 71,154 ----
}
+ /**
+ * Returns the componentClass.
+ * @return Class
+ */
+ public Class getComponentClass() {
+ return componentClass;
+ }
+
+ /**
+ * Returns the dynaClass.
+ * @return BasicDynaClass
+ */
+ public BasicDynaClass getDynaClass() {
+ return dynaClass;
+ }
+
+ /**
+ * Returns the owner.
+ * @return PersistentClass
+ */
+ public PersistentClass getOwner() {
+ return owner;
+ }
+
+ /**
+ * Returns the parentProperty.
+ * @return String
+ */
+ public String getParentProperty() {
+ return parentProperty;
+ }
+
+ /**
+ * Returns the properties.
+ * @return ArrayList
+ */
+ public ArrayList getProperties() {
+ return properties;
+ }
+
+ /**
+ * Sets the componentClass.
+ * @param componentClass The componentClass to set
+ */
+ public void setComponentClass(Class componentClass) {
+ this.componentClass = componentClass;
+ }
+
+ /**
+ * Sets the dynaClass.
+ * @param dynaClass The dynaClass to set
+ */
+ public void setDynaClass(BasicDynaClass dynaClass) {
+ this.dynaClass = dynaClass;
+ }
+
+ /**
+ * Sets the embedded.
+ * @param embedded The embedded to set
+ */
+ public void setEmbedded(boolean embedded) {
+ this.embedded = embedded;
+ }
+
+ /**
+ * Sets the owner.
+ * @param owner The owner to set
+ */
+ public void setOwner(PersistentClass owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Sets the parentProperty.
+ * @param parentProperty The parentProperty to set
+ */
+ public void setParentProperty(String parentProperty) {
+ this.parentProperty = parentProperty;
+ }
+
}
Index: Index.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Index.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Index.java 20 Jan 2003 12:48:13 -0000 1.4
--- Index.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 11,24 ****
public class Index implements RelationalModel {
private Table table;
private ArrayList columns = new ArrayList();
private String name;
! public String sqlCreateString(Dialect dialect, Mapping p)
! throws HibernateException {
StringBuffer buf = new StringBuffer("create index ")
! .append( dialect.qualifyIndexName() ? name : StringHelper.unqualify(name) )
! .append(" on ")
! .append( table.getQualifiedName() )
! .append(" (");
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
--- 11,25 ----
public class Index implements RelationalModel {
+
private Table table;
private ArrayList columns = new ArrayList();
private String name;
!
! public String sqlCreateString(Dialect dialect, Mapping p) throws HibernateException {
StringBuffer buf = new StringBuffer("create index ")
! .append( dialect.qualifyIndexName() ? name : StringHelper.unqualify(name) )
! .append(" on ")
! .append( table.getQualifiedName() )
! .append(" (");
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
***************
*** 29,35 ****
--- 30,38 ----
return buf.toString();
}
+
public String sqlDropString(Dialect dialect) {
return "drop index " + table.getQualifiedName() + StringHelper.DOT + name;
}
+
public Table getTable() {
return table;
Index: IndexedCollection.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/IndexedCollection.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** IndexedCollection.java 19 Jan 2003 11:47:07 -0000 1.4
--- IndexedCollection.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 4,21 ****
import java.util.Iterator;
- import net.sf.hibernate.MappingException;
-
- import org.w3c.dom.Node;
-
public abstract class IndexedCollection extends Collection {
! protected static final String DEFAULT_INDEX_COLUMN_NAME = "idx";
private Value index;
public Value getIndex() {
return index;
}
! void setIndex(Value index) {
this.index = index;
}
--- 4,25 ----
import java.util.Iterator;
public abstract class IndexedCollection extends Collection {
! public static final String DEFAULT_INDEX_COLUMN_NAME = "idx";
private Value index;
+ /**
+ * Constructor for IndexedCollection.
+ * @param owner
+ */
+ public IndexedCollection(PersistentClass owner) {
+ super(owner);
+ }
+
public Value getIndex() {
return index;
}
! public void setIndex(Value index) {
this.index = index;
}
***************
*** 23,29 ****
return true;
}
! public IndexedCollection(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! super(node, prefix, owner, root);
! }
public void createPrimaryKey() {
PrimaryKey pk = new PrimaryKey();
--- 27,32 ----
return true;
}
!
!
public void createPrimaryKey() {
PrimaryKey pk = new PrimaryKey();
Index: IntegerValue.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/IntegerValue.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** IntegerValue.java 19 Jan 2003 11:47:07 -0000 1.6
--- IntegerValue.java 27 Jan 2003 07:12:03 -0000 1.7
***************
*** 3,22 ****
import net.sf.hibernate.Hibernate;
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.Type;
- import org.w3c.dom.Node;
-
public class IntegerValue extends Value {
! public Type getType() {
! return Hibernate.INTEGER;
}
! public IntegerValue(Node node, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, isNullable, table, root, defaultColumnName);
! Column col = ( (Column) getColumnIterator().next() );
! col.setType( getType() );
! col.setTypeIndex(0);
}
--- 3,16 ----
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.type.Type;
public class IntegerValue extends Value {
! public IntegerValue(Table table) {
! super(table);
}
! public Type getType() {
! return Hibernate.INTEGER;
}
Index: List.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/List.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** List.java 19 Jan 2003 11:47:07 -0000 1.4
--- List.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 2,37 ****
package net.sf.hibernate.mapping;
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
-
public class List extends IndexedCollection {
! private boolean doneSecondPass;
!
! public List(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! super(node, prefix, owner, root);
! }
!
! public void secondPassCompile(java.util.Map classes) throws MappingException {
! super.secondPassCompile(classes);
! if (doneSecondPass) return;
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
! Node subnode = list.item(i);
! String name = subnode.getNodeName();
!
! if ( "index".equals(name) ) {
! setIndex( new IntegerValue(subnode, DEFAULT_INDEX_COLUMN_NAME, isOneToMany(), getTable(), root) );
! }
! }
! if ( !isOneToMany() ) createPrimaryKey();
!
! doneSecondPass = true;
}
!
public PersistentCollectionType getType() {
return TypeFactory.list( getRole() );
--- 2,18 ----
package net.sf.hibernate.mapping;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
public class List extends IndexedCollection {
! /**
! * Constructor for List.
! * @param owner
! */
! public List(PersistentClass owner) {
! super(owner);
}
!
public PersistentCollectionType getType() {
return TypeFactory.list( getRole() );
Index: ManyToOne.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/ManyToOne.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ManyToOne.java 5 Jan 2003 02:11:22 -0000 1.4
--- ManyToOne.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 2,33 ****
package net.sf.hibernate.mapping;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
-
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.util.ReflectHelper;
import net.sf.hibernate.type.EntityType;
- import net.sf.hibernate.type.Type;
import net.sf.hibernate.type.TypeFactory;
public class ManyToOne extends Association {
! // A many-to-one association
! public ManyToOne(Node node, String path, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, path, defaultColumnName, isNullable, table, root);
! }
!
! protected Type typeFromXML(Node node) throws MappingException {
!
! NamedNodeMap atts = node.getAttributes();
! Node typeNode = atts.getNamedItem("class");
! if (typeNode==null) return null;
! try {
! return TypeFactory.manyToOne( ReflectHelper.classForName( typeNode.getNodeValue() ) );
! }
! catch (Exception e) {
! throw new MappingException("Could not find class: " + typeNode.getNodeValue());
! }
}
--- 2,15 ----
package net.sf.hibernate.mapping;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.util.ReflectHelper;
import net.sf.hibernate.type.EntityType;
import net.sf.hibernate.type.TypeFactory;
public class ManyToOne extends Association {
! public ManyToOne(Table table) throws MappingException {
! super(table);
}
***************
*** 43,48 ****
}
! public void createForeignKeys(Root root, Table table) {
! createForeignKeyOfClass(root, table, ( (EntityType) getType() ).getPersistentClass() );
}
--- 25,30 ----
}
! public void createForeignKey() {
! createForeignKeyOfClass( ( (EntityType) getType() ).getPersistentClass() );
}
Index: Map.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Map.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Map.java 19 Jan 2003 11:47:07 -0000 1.7
--- Map.java 27 Jan 2003 07:12:03 -0000 1.8
***************
*** 2,78 ****
package net.sf.hibernate.mapping;
- import java.util.Comparator;
-
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
- import net.sf.hibernate.util.ReflectHelper;
-
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
public class Map extends IndexedCollection {
! private final boolean sorted;
! private Comparator comparator;
! private boolean doneSecondPass;
!
! public Map(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! super(node, prefix, owner, root);
!
! Node sortedAtt = node.getAttributes().getNamedItem("sort");
!
! // unsorted, natural, comparator.class.name
! if (sortedAtt==null|| sortedAtt.getNodeValue().equals("unsorted") ) {
! sorted = false;
! }
! else {
! sorted = true;
! String className = sortedAtt.getNodeValue();
! if ( !className.equals("natural") ) {
! try {
! comparator = (Comparator) ReflectHelper.classForName(className).newInstance();
! }
! catch (Exception e) {
! throw new MappingException( "Could not instantiate comparator class: " + className );
! }
! }
! }
!
! }
!
! public void secondPassCompile(java.util.Map classes) throws MappingException {
! super.secondPassCompile(classes);
! if (doneSecondPass) return;
! NodeList list = node.getChildNodes();
! for ( int i=0; i<list.getLength(); i++ ) {
! Node subnode = list.item(i);
! String name = subnode.getNodeName();
!
! if ( "index".equals(name) ) {
! setIndex( new Value(subnode, isOneToMany(), getTable(), root, DEFAULT_INDEX_COLUMN_NAME) );
! if ( getIndex().getType()==null ) throw new MappingException("map index element must specify a type");
! }
! else if ( "index-many-to-many".equals(name) ) {
! setIndex( new ManyToOne(subnode, null, DEFAULT_INDEX_COLUMN_NAME, isOneToMany(), getTable(), root ) );
!
! }
! else if ( "composite-index".equals(name) ) {
! setIndex( new Component(subnode, null, Root.ROOT_ROLE_NAME, null, isOneToMany(), getTable(), root) );
! }
! }
! if ( !isInverse() ) getIndex().createForeignKeys( root, getTable() );
!
! if ( !isOneToMany() ) createPrimaryKey();
!
! doneSecondPass = true;
}
!
public PersistentCollectionType getType() {
! return sorted ? TypeFactory.sortedMap( getRole(), comparator ): TypeFactory.map( getRole() );
}
public Class wrapperClass() {
! return sorted ? net.sf.hibernate.collection.SortedMap.class : net.sf.hibernate.collection.Map.class;
}
--- 2,24 ----
package net.sf.hibernate.mapping;
import net.sf.hibernate.type.PersistentCollectionType;
import net.sf.hibernate.type.TypeFactory;
public class Map extends IndexedCollection {
! /**
! * Constructor for Map.
! * @param owner
! */
! public Map(PersistentClass owner) {
! super(owner);
}
!
public PersistentCollectionType getType() {
! return isSorted() ? TypeFactory.sortedMap( getRole(), getComparator() ): TypeFactory.map( getRole() );
}
public Class wrapperClass() {
! return isSorted() ? net.sf.hibernate.collection.SortedMap.class : net.sf.hibernate.collection.Map.class;
}
Index: OneToMany.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/OneToMany.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** OneToMany.java 19 Jan 2003 11:47:07 -0000 1.4
--- OneToMany.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 2,11 ****
package net.sf.hibernate.mapping;
- import net.sf.hibernate.Hibernate;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.type.EntityType;
- import net.sf.hibernate.util.ReflectHelper;
-
- import org.w3c.dom.Node;
public class OneToMany {
--- 2,7 ----
***************
*** 13,18 ****
//TODO: actually keep a list of columns
! private final EntityType type;
! private final Table referencingTable;
public EntityType getType() {
--- 9,14 ----
//TODO: actually keep a list of columns
! private EntityType type;
! private Table referencingTable;
public EntityType getType() {
***************
*** 20,33 ****
}
! public OneToMany(Node node, PersistentClass owner) throws MappingException {
this.referencingTable = (owner==null) ? null : owner.getTable();
- try {
- type = (EntityType) Hibernate.association( ReflectHelper.classForName(
- node.getAttributes().getNamedItem("class").getNodeValue()
- ) );
- }
- catch (ClassNotFoundException cnfe) {
- throw new MappingException("Associated class not found", cnfe);
- }
}
--- 16,21 ----
}
! public OneToMany(PersistentClass owner) throws MappingException {
this.referencingTable = (owner==null) ? null : owner.getTable();
}
***************
*** 35,38 ****
--- 23,35 ----
return referencingTable;
}
+
+ /**
+ * Sets the type.
+ * @param type The type to set
+ */
+ public void setType(EntityType type) {
+ this.type = type;
+ }
+
}
Index: OneToOne.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/OneToOne.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** OneToOne.java 5 Jan 2003 02:11:22 -0000 1.4
--- OneToOne.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 5,11 ****
import java.util.Iterator;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
-
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
--- 5,8 ----
***************
*** 13,17 ****
import net.sf.hibernate.type.AssociationType;
import net.sf.hibernate.type.EntityType;
- import net.sf.hibernate.type.Type;
import net.sf.hibernate.type.TypeFactory;
--- 10,13 ----
***************
*** 22,49 ****
private Value identifier;
! // A one-to-one association
! public OneToOne(Node node, Value identifier, String path, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, isNullable, table, root);
this.identifier = identifier;
}
- protected Type typeFromXML(Node node) throws MappingException {
-
- NamedNodeMap atts = node.getAttributes();
- Node constrNode = atts.getNamedItem("constrained");
- constrained = constrNode!=null && constrNode.getNodeValue().equals("true");
-
- foreignKeyType = constrained ? AssociationType.FOREIGN_KEY_FROM_PARENT : AssociationType.FOREIGN_KEY_TO_PARENT;
-
- Node typeNode = atts.getNamedItem("class");
- if (typeNode==null) return null;
- try {
- return TypeFactory.oneToOne( ReflectHelper.classForName( typeNode.getNodeValue() ), foreignKeyType );
- }
- catch (Exception e) {
- throw new MappingException("Could not find class: " + typeNode.getNodeValue());
- }
- }
-
public void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException {
try {
--- 18,26 ----
private Value identifier;
! public OneToOne(Table table, Value identifier) throws MappingException {
! super(table);
this.identifier = identifier;
}
public void setTypeByReflection(Class propertyClass, String propertyName) throws MappingException {
try {
***************
*** 56,61 ****
}
}
! public void createForeignKeys(Root root, Table table) {
! if (constrained) createForeignKeyOfClass( root, table, ( (EntityType) getType() ).getPersistentClass() );
}
--- 33,38 ----
}
}
! public void createForeignKey() {
! if (constrained) createForeignKeyOfClass( ( (EntityType) getType() ).getPersistentClass() );
}
***************
*** 66,69 ****
--- 43,95 ----
return list;
}
+ /**
+ * Returns the constrained.
+ * @return boolean
+ */
+ public boolean isConstrained() {
+ return constrained;
+ }
+
+ /**
+ * Returns the foreignKeyType.
+ * @return AssociationType.ForeignKeyType
+ */
+ public AssociationType.ForeignKeyType getForeignKeyType() {
+ return foreignKeyType;
+ }
+
+ /**
+ * Returns the identifier.
+ * @return Value
+ */
+ public Value getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Sets the constrained.
+ * @param constrained The constrained to set
+ */
+ public void setConstrained(boolean constrained) {
+ this.constrained = constrained;
+ }
+
+ /**
+ * Sets the foreignKeyType.
+ * @param foreignKeyType The foreignKeyType to set
+ */
+ public void setForeignKeyType(
+ AssociationType.ForeignKeyType foreignKeyType) {
+ this.foreignKeyType = foreignKeyType;
+ }
+
+ /**
+ * Sets the identifier.
+ * @param identifier The identifier to set
+ */
+ public void setIdentifier(Value identifier) {
+ this.identifier = identifier;
+ }
+
}
Index: PersistentClass.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/PersistentClass.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** PersistentClass.java 25 Jan 2003 00:13:55 -0000 1.7
--- PersistentClass.java 27 Jan 2003 07:12:03 -0000 1.8
***************
*** 5,57 ****
import java.util.Iterator;
- import net.sf.hibernate.MappingException;
import net.sf.hibernate.cache.CacheConcurrencyStrategy;
import net.sf.hibernate.util.JoinedIterator;
- import net.sf.hibernate.util.ReflectHelper;
- import net.sf.hibernate.util.StringHelper;
-
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
public abstract class PersistentClass {
! private final Class persistentClass;
! private final String className;
! private final String discriminatorValue;
! private final ArrayList properties = new ArrayList();
private Table table;
private final ArrayList subclasses = new ArrayList();
private final ArrayList subclassProperties = new ArrayList();
private final ArrayList subclassTables = new ArrayList();
- private Class proxyInterface; //can be final
- private final boolean dynamicUpdate;
-
- protected PersistentClass(Node node) throws MappingException {
- NamedNodeMap atts = node.getAttributes();
- className = atts.getNamedItem("name").getNodeValue();
- //CLASS
- try {
- persistentClass = ReflectHelper.classForName(className);
- }
- catch ( ClassNotFoundException cnfe ) {
- throw new MappingException( "persistent class not found", cnfe );
- }
- //PROXY INTERFACE
- Node proxyNode = atts.getNamedItem("proxy");
- if (proxyNode!=null) {
- try {
- proxyInterface = ReflectHelper.classForName( proxyNode.getNodeValue() );
- }
- catch (ClassNotFoundException cnfe) {
- throw new MappingException(cnfe);
- }
- }
- //DISCRIMINATOR
- Node discriminatorNode = atts.getNamedItem("discriminator-value");
- discriminatorValue = (discriminatorNode==null) ? className : discriminatorNode.getNodeValue();
- //DYNAMIC UPDATE
- Node dynamicNode = atts.getNamedItem("dynamic-update");
- dynamicUpdate = (dynamicNode==null) ? false : "true".equals( dynamicNode.getNodeValue() );
- }
public boolean useDynamicUpdate() {
--- 5,22 ----
import java.util.Iterator;
import net.sf.hibernate.cache.CacheConcurrencyStrategy;
import net.sf.hibernate.util.JoinedIterator;
public abstract class PersistentClass {
!
! private Class persistentClass;
! private String discriminatorValue;
! private ArrayList properties = new ArrayList();
private Table table;
+ private Class proxyInterface;
+ private boolean dynamicUpdate;
private final ArrayList subclasses = new ArrayList();
private final ArrayList subclassProperties = new ArrayList();
private final ArrayList subclassTables = new ArrayList();
public boolean useDynamicUpdate() {
***************
*** 63,115 ****
}
! protected void addSubclass(Subclass subclass) {
subclasses.add(subclass);
}
- protected void propertiesFromXML(Node node, Root root) throws MappingException {
-
- NodeList list = node.getChildNodes();
- String path = StringHelper.unqualify(className);
- Table table = getTable();
- for ( int i=0; i<list.getLength(); i++ ) {
-
- Node subnode = list.item(i);
- String name = subnode.getNodeName();
- String propertyName = Property.getPropertyName(subnode);
-
- Root.CollectionType collectType = Root.CollectionType.collectionTypeFromString(name);
- Value value = null;
- if (collectType!=null) {
- Collection collection = collectType.create(subnode, path, this, root);
- root.addCollection(collection);
- value = new Value(subnode, true, table, root);
- value.setType( collection.getType() );
- }
- else if ( "many-to-one".equals(name) ) {
- value = new ManyToOne(subnode, path, propertyName, true, table, root);
- }
- else if ( "one-to-one".equals(name) ) {
- value = new OneToOne(subnode, getIdentifier(), path, true, table, root);
- }
- else if ( "property".equals(name) ) {
- value = new Value(subnode, true, table, root, propertyName);
- }
- else if ( "component".equals(name) || "dynabean".equals(name) ) {
- Class reflectedClass = ReflectHelper.getGetter( getPersistentClass(), propertyName ).getReturnType();
- value = new Component(subnode, reflectedClass, path, this, true, table, root);
- }
- else if ( "subclass".equals(name) || "joined-subclass".equals(name) ) {
- Subclass subclass = new Subclass( this, list.item(i), getTable(), root );
- addSubclass(subclass);
- root.addPersistentClass(subclass);
- }
- if ( value!=null) {
- value.setTypeByReflection(persistentClass, propertyName);
- value.createForeignKeys(root, table);
- addProperty( new Property(subnode, value, root) );
- }
- }
- }
-
public boolean hasSubclasses() {
return subclasses.size() > 0;
--- 28,35 ----
}
! public void addSubclass(Subclass subclass) {
subclasses.add(subclass);
}
public boolean hasSubclasses() {
return subclasses.size() > 0;
***************
*** 201,204 ****
--- 121,157 ----
public abstract RootClass getRootClass();
public abstract Value getKey();
+
+ /**
+ * Sets the discriminatorValue.
+ * @param discriminatorValue The discriminatorValue to set
+ */
+ public void setDiscriminatorValue(String discriminatorValue) {
+ this.discriminatorValue = discriminatorValue;
+ }
+
+ /**
+ * Sets the dynamicUpdate.
+ * @param dynamicUpdate The dynamicUpdate to set
+ */
+ public void setDynamicUpdate(boolean dynamicUpdate) {
+ this.dynamicUpdate = dynamicUpdate;
+ }
+
+ /**
+ * Sets the persistentClass.
+ * @param persistentClass The persistentClass to set
+ */
+ public void setPersistentClass(Class persistentClass) {
+ this.persistentClass = persistentClass;
+ }
+
+ /**
+ * Sets the proxyInterface.
+ * @param proxyInterface The proxyInterface to set
+ */
+ public void setProxyInterface(Class proxyInterface) {
+ this.proxyInterface = proxyInterface;
+ }
+
}
Index: PrimitiveArray.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/PrimitiveArray.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PrimitiveArray.java 19 Jan 2003 11:47:07 -0000 1.4
--- PrimitiveArray.java 27 Jan 2003 07:12:03 -0000 1.5
***************
*** 2,14 ****
package net.sf.hibernate.mapping;
- import net.sf.hibernate.MappingException;
-
- import org.w3c.dom.Node;
-
public class PrimitiveArray extends Array {
! public PrimitiveArray(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! super(node, prefix, owner, root);
}
!
public boolean isPrimitiveArray() {
return true;
--- 2,15 ----
package net.sf.hibernate.mapping;
public class PrimitiveArray extends Array {
!
! /**
! * Constructor for PrimitiveArray.
! * @param owner
! */
! public PrimitiveArray(PersistentClass owner) {
! super(owner);
}
!
public boolean isPrimitiveArray() {
return true;
Index: Property.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Property.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Property.java 24 Jan 2003 16:15:57 -0000 1.5
--- Property.java 27 Jan 2003 07:12:03 -0000 1.6
***************
*** 14,19 ****
public class Property {
! private final String name;
! private final Value value;
private String cascade;
private boolean mutable;
--- 14,19 ----
public class Property {
! private String name;
! private Value value;
private String cascade;
private boolean mutable;
***************
*** 39,56 ****
}
- public Property(Node node, Value value, Root root) throws MappingException {
- name = getPropertyName(node);
- this.value=value;
- Type type = value.getType();
- if (type==null) throw new MappingException( "Could not determine a property type for: " + name );
- Node cascadeNode = node.getAttributes().getNamedItem("cascade");
- cascade = (cascadeNode==null) ? root.getDefaultCascade() : cascadeNode.getNodeValue();
- Node mutableNode = node.getAttributes().getNamedItem("mutable");
- mutable = (mutableNode==null) ? true : "true".equals( mutableNode.getNodeValue() );
- }
-
public Value getValue() {
return value;
}
public static String getPropertyName(Node node) {
NamedNodeMap atts = node.getAttributes();
--- 39,46 ----
}
public Value getValue() {
return value;
}
+
public static String getPropertyName(Node node) {
NamedNodeMap atts = node.getAttributes();
***************
*** 61,65 ****
}
! public Cascades.CascadeStyle cascade() throws MappingException {
if ( value.getType().isComponentType() ) {
AbstractComponentType actype = (AbstractComponentType) value.getType();
--- 51,55 ----
}
! public Cascades.CascadeStyle getCascadeStyle() throws MappingException {
if ( value.getType().isComponentType() ) {
AbstractComponentType actype = (AbstractComponentType) value.getType();
***************
*** 90,93 ****
--- 80,123 ----
+ /**
+ * Returns the cascade.
+ * @return String
+ */
+ public String getCascade() {
+ return cascade;
+ }
+
+ /**
+ * Sets the cascade.
+ * @param cascade The cascade to set
+ */
+ public void setCascade(String cascade) {
+ this.cascade = cascade;
+ }
+
+ /**
+ * Sets the mutable.
+ * @param mutable The mutable to set
+ */
+ public void setMutable(boolean mutable) {
+ this.mutable = mutable;
+ }
+
+ /**
+ * Sets the name.
+ * @param name The name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Sets the value.
+ * @param value The value to set
+ */
+ public void setValue(Value value) {
+ this.value = value;
+ }
+
}
Index: Root.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Root.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Root.java 20 Jan 2003 12:48:13 -0000 1.6
--- Root.java 27 Jan 2003 07:12:03 -0000 1.7
***************
*** 2,12 ****
package net.sf.hibernate.mapping;
! import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
import net.sf.hibernate.MappingException;
--- 2,9 ----
package net.sf.hibernate.mapping;
! import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.hibernate.MappingException;
***************
*** 17,135 ****
import net.sf.hibernate.cache.ReadOnlyCache;
import net.sf.hibernate.cache.ReadWriteCache;
- import net.sf.hibernate.type.Type;
import net.sf.hibernate.util.StringHelper;
public class Root {
! static final String ROOT_ROLE_NAME = StringHelper.EMPTY_STRING;
! static final char ROLE_SEPERATOR = '/';
!
! Log log = LogFactory.getLog(Root.class);
!
! private final java.util.Map classes;
! private final java.util.Map collections;
! private final java.util.Map tables;
! private final java.util.Map queries;
! private final String schemaName;
! private final String defaultCascade;
! private static final String[] NO_STRINGS = {};
! private static final Type[] NO_TYPES = {};
! private static final Integer[] NO_INTEGERS = {};
! //This inner class implements a case statement....perhaps im being a bit over-clever here
! public static abstract class CollectionType {
! private String xmlTag;
! public abstract Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException;
! CollectionType(String xmlTag) {
! this.xmlTag = xmlTag;
! }
! public String toString() {
! return xmlTag;
! }
! private static final CollectionType MAP = new CollectionType("map") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new Map(node, prefix, owner, root);
! }
! };
! private static final CollectionType SET = new CollectionType("set") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new Set(node, prefix, owner, root);
! }
! };
! private static final CollectionType LIST = new CollectionType("list") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new List(node, prefix, owner, root);
! }
! };
! private static final CollectionType BAG = new CollectionType("bag") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new Bag(node, prefix, owner, root);
! }
! };
! private static final CollectionType ARRAY = new CollectionType("array") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new Array(node, prefix, owner, root);
! }
! };
! private static final CollectionType PRIMITIVE_ARRAY = new CollectionType("primitive-array") {
! public Collection create(Node node, String prefix, PersistentClass owner, Root root) throws MappingException {
! return new PrimitiveArray(node, prefix, owner, root);
! }
! };
! private static final HashMap INSTANCES = new HashMap();
! static {
! INSTANCES.put(MAP.toString(), MAP);
! INSTANCES.put(BAG.toString(), BAG);
! INSTANCES.put(SET.toString(), SET);
! INSTANCES.put(LIST.toString(), LIST);
! INSTANCES.put(ARRAY.toString(), ARRAY);
! INSTANCES.put(PRIMITIVE_ARRAY.toString(), PRIMITIVE_ARRAY);
! }
! public static CollectionType collectionTypeFromString(String xmlTagName) {
! return (CollectionType) INSTANCES.get(xmlTagName);
! }
! }
! public Root(
! Document doc,
! java.util.Map classes,
! java.util.Map collections,
! java.util.Map tables,
! java.util.Map queries
! ) throws Exception {
!
this.classes = classes;
this.collections = collections;
this.queries = queries;
this.tables = tables;
-
- // Create maps for all the collections and classes
-
- Node hmNode = doc.getElementsByTagName("hibernate-mapping").item(0);
- Node schemaNode = hmNode.getAttributes().getNamedItem("schema");
- schemaName = (schemaNode==null) ? null : schemaNode.getNodeValue();
- Node dcNode = hmNode.getAttributes().getNamedItem("default-cascade");
- defaultCascade = (dcNode==null) ? "none" : dcNode.getNodeValue();
-
- NodeList nodes = hmNode.getChildNodes();
- for ( int i=0; i<nodes.getLength(); i++ ) {
-
- Node n = nodes.item(i);
- String name = n.getNodeName();
- if ( name.equals("class") ) {
- RootClass rootclass = new RootClass( n, this );
- log.debug("Root class: " + rootclass.getName() + " -> " + rootclass.getTable().getName() );
- addPersistentClass(rootclass);
- }
- else if ( name.equals("query") ) {
- String qname = n.getAttributes().getNamedItem("name").getNodeValue();
- String query = n.getFirstChild().getNodeValue();
- log.debug("Named query: " + qname + " -> " + query);
- Object old = queries.put(qname, query);
- if (old!=null) throw new MappingException("duplicate query name: " + qname);
- }
-
- }
}
--- 14,38 ----
import net.sf.hibernate.cache.ReadOnlyCache;
import net.sf.hibernate.cache.ReadWriteCache;
import net.sf.hibernate.util.StringHelper;
public class Root {
! public static final String ROOT_ROLE_NAME = StringHelper.EMPTY_STRING;
! public static final char ROLE_SEPERATOR = '/';
! private static final Log log = LogFactory.getLog(Root.class);
! private final Map classes;
! private final Map collections;
! private final Map tables;
! private final Map queries;
! private String schemaName;
! private String defaultCascade;
! public Root(Map classes, Map collections, Map tables, Map queries) {
this.classes = classes;
this.collections = collections;
this.queries = queries;
this.tables = tables;
}
***************
*** 142,151 ****
if ( old!=null ) throw new MappingException( "duplicate collection role: " + collection.getRole() );
}
...
[truncated message content] |