Search in sources :

Example 1 with FlowDao

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

the class TestData method flow.

public static Flow flow(String name, String unit, FlowType type) {
    String flowId = KeyGen.get("flow", name, unit);
    FlowDao dao = new FlowDao(Tests.getDb());
    Flow flow = dao.getForRefId(flowId);
    if (flow != null)
        return flow;
    flow = new Flow();
    flow.name = name;
    flow.refId = flowId;
    flow.flowType = type;
    FlowProperty property = property(unit);
    FlowPropertyFactor factor = new FlowPropertyFactor();
    factor.flowProperty = property;
    factor.conversionFactor = 1;
    flow.flowPropertyFactors.add(factor);
    flow.referenceFlowProperty = property;
    return dao.insert(flow);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 2 with FlowDao

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

the class ExchangeUseSearchTest method addExchanges.

private void addExchanges() {
    for (int i = 1; i < 4; i++) {
        Flow flow = new Flow();
        flow.name = "flow_" + 1;
        flow = new FlowDao(db).insert(flow);
        modelStack.push(flow);
        Exchange ep = new Exchange();
        ep.flow = flow;
        ep.isInput = false;
        p.exchanges.add(ep);
        Exchange eq = ep.copy();
        eq.isInput = true;
        q.exchanges.add(eq);
    }
}
Also used : Exchange(org.openlca.core.model.Exchange) FlowDao(org.openlca.core.database.FlowDao) Flow(org.openlca.core.model.Flow)

Example 3 with FlowDao

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

the class FlowPropertyFactorUseSearchTest method setup.

@Before
public void setup() {
    flow = new Flow();
    flow.name = "flow";
    property = new FlowProperty();
    property.name = "property";
    factor = new FlowPropertyFactor();
    factor.flowProperty = property;
    flow.flowPropertyFactors.add(factor);
    property = new FlowPropertyDao(database).insert(property);
    flow = new FlowDao(database).insert(flow);
    factor = flow.getFactor(property);
    search = new FlowPropertyFactorUseSearch(flow, database);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyDao(org.openlca.core.database.FlowPropertyDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow) Before(org.junit.Before)

Example 4 with FlowDao

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

the class SystemExport method loadMaps.

private void loadMaps() {
    ProcessDao pDao = new ProcessDao(config.db);
    for (ProcessDescriptor pd : pDao.getDescriptors()) {
        processes.put(pd.id, pd);
        processIDs.put(pd.id, processIDs.size());
    }
    FlowDao fDao = new FlowDao(config.db);
    for (FlowDescriptor fd : fDao.getDescriptors()) {
        flows.put(fd.id, fd);
    }
    Set<Long> exchanges = system.processLinks.stream().map(link -> link.exchangeId).collect(Collectors.toSet());
    String query = "SELECT id, internal_id FROM tbl_exchanges";
    try {
        NativeSql.on(config.db).query(query, r -> {
            long id = r.getLong(1);
            if (exchanges.contains(id)) {
                exchangeIDs.put(id, r.getInt(2));
            }
            return true;
        });
    } catch (Exception e) {
        log.error("Failed to get internal exchange IDs", e);
    }
}
Also used : DataSetType(org.openlca.ilcd.commons.DataSetType) Technology(org.openlca.ilcd.models.Technology) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference) ProcessDao(org.openlca.core.database.ProcessDao) LoggerFactory(org.slf4j.LoggerFactory) Connection(org.openlca.ilcd.models.Connection) HashMap(java.util.HashMap) Ref(org.openlca.ilcd.commons.Ref) ProductSystem(org.openlca.core.model.ProductSystem) ModelName(org.openlca.ilcd.models.ModelName) Modelling(org.openlca.ilcd.models.Modelling) Map(java.util.Map) FlowDao(org.openlca.core.database.FlowDao) Models(org.openlca.ilcd.util.Models) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) ProcessLink(org.openlca.core.model.ProcessLink) FlowType(org.openlca.core.model.FlowType) Version(org.openlca.core.model.Version) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) Logger(org.slf4j.Logger) Process(org.openlca.ilcd.processes.Process) Set(java.util.Set) NativeSql(org.openlca.core.database.NativeSql) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Parameter(org.openlca.ilcd.models.Parameter) Model(org.openlca.ilcd.models.Model) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) DataSetInfo(org.openlca.ilcd.models.DataSetInfo) Classification(org.openlca.ilcd.commons.Classification) LangString(org.openlca.ilcd.commons.LangString) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) FlowDao(org.openlca.core.database.FlowDao) ProcessDao(org.openlca.core.database.ProcessDao) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) LangString(org.openlca.ilcd.commons.LangString)

Example 5 with FlowDao

use of org.openlca.core.database.FlowDao 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)

Aggregations

FlowDao (org.openlca.core.database.FlowDao)38 Flow (org.openlca.core.model.Flow)21 ProcessDao (org.openlca.core.database.ProcessDao)13 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)10 ArrayList (java.util.ArrayList)7 Collectors (java.util.stream.Collectors)6 FlowPropertyDao (org.openlca.core.database.FlowPropertyDao)6 IDatabase (org.openlca.core.database.IDatabase)6 FlowProperty (org.openlca.core.model.FlowProperty)6 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Test (org.junit.Test)4 LocationDao (org.openlca.core.database.LocationDao)4 Process (org.openlca.core.model.Process)4 Unit (org.openlca.core.model.Unit)4 TLongHashSet (gnu.trove.set.hash.TLongHashSet)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3