DAO Layer Implementation

revert-dabc3590
manoj 10 years ago
parent a3028b0683
commit 1e6d06027d

@ -20,42 +20,91 @@ package org.wso2.carbon.device.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceMgtDAO;
import org.wso2.carbon.device.mgt.core.dao.exception.CDMDAOException;
import org.wso2.carbon.device.mgt.core.dao.exception.CDMDatabaseConnectionException;
import org.wso2.carbon.device.mgt.core.dao.exception.DeviceDAOException;
import org.wso2.carbon.device.mgt.core.dao.exception.DeviceDatabaseConnectionException;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceDAOUtil;
import org.wso2.carbon.device.mgt.core.dao.util.ErrorHandler;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.dto.Status;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
public class DeviceMgtDAOImpl implements DeviceMgtDAO {
public class DeviceMgtDAOImpl extends DeviceDAO implements DeviceMgtDAO {
private static final Log log = LogFactory.getLog(DeviceMgtDAOImpl.class);
private DataSource dataSource;
@Override
public void addDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException {
public void addDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException {
Connection conn = null;
PreparedStatement addDeviceDBStatement = null;
try {
conn = getDataSourceConnection();
conn.setAutoCommit(false);
String createDBQuery =
"INSERT INTO DM_DEVICE(DESCRIPTION,NAME,DATE_OF_ENROLLMENT,DATE_OF_LAST_UPDATE,OWNERSHIP," +
"STATUS,DEVICE_TYPE_ID,DEVICE_IDENTIFICATION,OWNER) VALUES (?,?,?,?,?,?,?,?,?)";
addDeviceDBStatement = conn.prepareStatement(createDBQuery);
addDeviceDBStatement.setString(1, device.getDescription());
addDeviceDBStatement.setString(2, device.getName());
addDeviceDBStatement.setLong(3, new Date().getTime());
addDeviceDBStatement.setLong(4, new Date().getTime());
addDeviceDBStatement.setString(5, device.getOwnerShip());
addDeviceDBStatement.setString(6, device.getStatus().toString());
addDeviceDBStatement.setLong(7, device.getDeviceType().getId());
addDeviceDBStatement.setLong(8, device.getDeviceIdentificationId());
addDeviceDBStatement.setString(9, device.getOwnerId());
addDeviceDBStatement.executeUpdate();
conn.commit();
} catch (SQLException e) {
DeviceDAOUtil.rollback(conn, DeviceManagementConstants.ADD_DEVICE_ENTRY);
String msg = "Failed to enroll device " + device.getName() + " to CDM";
ErrorHandler errorHandler = new ErrorHandler(msg, log);
errorHandler.handleDAOException(msg, e);
} finally {
DeviceDAOUtil.cleanupResources(null, addDeviceDBStatement, conn, DeviceManagementConstants.ADD_DEVICE_ENTRY);
}
}
@Override
public void updateDevice(Device device) throws CDMDAOException, CDMDatabaseConnectionException {
public void updateDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException {
}
@Override
public void updateDeviceStatus(Long deviceId, Status status)
throws CDMDAOException, CDMDatabaseConnectionException {
throws DeviceDAOException, DeviceDatabaseConnectionException {
}
@Override
public void deleteDevice(Long deviceId) throws CDMDAOException, CDMDatabaseConnectionException {
public void deleteDevice(Long deviceId) throws DeviceDAOException, DeviceDatabaseConnectionException {
}
@Override
public List<Device> getDeviceByDeviceId(Long deviceId)
throws CDMDAOException, CDMDatabaseConnectionException {
throws DeviceDAOException, DeviceDatabaseConnectionException {
return null;
}
private Connection getDataSourceConnection() throws DeviceDatabaseConnectionException {
try {
return dataSource.getConnection();
} catch (SQLException e) {
String msg = "Error while acquiring the database connection. Meta Repository Database server may down";
throw new DeviceDatabaseConnectionException(msg, e);
}
}
}

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.dto;
import java.io.Serializable;
public class Device implements Serializable{
public class Device implements Serializable {
private static final long serialVersionUID = -8101106997837486245L;
private Long id;
@ -33,6 +33,15 @@ public class Device implements Serializable{
private String ownerId;
private String ownerShip;
private Long tenantId;
private DeviceType deviceType;
public DeviceType getDeviceType() {
return deviceType;
}
public void setDeviceType(DeviceType deviceType) {
this.deviceType = deviceType;
}
public Long getId() {
return id;

@ -45,8 +45,6 @@
</modules>
<dependencyManagement>
<dependencies>
<!--<dependency>
@ -90,16 +88,45 @@
<version>${stub.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId>
<version>${carbon.kernel.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.felix</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.api</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.mgt</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<carbon.kernel.version>4.3.0-SNAPSHOT</carbon.kernel.version>
<carbon.platform.version>4.2.0-SNAPSHOT</carbon.platform.version>
<carbon.platform.version>4.3.0-SNAPSHOT</carbon.platform.version>
<carbon.p2.plugin.version>1.5.4</carbon.p2.plugin.version>
<maven-buildnumber-plugin.version>1.3</maven-buildnumber-plugin.version>
<axis2.osgi.version.range>[1.6.1.wso2v11, 1.7.0)</axis2.osgi.version.range>
<jboss-transaction-api.version>1.0.0.Final</jboss-transaction-api.version>
<!--Testing -->
<test.framework.version>4.3.1</test.framework.version>
<testng.version>6.8</testng.version>

@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
DEVICE_TYPE_ID INT(11) NULL DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) NULL DEFAULT NULL,
OWNER VARCHAR(45) NULL DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION

@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS `DM_DEVICE` (
`DEVICE_TYPE_ID` INT(11) NULL DEFAULT NULL ,
`DEVICE_IDENTIFICATION` VARCHAR(300) NULL DEFAULT NULL ,
`OWNER` VARCHAR(45) NULL DEFAULT NULL ,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (`ID`) ,
INDEX `fk_DM_DEVICE_DM_DEVICE_TYPE2_idx` (`DEVICE_TYPE_ID` ASC) ,
CONSTRAINT `fk_DM_DEVICE_DM_DEVICE_TYPE2`

Loading…
Cancel
Save