db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian McCallister <bri...@chariotsolutions.com>
Subject Re: Named Queries, Stored Procedures, etc
Date Thu, 09 Dec 2004 21:06:22 GMT
Vadim had forwarded me this (edited to remove thread) as well (Vadim's  
patch):

-Brian

Vadim Gritsenko wrote:

<snip />

Ok, attached is a hack to make queries work with stored procedures and  
Oracle. There is one Oracle specific thing in there (sql type -10)  
which I don't know how should look like in general case - any ideas?

<snip />

Query calling stored function looks like:
   QueryFactory.newQuery(My.class, "{?=call my_function('param')}");

<snip />

Index: src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
===================================================================
RCS file:  
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ 
JdbcAccessImpl.java,v
retrieving revision 1.17.2.1
diff -u -u -r1.17.2.1 JdbcAccessImpl.java
--- src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java	7  
Jan 2004 13:02:04 -0000	1.17.2.1
+++ src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java	9  
Dec 2004 17:43:42 -0000
@@ -384,8 +346,20 @@
          try
          {
              PreparedStatement stmt = stmtMan.getPreparedStatement(cld,  
sqlStatement, scrollable);
-            stmtMan.bindValues(stmt, values, 1);
-            ResultSet rs = stmt.executeQuery();
+
+            ResultSet rs;
+            // FIXME: VG: If CALL, first argument is ResultSet, the  
rest should be shifted
+            if (stmt instanceof CallableStatement) {
+                // oracle.jdbc.OracleTypes.CURSOR
+                ((CallableStatement)stmt).registerOutParameter(1, -10);
+                stmtMan.bindValues(stmt, values, 2);
+                stmt.execute();
+                rs = (ResultSet)  
((CallableStatement)stmt).getObject(1);
+            } else {
+                stmtMan.bindValues(stmt, values, 1);
+                rs = stmt.executeQuery();
+            }
+
              // as we return the resultset for further operations, we  
cannot release the statement yet.
              // that has to be done by the JdbcAccess-clients (i.e.  
RsIterator, ProxyRsIterator and PkEnumeration.)
              retval = new ResultSetAndStatement(
Index:  
src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
===================================================================
RCS file:  
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ 
StatementsForClassImpl.java,v
retrieving revision 1.18
diff -u -u -r1.18 StatementsForClassImpl.java
---  
src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java	 
6 Oct 2003 07:24:02 -0000	1.18
+++  
src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java	 
9 Dec 2004 17:43:42 -0000
@@ -210,7 +164,8 @@
          PreparedStatement stmt = null;
          try
          {
-            stmt = prepareStatement(con, sql, scrollable);
+            // FIXME: VG: Hack to allow use of stored procedures in  
QueryBySQL
+            stmt = prepareStatement(con, sql, scrollable,  
!sql.toLowerCase().startsWith("{?=call"));
          }
          catch (java.sql.SQLException ex)
          {
@@ -228,7 +183,7 @@
          }
          try
          {
-            return prepareStatement(con, selectByPKSql,  
Query.NOT_SCROLLABLE);
+            return prepareStatement(con, selectByPKSql,  
Query.NOT_SCROLLABLE, true);
          }
          catch (SQLException ex)
          {
@@ -277,7 +232,7 @@
       * @param scrollable determines if the statement will be  
scrollable.
       * @param createPreparedStatement if <code>true</code>, then a
       * {@link PreparedStatement} will be created.  if  
<code>false</code>, then
-     * a {@link CallableStatement} will be created.
+     * a {@link java.sql.CallableStatement} will be created.
       *
       * @return a statement that can be used to execute the syntax  
contained in
       * the <code>sql</code> argument.


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message