|
From: <one...@us...> - 2003-01-09 12:24:54
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping
In directory sc8-pr-cvs1:/tmp/cvs-serv16192/net/sf/hibernate/mapping
Modified Files:
Association.java Collection.java Component.java
IntegerValue.java Map.java PersistentClass.java Root.java
RootClass.java Subclass.java Table.java Value.java
Log Message:
redesigned id generator package
applied Mark Woon's patch for generated alias lengths
minor refactoring of Transaction package
Index: Association.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Association.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Association.java 5 Jan 2003 02:11:22 -0000 1.4
--- Association.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 32,36 ****
// A many-to-one association
protected Association(Node node, String path, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, defaultColumnName, isNullable, table, root);
joinedFetch = initJoinedFetch(node);
}
--- 32,36 ----
// 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);
}
Index: Collection.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Collection.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Collection.java 5 Jan 2003 02:11:22 -0000 1.6
--- Collection.java 9 Jan 2003 12:24:51 -0000 1.7
***************
*** 138,142 ****
if ( "key".equals(name) || "generated-key".equals(name) ) {
! key = new Value(subnode, DEFAULT_KEY_COLUMN_NAME, isOneToMany, table, root);
key.setType( owner.getIdentifier().getType() );
if ( key.getType().returnedClass().isArray() ) throw new MappingException(
--- 138,142 ----
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().returnedClass().isArray() ) throw new MappingException(
***************
*** 145,149 ****
}
else if ( "element".equals(name) ) {
! element = new Value(subnode, DEFAULT_ELEMENT_COLUMN_NAME, true, table, root);
}
else if ( "many-to-many".equals(name) ) {
--- 145,149 ----
}
else if ( "element".equals(name) ) {
! element = new Value(subnode, true, table, root, DEFAULT_ELEMENT_COLUMN_NAME);
}
else if ( "many-to-many".equals(name) ) {
Index: Component.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Component.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Component.java 5 Jan 2003 02:11:22 -0000 1.4
--- Component.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 104,111 ****
}
else if ( "property".equals(name) || "key-property".equals(name) ) {
! value = new Value(subnode, propertyName, isNullable, table, root);
}
else if ( "collection".equals(name) ) {
! value = new Value(subnode, propertyName, isNullable, table, root);
}
else if ( "component".equals(name) || "nested-composite-element".equals(name) ) {
--- 104,111 ----
}
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) || "nested-composite-element".equals(name) ) {
Index: IntegerValue.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/IntegerValue.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** IntegerValue.java 5 Jan 2003 02:11:22 -0000 1.4
--- IntegerValue.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 14,18 ****
public IntegerValue(Node node, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
! super(node, defaultColumnName, isNullable, table, root);
Column col = ( (Column) getColumnIterator().next() );
col.setType( getType() );
--- 14,18 ----
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() );
Index: Map.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Map.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Map.java 5 Jan 2003 02:11:22 -0000 1.5
--- Map.java 9 Jan 2003 12:24:51 -0000 1.6
***************
*** 50,54 ****
if ( "index".equals(name) ) {
! setIndex( new Value(subnode, DEFAULT_INDEX_COLUMN_NAME, isOneToMany(), getTable(), root) );
if ( getIndex().getType()==null ) throw new MappingException("map index element must specify a type");
}
--- 50,54 ----
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");
}
Index: PersistentClass.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/PersistentClass.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PersistentClass.java 5 Jan 2003 02:11:22 -0000 1.4
--- PersistentClass.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 81,85 ****
}
else if ( "property".equals(name) ) {
! value = new Value(subnode, propertyName, true, table, root);
}
else if ( "component".equals(name) ) {
--- 81,85 ----
}
else if ( "property".equals(name) ) {
! value = new Value(subnode, true, table, root, propertyName);
}
else if ( "component".equals(name) ) {
Index: Root.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Root.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Root.java 5 Jan 2003 02:11:22 -0000 1.4
--- Root.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 2,7 ****
package net.sf.hibernate.mapping;
- import java.util.ArrayList;
- import java.util.Arrays;
import java.util.HashMap;
--- 2,5 ----
***************
*** 12,16 ****
import org.w3c.dom.NodeList;
- import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.cache.Cache;
--- 10,13 ----
***************
*** 20,25 ****
import net.sf.hibernate.cache.ReadOnlyCache;
import net.sf.hibernate.cache.ReadWriteCache;
- import net.sf.hibernate.util.ReflectHelper;
- import net.sf.hibernate.id.*;
import net.sf.hibernate.type.Type;
--- 17,20 ----
***************
*** 35,39 ****
private final java.util.Map tables;
private final java.util.Map queries;
- private final java.util.Map generators;
private final String schemaName;
private final String defaultCascade;
--- 30,33 ----
***************
*** 102,106 ****
java.util.Map collections,
java.util.Map tables,
- java.util.Map generators,
java.util.Map queries
) throws Exception {
--- 96,99 ----
***************
*** 110,114 ****
this.queries = queries;
this.tables = tables;
- this.generators = generators;
// Create maps for all the collections and classes
--- 103,106 ----
***************
*** 141,150 ****
}
- /*public Type getCollectionType(String role) throws MappingException {
- Collection coll = (Collection) collections.get(role);
- if (coll==null) throw new MappingException("undeclared collection role: " + role );
- return coll.getType();
- }*/
-
public void addPersistentClass(PersistentClass persistentClass) throws MappingException {
Object old = classes.put( persistentClass.getPersistentClass(), persistentClass );
--- 133,136 ----
***************
*** 178,238 ****
public String getDefaultCascade() {
return defaultCascade;
- }
-
-
- public IdentifierGenerator createIDGenerator(Node node) throws Exception {
-
- String className = node.getAttributes().getNamedItem("class").getNodeValue();
- Class idgenClass = (Class) idgenerators.get(className);
- if (idgenClass==null) {
- try {
- idgenClass = ReflectHelper.classForName(className);
- }
- catch (Exception e) {
- throw new HibernateException("ID generator class not found: " + className);
- }
- }
- ArrayList list = new ArrayList();
- NodeList nodes = node.getChildNodes();
- for (int i=0; i<nodes.getLength(); i++) {
- Node childNode = nodes.item(i);
- if ( childNode.getNodeName().equals("param") ) {
- list.add( childNode.getFirstChild().getNodeValue() );
- }
- }
- int size = list.size();
- Class[] argTypes = new Class[size];
- String[] args = new String[size];
- Arrays.fill(argTypes, String.class);
- list.toArray(args);
- IdentifierGenerator idgen;
- Object gen = null;
- try {
- gen = idgenClass.getConstructor(argTypes).newInstance(args);
- }
- catch(NoSuchMethodException e) {
- throw new MappingException("Exception while trying to instantiate " + idgenClass.getName() + " with " + list,e);
- }
-
- idgen = (IdentifierGenerator) gen;
-
- if ( PersistentIdentifierGenerator.class.isAssignableFrom(idgenClass) ) {
- generators.put( ( (PersistentIdentifierGenerator) idgen ).generatorKey(), idgen );
- }
- return idgen;
- }
-
- private static final HashMap idgenerators = new HashMap();
- static {
- idgenerators.put("uuid.hex", UUIDHexGenerator.class);
- idgenerators.put("uuid.string", UUIDStringGenerator.class);
- idgenerators.put("hilo.long", HiLoGenerator.class);
- idgenerators.put("hilo.hex", HiLoHexGenerator.class);
- idgenerators.put("vm.long", LongGenerator.class);
- idgenerators.put("vm.hex", HexGenerator.class);
- idgenerators.put("assigned", Assigned.class);
- idgenerators.put("native", NativeGenerator.class);
- idgenerators.put("sequence", SequenceGenerator.class);
- idgenerators.put("seqhilo.long", SequenceHiLoGenerator.class);
}
--- 164,167 ----
Index: RootClass.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/RootClass.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RootClass.java 5 Jan 2003 02:11:22 -0000 1.4
--- RootClass.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 139,149 ****
if ( "id".equals(name) ) {
if (propertyName==null) {
! identifier = new Value(subnode, DEFAULT_IDENTIFIER_COLUMN_NAME, false, table, root);
if (identifier.getType()==null) throw new MappingException( "must specify an identifier type: " + getPersistentClass().getName() );
identifierProperty = null;
}
else {
! identifier = new Value(subnode, propertyName, false, table, root);
identifier.setTypeByReflection( getPersistentClass(), propertyName );
identifierProperty = new Property(subnode, identifier, root);
}
--- 139,151 ----
if ( "id".equals(name) ) {
if (propertyName==null) {
! identifier = new Value(subnode, false, table, root, DEFAULT_IDENTIFIER_COLUMN_NAME);
if (identifier.getType()==null) throw new MappingException( "must specify an identifier type: " + getPersistentClass().getName() );
+ identifier.makeIdentifier(subnode, root);
identifierProperty = null;
}
else {
! identifier = new Value(subnode, false, table, root, propertyName);
identifier.setTypeByReflection( getPersistentClass(), propertyName );
+ identifier.makeIdentifier(subnode, root);
identifierProperty = new Property(subnode, identifier, root);
}
***************
*** 166,170 ****
else if ( "version".equals(name) || "timestamp".equals(name) ) {
//VERSION
! Value val = new Value(subnode, propertyName, false, table, root);
if ( val.getType()==null ) val.setType( "version".equals(name) ? Hibernate.INTEGER : Hibernate.TIMESTAMP );
version = new Property(subnode, val, root);
--- 168,172 ----
else if ( "version".equals(name) || "timestamp".equals(name) ) {
//VERSION
! Value val = new Value(subnode, false, table, root, propertyName);
if ( val.getType()==null ) val.setType( "version".equals(name) ? Hibernate.INTEGER : Hibernate.TIMESTAMP );
version = new Property(subnode, val, root);
***************
*** 173,177 ****
else if ( "discriminator".equals(name) ) {
//DISCRIMINATOR
! discriminator = new Value(subnode, DEFAULT_DISCRIMINATOR_COLUMN_NAME, false, table, root);
if ( discriminator.getType()==null ) {
discriminator.setType(Hibernate.STRING);
--- 175,179 ----
else if ( "discriminator".equals(name) ) {
//DISCRIMINATOR
! discriminator = new Value(subnode, false, table, root, DEFAULT_DISCRIMINATOR_COLUMN_NAME);
if ( discriminator.getType()==null ) {
discriminator.setType(Hibernate.STRING);
Index: Subclass.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Subclass.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Subclass.java 5 Jan 2003 02:11:22 -0000 1.3
--- Subclass.java 9 Jan 2003 12:24:51 -0000 1.4
***************
*** 124,128 ****
for ( int i=0; i<subnodes.getLength(); i++ ) {
if ( "key".equals( subnodes.item(i).getNodeName() ) ) {
! key = new Value( subnodes.item(i), Root.ROOT_ROLE_NAME, false, mytable, root );
}
}
--- 124,128 ----
for ( int i=0; i<subnodes.getLength(); i++ ) {
if ( "key".equals( subnodes.item(i).getNodeName() ) ) {
! key = new Value( subnodes.item(i), false, mytable, root, Root.ROOT_ROLE_NAME );
}
}
Index: Table.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Table.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Table.java 5 Jan 2003 02:11:22 -0000 1.3
--- Table.java 9 Jan 2003 12:24:51 -0000 1.4
***************
*** 8,14 ****
import net.sf.hibernate.engine.Mapping;
! import net.sf.hibernate.id.Assigned;
! import net.sf.hibernate.id.IdentifierGenerator;
! import net.sf.hibernate.id.NativeGenerator;
import net.sf.hibernate.dialect.Dialect;
import net.sf.hibernate.dialect.HSQLDialect;
--- 8,12 ----
import net.sf.hibernate.engine.Mapping;
! import net.sf.hibernate.id.IdentityGenerator;
import net.sf.hibernate.dialect.Dialect;
import net.sf.hibernate.dialect.HSQLDialect;
***************
*** 23,27 ****
private String schema;
private Map columns = new SequencedHashMap();
! private IdentifierGenerator identifierGenerator = Assigned.INSTANCE;
private PrimaryKey primaryKey;
private Map indexes = new HashMap();
--- 21,25 ----
private String schema;
private Map columns = new SequencedHashMap();
! private Value idValue;
private PrimaryKey primaryKey;
private Map indexes = new HashMap();
***************
*** 109,121 ****
.append(" (");
String pkname = null;
! // Try to find out the name of the primary key to create it as identity if the NativeGenerator is used
! boolean createIdentity;
! if (primaryKey != null) {
! createIdentity = dialect.supportsIdentityColumns() && ( identifierGenerator instanceof NativeGenerator );
pkname = ( (Column) primaryKey.getColumnIterator().next() ).getName();
}
- else
- createIdentity = false;
Iterator iter = columnIterator();
--- 107,117 ----
.append(" (");
+ boolean identityColumn = idValue!=null && idValue.createIdentifierGenerator(dialect) instanceof IdentityGenerator;
+
+ // Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used
String pkname = null;
! if (primaryKey != null && identityColumn ) {
pkname = ( (Column) primaryKey.getColumnIterator().next() ).getName();
}
Iterator iter = columnIterator();
***************
*** 127,131 ****
.append( col.getSqlType(dialect, p) );
! if ( createIdentity && col.getName().equals(pkname) ) {
buf.append(' ')
.append( dialect.getIdentityColumnString() );
--- 123,127 ----
.append( col.getSqlType(dialect, p) );
! if ( identityColumn && col.getName().equals(pkname) ) {
buf.append(' ')
.append( dialect.getIdentityColumnString() );
***************
*** 147,151 ****
}
if (primaryKey!=null) {
! if ( dialect instanceof HSQLDialect && identifierGenerator instanceof NativeGenerator ) {
// skip the primary key definition
// ugly, ugly hack!
--- 143,147 ----
}
if (primaryKey!=null) {
! if ( dialect instanceof HSQLDialect && identityColumn ) {
// skip the primary key definition
// ugly, ugly hack!
***************
*** 170,180 ****
}
- public IdentifierGenerator getIdentifierGenerator() {
- return identifierGenerator;
- }
- public void setIdentifierGenerator(IdentifierGenerator identifierGenerator) {
- this.identifierGenerator = identifierGenerator;
- }
-
public PrimaryKey getPrimaryKey() {
return primaryKey;
--- 166,169 ----
***************
*** 244,247 ****
--- 233,240 ----
public int getUniqueInteger() {
return uniqueInteger;
+ }
+
+ public void setIdentifierValue(Value idValue) {
+ this.idValue = idValue;
}
Index: Value.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/mapping/Value.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Value.java 5 Jan 2003 02:11:22 -0000 1.4
--- Value.java 9 Jan 2003 12:24:51 -0000 1.5
***************
*** 4,14 ****
import java.util.ArrayList;
import java.util.Iterator;
! import org.w3c.dom.*;
! import net.sf.hibernate.*;
! import net.sf.hibernate.util.ReflectHelper;
! import net.sf.hibernate.id.Assigned;
import net.sf.hibernate.id.IdentifierGenerator;
! import net.sf.hibernate.type.*;
import net.sf.hibernate.type.Type;
public class Value {
--- 4,21 ----
import java.util.ArrayList;
import java.util.Iterator;
! import java.util.Properties;
!
! import net.sf.hibernate.HibernateException;
! import net.sf.hibernate.MappingException;
! import net.sf.hibernate.dialect.Dialect;
import net.sf.hibernate.id.IdentifierGenerator;
! import net.sf.hibernate.id.IdentifierGeneratorFactory;
import net.sf.hibernate.type.Type;
+ import net.sf.hibernate.type.TypeFactory;
+ import net.sf.hibernate.util.ReflectHelper;
+
+ import org.w3c.dom.NamedNodeMap;
+ import org.w3c.dom.Node;
+ import org.w3c.dom.NodeList;
public class Value {
***************
*** 17,21 ****
private final ArrayList columns = new ArrayList();
private Type type;
! private IdentifierGenerator generator = Assigned.INSTANCE;
private String nullValue;
private Table table;
--- 24,29 ----
private final ArrayList columns = new ArrayList();
private Type type;
! private Properties identifierGeneratorProperties;
! private String identifierGeneratorStrategy = "assigned";
private String nullValue;
private Table table;
***************
*** 115,119 ****
//automatically makes a column with the default name if none is specifed by XML
! public Value(Node node, String defaultColumnName, boolean isNullable, Table table, Root root) throws MappingException {
this(node, isNullable, table, root);
if ( getColumnSpan()==0 ) {
--- 123,127 ----
//automatically makes a column with the default name if none is specifed by XML
! public Value(Node node, boolean isNullable, Table table, Root root, String defaultColumnName) throws MappingException {
this(node, isNullable, table, root);
if ( getColumnSpan()==0 ) {
***************
*** 123,126 ****
--- 131,137 ----
addColumn(col);
}
+ }
+
+ public void makeIdentifier(Node node, Root root) throws MappingException {
//GENERATOR
NodeList list = node.getChildNodes();
***************
*** 128,140 ****
Node subnode = list.item(i);
if ( "generator".equals( subnode.getNodeName() ) ) {
! try {
! generator = root.createIDGenerator(subnode);
! }
! catch (Exception e) {
! throw new MappingException( "Error creating ID generator",e);
}
! if (table!=null) table.setIdentifierGenerator(generator);
}
}
// UNSAVED-VALUE
Node nullValueNode = node.getAttributes().getNamedItem("unsaved-value");
--- 139,163 ----
Node subnode = list.item(i);
if ( "generator".equals( subnode.getNodeName() ) ) {
!
! identifierGeneratorStrategy = subnode.getAttributes().getNamedItem("class").getNodeValue();
!
! Properties params = new Properties();
! NodeList nodes = node.getChildNodes();
! for (int j=0; j<nodes.getLength(); j++) {
! Node childNode = nodes.item(j);
! if ( childNode.getNodeName().equals("param") ) {
! params.setProperty(
! childNode.getAttributes().getNamedItem("name").getNodeValue(),
! childNode.getFirstChild().getNodeValue()
! );
! }
}
!
! identifierGeneratorProperties = params;
}
}
+
+ table.setIdentifierValue(this);
+
// UNSAVED-VALUE
Node nullValueNode = node.getAttributes().getNamedItem("unsaved-value");
***************
*** 142,145 ****
--- 165,172 ----
}
+ public IdentifierGenerator createIdentifierGenerator(Dialect dialect) throws MappingException {
+ return IdentifierGeneratorFactory.create(identifierGeneratorStrategy, type, identifierGeneratorProperties, dialect);
+ }
+
protected Type typeFromXML(Node node) throws MappingException {
return getTypeFromXML(node);
***************
*** 149,160 ****
Type type;
NamedNodeMap atts = node.getAttributes();
- /*Node roleNode = atts.getNamedItem("role");
- if (roleNode!=null) {
- //System.out.println( path + Root.ROLE_SEPERATOR + roleNode.getNodeValue() );
- type = root.getCollectionType(
- path + Root.ROLE_SEPERATOR + roleNode.getNodeValue()
- );
- }
- else {*/
Node typeNode = atts.getNamedItem("type");
if (typeNode==null) {
--- 176,179 ----
***************
*** 165,169 ****
if (type==null) throw new MappingException( "Could not interpret type: " + typeNode.getNodeValue() );
}
- //}
return type;
}
--- 184,187 ----
***************
*** 189,194 ****
public int enableJoinedFetch() { return 0; }
! public IdentifierGenerator getIdentifierGenerator() {
! return generator;
}
--- 207,216 ----
public int enableJoinedFetch() { return 0; }
! public String getIdentifierStrategy() {
! return identifierGeneratorStrategy;
! }
!
! public Properties getIdentifierGeneratorProperties() {
! return identifierGeneratorProperties;
}
|