Skip to content
Snippets Groups Projects
Commit a8d08a6b authored by Katy Saintin's avatar Katy Saintin
Browse files

DataBrowser : Use Archiver and Extractor class property to set the connection...

DataBrowser : Use Archiver and Extractor class property to set the connection parameter to Mambo database see  JIRA EXPDATA-415
parent 2c31c6bb
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,10 @@ public class ArchivingUtil { ...@@ -9,6 +9,10 @@ public class ArchivingUtil {
private static final String HDB_CLASS_NAME = "HdbExtractor"; private static final String HDB_CLASS_NAME = "HdbExtractor";
private static final String TDB_CLASS_NAME = "TdbExtractor"; private static final String TDB_CLASS_NAME = "TdbExtractor";
private static final String HDB_ARCHIVER_CLASS_NAME = "HdbArchiver";
private static final String TDB_ARCHIVER_CLASS_NAME = "TdbArchiver";
public static final String ALL_ARCHIVED_CMD = "GetAttNameAll"; public static final String ALL_ARCHIVED_CMD = "GetAttNameAll";
public static final String CURRENT_ARCHIVED_CMD = "GetCurrentArchivedAtt"; public static final String CURRENT_ARCHIVED_CMD = "GetCurrentArchivedAtt";
...@@ -35,25 +39,25 @@ public class ArchivingUtil { ...@@ -35,25 +39,25 @@ public class ArchivingUtil {
} }
private static void initExtractorDevice(boolean hdb) { private static void initExtractorDevice(boolean hdb) {
String initDevice = hdbExtractorDevice; String extractorDevice = hdbExtractorDevice;
if (!hdb) { if (!hdb) {
initDevice = tdbExtractorDevice; extractorDevice = tdbExtractorDevice;
} }
if (initDevice == null) { if (extractorDevice == null) {
try { try {
String className = HDB_CLASS_NAME; String extractorClassName = HDB_CLASS_NAME;
if (!hdb) { if (!hdb) {
className = TDB_CLASS_NAME; extractorClassName = TDB_CLASS_NAME;
} }
Database database = TangoDeviceHelper.getDatabase(); Database database = TangoDeviceHelper.getDatabase();
if (database != null) { if (database != null) {
String[] deviceList = database.get_device_exported_for_class(className); String[] extractorList = database.get_device_exported_for_class(extractorClassName);
if ((deviceList != null) && (deviceList.length > 0)) { if ((extractorList != null) && (extractorList.length > 0)) {
initDevice = deviceList[0]; extractorDevice = extractorList[0];
if (hdb) { if (hdb) {
hdbExtractorDevice = initDevice; hdbExtractorDevice = extractorDevice;
} else { } else {
tdbExtractorDevice = initDevice; tdbExtractorDevice = extractorDevice;
} }
} }
} }
...@@ -71,15 +75,18 @@ public class ArchivingUtil { ...@@ -71,15 +75,18 @@ public class ArchivingUtil {
} }
private static void initArchivingEnvironnement(boolean hdb) { private static void initArchivingEnvironnement(boolean hdb) {
String initDevice = hdbExtractorDevice; String extractorDevice = hdbExtractorDevice;
String archiverDevice = HDB_ARCHIVER_CLASS_NAME;
if (!hdb) { if (!hdb) {
initDevice = tdbExtractorDevice; extractorDevice = tdbExtractorDevice;
archiverDevice = TDB_ARCHIVER_CLASS_NAME;
} }
if ((initDevice != null) && !initDevice.isEmpty()) {
if ((extractorDevice != null) && !extractorDevice.isEmpty()) {
String userPropertyName = getProperty(hdb, "DB_USER"); String userPropertyName = getProperty(hdb, "DB_USER");
String userProperty = SystemUtils.getSystemProperty(userPropertyName); String userProperty = SystemUtils.getSystemProperty(userPropertyName);
if ((userProperty == null) || userProperty.isEmpty()) { if ((userProperty == null) || userProperty.isEmpty()) {
userProperty = getDeviceProperty(initDevice, "DbUser"); userProperty = getDeviceProperty(extractorDevice, "DbUser");
if ((userProperty != null) && !userProperty.isEmpty()) { if ((userProperty != null) && !userProperty.isEmpty()) {
System.setProperty(userPropertyName, userProperty); System.setProperty(userPropertyName, userProperty);
} }
...@@ -88,12 +95,79 @@ public class ArchivingUtil { ...@@ -88,12 +95,79 @@ public class ArchivingUtil {
String passPropertyName = getProperty(hdb, "DB_PASSWORD"); String passPropertyName = getProperty(hdb, "DB_PASSWORD");
String passProperty = SystemUtils.getSystemProperty(passPropertyName); String passProperty = SystemUtils.getSystemProperty(passPropertyName);
if ((passProperty == null) || passProperty.isEmpty()) { if ((passProperty == null) || passProperty.isEmpty()) {
passProperty = getDeviceProperty(initDevice, "DbPassword"); passProperty = getDeviceProperty(extractorDevice, "DbPassword");
if ((passProperty != null) && !passProperty.isEmpty()) { if ((passProperty != null) && !passProperty.isEmpty()) {
System.setProperty(passPropertyName, passProperty); System.setProperty(passPropertyName, passProperty);
} }
} }
} }
if ((archiverDevice != null) && !archiverDevice.isEmpty()) {
String dbDriverPropertyName = getProperty(hdb, "DB_DRIVER");
String driverProperty = SystemUtils.getSystemProperty(dbDriverPropertyName);
if ((driverProperty == null) || driverProperty.isEmpty()) {
driverProperty = getClassProperty(archiverDevice, "DbType");
if ((driverProperty != null) && !driverProperty.isEmpty()) {
String driverType = "jdbc:mysql";
if(driverProperty.toLowerCase().contains("oracle")){
driverType = "jdbc:oracle:thin";
}
System.setProperty(dbDriverPropertyName, driverType);
}
}
String racPropertyName = getProperty(hdb, "DB_RAC");
String racProperty = SystemUtils.getSystemProperty(racPropertyName);
if ((racProperty == null) || racProperty.isEmpty()) {
racProperty = getClassProperty(archiverDevice, "isRac");
if ((racProperty != null) && !racProperty.isEmpty()) {
System.setProperty(racPropertyName, racProperty);
}
}
boolean isRac = Boolean.parseBoolean(racProperty);
String schemaPropertyName = getProperty(hdb, "DB_SCHEMA");
String schemaProperty = SystemUtils.getSystemProperty(schemaPropertyName);
if ((schemaProperty == null) || schemaProperty.isEmpty()) {
schemaProperty = getClassProperty(archiverDevice, "DbSchema");
if ((schemaProperty != null) && !schemaProperty.isEmpty()) {
System.setProperty(schemaPropertyName, schemaProperty);
}
}
String namePropertyName = getProperty(hdb, "DB_NAME");
String nameProperty = SystemUtils.getSystemProperty(namePropertyName);
if ((nameProperty == null) || nameProperty.isEmpty()) {
if(isRac){
nameProperty = getClassProperty(archiverDevice, "DbONSConf");
}
else {
nameProperty = getClassProperty(archiverDevice, "DbName");
}
if ((nameProperty != null) && !nameProperty.isEmpty()) {
System.setProperty(namePropertyName, nameProperty);
}
}
String hostPropertyName = getProperty(hdb, "DB_HOST");
String hostProperty = SystemUtils.getSystemProperty(hostPropertyName);
if ((hostProperty == null) || hostProperty.isEmpty()) {
if(isRac){
hostProperty = getClassProperty(archiverDevice, "DbTnsNames");
}
else {
hostProperty = getClassProperty(archiverDevice, "DbHost");
}
if ((hostProperty != null) && !hostProperty.isEmpty()) {
System.setProperty(hostPropertyName, hostProperty);
}
}
}
} }
private static String getDeviceProperty(final String deviceName, final String propertyName) { private static String getDeviceProperty(final String deviceName, final String propertyName) {
...@@ -107,6 +181,24 @@ public class ArchivingUtil { ...@@ -107,6 +181,24 @@ public class ArchivingUtil {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
}
return value;
}
private static String getClassProperty(final String className, final String propertyName) {
String value = null;
try {
Database database = TangoDeviceHelper.getDatabase();
if (database != null) {
DbDatum db_property = database.get_class_property(className, propertyName);
if ((db_property != null) && !db_property.is_empty()) {
value = db_property.extractString();
}
}
} catch (Exception e) {
e.printStackTrace();
} }
return value; return value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment