Search in sources :

Example 6 with Derby

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

the class Tests method initFileBasedDb.

private static IDatabase initFileBasedDb() {
    String tmpDirPath = System.getProperty("java.io.tmpdir");
    String dbName = "olca_test_db_1.4";
    File tmpDir = new File(tmpDirPath);
    File folder = new File(tmpDir, dbName);
    return new Derby(folder);
}
Also used : Derby(org.openlca.core.database.Derby) File(java.io.File)

Example 7 with Derby

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

the class DerbyDatabaseTest method testDumpMemoryDB.

@Test
public void testDumpMemoryDB() throws Exception {
    Derby db = Derby.createInMemory();
    Actor a = new Actor();
    a.name = "The Donald";
    a = new ActorDao(db).insert(a);
    long id = a.id;
    Path path = Files.createTempDirectory("_olca_test_");
    db.dump(path.toString());
    db.close();
    db = Derby.restoreInMemory(path.toString());
    a = new ActorDao(db).getForId(id);
    assertEquals("The Donald", a.name);
    db.close();
    Dirs.delete(path);
}
Also used : Path(java.nio.file.Path) Derby(org.openlca.core.database.Derby) ActorDao(org.openlca.core.database.ActorDao) Actor(org.openlca.core.model.Actor) Test(org.junit.Test)

Example 8 with Derby

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

the class DerbyDatabaseTest method testNoMemLeak.

@Test
@Ignore
public void testNoMemLeak() throws Exception {
    Runtime rt = Runtime.getRuntime();
    long initialUsed = rt.totalMemory() - rt.freeMemory();
    for (int i = 0; i < 1000; i++) {
        Derby db = Derby.createInMemory();
        db.close();
        long usedMem = rt.totalMemory() - rt.freeMemory();
        if (initialUsed * 10 < usedMem) {
            fail("There is probably a memory leak");
        }
        System.out.println("" + i + "\t" + (usedMem / (1024 * 1024)));
    }
}
Also used : Derby(org.openlca.core.database.Derby) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with Derby

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

the class DerbyDatabaseTest method testFromFolder.

@Test
@Ignore
public void testFromFolder() throws Exception {
    File dir = Files.createTempDirectory("olca_test_db").toFile();
    assertTrue(dir.delete());
    try (Derby db = new Derby(dir)) {
        assertEquals(dir.getName(), db.getName());
    }
    Dirs.delete(dir.getAbsolutePath());
}
Also used : Derby(org.openlca.core.database.Derby) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with Derby

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

the class Main method create.

private static void create(String name, String dataDir) throws Exception {
    System.out.println("  Create " + name + " database ...");
    var db = new Derby(F("build/" + name));
    if (dataDir != null) {
        new RefDataImport(F("data/" + dataDir), db).run();
        if ("all".equals(dataDir)) {
            importDQS(db);
            GeoImport.on(db);
        }
    }
    db.close();
    System.out.println("  done");
}
Also used : Derby(org.openlca.core.database.Derby) RefDataImport(org.openlca.io.refdata.RefDataImport)

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