|
|
@ -49,7 +49,9 @@ public class DeviceTypeDAOHandler {
|
|
|
|
Context ctx = new InitialContext();
|
|
|
|
Context ctx = new InitialContext();
|
|
|
|
dataSource = (DataSource) ctx.lookup(datasourceName);
|
|
|
|
dataSource = (DataSource) ctx.lookup(datasourceName);
|
|
|
|
} catch (NamingException e) {
|
|
|
|
} catch (NamingException e) {
|
|
|
|
throw new DeviceTypeDeployerPayloadException("Error while looking up the data source: " + datasourceName, e);
|
|
|
|
String msg = "Error while looking up the data source: " + datasourceName;
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceTypeDeployerPayloadException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -57,12 +59,16 @@ public class DeviceTypeDAOHandler {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
if (conn != null) {
|
|
|
|
if (conn != null) {
|
|
|
|
throw new IllegalTransactionStateException("Database connection has already been obtained.");
|
|
|
|
String msg = "Database connection has already been obtained.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalTransactionStateException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn = dataSource.getConnection();
|
|
|
|
conn = dataSource.getConnection();
|
|
|
|
currentConnection.set(conn);
|
|
|
|
currentConnection.set(conn);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceTypeMgtPluginException("Failed to get a database connection.", e);
|
|
|
|
String msg = "Failed to get a database connection.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceTypeMgtPluginException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,7 +78,9 @@ public class DeviceTypeDAOHandler {
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
currentConnection.set(conn);
|
|
|
|
currentConnection.set(conn);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceTypeMgtPluginException("Error occurred while retrieving datasource connection", e);
|
|
|
|
String msg = "Error occurred while retrieving datasource connection";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceTypeMgtPluginException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +89,9 @@ public class DeviceTypeDAOHandler {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
currentConnection.set(dataSource.getConnection());
|
|
|
|
currentConnection.set(dataSource.getConnection());
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceTypeMgtPluginException("Error occurred while retrieving data source connection", e);
|
|
|
|
String msg = "Error occurred while retrieving data source connection";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new DeviceTypeMgtPluginException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return currentConnection.get();
|
|
|
|
return currentConnection.get();
|
|
|
@ -90,25 +100,28 @@ public class DeviceTypeDAOHandler {
|
|
|
|
public void commitTransaction() {
|
|
|
|
public void commitTransaction() {
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
if (conn == null) {
|
|
|
|
if (conn == null) {
|
|
|
|
throw new IllegalStateException("No connection is associated with the current transaction. " +
|
|
|
|
String msg = "No connection is associated with the current transaction. This might have ideally been " +
|
|
|
|
"This might have ideally been caused by not properly initiating the " +
|
|
|
|
"caused by not properly initiating the transaction via " +
|
|
|
|
"transaction via 'beginTransaction'/'openConnection' methods");
|
|
|
|
"'beginTransaction'/'openConnection' methods";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn.commit();
|
|
|
|
conn.commit();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
log.error("Error occurred while committing the transaction.", e);
|
|
|
|
String msg = "Error occurred while committing the transaction.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void closeConnection() {
|
|
|
|
public void closeConnection() {
|
|
|
|
|
|
|
|
|
|
|
|
Connection con = currentConnection.get();
|
|
|
|
Connection con = currentConnection.get();
|
|
|
|
if (con != null) {
|
|
|
|
if (con != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
con.close();
|
|
|
|
con.close();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
log.error("Error occurred while close the connection");
|
|
|
|
String msg = "Error occurred while close the connection";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentConnection.remove();
|
|
|
|
currentConnection.remove();
|
|
|
@ -117,14 +130,17 @@ public class DeviceTypeDAOHandler {
|
|
|
|
public void rollbackTransaction() {
|
|
|
|
public void rollbackTransaction() {
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
Connection conn = currentConnection.get();
|
|
|
|
if (conn == null) {
|
|
|
|
if (conn == null) {
|
|
|
|
throw new IllegalStateException("No connection is associated with the current transaction. " +
|
|
|
|
String msg = "No connection is associated with the current transaction. This might have ideally been " +
|
|
|
|
"This might have ideally been caused by not properly initiating the " +
|
|
|
|
"caused by not properly initiating the transaction via " +
|
|
|
|
"transaction via 'beginTransaction'/'openConnection' methods");
|
|
|
|
"'beginTransaction'/'openConnection' methods";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn.rollback();
|
|
|
|
conn.rollback();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
log.error("Error occurred while roll-backing the transaction.", e);
|
|
|
|
String msg = "Error occurred while roll-backing the transaction.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|