openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r619471 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: kernel/SQLStoreQuery.java sql/DB2Dictionary.java sql/DBDictionary.java
Date Thu, 07 Feb 2008 16:01:10 GMT
Author: mikedd
Date: Thu Feb  7 08:01:06 2008
New Revision: 619471

URL: http://svn.apache.org/viewvc?rev=619471&view=rev
Log:
OPENJPA-511

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java?rev=619471&r1=619470&r2=619471&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
Thu Feb  7 08:01:06 2008
@@ -184,8 +184,7 @@
             String sql = StringUtils.trimToNull(ctx.getQueryString());
             if (sql == null)
                 throw new UserException(_loc.get("no-sql"));
-            _select = sql.length() > 6
-                && sql.substring(0, 6).equalsIgnoreCase("select");
+            _select = q.getStore().getDBDictionary().isSelect(sql);
             _call = sql.length() > 4
                 && sql.substring(0, 4).equalsIgnoreCase("call");
         }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=619471&r1=619470&r2=619471&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu Feb  7 08:01:06 2008
@@ -148,6 +148,8 @@
         }));
         
         super.setBatchLimit(defaultBatchLimit);
+        
+        selectWordSet.add("WITH");
     }
 
     public boolean supportsRandomAccessResultSet(Select sel,

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=619471&r1=619470&r2=619471&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
Thu Feb  7 08:01:06 2008
@@ -330,6 +330,12 @@
     protected final Set fixedSizeTypeNameSet = new HashSet();
     protected final Set typeModifierSet = new HashSet();
 
+    /**
+     * If a native query begins with any of the values found here then it will
+     * be treated as a select statement.  
+     */
+    protected final Set selectWordSet = new HashSet();
+
     // when we store values that lose precion, track the types so that the
     // first time it happens we can warn the user
     private Set _precisionWarnedTypes = null;
@@ -352,6 +358,8 @@
             "OTHER", "REAL", "REF", "SMALLINT", "STRUCT", "TIME", "TIMESTAMP",
             "TINYINT",
         }));
+        
+        selectWordSet.add("SELECT");
     }
 
     /**
@@ -4324,5 +4332,26 @@
     protected void calculateValue(Val val, Select sel, ExpContext ctx, 
         ExpState state, Path path, ExpState pathState) {
         val.calculateValue(sel, ctx, state, (Val) path, pathState);
-    }    
+    }
+
+    /**
+     * Determine whether the provided <code>sql</code> may be treated as a 
+     * select statement on this database.
+     *  
+     * @param sql   A sql statement. 
+     * 
+     * @return true if <code>sql</code> represents a select statement.
+     */
+    public boolean isSelect(String sql) {
+        Iterator i = selectWordSet.iterator();
+        String cur;
+        while (i.hasNext()) {
+            cur = (String) i.next();
+            if (sql.length() >= cur.length()
+                    && sql.substring(0, cur.length()).equalsIgnoreCase(cur)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }



Mime
View raw message