You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Kevin Sutter <kw...@gmail.com> on 2007/07/09 15:51:52 UTC

Re: Database versions

Hi Daniel,
So far, we have taken the approach to have a single dictionary for each
database that covers all applicable versions.  The JDBC driver is queried to
determine the version for any specific actions.  This approach has worked
for us thus far.  You can reference the connectedConfiguration method in the
DB2Dictionary as an example.  If (or when) this approach becomes too
cumbersome, then we'll have to consider individual dictionaries.

Kevin

On 7/9/07, Daniel Migowski <dm...@ikoffice.de> wrote:
>
>  Hello OpenJPA developers,
>
> I fixed some bugs in the Postgresqldatabase definition, and before
> submitting a patch, i wanted to know how support for different database
> versions is planned. Should the only be one definition per database or will
> the future bring definitions like postgres81, postgres80 etc.. I know that
> the automatic detection of a version is not possible directly from JDBC-URL,
> and IMO the standard definition (like "postgres") should be taken. I would
> prefer, if the user would be able to specify a more detailed definition like
> "postgres81" , instead of having to override their own schema (and there are
> some minor changes between the revisions).
>
> What you think?
>
> With regards,
> Daniel Migowski
>
> --
>
>  |¯¯|¯¯|    *IKOffice GmbH             Daniel Migowski*
>  |  |  |/|                            Mail: dmigowski@ikoffice.de
>  |  | // |  Nordstr. 10               Tel.: +49 (441) 21 98 89 52
>  |  | \\ |  26135 Oldenburg           Fax.: +49 (441) 21 98 89 55
>  |__|__|\|  http://www.ikoffice.de    Mob.: +49 (176) 22 31 20 76
>
>             Geschäftsführer: Ingo Kuhlmann, Daniel Migowski
>             Amtsgericht Oldenburg, HRB 201467
>             Steuernummer: 64/211/01864
>
>

Re: Database versions (+patch)

Posted by Daniel Migowski <dm...@ikoffice.de>.
Index: C:/IKOfficeRoot/Projekte/OpenJPA/openjpa/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
===================================================================
--- C:/IKOfficeRoot/Projekte/OpenJPA/openjpa/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java	(revision 554663)
+++ C:/IKOfficeRoot/Projekte/OpenJPA/openjpa/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java	(working copy)
@@ -32,6 +32,7 @@
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Sequence;
 import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.schema.Unique;
 import org.apache.openjpa.lib.jdbc.DelegatingConnection;
 import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
 import org.apache.openjpa.lib.util.Localizer;
@@ -36,6 +37,8 @@
 import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
 import org.apache.openjpa.lib.util.Localizer;
 
+import serp.util.Strings;
+
 /**
  * Dictionary for Postgres.
  */
@@ -93,10 +96,10 @@
         // PostgreSQL requires double-escape for strings
         searchStringEscape = "\\\\";
 
-        maxTableNameLength = 31;
-        maxColumnNameLength = 31;
-        maxIndexNameLength = 31;
-        maxConstraintNameLength = 31;
+        maxTableNameLength = 63;
+        maxColumnNameLength = 63;
+        maxIndexNameLength = 63;
+        maxConstraintNameLength = 63;
         schemaCase = SCHEMA_CASE_LOWER;
         rangePosition = RANGE_POST_LOCK;
         requiresAliasForSubselect = true;
@@ -301,6 +304,31 @@
         throws SQLException {
         return new PostgresConnection(super.decorate(conn), this);
     }
+    
+	/**
+     * Return the declaration SQL for the given unique constraint. This
+     * method is used from within {@link #getCreateTableSQL}.
+     * Returns	<code>CONSTRAINT &lt;name&gt; UNIQUE (&lt;col list&gt;)</code>
+     * by default. Only foreign key constraints can be deferred in PostgreSQL
+     * so we have to override the function in DbDictionary.
+     */
+    protected String getUniqueConstraintSQL(Unique unq) {
+        if (unq.isDeferred()) return null;
+
+        StringBuffer buf = new StringBuffer();
+        if (unq.getName() != null
+            && CONS_NAME_BEFORE.equals(constraintNameMode))
+            buf.append("CONSTRAINT ").append(unq.getName()).append(" ");
+        buf.append("UNIQUE ");
+        if (unq.getName() != null && CONS_NAME_MID.equals(constraintNameMode))
+            buf.append(unq.getName()).append(" ");
+        buf.append("(").append(Strings.join(unq.getColumns(), ", ")).
+            append(")");
+        if (unq.getName() != null
+            && CONS_NAME_AFTER.equals(constraintNameMode))
+            buf.append(" CONSTRAINT ").append(unq.getName());
+        return buf.toString();
+    }    
 
     /**
      * Connection wrapper to work around the postgres empty result set bug.