mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Refractor DAO Fatcory connections
This commit is contained in:
parent
df99f5a245
commit
eec444201d
@ -128,10 +128,17 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Connection getConnection() {
|
public static Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||||
|
if (currentConnection.get() == null) {
|
||||||
|
try {
|
||||||
|
currentConnection.set(dataSource.getConnection());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new MobileDeviceManagementDAOException("Error occurred while retrieving data source connection",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return currentConnection.get();
|
return currentConnection.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
public static void commitTransaction() throws MobileDeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
@ -145,9 +152,22 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
throw new MobileDeviceManagementDAOException("Error occurred while committing the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void closeConnection() throws MobileDeviceManagementDAOException {
|
||||||
|
|
||||||
|
Connection con = currentConnection.get();
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Error occurred while close the connection");
|
||||||
|
}
|
||||||
|
currentConnection.remove();
|
||||||
|
}
|
||||||
|
|
||||||
public static void rollbackTransaction() throws MobileDeviceManagementDAOException {
|
public static void rollbackTransaction() throws MobileDeviceManagementDAOException {
|
||||||
try {
|
try {
|
||||||
Connection conn = currentConnection.get();
|
Connection conn = currentConnection.get();
|
||||||
@ -161,6 +181,8 @@ public abstract class MobileDeviceManagementDAOFactory implements MobileDeviceMa
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new MobileDeviceManagementDAOException("Error occurred while rollbacking the transaction", e);
|
throw new MobileDeviceManagementDAOException("Error occurred while rollbacking the transaction", e);
|
||||||
|
} finally {
|
||||||
|
closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user