|
|
@ -21,10 +21,13 @@ 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.DataSourceNotAvailableException;
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.config.datasource.JNDILookupDefinition;
|
|
|
|
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.MobileDeviceManagementServiceComponent;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Hashtable;
|
|
|
@ -35,94 +38,104 @@ import java.util.List;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class MobileDeviceManagementDAOFactory {
|
|
|
|
public class MobileDeviceManagementDAOFactory {
|
|
|
|
|
|
|
|
|
|
|
|
private static DataSource dataSource;
|
|
|
|
private static DataSource dataSource;
|
|
|
|
private static MobileDataSourceConfig mobileDataSourceConfig;
|
|
|
|
private static MobileDataSourceConfig dsConfig;
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
|
|
|
|
|
|
|
|
private static boolean isInitialized;
|
|
|
|
public MobileDeviceManagementDAOFactory() {
|
|
|
|
|
|
|
|
|
|
|
|
public static void init() throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(dsConfig);
|
|
|
|
|
|
|
|
isInitialized = true;
|
|
|
|
public static void init() {
|
|
|
|
// MobileDeviceManagementServiceComponent.registerDataSourceListener(new DataSourceListener() {
|
|
|
|
try {
|
|
|
|
// @Override
|
|
|
|
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfig);
|
|
|
|
// public void notifyObserver() {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
// try {
|
|
|
|
log.error("Exception occurred while initializing the mobile datasource.",e);
|
|
|
|
// initDataSource();
|
|
|
|
}
|
|
|
|
// } catch (DeviceManagementException e) {
|
|
|
|
}
|
|
|
|
// log.error("Error occurred while registering data source");
|
|
|
|
|
|
|
|
// }
|
|
|
|
/**
|
|
|
|
// }
|
|
|
|
* Resolve data source from the data source definition.
|
|
|
|
// });
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @param config Mobile data source configuration
|
|
|
|
|
|
|
|
* @return data source resolved from the data source definition
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
* Resolve data source from the data source definition.
|
|
|
|
private static DataSource resolveDataSource(MobileDataSourceConfig config)
|
|
|
|
*
|
|
|
|
throws DeviceManagementException {
|
|
|
|
* @param config Mobile data source configuration
|
|
|
|
DataSource dataSource = null;
|
|
|
|
* @return data source resolved from the data source definition
|
|
|
|
if (config == null) {
|
|
|
|
*/
|
|
|
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
|
|
|
private static DataSource resolveDataSource(MobileDataSourceConfig config)
|
|
|
|
"is null and thus, is not initialized");
|
|
|
|
throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
DataSource dataSource = null;
|
|
|
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
|
|
|
if (config == null) {
|
|
|
|
if (jndiConfig != null) {
|
|
|
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
"is null and thus, is not initialized");
|
|
|
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
|
|
|
}
|
|
|
|
"Lookup Definition");
|
|
|
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
|
|
|
|
}
|
|
|
|
if (jndiConfig != null) {
|
|
|
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
jndiConfig.getJndiProperties();
|
|
|
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
|
|
|
if (jndiPropertyList != null) {
|
|
|
|
"Lookup Definition");
|
|
|
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
|
|
|
}
|
|
|
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
|
|
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
|
|
|
jndiProperties.put(prop.getName(), prop.getValue());
|
|
|
|
jndiConfig.getJndiProperties();
|
|
|
|
}
|
|
|
|
if (jndiPropertyList != null) {
|
|
|
|
dataSource =
|
|
|
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
|
|
|
MobileDeviceManagementDAOUtil
|
|
|
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
|
|
|
.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
|
|
jndiProperties.put(prop.getName(), prop.getValue());
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
dataSource = MobileDeviceManagementDAOUtil
|
|
|
|
dataSource =
|
|
|
|
.lookupDataSource(jndiConfig.getJndiName(), null);
|
|
|
|
MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
dataSource = MobileDeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
|
|
|
return dataSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataSource;
|
|
|
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
|
|
|
}
|
|
|
|
return new MobileDeviceDAOImpl(dataSource);
|
|
|
|
|
|
|
|
}
|
|
|
|
public static MobileDeviceDAO getMobileDeviceDAO() {
|
|
|
|
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
public static MobileOperationDAO getMobileOperationDAO() {
|
|
|
|
return new MobileDeviceDAOImpl(dataSource);
|
|
|
|
return new MobileOperationDAOImpl(dataSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MobileOperationDAO getMobileOperationDAO() {
|
|
|
|
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
return new MobileOperationPropertyDAOImpl(dataSource);
|
|
|
|
return new MobileOperationDAOImpl(dataSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
|
|
|
|
public static MobileOperationPropertyDAO getMobileOperationPropertyDAO() {
|
|
|
|
return new MobileDeviceOperationMappingDAOImpl(dataSource);
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
}
|
|
|
|
return new MobileOperationPropertyDAOImpl(dataSource);
|
|
|
|
|
|
|
|
}
|
|
|
|
public static MobileFeatureDAO getFeatureDAO() {
|
|
|
|
|
|
|
|
return new MobileFeatureDAOImpl(dataSource);
|
|
|
|
public static MobileDeviceOperationMappingDAO getMobileDeviceOperationDAO() {
|
|
|
|
}
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
|
|
|
|
return new MobileDeviceOperationMappingDAOImpl(dataSource);
|
|
|
|
public static MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
|
|
|
}
|
|
|
|
return new MobileFeaturePropertyDAOImpl(dataSource);
|
|
|
|
|
|
|
|
}
|
|
|
|
public static MobileFeatureDAO getFeatureDAO() {
|
|
|
|
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
public static MobileDataSourceConfig getMobileDeviceManagementConfig() {
|
|
|
|
return new MobileFeatureDAOImpl(dataSource);
|
|
|
|
return mobileDataSourceConfig;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static MobileFeaturePropertyDAO getFeaturePropertyDAO() {
|
|
|
|
public static void setMobileDataSourceConfig(
|
|
|
|
assertDataSourceInitialization();
|
|
|
|
MobileDataSourceConfig mobileDataSourceConfig) {
|
|
|
|
return new MobileFeaturePropertyDAOImpl(dataSource);
|
|
|
|
MobileDeviceManagementDAOFactory.mobileDataSourceConfig =
|
|
|
|
}
|
|
|
|
mobileDataSourceConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
public static void setDatSourceConfig(MobileDataSourceConfig dsConfig) {
|
|
|
|
|
|
|
|
MobileDeviceManagementDAOFactory.dsConfig = dsConfig;
|
|
|
|
public static DataSource getDataSource() {
|
|
|
|
}
|
|
|
|
return dataSource;
|
|
|
|
|
|
|
|
}
|
|
|
|
public static DataSource getDataSource() {
|
|
|
|
|
|
|
|
return dataSource;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void assertDataSourceInitialization() {
|
|
|
|
|
|
|
|
if (!isInitialized) {
|
|
|
|
|
|
|
|
throw new DataSourceNotAvailableException("Mobile device management metadata repository datasource " +
|
|
|
|
|
|
|
|
"is not initialized");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|