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;
}
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);
}
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));
}
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);
}
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);
}
}
}
}
Aggregations