Search in sources :

Example 6 with EntityCache

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

the class Utils method contribution.

RpcResponse contribution(RpcRequest req, ContributionHandler handler) {
    if (req == null || req.params == null || !req.params.isJsonObject())
        return Responses.invalidParams("No parameter given", req);
    JsonObject json = req.params.getAsJsonObject();
    ContributionResult result = getResult(json);
    EntityCache cache = EntityCache.create(ctx.db);
    return Responses.ok(handler.handle(result, cache), req);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) JsonObject(com.google.gson.JsonObject) ContributionResult(org.openlca.core.results.ContributionResult)

Example 7 with EntityCache

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

the class Utils method full.

RpcResponse full(RpcRequest req, Full handler) {
    if (req == null || req.params == null || !req.params.isJsonObject())
        return Responses.invalidParams("No parameter given", req);
    JsonObject json = req.params.getAsJsonObject();
    FullResult result = getResult(json);
    EntityCache cache = EntityCache.create(ctx.db);
    return Responses.ok(handler.handle(result, cache), req);
}
Also used : FullResult(org.openlca.core.results.FullResult) EntityCache(org.openlca.core.database.EntityCache) JsonObject(com.google.gson.JsonObject)

Example 8 with EntityCache

use of org.openlca.core.database.EntityCache in project olca-app by GreenDelta.

the class ModelEditor method doAfterUpdate.

protected void doAfterUpdate() {
    setDirty(false);
    var descriptor = getEditorInput().getDescriptor();
    EntityCache cache = Cache.getEntityCache();
    cache.refresh(descriptor.getClass(), descriptor.id);
    cache.invalidate(modelClass, model.id);
    this.setPartName(Labels.name(model));
    Cache.evict(descriptor);
    emitEvent(ON_SAVED);
    Navigator.refresh(Navigator.findElement(descriptor));
}
Also used : EntityCache(org.openlca.core.database.EntityCache)

Example 9 with EntityCache

use of org.openlca.core.database.EntityCache in project olca-app by GreenDelta.

the class ProviderDialog method getLabel.

private <T extends Descriptor> String getLabel(Class<T> clazz, long id) {
    EntityCache cache = Cache.getEntityCache();
    if (cache == null)
        return "?";
    T d = cache.get(clazz, id);
    if (d == null)
        return "?";
    return Labels.name(d);
}
Also used : EntityCache(org.openlca.core.database.EntityCache) SWT(org.eclipse.swt.SWT)

Example 10 with EntityCache

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

the class FlowInfo method getAll.

public static List<FlowInfo> getAll(SystemExportConfig conf, EnviIndex index) {
    EntityCache cache = conf.getEntityCache();
    Set<FlowDescriptor> flows = getFlowDescriptors(index);
    List<FlowInfo> infos = new ArrayList<>();
    for (FlowDescriptor flow : flows) {
        CategoryPair catPair = CategoryPair.create(flow, cache);
        FlowInfo info = new FlowInfo();
        info.realId = flow.id;
        info.id = flow.refId;
        info.name = flow.name;
        info.category = catPair.getCategory();
        info.subCategory = catPair.getSubCategory();
        if (flow.location != null) {
            Location location = cache.get(Location.class, flow.location);
            if (location != null)
                info.location = location.code;
        }
        String unit = DisplayValues.referenceUnit(flow, cache);
        info.unit = unit;
        infos.add(info);
    }
    return infos;
}
Also used : EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ArrayList(java.util.ArrayList) CategoryPair(org.openlca.io.CategoryPair) Location(org.openlca.core.model.Location)

Aggregations

EntityCache (org.openlca.core.database.EntityCache)18 JsonObject (com.google.gson.JsonObject)13 ContributionResult (org.openlca.core.results.ContributionResult)7 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)6 EnviFlow (org.openlca.core.matrix.index.EnviFlow)4 LocationDescriptor (org.openlca.core.model.descriptors.LocationDescriptor)4 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)4 FullResult (org.openlca.core.results.FullResult)4 ArrayList (java.util.ArrayList)3 Location (org.openlca.core.model.Location)2 FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)2 SimpleResult (org.openlca.core.results.SimpleResult)2 CategoryPair (org.openlca.io.CategoryPair)2 JsonArray (com.google.gson.JsonArray)1 Collection (java.util.Collection)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 SWT (org.eclipse.swt.SWT)1 IDatabase (org.openlca.core.database.IDatabase)1