use of org.openlca.core.database.UnitGroupDao in project olca-modules by GreenDelta.
the class RefData method loadUnits.
/**
* Loads the units, unit groups and flow properties from the database. This
* method must be called after unit sheets where read.
*/
void loadUnits(IDatabase database) throws Exception {
UnitDao unitDao = new UnitDao(database);
load(unitDao, units);
load(new UnitGroupDao(database), unitGroups);
load(new FlowPropertyDao(database), flowProperties);
}
use of org.openlca.core.database.UnitGroupDao in project olca-modules by GreenDelta.
the class ProcessTest method createCyclicModel.
private Process[] createCyclicModel(IDatabase db) {
UnitGroup ug = createUnitGroup(new UnitGroupDao(db));
FlowProperty fp = createFlowProperty(ug, new FlowPropertyDao(db));
Flow product1 = createProduct(fp, new FlowDao(db));
Flow product2 = createProduct(fp, new FlowDao(db));
ProcessDao dao = new ProcessDao(db);
Process p1 = createProcess(product1, dao);
Process p2 = createProcess(product2, dao);
p1 = addProvider(p1, p2, dao);
p2 = addProvider(p2, p1, dao);
return new Process[] { p1, p2 };
}
use of org.openlca.core.database.UnitGroupDao in project olca-modules by GreenDelta.
the class ConversionTableTest method testUnitFactor.
@Test
public void testUnitFactor() throws Exception {
BaseDao<UnitGroup> dao = new UnitGroupDao(database);
UnitGroup group = new UnitGroup();
group.name = "test-ug";
Unit refUnit = new Unit();
refUnit.name = "ref-unit";
refUnit.conversionFactor = 1d;
group.units.add(refUnit);
group.referenceUnit = refUnit;
Unit otherUnit = new Unit();
otherUnit.name = "other-unit";
otherUnit.conversionFactor = 42.42;
group.units.add(otherUnit);
dao.insert(group);
ConversionTable table = ConversionTable.create(database);
Assert.assertEquals(1d, table.getUnitFactor(refUnit.id), 1e-16);
Assert.assertEquals(42.42, table.getUnitFactor(otherUnit.id), 1e-16);
dao.delete(group);
}
use of org.openlca.core.database.UnitGroupDao in project olca-modules by GreenDelta.
the class UnitGroupSync method run.
public void run(IDatabase database) {
try {
Unit olcaRefUnit = olcaGroup.referenceUnit;
org.openlca.ilcd.units.Unit ilcdRefUnit = findRefUnit(olcaRefUnit);
if (ilcdRefUnit == null)
return;
double factor = olcaRefUnit.conversionFactor / ilcdRefUnit.factor;
boolean changed = syncUnits(factor);
if (changed) {
olcaGroup.lastChange = Calendar.getInstance().getTimeInMillis();
Version.incUpdate(olcaGroup);
new UnitGroupDao(database).update(olcaGroup);
}
} catch (Exception e) {
log.error("Failed to sync. unit groups", e);
}
}
Aggregations