Search in sources :

Example 16 with UnitGroupDao

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);
}
Also used : FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) UnitDao(org.openlca.core.database.UnitDao) UnitGroupDao(org.openlca.core.database.UnitGroupDao)

Example 17 with UnitGroupDao

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 };
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) FlowDao(org.openlca.core.database.FlowDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) ProcessDao(org.openlca.core.database.ProcessDao) Process(org.openlca.core.model.Process) UnitGroupDao(org.openlca.core.database.UnitGroupDao) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 18 with UnitGroupDao

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);
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) Unit(org.openlca.core.model.Unit) UnitGroupDao(org.openlca.core.database.UnitGroupDao) Test(org.junit.Test)

Example 19 with UnitGroupDao

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);
    }
}
Also used : Unit(org.openlca.core.model.Unit) UnitGroupDao(org.openlca.core.database.UnitGroupDao)

Aggregations

UnitGroupDao (org.openlca.core.database.UnitGroupDao)19 UnitGroup (org.openlca.core.model.UnitGroup)14 Unit (org.openlca.core.model.Unit)9 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)7 FlowProperty (org.openlca.core.model.FlowProperty)4 Test (org.junit.Test)3 FlowDao (org.openlca.core.database.FlowDao)3 ProcessDao (org.openlca.core.database.ProcessDao)3 ProductSystemDao (org.openlca.core.database.ProductSystemDao)2 UnitDao (org.openlca.core.database.UnitDao)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ActorDao (org.openlca.core.database.ActorDao)1 CategoryDao (org.openlca.core.database.CategoryDao)1 CurrencyDao (org.openlca.core.database.CurrencyDao)1 DQSystemDao (org.openlca.core.database.DQSystemDao)1 IDatabase (org.openlca.core.database.IDatabase)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)1 LocationDao (org.openlca.core.database.LocationDao)1