Search in sources :

Example 11 with DB

use of org.mapdb.DB in project tdq-studio-se by Talend.

the class MapDBManager method addDBRef.

/**
 * Record one db have been used how many times
 *
 * @param filePath
 */
public void addDBRef(File filePath) {
    DB db = dbMap.get(filePath);
    if (db == null) {
        return;
    }
    cancelCloseTask(db);
    Integer refConut = dbRefCountMap.get(db);
    if (refConut == null) {
        refConut = 0;
    }
    refConut++;
    dbRefCountMap.put(db, refConut);
}
Also used : DB(org.mapdb.DB)

Example 12 with DB

use of org.mapdb.DB in project tdq-studio-se by Talend.

the class MapDBManager method removeDBRef.

/**
 * Reduce the times which one db be used. When the count of times is 0 we will close this db.
 *
 * @param filePath
 */
public void removeDBRef(File filePath) {
    DB db = dbMap.get(filePath);
    if (db == null) {
        return;
    }
    Integer refConut = dbRefCountMap.get(db);
    if (refConut == null) {
        return;
    }
    refConut--;
    if (refConut > 0) {
        dbRefCountMap.put(db, refConut);
    } else {
        dbRefCountMap.remove(db);
        closeDB(db, filePath);
    }
}
Also used : DB(org.mapdb.DB)

Example 13 with DB

use of org.mapdb.DB in project mapdb by jankotek.

the class Issue794 method test.

@Test
public void test() {
    DB db = DBMaker.memoryDB().closeOnJvmShutdown().make();
    DB.TreeMapSink<Long, DataPoint> sIds2DataPointSink = db.treeMap("ids2DataPoint", Serializer.LONG, Serializer.ELSA).valuesOutsideNodesEnable().createFromSink();
    for (long i = 0; i < limit; i++) {
        DataPoint point = new DataPoint();
        point.add("aaa");
        point.add("aaa");
        point.add("aaa");
        point.add("aaa");
        //insert 70G DataPoint entities, each filled with 5 Strings
        sIds2DataPointSink.put(i, point);
    }
    //here the error occurs
    sIds2DataPointSink.create();
    db.close();
}
Also used : DB(org.mapdb.DB) Test(org.junit.Test)

Example 14 with DB

use of org.mapdb.DB in project tdq-studio-se by Talend.

the class MapDBManager method closeDB.

/**
 * If MapDB file is not exist or has been closed then this method will not do anything else will create new task to
 * close it.
 *
 * @param analysis
 */
public void closeDB(File filePath) {
    DB db = dbMap.get(filePath);
    closeDB(db, filePath);
}
Also used : DB(org.mapdb.DB)

Example 15 with DB

use of org.mapdb.DB in project tdq-studio-se by Talend.

the class MapDBManager method deleteDB.

/**
 * Delete mapDB file
 *
 * @param analysis
 */
public void deleteDB(Analysis analysis) {
    File mapDBFile = getMapDBFile(analysis);
    DB db = this.getDB(mapDBFile);
    // if db is in used close it first
    if (db != null) {
        this.removeDB(mapDBFile);
        dbRefCountMap.remove(db);
        db.close();
        while (!db.isClosed()) {
            try {
                Thread.currentThread().wait(1000);
            } catch (InterruptedException e) {
            }
        }
    }
    // delete data file and index file
    if (mapDBFile.exists()) {
        mapDBFile.delete();
        new File(mapDBFile.getAbsolutePath() + StoreDirect.DATA_FILE_EXT).delete();
    }
}
Also used : File(java.io.File) DB(org.mapdb.DB)

Aggregations

DB (org.mapdb.DB)24 Test (org.junit.Test)9 File (java.io.File)7 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)6 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)6 BlockDifficulty (co.rsk.core.BlockDifficulty)5 IOException (java.io.IOException)5 BigInteger (java.math.BigInteger)5 Block (org.ethereum.core.Block)5 HashMapDB (org.ethereum.datasource.HashMapDB)5 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 NullOutputStream (org.apache.commons.io.output.NullOutputStream)2