init operation mgt data connection

revert-70aa11f8
manoj 10 years ago
parent a32e811183
commit cf247128b3

@ -36,6 +36,7 @@ public class OperationManagementDAOFactory {
private static DataSource dataSource;
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
private static final Object LOCK = new Object();
public static OperationDAO getCommandOperationDAO() {
return new CommandOperationDAOImpl();
@ -60,6 +61,7 @@ public class OperationManagementDAOFactory {
public static void init(DataSource dtSource) {
dataSource = dtSource;
}
public static void init(DataSourceConfig config) {
dataSource = resolveDataSource(config);
}
@ -72,7 +74,18 @@ public class OperationManagementDAOFactory {
}
}
public static Connection getConnection() {
public static Connection getConnection() throws OperationManagementDAOException {
if (currentConnection.get() == null) {
synchronized (LOCK) {
try {
currentConnection.set(dataSource.getConnection());
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while retrieving datasource connection",
e);
}
}
}
return currentConnection.get();
}

@ -99,6 +99,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = " +
"dom.DEVICE_ID) ois ON o.ID = ois.OP_ID ORDER BY " +
"o.CREATED_TIMESTAMP ASC) po ON co.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType());
stmt.setString(1, deviceId.getId());

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
@ -70,7 +71,7 @@ public class OperationDAOImpl implements OperationDAO {
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
stmt.setString(2, operation.getStatus().toString());
stmt.setInt(3,operation.getId());
stmt.setInt(3, operation.getId());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
@ -117,11 +118,12 @@ public class OperationDAOImpl implements OperationDAO {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql =
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " +
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN "
+
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND d.DEVICE_IDENTIFICATION = ?) d1 "
+
"INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois ON o.ID = ois.OP_ID";
"INNER JOIN (SELECT dom.OPERATION_ID AS OP_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER " +
"JOIN " +
"DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND d" +
".DEVICE_IDENTIFICATION = ?) d1 "+
"INNER JOIN DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois " +
"ON o.ID = ois.OP_ID";
stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId());

Loading…
Cancel
Save