From 31d6ba3ca22b156e575b69fe9a1a33f8765c3b53 Mon Sep 17 00:00:00 2001 From: "tharsiga@wso2telco.com" Date: Wed, 19 Oct 2016 18:01:53 +0530 Subject: [PATCH] Remove Dbutil Exception --- components/dbutil/pom.xml | 5 ++ .../com/wso2telco/core/dbutils/DbService.java | 51 ++++++++++--------- .../com/wso2telco/core/dbutils/DbUtils.java | 23 +++++---- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/components/dbutil/pom.xml b/components/dbutil/pom.xml index 3c25530f..fb28a9be 100644 --- a/components/dbutil/pom.xml +++ b/components/dbutil/pom.xml @@ -35,6 +35,11 @@ org.wso2.carbon javax.cache.wso2 + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + 1.0.1.Final + diff --git a/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbService.java b/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbService.java index 279d1eb5..3e0cdd29 100644 --- a/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbService.java +++ b/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbService.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; +import javax.persistence.PersistenceException; + // TODO: Auto-generated Javadoc /** * The Class DbService. @@ -33,6 +35,7 @@ public class DbService { /** The log. */ private static Log log = LogFactory.getLog(DbService.class); + /** * Outbound subscription entry. * @@ -1037,13 +1040,13 @@ public boolean removeMerchantProvision(Integer appID, String subscriber, * @param countryCode * the country code * @return the prefix from country code - * @throws DBUtilException - * the db util exception + * @throws Persistence Exception + * the persistenceException exception * @throws SQLException * the SQL exception */ public String getPrefixFromCountryCode(String countryCode) - throws DBUtilException, SQLException { + throws PersistenceException, Exception { Connection con = null; PreparedStatement statement = null; @@ -1084,9 +1087,9 @@ public String getPrefixFromCountryCode(String countryCode) "database operation error while selecting from subscriptions ", e); throw e; - } catch (Exception e) { - DbUtils.handleException( - "Error while selecting from subscriptions. ", e); + } catch (PersistenceException e) { + throw new Exception("Error while selecting from subscriptions. ", e); + } finally { DbUtils.closeAllConnections(statement, con, rs); } @@ -1105,13 +1108,13 @@ public String getPrefixFromCountryCode(String countryCode) * @param pluginRequestIDs * the plugin request i ds * @return true, if successful - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the persistence exception */ public boolean insertSmsRequestIds(String requestID, String senderAddress, - Map pluginRequestIDs) throws DBUtilException, - SQLException { + Map pluginRequestIDs) throws PersistenceException, + Exception { Connection con = null; PreparedStatement ps = null; @@ -1156,7 +1159,7 @@ public boolean insertSmsRequestIds(String requestID, String senderAddress, e); throw e; } catch (Exception e) { - DbUtils.handleException( + throw new Exception( "Error while inserting in to sendsms_reqid. ", e); } finally { DbUtils.closeAllConnections(ps, con, null); @@ -1172,12 +1175,12 @@ public boolean insertSmsRequestIds(String requestID, String senderAddress, * @param senderAddress * the sender address * @return the sms request ids - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the Persistence exception */ public Map getSmsRequestIds(String requestID, - String senderAddress) throws DBUtilException, SQLException { + String senderAddress) throws PersistenceException, Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; @@ -1219,7 +1222,7 @@ public Map getSmsRequestIds(String requestID, e); throw e; } catch (Exception e) { - DbUtils.handleException( + throw new Exception( "Error while inserting in to sendsms_reqid. ", e); } finally { DbUtils.closeAllConnections(ps, con, rs); @@ -1237,12 +1240,12 @@ public Map getSmsRequestIds(String requestID, * @return the list * @throws SQLException * the SQL exception - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the persistenceException exception */ public List activeApplicationOperators(Integer appId, - String apitype) throws SQLException, DBUtilException { + String apitype) throws Exception, PersistenceException { Connection con = null; PreparedStatement statement = null; @@ -1293,7 +1296,7 @@ public List activeApplicationOperators(Integer appId, e); throw e; } catch (Exception e) { - DbUtils.handleException( + throw new Exception( "Error while selecting from endpointapps, operatorendpoints ", e); } finally { @@ -1309,11 +1312,11 @@ public List activeApplicationOperators(Integer appId, * @return the SP token map * @throws SQLException * the SQL exception - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the persistenceException exception */ - public Map getSPTokenMap() throws SQLException, - DBUtilException { + public Map getSPTokenMap() throws Exception, + PersistenceException { Connection con = null; PreparedStatement statement = null; @@ -1353,7 +1356,7 @@ public Map getSPTokenMap() throws SQLException, e); throw e; } catch (Exception e) { - DbUtils.handleException("Error while selecting from sp_token ", e); + throw new Exception("Error while selecting from sp_token ", e); } finally { DbUtils.closeAllConnections(statement, con, rs); } diff --git a/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbUtils.java b/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbUtils.java index efda4e5b..5b1afe62 100644 --- a/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbUtils.java +++ b/components/dbutil/src/main/java/com/wso2telco/core/dbutils/DbUtils.java @@ -19,12 +19,16 @@ import java.util.HashMap; import java.util.Map; import java.math.BigDecimal; + import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import javax.persistence.PersistenceException; import javax.sql.DataSource; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import com.wso2telco.core.dbutils.util.DataSourceNames; // TODO: Auto-generated Javadoc @@ -67,7 +71,7 @@ public class DbUtils { * the SQL exception * the db util exception */ - public static void initializeDatasources() throws SQLException, DBUtilException { + public static void initializeDatasources() throws Exception, PersistenceException { if (Datasource != null) { return; } @@ -77,8 +81,9 @@ public static void initializeDatasources() throws SQLException, DBUtilException Context ctx = new InitialContext(); DEP_DATA_SOURCE=(DataSourceNames.WSO2TELCO_DEP_DB.jndiName()); Datasource = (DataSource) ctx.lookup(DEP_DATA_SOURCE); + } catch (NamingException e) { - handleException("Error while looking up the data source: " + DEP_DATA_SOURCE, e); + throw new Exception("Error while looking up the data source: " + DEP_DATA_SOURCE, e); } } @@ -89,10 +94,10 @@ public static void initializeDatasources() throws SQLException, DBUtilException * @return the db connection * @throws SQLException * the SQL exception - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the persistenceException exception */ - public static Connection getDBConnection() throws SQLException, DBUtilException { + public static Connection getDBConnection() throws Exception, PersistenceException { initializeDatasources(); if (Datasource != null) { @@ -347,12 +352,12 @@ public void disconnect(Connection con) throws Exception { * the msg * @param t * the t - * @throws DBUtilException - * the db util exception + * @throws PersistenceException + * the persistenceException exception */ - public static void handleException(String msg, Throwable t) throws DBUtilException { + public static void handleException(String msg, Throwable t) throws PersistenceException { log.error(msg, t); - throw new DBUtilException(msg, t); + throw new PersistenceException(msg, t); } /**