Search in sources :

Example 1 with Derby

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

the class ImportExample method main.

public static void main(String[] args) {
    var zipPath = "C:/Users/ms/Desktop/rems/test_json.zip";
    var dbPath = "C:/Users/ms/openLCA-data-1.4/databases/proto_test";
    try (var store = ZipStore.open(new File(zipPath));
        var db = new Derby(new File(dbPath))) {
        var imp = new ProtoImport(store, db);
        imp.run();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Derby(org.openlca.core.database.Derby) ProtoImport(org.openlca.proto.io.input.ProtoImport) File(java.io.File)

Example 2 with Derby

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

the class MySQLDatabaseExport method createTemporaryDb.

private Derby createTemporaryDb() {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    String dbName = "olca_tempdb_" + UUID.randomUUID().toString().replace("-", "");
    File dbDir = new File(tempDir, dbName);
    return new Derby(dbDir);
}
Also used : Derby(org.openlca.core.database.Derby) File(java.io.File)

Example 3 with Derby

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

the class LibraryCalculatorExample method main.

public static void main(String[] args) throws Exception {
    var workspace = "C:/Users/Win10/openLCA-data-1.4";
    var db = new Derby(new File(workspace + "/databases/libre2"));
    var libDir = new LibraryDir(new File(workspace + "/libraries"));
    var system = db.get(ProductSystem.class, "6b32cda2-5aa4-44b9-b32a-c654da48436d");
    var setup = CalculationSetup.simple(system);
    var result = new SystemCalculator(db).calculateSimple(setup);
    var flow = result.enviIndex().at(0);
    System.out.println(flow.flow().name + " => " + result.getTotalFlowResult(flow));
    db.close();
}
Also used : Derby(org.openlca.core.database.Derby) File(java.io.File) SystemCalculator(org.openlca.core.math.SystemCalculator) LibraryDir(org.openlca.core.library.LibraryDir)

Example 4 with Derby

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

the class ProductSystemBuilderExample method main.

public static void main(String[] args) {
    String dbPath = "C:/Users/Besitzer/openLCA-data-1.4/databases/ecoinvent_2_2_unit";
    IDatabase db = new Derby(new File(dbPath));
    // load the reference process of the new product system
    Process p = new ProcessDao(db).getForRefId("81261285-cc4a-3588-8cce-3aabb786d7aa");
    // create and auto-complete the product system
    var config = new LinkingConfig().providerLinking(ProviderLinking.PREFER_DEFAULTS).preferredType(ProcessType.UNIT_PROCESS);
    var system = new ProductSystemBuilder(MatrixCache.createLazy(db), config).build(p);
    // save the product system
    new ProductSystemDao(db).insert(system);
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Derby(org.openlca.core.database.Derby) ProcessDao(org.openlca.core.database.ProcessDao) LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig) ProductSystemBuilder(org.openlca.core.matrix.ProductSystemBuilder) Process(org.openlca.core.model.Process) File(java.io.File) ProductSystemDao(org.openlca.core.database.ProductSystemDao)

Example 5 with Derby

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

the class ProductSystemInMemoryCalculationExample method main.

public static void main(String[] args) throws Exception {
    // load the database and matrix cache
    String workspace = "C:/Users/Besitzer/openLCA-data-1.4";
    String dbPath = workspace + "/databases/ecoinvent_2_2_unit";
    IDatabase db = new Derby(new File(dbPath));
    MatrixCache mcache = MatrixCache.createLazy(db);
    // load the reference process and create
    // the product system with auto-completion
    // the system is not saved in the database
    Process p = new ProcessDao(db).getForRefId("7ff672e3-a296-30e8-b1bb-a3173711a28b");
    var config = new LinkingConfig().providerLinking(ProviderLinking.PREFER_DEFAULTS).preferredType(ProcessType.UNIT_PROCESS);
    var builder = new ProductSystemBuilder(mcache, config);
    var system = builder.build(p);
    var method = db.get(ImpactMethod.class, "207ffac9-aaa8-401d-ac90-874defd3751a");
    // create the calculation setup
    var setup = CalculationSetup.simple(system).withImpactMethod(method);
    // load the native library and calculate the result
    // TODO: load Julia libraries first here
    SystemCalculator calc = new SystemCalculator(db);
    SimpleResult r = calc.calculateSimple(setup);
    // print the LCIA results
    for (ImpactDescriptor impact : r.getImpacts()) {
        System.out.println(impact.name + "\t" + r.getTotalImpactResult(impact) + "\t" + impact.referenceUnit);
    }
    // finally, close the database
    db.close();
}
Also used : IDatabase(org.openlca.core.database.IDatabase) Derby(org.openlca.core.database.Derby) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) Process(org.openlca.core.model.Process) SimpleResult(org.openlca.core.results.SimpleResult) MatrixCache(org.openlca.core.matrix.cache.MatrixCache) ProcessDao(org.openlca.core.database.ProcessDao) LinkingConfig(org.openlca.core.matrix.linking.LinkingConfig) ProductSystemBuilder(org.openlca.core.matrix.ProductSystemBuilder) File(java.io.File) SystemCalculator(org.openlca.core.math.SystemCalculator)

Aggregations

Derby (org.openlca.core.database.Derby)10 File (java.io.File)7 Test (org.junit.Test)3 Ignore (org.junit.Ignore)2 IDatabase (org.openlca.core.database.IDatabase)2 ProcessDao (org.openlca.core.database.ProcessDao)2 SystemCalculator (org.openlca.core.math.SystemCalculator)2 ProductSystemBuilder (org.openlca.core.matrix.ProductSystemBuilder)2 LinkingConfig (org.openlca.core.matrix.linking.LinkingConfig)2 Process (org.openlca.core.model.Process)2 Path (java.nio.file.Path)1 ActorDao (org.openlca.core.database.ActorDao)1 ProductSystemDao (org.openlca.core.database.ProductSystemDao)1 LibraryDir (org.openlca.core.library.LibraryDir)1 MatrixCache (org.openlca.core.matrix.cache.MatrixCache)1 Actor (org.openlca.core.model.Actor)1 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)1 SimpleResult (org.openlca.core.results.SimpleResult)1 RefDataImport (org.openlca.io.refdata.RefDataImport)1 ProtoImport (org.openlca.proto.io.input.ProtoImport)1