Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/map In directory sc8-pr-cvs1:/tmp/cvs-serv27566/hibernate/map Modified Files: Collection.java OneToOne.java PersistentClass.java RootClass.java Subclass.java Table.java Value.java Log Message: fk constraint generation between <joined-subclass> tables Index: Collection.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Collection.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** Collection.java 15 Dec 2002 07:27:37 -0000 1.51 --- Collection.java 25 Dec 2002 04:16:36 -0000 1.52 *************** *** 169,173 **** } ! if (!isIndexed()) createIndex(); doneSecondPass=true; --- 169,173 ---- } ! if ( !isIndexed() ) createIndex(); doneSecondPass=true; *************** *** 212,216 **** Index index = table.getIndex(name); Iterator iter = getKey().getColumnIterator(); ! while (iter.hasNext()) index.addColumn((Column)iter.next()); return index; } --- 212,216 ---- Index index = table.getIndex(name); Iterator iter = getKey().getColumnIterator(); ! while ( iter.hasNext() ) index.addColumn( (Column) iter.next() ); return index; } Index: OneToOne.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/OneToOne.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OneToOne.java 30 Nov 2002 08:19:00 -0000 1.5 --- OneToOne.java 25 Dec 2002 04:16:36 -0000 1.6 *************** *** 2,5 **** --- 2,6 ---- package cirrus.hibernate.map; + import java.util.ArrayList; import java.util.Iterator; *************** *** 59,64 **** } ! public Iterator getConstraintColumnIterator() { ! return identifier.getColumnIterator(); } } --- 60,68 ---- } ! public java.util.List getConstraintColumns() { ! ArrayList list = new ArrayList(); ! Iterator iter = identifier.getColumnIterator(); ! while ( iter.hasNext() ) list.add( iter.next() ); ! return list; } } Index: PersistentClass.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/PersistentClass.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** PersistentClass.java 30 Nov 2002 08:19:00 -0000 1.43 --- PersistentClass.java 25 Dec 2002 04:16:36 -0000 1.44 *************** *** 15,19 **** private final String discriminatorValue; private final ArrayList properties = new ArrayList(); ! private final ArrayList tables = new ArrayList(); private final ArrayList subclasses = new ArrayList(); private final ArrayList subclassProperties = new ArrayList(); --- 15,19 ---- 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(); *************** *** 136,147 **** properties.add(p); } ! public void addTable(Table table) { ! tables.add(table); } public Iterator getPropertyIterator() { return properties.iterator(); } ! public Iterator getTableIterator() { ! return tables.iterator(); } --- 136,147 ---- properties.add(p); } ! public void setTable(Table table) { ! this.table=table; } public Iterator getPropertyIterator() { return properties.iterator(); } ! public Table getTable() { ! return table; } *************** *** 163,167 **** public abstract boolean isPolymorphic(); public abstract boolean isVersioned(); - public abstract Table getTable(); public abstract CacheConcurrencyStrategy getCache(); public abstract PersistentClass getSuperclass(); --- 163,166 ---- Index: RootClass.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/RootClass.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** RootClass.java 14 Dec 2002 09:27:55 -0000 1.54 --- RootClass.java 25 Dec 2002 04:16:36 -0000 1.55 *************** *** 2,5 **** --- 2,6 ---- package cirrus.hibernate.map; + import java.util.Collections; import java.util.Iterator; *************** *** 27,31 **** private Property version; //may be final private boolean polymorphic; - private final Table table; private CacheConcurrencyStrategy cache; private Value discriminator; //may be final --- 28,31 ---- *************** *** 39,45 **** } - public Table getTable() { - return table; - } public Property getIdentifierProperty() { return identifierProperty; --- 39,42 ---- *************** *** 74,78 **** } public Iterator getTableClosureIterator() { ! return getTableIterator(); } --- 71,75 ---- } public Iterator getTableClosureIterator() { ! return Collections.singletonList( getTable() ).iterator(); } *************** *** 98,103 **** Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! table = root.addTable(schema, tableName); ! addTable(table); //PERSISTER --- 95,100 ---- Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! Table table = root.addTable(schema, tableName); ! setTable(table); //PERSISTER Index: Subclass.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Subclass.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Subclass.java 14 Dec 2002 09:27:55 -0000 1.22 --- Subclass.java 25 Dec 2002 04:16:36 -0000 1.23 *************** *** 14,18 **** public class Subclass extends PersistentClass { private final PersistentClass superclass; - private final Table table; private Value key; --- 14,17 ---- *************** *** 54,60 **** return true; } - public Table getTable() { - return table; - } public void addProperty(Property p) { --- 53,56 ---- *************** *** 62,74 **** getSuperclass().addSubclassProperty(p); } ! public void addTable(Table table) { ! super.addTable(table); getSuperclass().addSubclassTable(table); } public Iterator getPropertyClosureIterator() { ! return new JoinedIterator( new Iterator[] { getPropertyIterator(), getSuperclass().getPropertyClosureIterator() } ); } public Iterator getTableClosureIterator() { ! return new JoinedIterator( new Iterator[] { getTableIterator(), getSuperclass().getTableClosureIterator() } ); } protected void addSubclassProperty(Property p) { --- 58,76 ---- getSuperclass().addSubclassProperty(p); } ! public void setTable(Table table) { ! super.setTable(table); getSuperclass().addSubclassTable(table); } public Iterator getPropertyClosureIterator() { ! return new JoinedIterator( new Iterator[] { ! getPropertyIterator(), ! getSuperclass().getPropertyClosureIterator() } ! ); } public Iterator getTableClosureIterator() { ! return new JoinedIterator( new Iterator[] { ! getSuperclass().getTableClosureIterator(), ! Collections.singletonList( getTable() ).iterator() ! } ); } protected void addSubclassProperty(Property p) { *************** *** 98,102 **** } ! this.table = table; } else { --- 100,104 ---- } ! setTable(table); } else { *************** *** 110,137 **** Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! this.table = root.addTable(schema, tableName); ! addTable(this.table); //Primary key constraint PrimaryKey pk = new PrimaryKey(); ! pk.setTable(this.table); pk.setName( StringHelper.suffix( tableName, "PK" ) ); ! this.table.setPrimaryKey(pk); ! NodeList subnodes = node.getChildNodes(); 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, this.table, root ); } } - /*if ( key==null) { - key = getIdentifier(); - Iterator iter = key.getColumnIterator(); - while ( iter.hasNext() ) { - Column col = (Column) iter.next(); - this.table.addColumn(col); - } - }*/ key.setType( getIdentifier().getType() ); --- 112,130 ---- Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! Table mytable = root.addTable(schema, tableName); ! setTable(mytable); //Primary key constraint PrimaryKey pk = new PrimaryKey(); ! pk.setTable(mytable); pk.setName( StringHelper.suffix( tableName, "PK" ) ); ! mytable.setPrimaryKey(pk); NodeList subnodes = node.getChildNodes(); 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 ); } } key.setType( getIdentifier().getType() ); *************** *** 142,145 **** --- 135,142 ---- pk.addColumn(col); } + + ForeignKey fk = mytable.getForeignKey( key.getConstraintColumns() ); + fk.setReferencedClass( superclass.getPersistentClass() ); + } Index: Table.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Table.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Table.java 15 Dec 2002 07:27:38 -0000 1.32 --- Table.java 25 Dec 2002 04:16:36 -0000 1.33 *************** *** 3,6 **** --- 3,7 ---- import java.util.Iterator; + import java.util.List; import java.util.Map; import java.util.HashMap; *************** *** 197,203 **** } ! public ForeignKey getForeignKey(String name) ! { ! ForeignKey fk = (ForeignKey)foreignKeys.get(name); if (fk == null) { --- 198,205 ---- } ! public ForeignKey getForeignKey(List columns) { ! ! String name = "FK" + uniqueColumnString( columns.iterator() ); ! ForeignKey fk = (ForeignKey) foreignKeys.get(name); if (fk == null) { *************** *** 207,211 **** foreignKeys.put(name, fk); } ! return fk; } --- 209,214 ---- foreignKeys.put(name, fk); } ! Iterator iter = columns.iterator(); ! while ( iter.hasNext() ) fk.addColumn( (Column) iter.next() ); return fk; } Index: Value.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Value.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** Value.java 15 Dec 2002 07:27:38 -0000 1.43 --- Value.java 25 Dec 2002 04:16:36 -0000 1.44 *************** *** 22,26 **** public void addColumn(Column column) { ! if (!columns.contains(column)) columns.add(column); } public int getColumnSpan() { --- 22,26 ---- public void addColumn(Column column) { ! if ( !columns.contains(column) ) columns.add(column); } public int getColumnSpan() { *************** *** 30,35 **** return columns.iterator(); } ! public Iterator getConstraintColumnIterator() { ! return columns.iterator(); } --- 30,35 ---- return columns.iterator(); } ! public java.util.List getConstraintColumns() { ! return columns; } *************** *** 105,112 **** public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) { //foreign key ! String name = "FK" + table.uniqueColumnString( getConstraintColumnIterator() ); ! ForeignKey fk = table.getForeignKey(name); ! Iterator iter = getConstraintColumnIterator(); ! while (iter.hasNext()) fk.addColumn((Column)iter.next()); fk.setReferencedClass(persistentClass); } --- 105,109 ---- public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) { //foreign key ! ForeignKey fk = table.getForeignKey( getConstraintColumns() ); fk.setReferencedClass(persistentClass); } |