forked from community/device-mgt-core
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
commit
3899e8779f
121
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java
121
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
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 org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.GenericOperationDAOImpl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of OperationDAO which can be used to support Oracle db syntax.
|
||||
*/
|
||||
public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsForDevice(int enrolmentId, int index, int limit)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC " +
|
||||
"OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setInt(2, index);
|
||||
stmt.setInt(3, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, int index, int limit,
|
||||
Operation.Status status)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
"FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
|
||||
"o.CREATED_TIMESTAMP ASC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, index);
|
||||
stmt.setInt(4, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(status);
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
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 org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.GenericOperationDAOImpl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of OperationDAO which can be used to support PostgreSQL db syntax.
|
||||
*/
|
||||
public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsForDevice(int enrolmentId, int index, int limit)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC LIMIT ? OFFSET ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setInt(2, limit);
|
||||
stmt.setInt(3, index);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, int index, int limit,
|
||||
Operation.Status status)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
"FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
|
||||
"o.CREATED_TIMESTAMP ASC LIMIT ? OFFSET ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, limit);
|
||||
stmt.setInt(4, index);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(status);
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.operation;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
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 org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl.GenericOperationDAOImpl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of OperationDAO which can be used to support SQLServer db syntax.
|
||||
*/
|
||||
public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsForDevice(int enrolmentId, int index, int limit)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC " +
|
||||
"OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setInt(2, index);
|
||||
stmt.setInt(3, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, int index, int limit,
|
||||
Operation.Status status)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
Operation operation;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
"FROM DM_OPERATION o " +
|
||||
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
|
||||
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
|
||||
"o.CREATED_TIMESTAMP ASC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, index);
|
||||
stmt.setInt(4, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
operation = new Operation();
|
||||
operation.setId(rs.getInt("ID"));
|
||||
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
||||
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
||||
if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
||||
operation.setReceivedTimeStamp("");
|
||||
} else {
|
||||
operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
||||
}
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
operation.setStatus(status);
|
||||
operations.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
|
||||
"available for the device'" + enrolmentId + "' with status '" + status.toString(), e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue