[jboss-svn-commits] JBL Code SVN: r6249 - labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Sep 16 16:16:28 EDT 2006
Author: mohit309
Date: 2006-09-16 16:16:27 -0400 (Sat, 16 Sep 2006)
New Revision: 6249
Modified:
labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
Log:
Modified for throwing SQLException and corrected method names to reflect full logical names
Modified: labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java 2006-09-16 19:16:17 UTC (rev 6248)
+++ labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java 2006-09-16 20:16:27 UTC (rev 6249)
@@ -25,13 +25,18 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
-
+/**
+ * This class is used to make calls to database. It uses the underlying Datasource to get a connection.
+ * It contains a list of user specified Preparestatements which is then fired in a batch mode
+ *
+ */
public class JdbcCleanConn {
private DataSource m_oDS = null;
@@ -41,17 +46,17 @@
protected Logger m_oLogger;
- public JdbcCleanConn(DataSource p_oDS) throws Exception {
+ public JdbcCleanConn(DataSource p_oDS) throws SQLException {
m_oDS = p_oDS;
m_oLogger = Logger.getLogger(this.getClass());
}
- public void commit() throws Exception {
+ public void commit() throws SQLException {
if (null != m_conn)
m_conn.commit();
}
- public void rollback() throws Exception {
+ public void rollback() throws SQLException {
if (null != m_conn)
m_conn.rollback();
}
@@ -60,17 +65,17 @@
if (null != m_conn) {
try {
m_conn.rollback();
- } catch (Exception eRoll) {
+ } catch (SQLException eRoll) {
}
for (PreparedStatement PS : m_olPrepSt)
try {
PS.close();
- } catch (Exception e) {
+ } catch (SQLException e) {
}
try {
m_conn.close();
- } catch (Exception e1) {
+ } catch (SQLException e1) {
}
}
m_olPrepSt.clear();
@@ -78,7 +83,7 @@
} // __________________________________
public PreparedStatement prepareStatement(String p_sSt, int p_i1, int p_i2)
- throws Exception {
+ throws SQLException {
if (null == m_conn)
connect();
PreparedStatement PS = m_conn.prepareStatement(p_sSt, p_i1, p_i2);
@@ -86,7 +91,7 @@
return PS;
} // __________________________________
- public PreparedStatement prepareStatement(String p_sSt) throws Exception {
+ public PreparedStatement prepareStatement(String p_sSt) throws SQLException {
if (null == m_conn)
connect();
PreparedStatement PS = m_conn.prepareStatement(p_sSt);
@@ -95,57 +100,68 @@
} // __________________________________
public ResultSet execQueryWait(PreparedStatement p_PS, int p_iQtry)
- throws Exception {
- Exception eRet = null;
+ throws SQLException {
+ SQLException eRet = null;
int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
for (int i1 = 0; i1 < iQtry; i1++) {
try {
return p_PS.executeQuery();
- } catch (Exception e) {
+ } catch (SQLException e) {
+ m_oLogger
+ .error("execQueryWait: Error while executing query", e);
if (null == eRet)
- eRet = new Exception(e.getMessage());
- // System.out.println("Retrying "+i1);
- Thread.sleep(100 + (new Double(100 * Math.random()))
- .longValue());
+ eRet = e;
+ try {
+ Thread.sleep(100 + (new Double(100 * Math.random()))
+ .longValue());
+ } catch (InterruptedException e1) {
+ m_oLogger.info("execQueryWait: Interrupted Exception", e);
+ }
}
}
m_oLogger.error("execQueryWait() FAILED", eRet);
throw eRet;
} // __________________________________
- public void execUpdWait(PreparedStatement p_PS, int p_iQtry)
- throws Exception {
- Exception eRet = null;
+ public void execUpdateWait(PreparedStatement p_PS, int p_iQtry)
+ throws SQLException {
+ SQLException eRet = null;
int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
for (int i1 = 0; i1 < iQtry; i1++) {
try {
p_PS.executeUpdate();
return;
- } catch (Exception e) {
+ } catch (SQLException e) {
if (null == eRet)
eRet = e;
- // System.out.println("Retrying "+i1);
- Thread.sleep(100 + (new Double(100 * Math.random()))
- .longValue());
+ try {
+ Thread.sleep(100 + (new Double(100 * Math.random()))
+ .longValue());
+ } catch (InterruptedException e1) {
+ m_oLogger.info("execUpdWait: Interrupted Exception", e);
+ }
}
}
m_oLogger.error("execUpdWait() FAILED", eRet);
throw eRet;
} // __________________________________
- private void connect() throws Exception {
- Exception eRet = null;
+ private void connect() throws SQLException {
+ SQLException eRet = null;
for (int i1 = 0; i1 < 5; i1++) {
try {
m_conn = m_oDS.getConnection();
eRet = null;
break;
- } catch (Exception e) {
+ } catch (SQLException e) {
if (null == eRet)
eRet = e;
- System.out.println("Connecting " + i1);
- Thread.sleep(2000 + (new Double(100 * Math.random()))
- .longValue());
+ m_oLogger.debug("Connecting " + i1);
+ try{
+ Thread.sleep(2000 + (new Double(100 * Math.random())).longValue());
+ }catch(InterruptedException e1){
+ m_oLogger.info("connect: Interrupted Exception", e1);
+ }
}
}
if (null != eRet) {
@@ -154,9 +170,7 @@
}
m_conn.setAutoCommit(false);
m_conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
-
m_olPrepSt.clear();
-
} // __________________________________
} // ____________________________________________________________________________
Modified: labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-09-16 19:16:17 UTC (rev 6248)
+++ labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-09-16 20:16:27 UTC (rev 6249)
@@ -21,10 +21,14 @@
*/
package org.jboss.soa.esb.helpers.persist;
-import java.io.*;
-import java.sql.*;
-import javax.sql.*;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.DomElement;
/**
@@ -57,6 +61,9 @@
public static final String PASSWORD = "password";
+ private static Logger m_oLogger = Logger.getLogger(SimpleDataSource.class);
+
+
private SimpleDataSource() {
}
@@ -73,12 +80,12 @@
* @param p_oP
* DomElement - Parameter tree that contains the 4 attributes
* needed
- * @throws Exception
+ * @throws SQLException
* @see DomElement
* @see SimpleDataSource#SimpleDataSource(String,String,String,String)
* @see javax.sql.DataSource
*/
- public SimpleDataSource(DomElement p_oP) throws Exception {
+ public SimpleDataSource(DomElement p_oP) throws SQLException {
this(p_oP.getAttr(DRIVER), p_oP.getAttr(URL), p_oP.getAttr(USER), p_oP
.getAttr(PASSWORD));
} // ________________________________
@@ -96,29 +103,32 @@
* String - Username
* @param p_sPwd
* String - Password
- * @throws Exception
+ * @throws SQLException
* @see DriverManager#getConnection(String,String,String)
* @see javax.sql.DataSource
*/
public SimpleDataSource(String p_sDriver, String p_sDbURL, String p_sUsr,
- String p_sPwd) throws Exception {
- Class.forName(p_sDriver);
+ String p_sPwd) throws SQLException {
+ try {
+ Class.forName(p_sDriver);
+ } catch (ClassNotFoundException e) {
+ m_oLogger.error("JDBC Driver could not be instantiated",e);
+ SQLException excep = new SQLException("JDBC Driver could not be instantiated");
+ excep.setStackTrace(e.getStackTrace());
+ throw excep;
+ }
m_sUrl = p_sDbURL;
getConnection(p_sUsr, p_sPwd);
} // ________________________________
- public Connection getConnection() {
+ public Connection getConnection(){
return m_oConn;
}
- public Connection getConnection(String username, String password) {
+ public Connection getConnection(String username, String password) throws SQLException{
m_sUsr = username;
m_sPwd = password;
- try {
- m_oConn = DriverManager.getConnection(m_sUrl, m_sUsr, m_sPwd);
- } catch (Exception e) {
- m_oConn = null;
- }
+ m_oConn = DriverManager.getConnection(m_sUrl, m_sUsr, m_sPwd);
return m_oConn;
} // ________________________________
Modified: labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-09-16 19:16:17 UTC (rev 6248)
+++ labs/jbossesb/branches/JBESB_4_0_Beta1_maint/product/core/common/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-09-16 20:16:27 UTC (rev 6249)
@@ -54,14 +54,14 @@
initFields();
} // ________________________________
- public abstract int setInsValues(PreparedStatement p_PS, Object bobj)
+ public abstract int setInsertValues(PreparedStatement p_PS, Object bobj)
throws Exception;
- public abstract Object getFromRS(ResultSet p_oRS) throws Exception;
+ public abstract Object getFromResultSet(ResultSet p_oRS) throws Exception;
protected abstract String getSelectFields();
- public String getFldName(int p_i) {
+ public String getFieldName(int p_i) {
return (null == m_oaFields) ? null : (p_i < 0) ? null
: (p_i >= m_oaFields.length) ? null : m_oaFields[p_i]
.getFieldName();
More information about the jboss-svn-commits
mailing list