You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jo...@apache.org on 2002/02/25 20:30:38 UTC
cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model Index.java
jon 02/02/25 11:30:38
Modified: src/java/org/apache/torque/engine/database/model Index.java
Log:
I made this patch to help solve a problem i was having with unnamed
unique constraints. When you create a unique constraint with no
supplied name (<unique><unique-column ...></unique>), the resulting SQL
will not parse for Oracle because Oracle demands named constraints and
the SQL contains "$unique.Name" because unique.getName() is null.
It looks like the same thing goes for indexes.
Probably this is happening because the particular constructor for Index
which sets a default name, if necessary, was not ever getting called.
It might make more sense to call createName() from loadFromXML, rather
than generating the name lazily, but I wasn't sure if you had all the
other relevant info loaded at that point.
Bill Schneider <bs...@vecna.com>
Revision Changes Path
1.17 +34 -10 jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Index.java
Index: Index.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Index.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Index.java 8 Nov 2001 17:20:52 -0000 1.16
+++ Index.java 25 Feb 2002 19:30:38 -0000 1.17
@@ -67,7 +67,7 @@
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
* @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
- * @version $Id: Index.java,v 1.16 2001/11/08 17:20:52 mpoeschl Exp $
+ * @version $Id: Index.java,v 1.17 2002/02/25 19:30:38 jon Exp $
*/
public class Index
{
@@ -105,15 +105,7 @@
if (indexColumns.size() > 0)
{
this.indexColumns = indexColumns;
-
- List inputs = new ArrayList(4);
- inputs.add(table.getDatabase());
- inputs.add(table.getName());
- inputs.add("I");
- // ASSUMPTION: This Index not yet added to the list.
- inputs.add(new Integer(table.getIndices().length + 1));
- indexName = NameFactory.generateName
- (NameFactory.CONSTRAINT_GENERATOR, inputs);
+ createName();
if (DEBUG)
{
@@ -129,6 +121,26 @@
}
}
+ private void createName() throws TorqueException
+ {
+ Table table = getTable();
+ List inputs = new ArrayList(4);
+ inputs.add(table.getDatabase());
+ inputs.add(table.getName());
+ if (isUnique())
+ {
+ inputs.add("U");
+ }
+ else
+ {
+ inputs.add("I");
+ }
+ // ASSUMPTION: This Index not yet added to the list.
+ inputs.add(new Integer(table.getIndices().length + 1));
+ indexName = NameFactory.generateName
+ (NameFactory.CONSTRAINT_GENERATOR, inputs);
+ }
+
/**
* Imports index from an XML specification
*/
@@ -168,6 +180,18 @@
*/
public String getName()
{
+ if (indexName == null)
+ {
+ try
+ {
+ // generate an index name if we don't have a supplied one
+ createName();
+ }
+ catch (TorqueException e)
+ {
+ // still no name
+ }
+ }
return indexName;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>