Skip to content

Commit 7e369f1

Browse files
committed
Update to ensure faster install
1 parent 78bb846 commit 7e369f1

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

src/com/prtech/svarog/DbInit.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7718,6 +7718,7 @@ public static Map<String, String> loadCustomResourcesFromJar(String pathToJar, S
77187718
resourceName = resourceName.toLowerCase();
77197719
suffix = suffix.toLowerCase();
77207720
Gson g = new Gson();
7721+
77217722
if (pathToJar != null && !pathToJar.equals("")) {
77227723
try (JarFile jarFile = new JarFile(pathToJar)) {
77237724
Enumeration<JarEntry> e = jarFile.entries();
@@ -7726,8 +7727,10 @@ public static Map<String, String> loadCustomResourcesFromJar(String pathToJar, S
77267727
String fileName = je.getName().toLowerCase();
77277728
if (fileName.startsWith(resourceName) && fileName.endsWith(suffix)) {
77287729
try (InputStream is = jarFile.getInputStream(je)) {
7729-
retVal.put(jarFile.getName() + ":" + fileName.replace(resourceName, ""),
7730+
File fl = new File(pathToJar);
7731+
retVal.put(fl.getName() + "_" + fileName.replace(resourceName, ""),
77307732
IOUtils.toString(is, "UTF-8"));
7733+
77317734
} catch (Exception e2) {
77327735
log4j.error("Error loading resource: " + pathToJar + "!" + fileName, e);
77337736
}

src/com/prtech/svarog/SvarogInstall.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ static Options getOptions() {
11521152
* 3. Generate DbDataObjects for the Labels loaded from all OSGi bundles
11531153
*
11541154
* @return 0 if success, -1 if failed
1155-
* @throws SvException
1155+
* @throws SvException
11561156
*/
11571157
private static int generateJsonCfg() throws SvException {
11581158
// we should not connect to database at all and check if svarog is
@@ -1173,32 +1173,31 @@ private static int generateJsonCfg() throws SvException {
11731173
log4j.error("Error deleting conf resources ", e);
11741174
}
11751175

1176-
Map<String, String> jsonTables = DbInit.loadTextFilesFromDir(SvConf.getParam(AutoProcessor.AUTO_DEPLOY_DIR_PROPERTY), jsonTablesPath, "json");
1176+
Map<String, String> jsonTables = DbInit
1177+
.loadTextFilesFromDir(SvConf.getParam(AutoProcessor.AUTO_DEPLOY_DIR_PROPERTY), jsonTablesPath, "json");
11771178

11781179
Map<String, List<DbDataTable>> allJsonTables = DbInit.getJsonTableList(jsonTables);
11791180

11801181
// first get map of all available dbInit instances
1181-
Map<IDbInit, String> dbInits = DbInit.loadDbInitFromDir(SvConf.getParam(AutoProcessor.AUTO_DEPLOY_DIR_PROPERTY));
1182+
Map<IDbInit, String> dbInits = DbInit
1183+
.loadDbInitFromDir(SvConf.getParam(AutoProcessor.AUTO_DEPLOY_DIR_PROPERTY));
11821184
// Load all available table configurations
11831185
Map<String, List<DbDataTable>> allTables = DbInit.getDbInitTableList(dbInits);
1184-
1186+
11851187
allTables.putAll(allJsonTables);
11861188

11871189
String errorMessage = DbInit.verifyTables(allTables);
11881190
if (!errorMessage.equals("")) {
11891191
log4j.error("Error verifying tables. " + errorMessage);
11901192
return -1;
11911193
}
1192-
11931194

11941195
// Load all available table configurations
11951196
allTables = DbInit.applyDbDataTableExtensions(allTables);
1196-
1197+
11971198
// Load all available table configurations
11981199
Map<String, List<DbDataObject>> allObjects = DbInit.getDbInitObjectInstances(dbInits);
11991200

1200-
1201-
12021201
// create all JSON configurations from DbDataTables to prepare for SCHEMA
12031202
// upgrade (creation of tables and views)
12041203
errorMessage = DbInit.createJsonSvarogRepo(allTables);
@@ -3759,6 +3758,23 @@ static void upgradeObjectCfg(DbDataArray dbTablesUpgrade, DbDataArray dbFieldsUp
37593758
}
37603759
}
37613760

3761+
static Map<String, Long> codeLists = null;
3762+
3763+
synchronized static Map<String, Long> getCodeLists(SvCore svc) throws SvException {
3764+
if (codeLists == null) {
3765+
try (CodeList cl = new CodeList(svc)) {
3766+
HashMap<Long, String> tmpcl = cl.getCodeListIdValues(0L);
3767+
codeLists = new HashMap<String, Long>();
3768+
for (Map.Entry<Long, String> e : tmpcl.entrySet()) {
3769+
codeLists.put(e.getValue(), e.getKey());
3770+
}
3771+
3772+
}
3773+
}
3774+
return codeLists;
3775+
3776+
}
3777+
37623778
/**
37633779
* Method to perform upgrade of the fields in the svarog platform
37643780
*
@@ -3806,31 +3822,17 @@ static void upgradeObjectFields(String parentTableName, DbDataArray dbTablesUpgr
38063822
existingField = dbFields.getItemByIdx((String) dboUpgrade.getVal("FIELD_NAME"),
38073823
fieldDbParent.getObjectId());
38083824

3809-
if (dboUpgrade.getVal("CODE_LIST_MNEMONIC") != null) {
3825+
String clMnemonic = dboUpgrade.getAsString("CODE_LIST_MNEMONIC");
3826+
if (clMnemonic != null && clMnemonic.trim().length() > 0) {
38103827
// sync ids of the code lists in the db
3811-
DbSearchCriterion critCodeVal = new DbSearchCriterion("CODE_VALUE", DbCompareOperand.EQUAL,
3812-
dboUpgrade.getVal("CODE_LIST_MNEMONIC"));
3813-
DbSearchCriterion critCodeParent = new DbSearchCriterion("PARENT_ID", DbCompareOperand.EQUAL, 0L);
3814-
DbSearchExpression searchCode = new DbSearchExpression();
3815-
searchCode.addDbSearchItem(critCodeVal);
3816-
searchCode.addDbSearchItem(critCodeParent);
3817-
3818-
log4j.trace("Decoding CODE_LIST_MNEMONIC:" + dboUpgrade.getVal("CODE_LIST_MNEMONIC"));
3819-
DbDataArray codes = null;
3820-
try {
3821-
svr = new SvReader(dbu);
3822-
codes = svr.getObjects(searchCode, svCONST.OBJECT_TYPE_CODE, null, 0, 0);
3823-
} catch (Exception ex) {
3824-
log4j.error("Failed decoding mnemonic", ex);
3825-
} finally {
3826-
if (svr != null)
3827-
svr.release();
3828-
}
3829-
if (codes != null && codes.getItems().size() > 0) {
3830-
dboUpgrade.setVal("CODE_LIST_ID", codes.getItems().get(0).getObjectId());
3828+
log4j.trace("Decoding CODE_LIST_MNEMONIC:" + clMnemonic);
3829+
Map<String, Long> codeLists = getCodeLists(dbu);
3830+
3831+
if (codeLists.containsKey(clMnemonic)) {
3832+
dboUpgrade.setVal("CODE_LIST_ID", codeLists.get(clMnemonic));
38313833
} else {
38323834
throw (new SvException("system.error.upgrade_no_codelist", dbu.instanceUser, dboUpgrade,
3833-
searchCode));
3835+
clMnemonic));
38343836

38353837
}
38363838
}

0 commit comments

Comments
 (0)