Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/map In directory sc8-pr-cvs1:/tmp/cvs-serv888/map Modified Files: Collection.java Column.java Constraint.java Index.java Root.java RootClass.java Subclass.java Table.java Value.java Log Message: Benoit Menendez patches to SchemaUpdater and blob support Index: Collection.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Collection.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** Collection.java 26 Nov 2002 03:35:42 -0000 1.49 --- Collection.java 14 Dec 2002 09:27:55 -0000 1.50 *************** *** 110,117 **** Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! table = new Table(); ! table.setName(tableName); ! table.setSchema(schema); ! if (!readonly) root.addTable(table); } //LAZINESS --- 110,114 ---- Node schemaNode = atts.getNamedItem("schema"); String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! table = root.addTable(schema, tableName); } //LAZINESS *************** *** 170,177 **** if (!toplevel) key.createForeignKeyOfClass( root, table, owner.getPersistentClass() ); // no foreign key for a toplevel - - if ( !isIndexed() ) root.addIndex( createIndex() ); } doneSecondPass=true; } --- 167,174 ---- if (!toplevel) key.createForeignKeyOfClass( root, table, owner.getPersistentClass() ); // no foreign key for a toplevel } + if (!isIndexed()) createIndex(); + doneSecondPass=true; } *************** *** 195,199 **** return false; } ! public boolean isArray() { return false; } --- 192,197 ---- return false; } ! ! public boolean isArray() { return false; } *************** *** 211,221 **** } public Index createIndex() { ! Index index = new Index(); ! index.setName( StringHelper.suffix( table.getQualifiedName(), "IDX" + table.generateConstraintID() ) ); ! index.setTable(table); Iterator iter = getKey().getColumnIterator(); ! while ( iter.hasNext() ) { ! index.addColumn( (Column) iter.next() ); ! } return index; } --- 209,217 ---- } public Index createIndex() { ! int indexID = table.generateConstraintID(getKey().getColumnIterator()); ! String name = StringHelper.suffix(table.getQualifiedName(), "IDX" + Integer.toHexString(indexID).toUpperCase()); ! Index index = table.getIndex(name); Iterator iter = getKey().getColumnIterator(); ! while (iter.hasNext()) index.addColumn((Column)iter.next()); return index; } Index: Column.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Column.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Column.java 26 Nov 2002 03:35:43 -0000 1.20 --- Column.java 14 Dec 2002 09:27:55 -0000 1.21 *************** *** 72,76 **** this.typeIndex = typeIndex; } ! public int getSQLType(Mapping pi) throws MappingException { try { return getType().sqlTypes(pi)[ getTypeIndex() ]; --- 72,77 ---- this.typeIndex = typeIndex; } ! ! public int getSQLType(Mapping pi) throws MappingException { try { return getType().sqlTypes(pi)[ getTypeIndex() ]; *************** *** 91,94 **** } ! } --- 92,111 ---- } ! public boolean equals(Object object) ! { ! return object instanceof Column && equals((Column)object); ! } + public boolean equals(Column column) + { + if (null == column) return false; + if (this == column) return true; + + return name.equals(column.name); + } + + public int hashCode() + { + return name.hashCode(); + } + } \ No newline at end of file Index: Constraint.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Constraint.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Constraint.java 26 Nov 2002 03:35:43 -0000 1.9 --- Constraint.java 14 Dec 2002 09:27:55 -0000 1.10 *************** *** 21,25 **** } public void addColumn(Column column) { ! this.columns.add(column); } public int getColumnSpan() { --- 21,25 ---- } public void addColumn(Column column) { ! if (!columns.contains(column)) columns.add(column); } public int getColumnSpan() { *************** *** 35,39 **** this.table = table; } ! public String sqlDropString(Dialect dialect) { return "alter table " + getTable().getQualifiedName() + " drop constraint " + getName(); } --- 35,40 ---- this.table = table; } ! ! public String sqlDropString(Dialect dialect) { return "alter table " + getTable().getQualifiedName() + " drop constraint " + getName(); } Index: Index.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Index.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Index.java 26 Nov 2002 03:35:43 -0000 1.5 --- Index.java 14 Dec 2002 09:27:55 -0000 1.6 *************** *** 42,46 **** } public void addColumn(Column column) { ! this.columns.add(column); } public String getName() { --- 42,46 ---- } public void addColumn(Column column) { ! if (!columns.contains(column)) columns.add(column); } public String getName() { Index: Root.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Root.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Root.java 27 Oct 2002 03:11:33 -0000 1.35 --- Root.java 14 Dec 2002 09:27:55 -0000 1.36 *************** *** 33,45 **** private final java.util.Map classes; private final java.util.Map collections; ! private final java.util.List tables; ! private final java.util.List primaryKeys; ! private final java.util.List foreignKeys; ! private final java.util.List indexes; private final java.util.Map queries; private final java.util.Map generators; private final String schemaName; private final String defaultCascade; - private final java.util.Map indexLookup = new HashMap(); private static final String[] NO_STRINGS = {}; --- 33,41 ---- 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 java.util.Map generators; private final String schemaName; private final String defaultCascade; private static final String[] NO_STRINGS = {}; *************** *** 105,112 **** java.util.Map classes, java.util.Map collections, ! java.util.List tables, ! java.util.List foreignKeys, ! java.util.List primaryKeys, ! java.util.List indexes, java.util.Map generators, java.util.Map queries --- 101,105 ---- java.util.Map classes, java.util.Map collections, ! java.util.Map tables, java.util.Map generators, java.util.Map queries *************** *** 116,122 **** this.collections = collections; this.queries = queries; - this.foreignKeys = foreignKeys; - this.primaryKeys = primaryKeys; - this.indexes = indexes; this.tables = tables; this.generators = generators; --- 109,112 ---- *************** *** 167,191 **** Object old = classes.put( persistentClass.getPersistentClass(), persistentClass ); if ( old!=null ) throw new MappingException( "duplicate class mapping: " + persistentClass.getPersistentClass().getName() ); ! } public void addCollection(Collection collection) throws MappingException { Object old = collections.put( collection.getRole(), collection ); if ( old!=null ) throw new MappingException( "duplicate collection role: " + collection.getRole() ); } ! public void addTable(Table table) { ! tables.add(table); ! } ! public void addPrimaryKey(PrimaryKey pk) { ! primaryKeys.add(pk); ! } ! public void addForeignKey(ForeignKey fk) { ! foreignKeys.add(fk); ! } ! public void addIndex(Index index) { ! indexes.add(index); ! indexLookup.put( index.getName(), index ); ! } ! public Index getIndex(String name) { ! return (Index) indexLookup.get(name); } --- 157,180 ---- Object old = classes.put( persistentClass.getPersistentClass(), persistentClass ); if ( old!=null ) throw new MappingException( "duplicate class mapping: " + persistentClass.getPersistentClass().getName() ); ! } ! public void addCollection(Collection collection) throws MappingException { Object old = collections.put( collection.getRole(), collection ); if ( old!=null ) throw new MappingException( "duplicate collection role: " + collection.getRole() ); } ! public Table addTable(String schema, String name) ! { ! String key = schema != null ? schema + "." + name : name; ! ! Table table = (Table)tables.get(key); ! ! if (table == null) { ! table = new Table(); ! table.setName(name); ! table.setSchema(schema); ! tables.put(key, table); ! } ! return table; } Index: RootClass.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/RootClass.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** RootClass.java 30 Nov 2002 08:19:00 -0000 1.53 --- RootClass.java 14 Dec 2002 09:27:55 -0000 1.54 *************** *** 96,106 **** tableNameNode.getNodeValue(); - table = new Table(); - table.setName(tableName); Node schemaNode = atts.getNamedItem("schema"); ! table.setSchema( ! (schemaNode==null) ? root.getSchemaName() : schemaNode.getNodeValue() ! ); ! root.addTable(table); addTable(table); --- 96,102 ---- tableNameNode.getNodeValue(); Node schemaNode = atts.getNamedItem("schema"); ! String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! table = root.addTable(schema, tableName); addTable(table); Index: Subclass.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Subclass.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Subclass.java 26 Nov 2002 08:37:25 -0000 1.21 --- Subclass.java 14 Dec 2002 09:27:55 -0000 1.22 *************** *** 108,117 **** // joined subclasses String tableName = tableNameNode.getNodeValue(); - this.table = new Table(); - this.table.setName(tableName); Node schemaNode = atts.getNamedItem("schema"); ! this.table.setSchema( ! (schemaNode==null) ? root.getSchemaName() : schemaNode.getNodeValue() ! ); addTable(this.table); --- 108,114 ---- // joined subclasses String tableName = tableNameNode.getNodeValue(); Node schemaNode = atts.getNamedItem("schema"); ! String schema = schemaNode==null ? root.getSchemaName() : schemaNode.getNodeValue(); ! this.table = root.addTable(schema, tableName); addTable(this.table); *************** *** 145,150 **** pk.addColumn(col); } - - root.addTable(this.table); } --- 142,145 ---- Index: Table.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Table.java,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** Table.java 25 Nov 2002 05:17:59 -0000 1.30 --- Table.java 14 Dec 2002 09:27:55 -0000 1.31 *************** *** 4,7 **** --- 4,8 ---- import java.util.Iterator; import java.util.Map; + import java.util.HashMap; import cirrus.hibernate.engine.Mapping; *************** *** 12,16 **** import cirrus.hibernate.sql.HSQLDialect; import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.tools.JdbcColumnInfo; import org.apache.commons.collections.SequencedHashMap; --- 13,19 ---- import cirrus.hibernate.sql.HSQLDialect; import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.tools.updater.JdbcColumnInfo; ! import cirrus.hibernate.tools.updater.JdbcTableInfo; ! import org.apache.commons.collections.SequencedHashMap; *************** *** 21,25 **** private IdentifierGenerator identifierGenerator = Assigned.INSTANCE; private PrimaryKey primaryKey; ! private int counter=0; private final int uniqueInteger; private static int tableCounter=0; --- 24,29 ---- private IdentifierGenerator identifierGenerator = Assigned.INSTANCE; private PrimaryKey primaryKey; ! private Map indexes = new HashMap(); ! private Map foreignKeys = new HashMap(); private final int uniqueInteger; private static int tableCounter=0; *************** *** 60,65 **** return columns.values().iterator(); } ! public String sqlAlterString(Dialect dialect,Mapping p,java.util.Map columns) throws HibernateException { // String pkname = null; --- 64,75 ---- return columns.values().iterator(); } + public Iterator indexIterator() { + return indexes.values().iterator(); + } + public Iterator foreignKeyIterator() { + return foreignKeys.values().iterator(); + } ! public String sqlAlterString(Dialect dialect,Mapping p,JdbcTableInfo tableInfo) throws HibernateException { // String pkname = null; *************** *** 78,89 **** Column col=(Column) iter.next(); ! String name=col.getName().toLowerCase(); ! JdbcColumnInfo ci=(JdbcColumnInfo) columns.get(name); ! if (ci==null) { // the column doesnt exist at all. if (buf.length()!=0) ! buf.append(','); ! buf.append("add ").append(name).append(' ').append(col.getSqlType(dialect,p)); if (col.isUnique()&&dialect.supportsUnique()) { buf.append(" unique"); --- 88,98 ---- Column col=(Column) iter.next(); ! JdbcColumnInfo columnInfo=tableInfo.getColumnInfo(col.getName()); ! if (columnInfo==null) { // the column doesnt exist at all. if (buf.length()!=0) ! buf.append(", "); ! buf.append(col.getName()).append(' ').append(col.getSqlType(dialect,p)); if (col.isUnique()&&dialect.supportsUnique()) { buf.append(" unique"); *************** *** 96,100 **** return null; ! return new StringBuffer("alter table ").append(getQualifiedName()).append(" ").append(buf).toString(); } --- 105,109 ---- return null; ! return new StringBuffer("alter table ").append(getQualifiedName()).append(" add ").append(buf).toString(); } *************** *** 174,179 **** } ! public int generateConstraintID() { ! return counter++; } --- 183,220 ---- } ! public Index getIndex(String name) ! { ! Index index = (Index)indexes.get(name); ! ! if (index == null) { ! index = new Index(); ! index.setName(name); ! index.setTable(this); ! indexes.put(name, index); ! } ! ! return index; ! } ! ! public ForeignKey getForeignKey(String name) ! { ! ForeignKey fk = (ForeignKey)foreignKeys.get(name); ! ! if (fk == null) { ! fk = new ForeignKey(); ! fk.setName(name); ! fk.setTable(this); ! foreignKeys.put(name, fk); ! } ! ! return fk; ! } ! ! public int generateConstraintID(Iterator iterator) { ! int result = 0; ! ! while (iterator.hasNext()) result += iterator.next().hashCode(); ! ! return result; } Index: Value.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Value.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Value.java 22 Nov 2002 00:27:08 -0000 1.41 --- Value.java 14 Dec 2002 09:27:55 -0000 1.42 *************** *** 23,27 **** public void addColumn(Column column) { ! this.columns.add(column); } public int getColumnSpan() { --- 23,27 ---- public void addColumn(Column column) { ! if (!columns.contains(column)) columns.add(column); } public int getColumnSpan() { *************** *** 87,98 **** if ( indexNode!=null && table!=null ) { //TODO: what do you do about associations?? (second pass compile) String iname = indexNode.getNodeValue(); ! Index index = root.getIndex(iname); ! if ( index==null ) { ! index = new Index(); ! index.setName(iname); ! index.setTable(table); ! root.addIndex(index); ! } ! index.addColumn(col); } } --- 87,91 ---- if ( indexNode!=null && table!=null ) { //TODO: what do you do about associations?? (second pass compile) String iname = indexNode.getNodeValue(); ! table.getIndex(iname).addColumn(col); } } *************** *** 113,125 **** public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) { //foreign key ! ForeignKey fk = new ForeignKey(); Iterator iter = getConstraintColumnIterator(); ! while ( iter.hasNext() ) { ! fk.addColumn( (Column) iter.next() ); ! } ! fk.setTable(table); ! fk.setName( StringHelper.suffix( table.getName(), "FK" + table.generateConstraintID() ) ); fk.setReferencedClass(persistentClass); - root.addForeignKey(fk); } --- 106,115 ---- public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) { //foreign key ! int keyID = table.generateConstraintID(getConstraintColumnIterator()); ! String name = StringHelper.suffix(table.getName(), "FK" + Integer.toHexString(keyID).toUpperCase()); ! ForeignKey fk = table.getForeignKey(name); Iterator iter = getConstraintColumnIterator(); ! while (iter.hasNext()) fk.addColumn((Column)iter.next()); fk.setReferencedClass(persistentClass); } |