Modify error messages and exception handling

revert-70aa11f8
Saad Sahibjan 5 years ago
parent 0d203e0cd5
commit f0103f27c4

@ -70,25 +70,21 @@ public class DeviceTypeDAOHandler {
return currentConnection.get(); return currentConnection.get();
} }
public void commitTransaction() throws DeviceTypeMgtPluginException { public void commitTransaction() {
try {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn != null) { if (conn == null) {
conn.commit(); throw new IllegalStateException("No connection is associated with the current transaction. " +
} else { "This might have ideally been caused by not properly initiating the " +
if (log.isDebugEnabled()) { "transaction via 'beginTransaction'/'openConnection' methods");
log.debug("Datasource connection associated with the current thread is null, hence commit "
+ "has not been attempted");
}
} }
try {
conn.commit();
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceTypeMgtPluginException("Error occurred while committing the transaction", e); log.error("Error occurred while committing the transaction.", e);
} finally {
closeConnection();
} }
} }
public void closeConnection() throws DeviceTypeMgtPluginException { public void closeConnection() {
Connection con = currentConnection.get(); Connection con = currentConnection.get();
if (con != null) { if (con != null) {
@ -101,21 +97,17 @@ public class DeviceTypeDAOHandler {
currentConnection.remove(); currentConnection.remove();
} }
public void rollbackTransaction() throws DeviceTypeMgtPluginException { public void rollbackTransaction() {
try {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn != null) { if (conn == null) {
conn.rollback(); throw new IllegalStateException("No connection is associated with the current transaction. " +
} else { "This might have ideally been caused by not properly initiating the " +
if (log.isDebugEnabled()) { "transaction via 'beginTransaction'/'openConnection' methods");
log.debug("Datasource connection associated with the current thread is null, hence rollback "
+ "has not been attempted");
}
} }
try {
conn.rollback();
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceTypeMgtPluginException("Error occurred while rollback the transaction", e); log.error("Error occurred while roll-backing the transaction.", e);
} finally {
closeConnection();
} }
} }
} }

Loading…
Cancel
Save