mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
init operation mgt data connection
This commit is contained in:
parent
a32e811183
commit
cf247128b3
@ -36,6 +36,7 @@ public class OperationManagementDAOFactory {
|
|||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
|
private static final Log log = LogFactory.getLog(OperationManagementDAOFactory.class);
|
||||||
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
private static final Object LOCK = new Object();
|
||||||
|
|
||||||
public static OperationDAO getCommandOperationDAO() {
|
public static OperationDAO getCommandOperationDAO() {
|
||||||
return new CommandOperationDAOImpl();
|
return new CommandOperationDAOImpl();
|
||||||
@ -60,6 +61,7 @@ public class OperationManagementDAOFactory {
|
|||||||
public static void init(DataSource dtSource) {
|
public static void init(DataSource dtSource) {
|
||||||
dataSource = dtSource;
|
dataSource = dtSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(DataSourceConfig config) {
|
public static void init(DataSourceConfig config) {
|
||||||
dataSource = resolveDataSource(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();
|
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 = " +
|
"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 " +
|
"dom.DEVICE_ID) ois ON o.ID = ois.OP_ID ORDER BY " +
|
||||||
"o.CREATED_TIMESTAMP ASC) po ON co.OPERATION_ID = po.OPERATION_ID";
|
"o.CREATED_TIMESTAMP ASC) po ON co.OPERATION_ID = po.OPERATION_ID";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceId.getType());
|
stmt.setString(1, deviceId.getType());
|
||||||
stmt.setString(1, deviceId.getId());
|
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.OperationManagementDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -70,7 +71,7 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
||||||
stmt.setString(2, operation.getStatus().toString());
|
stmt.setString(2, operation.getStatus().toString());
|
||||||
stmt.setInt(3,operation.getId());
|
stmt.setInt(3, operation.getId());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|
||||||
rs = stmt.getGeneratedKeys();
|
rs = stmt.getGeneratedKeys();
|
||||||
@ -103,7 +104,7 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation getOperation(DeviceIdentifier deviceId,
|
public Operation getOperation(DeviceIdentifier deviceId,
|
||||||
Operation.Status status) throws OperationManagementDAOException {
|
Operation.Status status) throws OperationManagementDAOException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,11 +118,12 @@ public class OperationDAOImpl implements OperationDAO {
|
|||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql =
|
String sql =
|
||||||
"SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS FROM DM_OPERATION o " +
|
"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 "
|
"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 "
|
"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 DM_DEVICE_OPERATION_MAPPING dom ON d1.ID = dom.DEVICE_ID) ois " +
|
||||||
|
"ON o.ID = ois.OP_ID";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, deviceId.getType());
|
stmt.setString(1, deviceId.getType());
|
||||||
stmt.setString(2, deviceId.getId());
|
stmt.setString(2, deviceId.getId());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user