Merge pull request #353 from Megala21/master

Adding the check on the existence of the database before creating one
revert-dabc3590
Harshan Liyanage 8 years ago committed by GitHub
commit a30a2e7033

@ -92,8 +92,13 @@ public class AndroidSenseUtils {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasource);
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
String checkSql = "select * from ANDROID_SENSE_DEVICE";
if (!initializer.isDatabaseStructureCreated(checkSql)) {
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
} else {
log.info("Device management repository database already exists. Not creating a new database.");
}
} catch (NamingException e) {
log.error("Error while looking up the data source: " + datasource, e);

@ -105,8 +105,13 @@ public class ArduinoUtils {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasource);
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
String checkSql = "select * from ARDUINO_DEVICE";
if (!initializer.isDatabaseStructureCreated(checkSql)) {
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
} else {
log.info("Device management repository database already exists. Not creating a new database.");
}
} catch (NamingException e) {
log.error("Error while looking up the data source: " + datasource, e);

@ -94,8 +94,13 @@ public class RaspberrypiUtils {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasource);
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
String checkSql = "select * from RASPBERRYPI_DEVICE";
if (!initializer.isDatabaseStructureCreated(checkSql)) {
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
} else {
log.info("Device management repository database already exists. Not creating a new database.");
}
} catch (NamingException e) {
log.error("Error while looking up the data source: " + datasource, e);
} catch (Exception e) {

@ -99,8 +99,13 @@ public class VirtualFireAlarmUtils {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(datasourceName);
DeviceSchemaInitializer initializer = new DeviceSchemaInitializer(dataSource);
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
String checkSql = "select * from VIRTUAL_FIREALARM_DEVICE";
if (!initializer.isDatabaseStructureCreated(checkSql)) {
log.info("Initializing device management repository database schema");
initializer.createRegistryDatabase();
} else {
log.info("Device management repository database already exists. Not creating a new database.");
}
} catch (NamingException e) {
log.error("Error while looking up the data source: " + datasourceName, e);
} catch (Exception e) {

@ -93,9 +93,22 @@ public class MobileDeviceManagementDAOUtil {
public static void setupMobileDeviceManagementSchema(DataSource dataSource, String pluginType) throws MobileDeviceMgtPluginException {
MobileDeviceManagementSchemaInitializer initializer =
new MobileDeviceManagementSchemaInitializer(dataSource, pluginType);
log.info("Initializing mobile device management repository database schema for : " + pluginType);
String checkSql = "select * from ";
if (pluginType.equalsIgnoreCase("android")) {
checkSql += "AD_DEVICE";
} else if (pluginType.equalsIgnoreCase("windows")) {
checkSql += "WIN_DEVICE";
} else {
checkSql += "IOS_DEVICE";
}
try {
initializer.createRegistryDatabase();
if (!initializer.isDatabaseStructureCreated(checkSql)) {
log.info("Initializing mobile device management repository database schema for : " + pluginType);
initializer.createRegistryDatabase();
} else {
log.info("Mobile device management repository database for " + pluginType
+ " already exists. Not creating a new database.");
}
} catch (Exception e) {
throw new MobileDeviceMgtPluginException("Error occurred while initializing Mobile Device " +
"Management database schema", e);

Loading…
Cancel
Save