use of org.openlca.core.database.ParameterDao in project olca-modules by GreenDelta.
the class ParameterReferenceSearch method findParameterReferences.
private List<Reference> findParameterReferences(Set<Long> ids) {
List<String> formulaQueries = Search.createQueries("SELECT id, lower(formula) FROM tbl_parameters", "WHERE id IN", ids);
Map<Long, Set<String>> variables = getVariablesUsedInFormulas(formulaQueries);
Set<String> names = new HashSet<>();
for (Long key : variables.keySet()) names.addAll(variables.get(key));
List<Reference> results = new ArrayList<>();
List<ParameterDescriptor> descriptors = new ParameterDao(database).getDescriptors(names.toArray(new String[names.size()]), ParameterScope.GLOBAL);
results.addAll(toReferences(descriptors, false, variables));
Set<String> found = new HashSet<>();
for (ParameterDescriptor d : descriptors) found.add(d.name.toLowerCase());
for (String name : names) if (!found.contains(name)) {
List<Reference> refs = createMissingReferences(name, variables);
results.addAll(refs);
}
return results;
}
use of org.openlca.core.database.ParameterDao in project olca-modules by GreenDelta.
the class ProcessParameterConversion method addDatabaseParams.
private void addDatabaseParams(List<org.openlca.ilcd.processes.Parameter> params) {
ParameterDao dao = new ParameterDao(config.db);
for (Parameter param : dao.getGlobalParameters()) {
if (!valid(param))
continue;
org.openlca.ilcd.processes.Parameter iParam = convertParam(param);
params.add(iParam);
addScope(iParam, ParameterScope.GLOBAL);
}
}
use of org.openlca.core.database.ParameterDao in project olca-modules by GreenDelta.
the class ParameterSheet method syncGlobals.
private void syncGlobals(List<Parameter> sheetParams) {
ParameterDao dao = new ParameterDao(config.database);
List<Parameter> globals = new ArrayList<>();
globals.addAll(dao.getGlobalParameters());
for (Parameter p : sheetParams) {
boolean found = false;
for (Parameter global : globals) {
String name = global.name;
if (name == null)
continue;
if (name.equalsIgnoreCase(p.name)) {
found = true;
break;
}
}
if (!found)
globals.add(dao.insert(p));
}
}
use of org.openlca.core.database.ParameterDao in project olca-modules by GreenDelta.
the class ProcessImport method handleParameters.
private void handleParameters(DataSet dataSet, Process process) {
List<Parameter> list = Parameters.fetch(dataSet, config);
List<Parameter> newGlobals = new ArrayList<>();
for (Parameter p : list) {
if (p.scope == ParameterScope.PROCESS)
process.parameters.add(p);
else if (p.scope == ParameterScope.GLOBAL)
newGlobals.add(p);
}
ParameterDao dao = new ParameterDao(config.db);
Map<String, Boolean> map = new HashMap<>();
for (Parameter p : dao.getGlobalParameters()) map.put(p.name, Boolean.TRUE);
for (Parameter newGlobal : newGlobals) {
Boolean exists = map.get(newGlobal.name);
if (exists == null) {
dao.insert(newGlobal);
map.put(newGlobal.name, Boolean.TRUE);
}
}
}
use of org.openlca.core.database.ParameterDao in project olca-modules by GreenDelta.
the class ParameterTableTest method tearDown.
@After
public void tearDown() {
IDatabase db = Tests.getDb();
new ParameterDao(db).deleteAll();
new ProcessDao(db).deleteAll();
}
Aggregations