mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
DAO Layer Implementation
This commit is contained in:
parent
f37df2e6b7
commit
630c065d4e
@ -14,48 +14,26 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.core.config;
|
||||
|
||||
import org.wso2.carbon.rssmanager.core.environment.Environment;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Represents RSS configuration.
|
||||
* Represents Device Mgt configuration.
|
||||
*/
|
||||
@XmlRootElement(name = "RSSConfiguration")
|
||||
@XmlRootElement(name = "DeviceMgtConfiguration")
|
||||
public final class DeviceMgtConfig {
|
||||
|
||||
private String rssProvider;
|
||||
private Environment[] environments;
|
||||
private RSSManagementRepository rssMgtRepository;
|
||||
private String deviceMgtProvider;
|
||||
|
||||
@XmlElement(name = "ManagementRepository", nillable = false)
|
||||
public RSSManagementRepository getRSSManagementRepository() {
|
||||
return rssMgtRepository;
|
||||
}
|
||||
@XmlElement(name = "ManagementRepository", nillable = false)
|
||||
public DeviceManagementRepository getDeviceMgtRepository() {
|
||||
return deviceMgtRepository;
|
||||
}
|
||||
|
||||
public void setRSSManagementRepository(RSSManagementRepository rssMgtRepository) {
|
||||
this.rssMgtRepository = rssMgtRepository;
|
||||
}
|
||||
public void setDeviceMgtRepository(DeviceManagementRepository deviceMgtRepository) {
|
||||
this.deviceMgtRepository = deviceMgtRepository;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "Environments", nillable = false)
|
||||
@XmlElement(name = "Environment", nillable = false)
|
||||
public Environment[] getRSSEnvironments() {
|
||||
return environments;
|
||||
}
|
||||
|
||||
public void setRSSEnvironments(Environment[] environments) {
|
||||
this.environments = environments;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Provider", nillable = false)
|
||||
public String getRSSProvider() {
|
||||
return rssProvider;
|
||||
}
|
||||
|
||||
public void setRSSProvider(String rssProvider) {
|
||||
this.rssProvider = rssProvider;
|
||||
}
|
||||
private DeviceManagementRepository deviceMgtRepository;
|
||||
|
||||
}
|
||||
|
||||
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*
|
||||
* Copyright (c) 2014, 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.
|
||||
* 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.config.datasource;
|
||||
|
||||
@ -1,20 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2005-2013, 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.
|
||||
*
|
||||
* Copyright (c) 2014, 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.
|
||||
* 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.config.datasource;
|
||||
|
||||
@ -1,29 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2005-2013, 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.
|
||||
*
|
||||
* Copyright (c) 2014, 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.
|
||||
* 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.config.datasource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,29 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*
|
||||
* Copyright (c) 2014, 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.
|
||||
* 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.config.datasource;
|
||||
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@ -24,7 +24,7 @@ public class DeviceDAO {
|
||||
private DataSource dataSource;
|
||||
|
||||
public DeviceDAO(DataSource dataSource) {
|
||||
this.dataSource = ;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.dto.Device;
|
||||
@ -27,14 +28,14 @@ import java.util.List;
|
||||
|
||||
public interface DeviceMgtDAO {
|
||||
|
||||
void addDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException;
|
||||
void addDevice(Device device) throws DeviceDAOException, DeviceManagementException;
|
||||
|
||||
void updateDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException;
|
||||
void updateDevice(Device device) throws DeviceDAOException, DeviceManagementException;
|
||||
|
||||
void updateDeviceStatus(Long deviceId, Status status) throws DeviceDAOException, DeviceDatabaseConnectionException;
|
||||
void updateDeviceStatus(Long deviceId, Status status) throws DeviceDAOException, DeviceManagementException;
|
||||
|
||||
void deleteDevice(Long deviceId) throws DeviceDAOException, DeviceDatabaseConnectionException;
|
||||
void deleteDevice(Long deviceId) throws DeviceDAOException, DeviceManagementException;
|
||||
|
||||
List<Device> getDeviceByDeviceId(Long deviceId) throws DeviceDAOException, DeviceDatabaseConnectionException;
|
||||
List<Device> getDeviceByDeviceId(Long deviceId) throws DeviceDAOException, DeviceManagementException;
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ 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.common.DeviceManagementException;
|
||||
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.DeviceDAOException;
|
||||
@ -29,6 +30,7 @@ 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 org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
@ -37,13 +39,17 @@ import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceMgtDAOImpl extends DeviceDAO implements DeviceMgtDAO {
|
||||
public class DeviceMgtDAOImpl implements DeviceMgtDAO {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceMgtDAOImpl.class);
|
||||
private DataSource dataSource;
|
||||
|
||||
public DeviceMgtDAOImpl() {
|
||||
this.dataSource = DeviceManagerUtil.getDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException {
|
||||
public void addDevice(Device device) throws DeviceDAOException, DeviceManagementException {
|
||||
|
||||
Connection conn = null;
|
||||
PreparedStatement addDeviceDBStatement = null;
|
||||
@ -78,33 +84,33 @@ public class DeviceMgtDAOImpl extends DeviceDAO implements DeviceMgtDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(Device device) throws DeviceDAOException, DeviceDatabaseConnectionException {
|
||||
public void updateDevice(Device device) throws DeviceDAOException, DeviceManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceStatus(Long deviceId, Status status)
|
||||
throws DeviceDAOException, DeviceDatabaseConnectionException {
|
||||
throws DeviceDAOException, DeviceManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDevice(Long deviceId) throws DeviceDAOException, DeviceDatabaseConnectionException {
|
||||
public void deleteDevice(Long deviceId) throws DeviceDAOException, DeviceManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDeviceByDeviceId(Long deviceId)
|
||||
throws DeviceDAOException, DeviceDatabaseConnectionException {
|
||||
throws DeviceDAOException, DeviceManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Connection getDataSourceConnection() throws DeviceDatabaseConnectionException {
|
||||
private Connection getDataSourceConnection() throws DeviceManagementException {
|
||||
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);
|
||||
String msg = "Error while acquiring the database connection";
|
||||
throw new DeviceManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,18 @@ package org.wso2.carbon.device.mgt.core.internal;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
||||
import org.wso2.carbon.device.mgt.core.util.DeviceMgtDbCreator;
|
||||
import org.wso2.carbon.utils.CarbonUtils;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.transaction.TransactionManager;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @scr.component name="org.wso2.carbon.device.manager" immediate="true"
|
||||
@ -28,6 +39,7 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
public class DeviceMgtServiceComponent {
|
||||
|
||||
private static Log log = LogFactory.getLog(DeviceMgtServiceComponent.class);
|
||||
private final String deviceMgtSetupSql = CarbonUtils.getCarbonHome() + File.separator + "dbscripts" ;
|
||||
|
||||
protected void setDeviceManagerService(DeviceManagerService deviceManager) {
|
||||
if (log.isDebugEnabled()) {
|
||||
@ -41,5 +53,61 @@ public class DeviceMgtServiceComponent {
|
||||
}
|
||||
}
|
||||
|
||||
protected void activate(ComponentContext componentContext) {
|
||||
BundleContext bundleContext = componentContext.getBundleContext();
|
||||
|
||||
|
||||
try {
|
||||
|
||||
/* Looks up for the JNDI registered transaction manager */
|
||||
DeviceManagerDataHolder.getInstance().setTransactionManager(this.lookupTransactionManager());
|
||||
/* Initializing RSS Configuration */
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
|
||||
String setupOption = System.getProperty("setup");
|
||||
//if -Dsetup option specified then create rss manager tables
|
||||
if (setupOption != null) {
|
||||
log.info("Setup option specified");
|
||||
DeviceMgtDbCreator dbCreator = new DeviceMgtDbCreator(DeviceManagerUtil.getDataSource());
|
||||
dbCreator.setRssDBScriptDirectory(deviceMgtSetupSql);
|
||||
log.info("Creating Meta Data tables");
|
||||
dbCreator.createRegistryDatabase();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
String msg = "Error occurred while initializing RSS Manager core bundle";
|
||||
log.error(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
private TransactionManager lookupTransactionManager() {
|
||||
TransactionManager transactionManager = null;
|
||||
try {
|
||||
Object txObj = InitialContext.doLookup(
|
||||
DeviceManagementConstants.STANDARD_USER_TRANSACTION_JNDI_NAME);
|
||||
if (txObj instanceof TransactionManager) {
|
||||
transactionManager = (TransactionManager) txObj;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Cannot find transaction manager at: "
|
||||
+ DeviceManagementConstants.STANDARD_USER_TRANSACTION_JNDI_NAME, e);
|
||||
}
|
||||
/* ignore, move onto next step */
|
||||
}
|
||||
if (transactionManager == null) {
|
||||
try {
|
||||
transactionManager = InitialContext.doLookup(
|
||||
DeviceManagementConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME);
|
||||
} catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Cannot find transaction manager at: " +
|
||||
DeviceManagementConstants.STANDARD_TRANSACTION_MANAGER_JNDI_NAME, e);
|
||||
}
|
||||
/* we'll do the lookup later, maybe user provided a custom JNDI name */
|
||||
}
|
||||
}
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
|
||||
<datasources>
|
||||
<datasource>
|
||||
<name>WSO2_EMM_DB</name>
|
||||
<name>WSO2DEVICE_DB</name>
|
||||
<description>The datasource used for EMM</description>
|
||||
<jndiConfig>
|
||||
<name>jdbc/WSO2EMMDB</name>
|
||||
<name>jdbc/WSO2DEVICE_DB</name>
|
||||
</jndiConfig>
|
||||
<definition type="RDBMS">
|
||||
<configuration>
|
||||
<url>jdbc:h2:repository/database/WSO2EMM_DB;DB_CLOSE_ON_EXIT=FALSE</url>
|
||||
<url>jdbc:h2:repository/database/WSO2DEVICE_DB;DB_CLOSE_ON_EXIT=FALSE</url>
|
||||
<username>wso2carbon</username>
|
||||
<password>wso2carbon</password>
|
||||
<driverClassName>org.h2.Driver</driverClassName>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user