openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1399948 - in /openjpa/branches/2.2.x/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 Fri, 19 Oct 2012 02:19:57 GMT
Author: hthomann
Date: Fri Oct 19 02:19:56 2012
New Revision: 1399948

URL: http://svn.apache.org/viewvc?rev=1399948&view=rev
Log:
OPENJPA-2196: Back-ported Albert's trunk changes to 2.2.x

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

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java?rev=1399948&r1=1399947&r2=1399948&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/NativeJDBCSeq.java
Fri Oct 19 02:19:56 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/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1399948&r1=1399947&r2=1399948&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Fri Oct 19 02:19:56 2012
@@ -3489,7 +3489,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/branches/2.2.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=1399948&r1=1399947&r2=1399948&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
Fri Oct 19 02:19:56 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