use of org.openlca.core.database.FlowDao in project olca-app by GreenDelta.
the class ProcessCreator method createFlow.
private Flow createFlow() {
Flow flow = new Flow();
flow.refId = UUID.randomUUID().toString();
if (!Strings.isNullOrEmpty(flowName))
flow.name = flowName;
else
flow.name = name;
flow.description = description;
flow.flowType = wasteProcess ? FlowType.WASTE_FLOW : FlowType.PRODUCT_FLOW;
flow.referenceFlowProperty = flowProperty;
var factor = new FlowPropertyFactor();
factor.conversionFactor = 1;
factor.flowProperty = flowProperty;
flow.flowPropertyFactors.add(factor);
new FlowDao(db).insert(flow);
return flow;
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class FlowDirectionCheck method run.
@Override
public void run() {
try {
var flows = new FlowDao(v.db).descriptorMap();
// collect the IDs of quantitative references
var qrefs = new TLongHashSet();
var qrefQuery = "select f_quantitative_reference from tbl_processes";
NativeSql.on(v.db).query(qrefQuery, r -> {
qrefs.add(r.getLong(1));
return true;
});
checkDirections(flows, qrefs);
if (!foundErrors && !v.wasCanceled()) {
v.ok("checked flow directions");
}
} catch (Exception e) {
v.error("error in flow direction check", e);
} finally {
v.workerFinished();
}
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class CategoriesTest method testFindOrAddModel.
@Test
public void testFindOrAddModel() {
IDatabase db = Tests.getDb();
String[] path = { "A", "B", "C", "D", "E" };
Category c = null;
for (int i = 0; i < 10; i++) {
Category next = Categories.findOrAdd(db, ModelType.FLOW, path);
if (c != null) {
assertEquals(c.id, next.id);
} else {
c = next;
}
Flow f = new Flow();
f.category = c;
FlowDao dao = new FlowDao(db);
dao.insert(f);
f = dao.getForId(f.id);
checkCat(path, f.category);
}
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class FlowPropertyFactorUseSearchTest method tearDown.
@After
public void tearDown() {
new FlowDao(database).delete(flow);
new FlowPropertyDao(database).delete(property);
}
use of org.openlca.core.database.FlowDao in project olca-modules by GreenDelta.
the class FlowPropertyFactorExport method doIt.
@Override
protected void doIt(CSVPrinter printer, IDatabase db) throws IOException {
log.trace("write flow property factors");
FlowDao dao = new FlowDao(db);
int count = 0;
for (Flow flow : dao.getAll()) {
for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
Object[] line = createLine(flow, factor);
printer.printRecord(line);
count++;
}
}
log.trace("{} flow property factors written", count);
}
Aggregations