|
From: <one...@us...> - 2002-12-26 03:35:11
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/map
In directory sc8-pr-cvs1:/tmp/cvs-serv22091/hibernate/map
Modified Files:
Constraint.java Subclass.java Table.java Value.java
Log Message:
support for multi-column unique constraints via unique-key attribute
Index: Constraint.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Constraint.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Constraint.java 14 Dec 2002 09:27:55 -0000 1.10
--- Constraint.java 26 Dec 2002 03:35:07 -0000 1.11
***************
*** 21,25 ****
}
public void addColumn(Column column) {
! if (!columns.contains(column)) columns.add(column);
}
public int getColumnSpan() {
--- 21,25 ----
}
public void addColumn(Column column) {
! if ( !columns.contains(column) ) columns.add(column);
}
public int getColumnSpan() {
Index: Subclass.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Subclass.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** Subclass.java 25 Dec 2002 04:16:36 -0000 1.23
--- Subclass.java 26 Dec 2002 03:35:07 -0000 1.24
***************
*** 136,140 ****
}
! ForeignKey fk = mytable.getForeignKey( key.getConstraintColumns() );
fk.setReferencedClass( superclass.getPersistentClass() );
--- 136,140 ----
}
! ForeignKey fk = mytable.createForeignKey( key.getConstraintColumns() );
fk.setReferencedClass( superclass.getPersistentClass() );
Index: Table.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Table.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** Table.java 25 Dec 2002 04:16:36 -0000 1.33
--- Table.java 26 Dec 2002 03:35:07 -0000 1.34
***************
*** 27,30 ****
--- 27,31 ----
private Map indexes = new HashMap();
private Map foreignKeys = new HashMap();
+ private Map uniqueKeys = new HashMap();
private final int uniqueInteger;
private static int tableCounter=0;
***************
*** 71,87 ****
return foreignKeys.values().iterator();
}
public String sqlAlterString(Dialect dialect,Mapping p,JdbcTableInfo tableInfo) throws HibernateException {
- // 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();
StringBuffer buf=new StringBuffer(50);
--- 72,81 ----
return foreignKeys.values().iterator();
}
+ public Iterator uniqueKeyIterator() {
+ return uniqueKeys.values().iterator();
+ }
public String sqlAlterString(Dialect dialect,Mapping p,JdbcTableInfo tableInfo) throws HibernateException {
Iterator iter=columnIterator();
StringBuffer buf=new StringBuffer(50);
***************
*** 161,164 ****
--- 155,165 ----
}
}
+ if ( dialect.supportsUnique() ) {
+ Iterator ukiter = uniqueKeyIterator();
+ while ( ukiter.hasNext() ) {
+ UniqueKey uk = (UniqueKey) ukiter.next();
+ buf.append(',').append( uk.sqlConstraintString(dialect) );
+ }
+ }
buf.append(")");
***************
*** 184,189 ****
}
! public Index getIndex(String name)
! {
Index index = (Index)indexes.get(name);
--- 185,189 ----
}
! public Index getIndex(String name) {
Index index = (Index)indexes.get(name);
***************
*** 197,202 ****
return index;
}
! public ForeignKey getForeignKey(List columns) {
String name = "FK" + uniqueColumnString( columns.iterator() );
--- 197,215 ----
return index;
}
+
+ public UniqueKey getUniqueKey(String name) {
! UniqueKey uk = (UniqueKey) uniqueKeys.get(name);
!
! if (uk == null) {
! uk = new UniqueKey();
! uk.setName(name);
! uk.setTable(this);
! uniqueKeys.put(name, uk);
! }
! return uk;
! }
!
! public ForeignKey createForeignKey(List columns) {
String name = "FK" + uniqueColumnString( columns.iterator() );
Index: Value.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/map/Value.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** Value.java 25 Dec 2002 04:16:36 -0000 1.44
--- Value.java 26 Dec 2002 03:35:07 -0000 1.45
***************
*** 88,91 ****
--- 88,96 ----
table.getIndex(iname).addColumn(col);
}
+ Node uniqueNode = subnode.getAttributes().getNamedItem("unique-key");
+ if ( uniqueNode!=null && table!=null ) { //TODO: what do you do about associations?? (second pass compile)
+ String iname = uniqueNode.getNodeValue();
+ table.getUniqueKey(iname).addColumn(col);
+ }
}
}
***************
*** 105,109 ****
public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) {
//foreign key
! ForeignKey fk = table.getForeignKey( getConstraintColumns() );
fk.setReferencedClass(persistentClass);
}
--- 110,114 ----
public void createForeignKeyOfClass(Root root, Table table, Class persistentClass) {
//foreign key
! ForeignKey fk = table.createForeignKey( getConstraintColumns() );
fk.setReferencedClass(persistentClass);
}
|