Search in sources :

Example 1 with UnitDao

use of org.openlca.core.database.UnitDao in project olca-modules by GreenDelta.

the class TestData method unit.

public static Unit unit(String name) {
    String unitId = KeyGen.get("unit", name);
    UnitDao dao = new UnitDao(Tests.getDb());
    Unit unit = dao.getForRefId(unitId);
    if (unit != null)
        return unit;
    UnitGroup group = unitGroup(name);
    return group.referenceUnit;
}
Also used : UnitGroup(org.openlca.core.model.UnitGroup) UnitDao(org.openlca.core.database.UnitDao) Unit(org.openlca.core.model.Unit)

Example 2 with UnitDao

use of org.openlca.core.database.UnitDao in project olca-modules by GreenDelta.

the class RefSwitcher method switchRef.

Unit switchRef(Unit srcUnit) {
    if (srcUnit == null)
        return null;
    long id = seq.get(seq.UNIT, srcUnit.refId);
    if (id == 0)
        return null;
    UnitDao dao = new UnitDao(dest);
    return dao.getForId(id);
}
Also used : UnitDao(org.openlca.core.database.UnitDao)

Example 3 with UnitDao

use of org.openlca.core.database.UnitDao in project olca-modules by GreenDelta.

the class Sequence method init.

private void init(IDatabase db) {
    index(CATEGORY, new CategoryDao(db));
    index(LOCATION, new LocationDao(db));
    index(ACTOR, new ActorDao(db));
    index(SOURCE, new SourceDao(db));
    index(UNIT, new UnitDao(db));
    index(UNIT_GROUP, new UnitGroupDao(db));
    index(FLOW_PROPERTY, new FlowPropertyDao(db));
    index(FLOW, new FlowDao(db));
    index(CURRENCY, new CurrencyDao(db));
    index(PROCESS, new ProcessDao(db));
    index(PRODUCT_SYSTEM, new ProductSystemDao(db));
    index(IMPACT_CATEGORY, new ImpactCategoryDao(db));
    index(IMPACT_METHOD, new ImpactMethodDao(db));
    index(NW_SET, new NwSetDao(db));
    index(PROJECT, new ProjectDao(db));
    index(DQ_SYSTEM, new DQSystemDao(db));
    index(SOCIAL_INDICATOR, new SocialIndicatorDao(db));
}
Also used : SourceDao(org.openlca.core.database.SourceDao) CurrencyDao(org.openlca.core.database.CurrencyDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) CategoryDao(org.openlca.core.database.CategoryDao) ActorDao(org.openlca.core.database.ActorDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) LocationDao(org.openlca.core.database.LocationDao) UnitDao(org.openlca.core.database.UnitDao) DQSystemDao(org.openlca.core.database.DQSystemDao) NwSetDao(org.openlca.core.database.NwSetDao) FlowDao(org.openlca.core.database.FlowDao) ImpactMethodDao(org.openlca.core.database.ImpactMethodDao) ProcessDao(org.openlca.core.database.ProcessDao) UnitGroupDao(org.openlca.core.database.UnitGroupDao) SocialIndicatorDao(org.openlca.core.database.SocialIndicatorDao) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao) ProductSystemDao(org.openlca.core.database.ProductSystemDao) ProjectDao(org.openlca.core.database.ProjectDao)

Example 4 with UnitDao

use of org.openlca.core.database.UnitDao 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 5 with UnitDao

use of org.openlca.core.database.UnitDao in project olca-modules by GreenDelta.

the class RefDataImport method loadUnitMaps.

private void loadUnitMaps(IDatabase database) throws Exception {
    var is = getClass().getResourceAsStream("ei3_unit_map.csv");
    if (is == null)
        return;
    try (var reader = new BufferedReader(new InputStreamReader(is))) {
        String line;
        while ((line = reader.readLine()) != null) {
            String[] args = line.split(",");
            String eiUnitKey = args[0];
            UnitDao unitDao = new UnitDao(database);
            Unit unit = unitDao.getForRefId(args[1]);
            FlowPropertyDao propDao = new FlowPropertyDao(database);
            FlowProperty prop = propDao.getForRefId(args[2]);
            if (unit == null || prop == null)
                log.warn("no unit or property found for '" + eiUnitKey + "' in database, no reference data?");
            else {
                index.putUnit(eiUnitKey, unit);
                index.putFlowProperty(eiUnitKey, prop);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) BufferedReader(java.io.BufferedReader) UnitDao(org.openlca.core.database.UnitDao) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty)

Aggregations

UnitDao (org.openlca.core.database.UnitDao)5 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)3 UnitGroupDao (org.openlca.core.database.UnitGroupDao)2 Unit (org.openlca.core.model.Unit)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)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 FlowDao (org.openlca.core.database.FlowDao)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ImpactMethodDao (org.openlca.core.database.ImpactMethodDao)1 LocationDao (org.openlca.core.database.LocationDao)1 NwSetDao (org.openlca.core.database.NwSetDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 ProjectDao (org.openlca.core.database.ProjectDao)1 SocialIndicatorDao (org.openlca.core.database.SocialIndicatorDao)1 SourceDao (org.openlca.core.database.SourceDao)1