openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r619479 - in /openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: kernel/SQLStoreQuery.java sql/DB2Dictionary.java sql/DBDictionary.java
Date Thu, 07 Feb 2008 16:17:32 GMT
Author: mikedd
Date: Thu Feb  7 08:17:24 2008
New Revision: 619479

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

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

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java?rev=619479&r1=619478&r2=619479&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
Thu Feb  7 08:17:24 2008
@@ -183,8 +183,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/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=619479&r1=619478&r2=619479&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu Feb  7 08:17:24 2008
@@ -144,6 +144,8 @@
             "TYPE", "UNDO", "UNTIL", "VALIDPROC", "VARIABLE", "VARIANT", "VCAT",
             "VOLUMES", "WHILE", "WLM", "YEARS",
         }));
+        
+        selectWordSet.add("WITH");
     }
 
     public boolean supportsRandomAccessResultSet(Select sel,

Modified: openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=619479&r1=619478&r2=619479&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu Feb  7 08:17:24 2008
@@ -307,6 +307,12 @@
     protected final Set systemTableSet = new HashSet();
     protected final Set fixedSizeTypeNameSet = 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;
@@ -323,6 +329,8 @@
             "OTHER", "REAL", "REF", "SMALLINT", "STRUCT", "TIME", "TIMESTAMP",
             "TINYINT",
         }));
+        
+        selectWordSet.add("SELECT");
     }
 
     /**
@@ -3988,5 +3996,26 @@
      */
     public void createIndexIfNecessary(Schema schema, String table,
             Column pkColumn) {
+    }
+
+    /**
+     * 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