From e75b04f5350080fa18bc745fdcb3d554556795f5 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 29 Jan 2007 05:10:50 +0000 Subject: [PATCH] * [ 1644635 ] WAN: DB.prepareCall not working --- dbPort/src/org/compiere/util/DB.java | 41 ++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/dbPort/src/org/compiere/util/DB.java b/dbPort/src/org/compiere/util/DB.java index c9ab35cdfe..74ac334666 100644 --- a/dbPort/src/org/compiere/util/DB.java +++ b/dbPort/src/org/compiere/util/DB.java @@ -743,22 +743,47 @@ public final class DB log.fine("closed"); } // closeTarget - /************************************************************************** * Prepare Forward Read Only Call - * @param RO_SQL sql (RO) + * @param SQL sql * @return Callable Statement */ - public static CallableStatement prepareCall(String RO_SQL) + public static CallableStatement prepareCall(String sql) { - if (RO_SQL == null || RO_SQL.length() == 0) - throw new IllegalArgumentException("Required parameter missing - " + RO_SQL); + return prepareCall(sql, ResultSet.CONCUR_UPDATABLE, null); + } + + /************************************************************************** + * Prepare Call + * @param SQL sql + * @param readOnly + * @param trxName + * @return Callable Statement + */ + public static CallableStatement prepareCall(String SQL, int resultSetConcurrency, String trxName) + { + if (SQL == null || SQL.length() == 0) + throw new IllegalArgumentException("Required parameter missing - " + SQL); // - String sql = getDatabase().convertStatement(RO_SQL); + String sql = getDatabase().convertStatement(SQL); try { - return getConnectionRO().prepareCall - (sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + Connection conn = null; + Trx trx = trxName == null ? null : Trx.get(trxName, true); + if (trx != null) + conn = trx.getConnection(); + else + { + if (resultSetConcurrency == ResultSet.CONCUR_UPDATABLE) + conn = DB.getConnectionRW (); + else + conn = DB.getConnectionRO(); + } + if (conn == null) + throw new DBException("No Connection"); + + return conn.prepareCall + (sql, ResultSet.TYPE_FORWARD_ONLY, resultSetConcurrency); } catch (SQLException e) {