DAO Layer Implementation

revert-70aa11f8
manoj 10 years ago
parent 23938f5e0b
commit f37df2e6b7

@ -18,13 +18,26 @@ package org.wso2.carbon.device.mgt.common;
public final class DeviceManagementConstants {
/*DEVICE Manager operations*/
public static final String ADD_DEVICE_ENTRY = "Add device entry";
public static final String ADD_DEVICE_ENTRY = "Add device entry";
public static final String STANDARD_TRANSACTION_MANAGER_JNDI_NAME = "java:comp/TransactionManager";
public static final String STANDARD_USER_TRANSACTION_JNDI_NAME = "java:comp/UserTransaction";
/*Data Source Configurations */
public static final class DataSourceProperties {
public static final String DB_CHECK_QUERY = "SELECT * FROM DM_DEVICE";
public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration";
public static final String DEVICE_CONFIG_XML_NAME = "device-config.xml";
}
public static final class SecureValueProperties {
private SecureValueProperties() {
throw new AssertionError();
}
public static final String SECRET_ALIAS_ATTRIBUTE_NAME_WITH_NAMESPACE = "secretAlias";
public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration";
}
}

@ -16,6 +16,7 @@
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
@ -57,6 +58,7 @@
org.osgi.framework,
org.osgi.service.component,
org.apache.commons.logging,
javax.transaction.*,
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.core.internal,

@ -20,15 +20,10 @@ import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.rssmanager.core.dao.RSSDAOFactory;
import org.wso2.carbon.rssmanager.core.environment.EnvironmentManager;
import org.wso2.carbon.rssmanager.core.environment.EnvironmentManagerFactory;
import org.wso2.carbon.rssmanager.core.exception.RSSManagerException;
import org.wso2.carbon.rssmanager.core.manager.adaptor.EnvironmentAdaptor;
import org.wso2.carbon.rssmanager.core.util.RSSDbCreator;
import org.wso2.carbon.rssmanager.core.util.RSSManagerUtil;
import org.wso2.carbon.device.mgt.core.dao.exception.DeviceMgtDAOFactory;
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.sql.DataSource;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@ -39,12 +34,11 @@ import java.io.File;
*/
public class DeviceConfigurationManager {
private RSSConfig currentRSSConfig;
private DeviceMgtConfig currentDeviceConfig;
private static DeviceConfigurationManager deviceConfigManager;
private static final Log log = LogFactory.getLog(DeviceConfigurationManager.class);
private final String rssConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "conf" + File
.separator +
private final String deviceMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
DeviceManagementConstants.DataSourceProperties.DEVICE_CONFIG_XML_NAME;
private final String cdmSetupSql = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
@ -64,41 +58,30 @@ public class DeviceConfigurationManager {
public synchronized void initConfig() throws DeviceManagementException {
try {
File rssConfig = new File(rssConfigXMLPath);
Document doc = RSSManagerUtil.convertToDocument(rssConfig);
File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
/* Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
//rss-config supports secure vault as it needs to be resolve when parsing
RSSManagerUtil.secureResolveDocument(doc);
DeviceManagerUtil.secureResolveDocument(doc);*/
/* Un-marshaling RSS configuration */
JAXBContext rssContext = JAXBContext.newInstance(RSSConfig.class);
JAXBContext rssContext = JAXBContext.newInstance(DeviceMgtConfig.class);
Unmarshaller unmarshaller = rssContext.createUnmarshaller();
this.currentRSSConfig = (RSSConfig) unmarshaller.unmarshal(doc);
this.currentDeviceConfig = (DeviceMgtConfig) unmarshaller.unmarshal(doc);
//set jndi data source name for future use
RSSManagerUtil.setJndiDataSourceName(currentRSSConfig.getRSSManagementRepository().getDataSourceConfig().
DeviceManagerUtil.setJndiDataSourceName(currentDeviceConfig.getDeviceMgtRepository().getDataSourceConfig().
getJndiLookupDefintion().getJndiName());
DataSource dataSource = RSSDAOFactory.resolveDataSource(this.currentRSSConfig.getRSSManagementRepository()
.getDataSourceConfig());
RSSManagerUtil.setDataSource(dataSource);
String setupOption = System.getProperty("setup");
//if -Dsetup option specified then create rss manager tables
if (setupOption != null) {
log.info("Setup option specified");
RSSDbCreator dbCreator = new RSSDbCreator(dataSource);
dbCreator.setRssDBScriptDirectory(cdmSetupSql);
log.info("Creating Meta Data tables");
dbCreator.createRegistryDatabase();
}
//Initialization of environment manager
EnvironmentManager environmentManager = EnvironmentManagerFactory.getEnvironmentManager(currentRSSConfig.
getRSSEnvironments());
environmentManager
.initEnvironments(currentRSSConfig.getRSSProvider(), currentRSSConfig.getRSSManagementRepository());
this.adaptor = new EnvironmentAdaptor(environmentManager);
DataSource dataSource = DeviceMgtDAOFactory.resolveDataSource(this.currentDeviceConfig.getDeviceMgtRepository()
.getDataSourceConfig());
DeviceManagerUtil.setDataSource(dataSource);
} catch (Exception e) {
throw new RSSManagerException("Error occurred while initializing RSS config", e);
throw new DeviceManagementException("Error occurred while initializing RSS config", e);
}
}
public RSSConfig getCurrentRSSConfig() {
return currentRSSConfig;
public DeviceMgtConfig getCurrentDeviceConfig() {
return currentDeviceConfig;
}
}

Loading…
Cancel
Save