Author: ppoddar
Date: Thu May  9 22:23:47 2013
New Revision: 1480815

URL: http://svn.apache.org/r1480815
Log:
Revert changes

Modified:
    
openjpa/sandboxes/21/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java

Modified: 
openjpa/sandboxes/21/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
URL: 
http://svn.apache.org/viewvc/openjpa/sandboxes/21/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java?rev=1480815&r1=1480814&r2=1480815&view=diff
==============================================================================
--- 
openjpa/sandboxes/21/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
 (original)
+++ 
openjpa/sandboxes/21/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/SQLStoreQuery.java
 Thu May  9 22:23:47 2013
@@ -30,7 +30,6 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
@@ -40,9 +39,7 @@ import org.apache.openjpa.jdbc.sql.DBDic
 import org.apache.openjpa.jdbc.sql.ResultSetResult;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.SQLExceptions;
-import org.apache.openjpa.jdbc.sql.StoredProcedure;
 import org.apache.openjpa.kernel.AbstractStoreQuery;
-import org.apache.openjpa.kernel.Query;
 import org.apache.openjpa.kernel.QueryContext;
 import org.apache.openjpa.kernel.StoreQuery;
 import org.apache.openjpa.lib.rop.RangeResultObjectProvider;
@@ -61,7 +58,8 @@ import org.apache.openjpa.util.UserExcep
 public class SQLStoreQuery
     extends AbstractStoreQuery {
 
-    private static final Localizer _loc = 
Localizer.forPackage(SQLStoreQuery.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (SQLStoreQuery.class);
 
     private transient final JDBCStore _store;
 
@@ -104,8 +102,8 @@ public class SQLStoreQuery
         extends AbstractExecutor {
 
         private final ClassMetaData _meta;
-        private boolean _select;
-        private boolean _call;   // native call stored procedure
+        private final boolean _select;
+        private final boolean _call;   // native call stored procedure
         private final QueryResultMapping _resultMapping;
 
         public SQLExecutor(SQLStoreQuery q, ClassMetaData candidate) {
@@ -114,46 +112,20 @@ public class SQLStoreQuery
             if (resultMapping == null)
                 _resultMapping = null;
             else {
-                ClassLoader envLoader = ctx.getStoreContext().getClassLoader();
-                MappingRepository repos = q.getStore().getConfiguration().
-                    getMappingRepositoryInstance();
-                _resultMapping = repos.getQueryResultMapping
-                    (ctx.getResultMappingScope(), resultMapping, envLoader, 
true);
+                MappingRepository repos = 
q.getStore().getConfiguration().getMappingRepositoryInstance();
+                _resultMapping = 
repos.getQueryResultMapping(ctx.getResultMappingScope(), resultMapping, 
+                               null, true);
             }
             _meta = candidate;
 
             String sql = StringUtils.trimToNull(ctx.getQueryString());
             if (sql == null)
                 throw new UserException(_loc.get("no-sql"));
-            DBDictionary dict = q.getStore().getDBDictionary();
-            _select = dict.isSelect(sql);
-            if (!_select) {
-               String verb = getSQLVerb(sql);
-               
-               _call = "call".equalsIgnoreCase(verb);
-               if (!_call && !("drop".equalsIgnoreCase(verb) || 
"create".equalsIgnoreCase(verb))) {
-                       
-                       Connection conn = q.getStore().getConnection();
-                       try {
-                               StoredProcedure sp = 
dict.getStoredProcedure(conn.getMetaData(), null, null, 
-                                               
q.getContext().getQueryString());
-                               q.setQuery(sp.getCallSQL()); 
-                               _call = sp != null;
-                               
((Query)q.getContext()).setQuery(sp.getCallSQL());
-                               System.err.println("Call [" + sp.getCallSQL() + 
"]");
-                       } catch (SQLException ex) {
-                               throw new RuntimeException(ex);
-                       } finally {
-                               try {
-                                       conn.close();
-                               } catch (SQLException ex) {
-                                       
-                               }
-                       }
-                }
-            }
+            _select = q.getStore().getDBDictionary().isSelect(sql);
+            _call = sql.length() > 4
+                && sql.substring(0, 4).equalsIgnoreCase("call");
         }
-        
+
         public int getOperation(StoreQuery q) {
            return _select ? OP_SELECT : 
                 (q.getContext().getCandidateType() != null
@@ -166,15 +138,16 @@ public class SQLStoreQuery
         public Number executeUpdate(StoreQuery q, Object[] params) {
             JDBCStore store = ((SQLStoreQuery) q).getStore();
             DBDictionary dict = store.getDBDictionary();
-            // we need to make sure we have an active store connection
-            store.getContext().beginStore();
-            Connection conn = store.getConnection();
             String sql = q.getContext().getQueryString();
-            
+
             List paramList = new ArrayList(Arrays.asList(params));
             SQLBuffer buf = new SQLBuffer(dict).append(sql);
             
-            JDBCFetchConfiguration fetch = 
(JDBCFetchConfiguration)q.getContext().getFetchConfiguration();
+            // we need to make sure we have an active store connection
+            store.getContext().beginStore();
+            Connection conn = store.getConnection();
+            JDBCFetchConfiguration fetch = (JDBCFetchConfiguration)
+                q.getContext().getFetchConfiguration();
 
             PreparedStatement stmnt = null;
             try {
@@ -186,7 +159,7 @@ public class SQLStoreQuery
                 buf.setParameters(paramList);
                 if (stmnt != null)
                     buf.setParameters(stmnt);
-                
+
                 dict.setTimeouts(stmnt, fetch, true);
                 
                 int count = executeUpdate(store, conn, stmnt, buf);  
@@ -276,7 +249,6 @@ public class SQLStoreQuery
             return q.getContext().getCandidateType() == null;
         }
         
-        
         /**
          * This method is to provide override for non-JDBC or JDBC-like 
          * implementation of preparing call statement.
@@ -369,22 +341,16 @@ public class SQLStoreQuery
             int idx = 0;
             for (Integer key : paramOrder) {
                 if (!userParams.containsKey(key)) 
-                    throw new UserException(_loc.get("uparam-missing", key, 
sql, userParams));
+                    throw new UserException(_loc.get("uparam-missing", 
+                        key, sql, userParams));
                 result[idx++] = userParams.get(key);
             }
             // modify original JPA-style SQL to proper SQL
             q.getContext().getQuery().setQuery(sql);
             return result;
         }
-        
-        String getSQLVerb(String s) {
-               if (s == null || s.trim().isEmpty()) 
-                       throw new RuntimeException("No SQL verb in [" + s + 
"]");
-               return new StringTokenizer(s).nextToken();
-        }
     }
-    private static final char SINGLE_QUOTE = '\'';
-    private static final char QUESTION_MARK = '?';
+    
     /**
      * Utility method to substitute '?num' for parameters in the given SQL
      * statement, and fill-in the order of the parameter tokens
@@ -393,24 +359,25 @@ public class SQLStoreQuery
             throws IOException {
             // if there's no "?" parameter marker, then we don't need to
             // perform the parsing process
-            if (sql.indexOf(QUESTION_MARK) == -1)
+            if (sql.indexOf("?") == -1)
                 return sql;
 
             paramOrder.clear();
             StreamTokenizer tok = new StreamTokenizer(new StringReader(sql));
             tok.resetSyntax();
-            tok.quoteChar(SINGLE_QUOTE);
+            tok.quoteChar('\'');
             tok.wordChars('0', '9');
-            tok.wordChars(QUESTION_MARK, QUESTION_MARK);
+            tok.wordChars('?', '?');
 
             StringBuilder buf = new StringBuilder(sql.length());
-            for (int ttype; (ttype = tok.nextToken()) != 
StreamTokenizer.TT_EOF;) {
+            for (int ttype; (ttype = tok.nextToken()) !=
+                    StreamTokenizer.TT_EOF;) {
                 switch (ttype) {
                     case StreamTokenizer.TT_WORD:
                         // a token is a positional parameter if it starts with
                         // a "?" and the rest of the token are all numbers
-                        if (tok.sval.startsWith(""+QUESTION_MARK)) {
-                            buf.append(QUESTION_MARK);
+                        if (tok.sval.startsWith("?")) {
+                            buf.append("?");
                             String pIndex = tok.sval.substring(1);
                             if (pIndex.length() > 0) {
                                 paramOrder.add(Integer.valueOf(pIndex));
@@ -420,11 +387,11 @@ public class SQLStoreQuery
                         } else
                             buf.append(tok.sval);
                         break;
-                    case '\'':
-                        buf.append(SINGLE_QUOTE);
+                    case'\'':
+                        buf.append('\'');
                         if (tok.sval != null) {
                             buf.append(tok.sval);
-                            buf.append(SINGLE_QUOTE);
+                            buf.append('\'');
                         }
                         break;
                     default:


Reply via email to