Create database in plugin level

revert-dabc3590
manoj 10 years ago
commit 9452631abc

@ -66,6 +66,7 @@
org.wso2.carbon.core,
org.wso2.carbon.utils.*,
org.wso2.carbon.device.mgt.common.*,
org.wso2.carbon.ndatasource.core
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.mobile.internal,
@ -116,6 +117,10 @@
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>

@ -0,0 +1,52 @@
/*
* *
* * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* * Licensed 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.
*
*/
package org.wso2.carbon.device.mgt.mobile;
public class DataSourceNotAvailableException extends RuntimeException {
private String message;
private static final long serialVersionUID = 2021891706072918866L;
public DataSourceNotAvailableException(String message, Exception nestedException) {
super(message, nestedException);
setErrorMessage(message);
}
public DataSourceNotAvailableException(String message, Throwable cause) {
super(message, cause);
setErrorMessage(message);
}
public DataSourceNotAvailableException(String message) {
super(message);
setErrorMessage(message);
}
public DataSourceNotAvailableException(Throwable cause) {
super(cause);
}
public String getMessage() {
return message;
}
public void setErrorMessage(String errorMessage) {
this.message = errorMessage;
}
}

@ -76,4 +76,5 @@ public class MobileDeviceManagementDAOException extends Exception {
public void setErrorMessage(String errorMessage) {
this.message = errorMessage;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.mobile.dao;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
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.MobileDataSourceConfig;
import org.wso2.carbon.device.mgt.mobile.dao.impl.*;
@ -37,27 +38,26 @@ import java.util.Map;
public class MobileDeviceManagementDAOFactory {
private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
private static Map<String,MobileDataSourceConfig> mobileDataSourceConfigMap;
private static Map<String,DataSource> dataSourceMap;
private static Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap;
private static Map<String, DataSource> dataSourceMap;
private String pluginProvider;
private DataSource dataSource;
private static boolean isInitialized;
public MobileDeviceManagementDAOFactory(String pluginProvider) {
this.pluginProvider = pluginProvider;
this.dataSource = dataSourceMap.get(pluginProvider);
}
public static void init() {
try {
public static void init() throws DeviceManagementException {
DataSource dataSource;
for(String pluginType:mobileDataSourceConfigMap.keySet()){
for (String pluginType : mobileDataSourceConfigMap.keySet()) {
dataSource = MobileDeviceManagementDAOFactory.resolveDataSource(mobileDataSourceConfigMap.get
(pluginType));
dataSourceMap.put(pluginType,dataSource);
}
} catch (DeviceManagementException e) {
log.error("Exception occurred while initializing the mobile data source.",e);
dataSourceMap.put(pluginType, dataSource);
}
isInitialized = true;
}
/**
@ -140,4 +140,11 @@ public class MobileDeviceManagementDAOFactory {
public static Map<String, DataSource> getDataSourceMap() {
return dataSourceMap;
}
private static void assertDataSourceInitialization() {
if (!isInitialized) {
throw new DataSourceNotAvailableException("Mobile device management metadata repository datasource " +
"is not initialized");
}
}
}

@ -65,7 +65,6 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B
.getMobileDeviceManagementConfig();
Map<String, MobileDataSourceConfig> mobileDataSourceConfigMap =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(mobileDataSourceConfigMap);
androidServiceRegRef =

@ -25,6 +25,7 @@ import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.mobile.DataSourceListener;
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig;
@ -33,6 +34,7 @@ import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager;
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager;
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import javax.sql.DataSource;
import java.util.Map;
@ -40,6 +42,12 @@ import java.util.Map;
/**
* @scr.component name="org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementServiceComponent"
* immediate="true"
* @scr.reference name="org.wso2.carbon.ndatasource"
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
* <p/>
* Adding reference to API Manager Configuration service is an unavoidable hack to get rid of NPEs thrown while
* initializing APIMgtDAOs attempting to register APIs programmatically. APIMgtDAO needs to be proper cleaned up
@ -47,10 +55,10 @@ import java.util.Map;
*/
public class MobileDeviceManagementServiceComponent {
private ServiceRegistration serverStartupObserverRef;
private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef;
private ServiceRegistration serverStartupObserverRef;
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
@ -67,7 +75,6 @@ public class MobileDeviceManagementServiceComponent {
.getMobileDeviceManagementConfig();
Map<String, MobileDataSourceConfig> dsConfigMap =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfigMap();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfigMap(dsConfigMap);
MobileDeviceManagementDAOFactory.init();
String setupOption = System.getProperty("setup");
@ -108,11 +115,15 @@ public class MobileDeviceManagementServiceComponent {
log.debug("De-activating Mobile Device Management Service Component");
}
try {
if (androidServiceRegRef != null) {
androidServiceRegRef.unregister();
}
if (iOSServiceRegRef != null) {
iOSServiceRegRef.unregister();
}
if (windowsServiceRegRef != null) {
windowsServiceRegRef.unregister();
serverStartupObserverRef.unregister();
}
if (log.isDebugEnabled()) {
log.debug(
"Mobile Device Management Service Component has been successfully de-activated");
@ -122,4 +133,17 @@ public class MobileDeviceManagementServiceComponent {
}
}
protected void setDataSourceService(DataSourceService dataSourceService) {
/* This is to avoid mobile device management component getting initialized before the underlying datasources
are registered */
try {
MobileDeviceManagementDAOFactory.init();
} catch (DeviceManagementException e) {
log.error("Error occurred while initializing mobile device management repository datasource", e);
}
}
protected void unsetDataSourceService(DataSourceService dataSourceService) {
//do nothing
}
}

@ -196,8 +196,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<!--CDM core dependencies-->
<!-- Device Management Core dependencies -->
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>

Loading…
Cancel
Save