openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r1365688 - in /openjpa/trunk/openjpa-jdbc/src/main: java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java java/org/apache/openjpa/jdbc/sql/DBDictionary.java resources/org/apache/openjpa/jdbc/kernel/localizer.properties
Date Wed, 25 Jul 2012 18:30:32 GMT
Author: allee8285
Date: Wed Jul 25 18:30:31 2012
New Revision: 1365688

URL: http://svn.apache.org/viewvc?rev=1365688&view=rev
Log:
OPENJPA-2196 - Commit contribution by Scott Parkerson.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=1365688&r1=1365687&r2=1365688&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
Wed Jul 25 18:30:31 2012
@@ -82,6 +82,7 @@ public class NativeJDBCSeq
     private DBIdentifier _schema = DBIdentifier.NULL;
 
     private boolean alterIncrementBy = false;
+    private boolean alreadyLoggedAlterSeqFailure = false;
 
     /**
      * The sequence name. Defaults to <code>OPENJPA_SEQUENCE</code>.
@@ -218,7 +219,18 @@ public class NativeJDBCSeq
         try {
             if (!alterIncrementBy) {
                 DBDictionary dict = _conf.getDBDictionaryInstance();
-                udpateSql(conn, dict.getAlterSequenceSQL(_seq));
+                // If this fails, we will warn the user at most one time and set _allocated
and _increment to 1 so
+                // as to not potentially insert records ahead of what the database thinks
is the next sequence value.
+                if (updateSql(conn, dict.getAlterSequenceSQL(_seq)) == -1) {
+                    if (!alreadyLoggedAlterSeqFailure) {
+                        Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+                        if (log.isWarnEnabled()) {
+                            log.warn(_loc.get("fallback-no-seq-cache", _seqName));
+                        }
+                    }
+                    alreadyLoggedAlterSeqFailure = true;
+                    _allocate = 1;
+                }
             }
             _nextValue = getSequence(conn);
             _maxValue = _nextValue + _allocate * _increment;
@@ -311,7 +323,7 @@ public class NativeJDBCSeq
         }
     }
 
-    private int udpateSql(Connection conn, String sql) throws SQLException {
+    private int updateSql(Connection conn, String sql) throws SQLException {
         DBDictionary dict = _conf.getDBDictionaryInstance();
         PreparedStatement stmnt = null;
         int rc = -1;
@@ -320,7 +332,8 @@ public class NativeJDBCSeq
             dict.setTimeouts(stmnt, _conf, false);
             rc = stmnt.executeUpdate();
         } catch (Exception e) {
-            // tolerate exception when attempting to alter increment
+            // tolerate exception when attempting to alter increment,
+            // however, caller should check rc and not cache sequence values if rc != -1.
         } finally {
             // clean up our resources
             if (stmnt != null) {

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1365688&r1=1365687&r2=1365688&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Wed Jul 25 18:30:31 2012
@@ -3477,7 +3477,7 @@ public class DBDictionary
         buf.append(seqName);
         if (create && seq.getInitialValue() != 0)
             buf.append(" START WITH ").append(seq.getInitialValue());
-        if ((seq.getIncrement() > 1) || (seq.getAllocate() > 1))
+        if ((seq.getIncrement() >= 1) || (seq.getAllocate() >= 1))
             buf.append(" INCREMENT BY ").append(seq.getIncrement() * seq.getAllocate());
         return new String[]{ buf.toString() };
     }

Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=1365688&r1=1365687&r2=1365688&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
Wed Jul 25 18:30:31 2012
@@ -172,4 +172,7 @@ exclude-in-expression: Query "{0}" is no
 exclude-user-strategy: Query "{0}" is not cached because some parameterized \
     field value depends on user-defined field strategy.        
 exclude-pagination: Query "{0}" is not cached because it uses pagination.
+fallback-no-seq-cache: Unable to cache sequence values for sequence "{0}". \
+    This can occur if your application is not configured connecting to the \
+    database with the appropriate permission to execute an ALTER SEQUENCE command.
       
\ No newline at end of file



Mime
View raw message