From 38607842164f59a131fd4862fc41958653df6f92 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Mon, 29 Oct 2007 18:21:56 +0000 Subject: [PATCH] OPENJPA-399 committing Teresa's patch git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@589784 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/TableJDBCSeq.java | 13 ++++++------ .../openjpa/jdbc/sql/DB2Dictionary.java | 20 +++++++++++++++++++ .../apache/openjpa/jdbc/sql/DBDictionary.java | 7 +++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java index b5602fe17..25b2bd67b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java @@ -235,16 +235,15 @@ public class TableJDBCSeq schema = group.addSchema(schemaName); schema.importTable(_pkColumn.getTable()); - // build the index for the sequence tables - // the index name will the fully qualified table name +_IDX - Table tab = schema.getTable(_table); - Index idx = tab.addIndex(tab.getFullName()+"_IDX"); - idx.setUnique(true); // we need to reset the table name in the column with the // fully qualified name for matching the table name from the // Column. - _pkColumn.resetTableName(schemaName+"."+_pkColumn.getTableName()); - idx.addColumn(_pkColumn); + _pkColumn.resetTableName(schemaName + "." + + _pkColumn.getTableName()); + // some databases require to create an index for the sequence table + _conf.getDBDictionaryInstance().createIndexIfNecessary(schema, + _table, _pkColumn); + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java index d487f7b67..d8a2d445c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java @@ -31,12 +31,17 @@ import org.apache.openjpa.jdbc.kernel.exps.FilterValue; import org.apache.openjpa.jdbc.kernel.exps.Lit; import org.apache.openjpa.jdbc.kernel.exps.Param; import org.apache.openjpa.jdbc.kernel.exps.Val; +import org.apache.openjpa.jdbc.schema.Column; +import org.apache.openjpa.jdbc.schema.Index; +import org.apache.openjpa.jdbc.schema.Schema; import org.apache.openjpa.jdbc.schema.Sequence; +import org.apache.openjpa.jdbc.schema.Table; import org.apache.openjpa.kernel.Filters; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.util.OpenJPAException; import org.apache.openjpa.util.UnsupportedException; + import serp.util.Strings; /** @@ -742,4 +747,19 @@ public class DB2Dictionary } } } + + /** + * Create an index if necessary for some database tables + */ + public void createIndexIfNecessary(Schema schema, String table, + Column pkColumn) { + if (isDB2ZOSV8xOrLater()) { + // build the index for the sequence tables + // the index name will the fully qualified table name + _IDX + Table tab = schema.getTable(table); + Index idx = tab.addIndex(tab.getFullName() + "_IDX"); + idx.setUnique(true); + idx.addColumn(pkColumn); + } + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 9a066d286..81ec45f7c 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -3982,4 +3982,11 @@ public class DBDictionary public String getCastFunction(Val val, String func) { return func; } + + /** + * Create an index if necessary for some database tables + */ + public void createIndexIfNecessary(Schema schema, String table, + Column pkColumn) { + } }