|
|
@ -19,18 +19,19 @@ package org.wso2.carbon.device.mgt.mobile.dao;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.DataSourceListener;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.*;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.impl.*;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.internal.MobileDeviceManagementBundleActivator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Factory class used to create MobileDeviceManagement related DAO objects.
|
|
|
|
* Factory class used to create MobileDeviceManagement related DAO objects.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
|
|
|
public class MobileDeviceManagementDAOFactory {
|
|
|
|
|
|
|
|
|
|
|
|
private static DataSource dataSource;
|
|
|
|
private static DataSource dataSource;
|
|
|
|
private static MobileDataSourceConfig mobileDataSourceConfig;
|
|
|
|
private static MobileDataSourceConfig mobileDataSourceConfig;
|
|
|
@ -40,13 +41,49 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void init() throws DeviceManagementException {
|
|
|
|
public static void init() {
|
|
|
|
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
|
|
|
try {
|
|
|
|
if (dataSource != null) {
|
|
|
|
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig);
|
|
|
|
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
log.error("Exception occurred while initializing the mobile datasource.",e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Resolve data source from the data source definition.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param config Mobile data source configuration
|
|
|
|
|
|
|
|
* @return data source resolved from the data source definition
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static DataSource resolveDataSource(MobileDataSourceConfig config)
|
|
|
|
|
|
|
|
throws DeviceManagementException {
|
|
|
|
|
|
|
|
DataSource dataSource = null;
|
|
|
|
|
|
|
|
if (config == null) {
|
|
|
|
|
|
|
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
|
|
|
|
|
|
|
"is null and thus, is not initialized");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
|
|
|
|
|
|
|
|
if (jndiConfig != null) {
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
|
|
|
|
|
|
|
"Lookup Definition");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
|
|
|
|
|
|
|
jndiConfig.getJndiProperties();
|
|
|
|
|
|
|
|
if (jndiPropertyList != null) {
|
|
|
|
|
|
|
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
|
|
|
|
|
|
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
|
|
|
|
|
|
|
jndiProperties.put(prop.getName(), prop.getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSource =
|
|
|
|
|
|
|
|
MobileDeviceManagementDAOUtil
|
|
|
|
|
|
|
|
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
|
|
|
|
dataSource = MobileDeviceManagementDAOUtil
|
|
|
|
|
|
|
|
.lookupDataSource(jndiConfig.getJndiName(), null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
|
|
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
|
|
@ -86,14 +123,4 @@ public class MobileDeviceManagementDAOFactory implements DataSourceListener {
|
|
|
|
public static DataSource getDataSource() {
|
|
|
|
public static DataSource getDataSource() {
|
|
|
|
return dataSource;
|
|
|
|
return dataSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void notifyObserver() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
dataSource = MobileDeviceManagementDAOUtil.resolveDataSource(mobileDataSourceConfig);
|
|
|
|
|
|
|
|
MobileDeviceManagementDAOUtil.createDataSource(dataSource);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while resolving mobile device management metadata repository data source", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|