Skip to content

Commit

Permalink
Remove Dbutil Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tharsigam authored and Nuwan Walisundara committed Nov 17, 2016
1 parent 1de7f05 commit 31d6ba3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
5 changes: 5 additions & 0 deletions components/dbutil/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<groupId>org.wso2.carbon</groupId>
<artifactId>javax.cache.wso2</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Map;

import javax.persistence.PersistenceException;

// TODO: Auto-generated Javadoc
/**
* The Class DbService.
Expand All @@ -33,6 +35,7 @@ public class DbService {
/** The log. */
private static Log log = LogFactory.getLog(DbService.class);


/**
* Outbound subscription entry.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<String, String> pluginRequestIDs) throws DBUtilException,
SQLException {
Map<String, String> pluginRequestIDs) throws PersistenceException,
Exception {
Connection con = null;
PreparedStatement ps = null;

Expand Down Expand Up @@ -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);
Expand All @@ -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<String, String> getSmsRequestIds(String requestID,
String senderAddress) throws DBUtilException, SQLException {
String senderAddress) throws PersistenceException, Exception {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Expand Down Expand Up @@ -1219,7 +1222,7 @@ public Map<String, String> 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);
Expand All @@ -1237,12 +1240,12 @@ public Map<String, String> getSmsRequestIds(String requestID,
* @return the list
* @throws SQLException
* the SQL exception
* @throws DBUtilException
* the db util exception
* @throws PersistenceException
* the persistenceException exception
*/

public List<Integer> activeApplicationOperators(Integer appId,
String apitype) throws SQLException, DBUtilException {
String apitype) throws Exception, PersistenceException {

Connection con = null;
PreparedStatement statement = null;
Expand Down Expand Up @@ -1293,7 +1296,7 @@ public List<Integer> activeApplicationOperators(Integer appId,
e);
throw e;
} catch (Exception e) {
DbUtils.handleException(
throw new Exception(
"Error while selecting from endpointapps, operatorendpoints ",
e);
} finally {
Expand All @@ -1309,11 +1312,11 @@ public List<Integer> 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<String, String> getSPTokenMap() throws SQLException,
DBUtilException {
public Map<String, String> getSPTokenMap() throws Exception,
PersistenceException {

Connection con = null;
PreparedStatement statement = null;
Expand Down Expand Up @@ -1353,7 +1356,7 @@ public Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 31d6ba3

Please sign in to comment.