本文整理匯總了Java中org.mapdb.DBMaker類的典型用法代碼示例。如果您正苦於以下問題:Java DBMaker類的具體用法?Java DBMaker怎麽用?Java DBMaker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DBMaker類屬於org.mapdb包,在下文中一共展示了DBMaker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ChromaPrintStrategy
import org.mapdb.DBMaker; //導入依賴的package包/類
public ChromaPrintStrategy() {
String chomaprintDBFileName = "chormaprint.db";
File dbFile = new File(chomaprintDBFileName);
db = DBMaker.fileDB(dbFile)
.closeOnJvmShutdown() // close the database automatically
.make();
final String chromaPrintStoreName = "chroma_print_store";
// The meta-data store.
chromaPrintStore = db.treeMap(chromaPrintStoreName)
.keySerializer(Serializer.LONG)
.valueSerializer(Serializer.STRING)
.counterEnable() // enable size counter
.createOrOpen();
// The meta-data store.
final String audioStoreName = "audio_store";
audioNameStore = db.treeMap(audioStoreName)
.keySerializer(Serializer.INTEGER)
.valueSerializer(Serializer.STRING)
.counterEnable() // enable size counter
.createOrOpen();
}
示例2: RafsStrategy
import org.mapdb.DBMaker; //導入依賴的package包/類
public RafsStrategy(){
String mapsDBFileName = Config.get(Key.RAFS_DATABASE);
int searchRadius = Config.getInt(Key.RAFS_HAMMINNG_SEARCH_RADIUS);
int chunks = Config.getInt(Key.RAFS_MIH_CHUNKS);
int numBits = Config.getInt(Key.RAFS_HAMMING_SPACE_NUM_BITS);
mih = new MultiIndexHasher(numBits, searchRadius, chunks, new MapDBStorage(chunks,mapsDBFileName));
File dbFile = new File(Config.get(Key.RAFS_DATABASE) + "desc.db");
db = DBMaker.fileDB(dbFile)
.closeOnJvmShutdown() // close the database automatically
.make();
final String audioStore = "audio_store";
// The meta-data store.
audioNameStore = db.treeMap(audioStore).keySerializer(Serializer.INTEGER).valueSerializer(Serializer.STRING)
.counterEnable() // enable size counter
.createOrOpen();
}
示例3: setConnectionToDB
import org.mapdb.DBMaker; //導入依賴的package包/類
public void setConnectionToDB(DockerConnection dc, File configFile, File certFile) throws IOException {
File database = new File("./connections.db");
DB db = DBMaker
.fileDB(database)
.transactionEnable()
.closeOnJvmShutdown()
.fileChannelEnable()
.make();
ConcurrentMap mapa = db.hashMap("map").createOrOpen();
dc.getWithTls().setDockerCertPath(Paths.get("server/certs/").relativize(certFile.toPath()).toString());
dc.getWithTls().setDockerConfig(Paths.get("server/certs/").relativize(configFile.toPath()).toString());
mapa.put(dc.getName(), dc);
db.commit();
db.close();
}
示例4: getConnectionFromDB
import org.mapdb.DBMaker; //導入依賴的package包/類
public Map<UUID, DockerConnection> getConnectionFromDB() throws IOException {
Map<UUID, DockerConnection> listOfConnections = new HashMap<>();
File database = new File("./connections.db");
DB db = DBMaker
.fileDB(database)
.transactionEnable()
.closeOnJvmShutdown()
.fileChannelEnable()
.make();
ConcurrentMap mapa = db.hashMap("map").createOrOpen();
mapa.forEach((uuid, connection) -> {
listOfConnections.put((UUID) uuid, (DockerConnection) connection);
});
db.close();
return listOfConnections;
}
示例5: initialize
import org.mapdb.DBMaker; //導入依賴的package包/類
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
throws ResourceInitializationException {
boolean ret = super.initialize(aSpecifier, aAdditionalParams);
// initialize delegate
CustomResourceSpecifier delegateResourceSpecifier = new CustomResourceSpecifier_impl();
delegateResourceSpecifier.setResourceClassName(delegateClass.getCanonicalName());
delegate = delegateClass.cast(UIMAFramework.produceResource(delegateClass,
delegateResourceSpecifier, aAdditionalParams));
// initialize mapdb
File file = new File((String) getParameterValue("db-file"));
db = DBMaker.newFileDB(file).compressionEnable().commitFileSyncDisable().cacheSize(128)
.closeOnJvmShutdown().make();
String map = (String) getParameterValue("map-name");
id2synonyms = db.getHashMap(map);
return ret;
}
示例6: initialize
import org.mapdb.DBMaker; //導入依賴的package包/類
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
throws ResourceInitializationException {
boolean ret = super.initialize(aSpecifier, aAdditionalParams);
// initialize delegate
CustomResourceSpecifier delegateResourceSpecifier = new CustomResourceSpecifier_impl();
delegateResourceSpecifier.setResourceClassName(delegateClass.getCanonicalName());
delegate = delegateClass.cast(UIMAFramework.produceResource(delegateClass,
delegateResourceSpecifier, aAdditionalParams));
// initialize mapdb
File file = new File((String) getParameterValue("db-file"));
db = DBMaker.newFileDB(file).compressionEnable().commitFileSyncDisable().cacheSize(128)
.closeOnJvmShutdown().make();
String map = (String) getParameterValue("map-name");
string2concept = db.getHashMap(map);
return ret;
}
示例7: initStore
import org.mapdb.DBMaker; //導入依賴的package包/類
public void initStore() {
if (m_storePath == null || m_storePath.isEmpty()) {
m_db = DBMaker.newMemoryDB().make();
} else {
File tmpFile;
try {
tmpFile = new File(m_storePath);
boolean fileNewlyCreated = tmpFile.createNewFile();
LOG.info("Starting with {} [{}] db file", fileNewlyCreated ? "fresh" : "existing", m_storePath);
} catch (IOException ex) {
LOG.error(null, ex);
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
}
m_db = DBMaker.newFileDB(tmpFile).make();
}
m_scheduler.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
m_db.commit();
}
}, this.m_autosaveInterval, this.m_autosaveInterval, TimeUnit.SECONDS);
}
示例8: preProcess
import org.mapdb.DBMaker; //導入依賴的package包/類
/**
* If grouping is enabled, initialize the temporary cache that will hold grouped objects.
*/
@SuppressWarnings("unchecked")
@Override
protected final boolean preProcess(Context context) {
if ( isGroupingEnabled(context) ) {
IContextGrouping ctx = context.as(IContextGrouping.class);
DB db = DBMaker.tempFileDB()
.closeOnJvmShutdown().fileDeleteAfterClose()
.fileMmapEnableIfSupported()
.make();
Map<String, List<Object>> groups = db.hashMap("groups", Serializer.STRING, Serializer.JAVA).create();
groups.clear(); // Make sure that we start with a clean cache
ctx.setGroupByExpressionsMapDB(db);
ctx.setGroupByExpressionsGroupsMap(groups);
}
return preProcessBeforeGrouping(context);
}
示例9: setReadOnly
import org.mapdb.DBMaker; //導入依賴的package包/類
@Override
public void setReadOnly() {
clusterContainer.close();
Path projectPath = Paths.get(Configuration.getParameters().getString("Experiment.projectPath"));
Path poolDataPath = Paths.get(projectPath.toString(), "clusterdata");
String containerFileName = "clusters.mapdb";
DB db = DBMaker
.fileDB(Paths.get(poolDataPath.toString(), containerFileName).toFile())
.fileMmapEnableIfSupported() // Only enable mmap on supported platforms
.concurrencyScale(8) // TODO: Number of threads make this a parameter?
.executorEnable()
.readOnly()
.make();
clusterContainer = db.treeMap("map")
.keySerializer(Serializer.INTEGER)
.valueSerializer(Serializer.INTEGER)
.open();
AptaLogger.log(Level.CONFIG, this.getClass(), "Reopened as read only file " + Paths.get(poolDataPath.toString(), containerFileName).toString() );
}
示例10: setReadOnly
import org.mapdb.DBMaker; //導入依賴的package包/類
public void setReadOnly() {
poolContentCounts.close();
Path projectPath = Paths.get(Configuration.getParameters().getString("Experiment.projectPath"));
Path poolDataPath = Paths.get(projectPath.toString(), "cycledata");
String cycleFileName = round + "_" + name + ".mapdb";
DB db = DBMaker
.fileDB(Paths.get(poolDataPath.toString(), cycleFileName).toFile())
.fileMmapEnableIfSupported() // Only enable mmap on supported platforms
.concurrencyScale(8) // TODO: Number of threads make this a parameter?
.executorEnable()
.readOnly()
.make();
poolContentCounts = db.treeMap("map")
.keySerializer(Serializer.INTEGER)
.valueSerializer(Serializer.INTEGER)
.open();
AptaLogger.log(Level.CONFIG, this.getClass(), "Reopened as read only file " + Paths.get(poolDataPath.toString(), cycleFileName).toString() );
}
示例11: setReadWrite
import org.mapdb.DBMaker; //導入依賴的package包/類
@Override
public void setReadWrite() {
poolContentCounts.close();
Path projectPath = Paths.get(Configuration.getParameters().getString("Experiment.projectPath"));
Path poolDataPath = Paths.get(projectPath.toString(), "cycledata");
String cycleFileName = round + "_" + name + ".mapdb";
DB db = DBMaker
.fileDB(Paths.get(poolDataPath.toString(), cycleFileName).toFile())
.fileMmapEnableIfSupported() // Only enable mmap on supported platforms
.concurrencyScale(8) // TODO: Number of threads make this a parameter?
.executorEnable()
.make();
poolContentCounts = db.treeMap("map")
.keySerializer(Serializer.INTEGER)
.valueSerializer(Serializer.INTEGER)
.open();
AptaLogger.log(Level.CONFIG, this.getClass(), "Reopened as read/write file " + Paths.get(poolDataPath.toString(), cycleFileName).toString() );
}
示例12: MapDbPersistentStore
import org.mapdb.DBMaker; //導入依賴的package包/類
/**
* Creates a new MapDB based persistent store.
*
* @param filename filename of the database on disk
* @param executor executor to use for tasks that write to the disk
* @param serializer serializer for keys and values
*/
MapDbPersistentStore(String filename, ExecutorService executor,
KryoSerializer serializer) {
this.executor = checkNotNull(executor);
this.serializer = checkNotNull(serializer);
File databaseFile = new File(filename);
database = DBMaker.newFileDB(databaseFile).make();
items = database.createHashMap("items")
.keySerializer(Serializer.BYTE_ARRAY)
.valueSerializer(Serializer.BYTE_ARRAY)
.hasher(Hasher.BYTE_ARRAY)
.makeOrGet();
tombstones = database.createHashMap("tombstones")
.keySerializer(Serializer.BYTE_ARRAY)
.valueSerializer(Serializer.BYTE_ARRAY)
.hasher(Hasher.BYTE_ARRAY)
.makeOrGet();
}
示例13: constructDB
import org.mapdb.DBMaker; //導入依賴的package包/類
private static DB constructDB(String dbFile) {
DB db;
try{
DBMaker dbMaker = DBMaker.newFileDB(new File(dbFile));
db = dbMaker
.transactionDisable()
.mmapFileEnable()
.asyncWriteEnable()
.compressionEnable()
// .cacheSize(1024 * 1024) this bloats memory consumption
.make();
return db;
} catch (ExecutionError | IOError | Exception e) {
LOG.error("Could not construct db from file.", e);
return null;
}
}
示例14: subset_of_data_should_be_selected
import org.mapdb.DBMaker; //導入依賴的package包/類
@Test
public void subset_of_data_should_be_selected(){
DB db = DBMaker.tempFileDB().transactionDisable().fileMmapCleanerHackEnable().make();
CubeDataBuilder cubeDataBuilder = CubeData.builder(db);
cubeDataBuilder.add(Lists.newArrayList(2, 2, 2), Lists.newArrayList("12002","..."));
cubeDataBuilder.add(Lists.newArrayList(3, 3, 3), Lists.newArrayList("12002","..."));
cubeDataBuilder.add(Lists.newArrayList(1, 2, 3), Lists.newArrayList("12002","..."));
cubeDataBuilder.add(Lists.newArrayList(1, 1, 1), Lists.newArrayList("12002","..."));
cubeDataBuilder.add(Lists.newArrayList(1, 1, 2), Lists.newArrayList("12002","..."));
CubeData cubeData = cubeDataBuilder.build();
Map<Integer, List<Integer>> query = ImmutableMap.<Integer, List<Integer>>builder()
.put(0, Lists.newArrayList(1))
.put(1, Lists.newArrayList(1)).build();
Iterator<CubeEntry> it = cubeData.query(query);
List<CubeEntry> result = Lists.newArrayList(it);
assertEquals(2, result.size());
assertArrayEquals(new int[]{1, 1, 1}, result.get(0).vector);
assertArrayEquals(new int[]{1, 1, 2}, result.get(1).vector);
assertArrayEquals(new int[]{3, 3, 3}, cubeData.getSizes());
}
示例15: test_seek_with_missing_values
import org.mapdb.DBMaker; //導入依賴的package包/類
@Test
public void test_seek_with_missing_values(){
DB db = DBMaker.tempFileDB().transactionDisable().fileMmapCleanerHackEnable().make();
CubeDataBuilder cubeDataBuilder = CubeData.builder(db);
cubeDataBuilder.add(Lists.newArrayList(2, 2, 2), Lists.newArrayList("12002","..."));
cubeDataBuilder.add(Lists.newArrayList(3, 3, 3), Lists.newArrayList("12003","..."));
cubeDataBuilder.add(Lists.newArrayList(4, 4, 4), Lists.newArrayList("12004","..."));
cubeDataBuilder.add(Lists.newArrayList(5, 5, 5), Lists.newArrayList("12005","..."));
cubeDataBuilder.add(Lists.newArrayList(1, 1, 1), Lists.newArrayList("12006","..."));
CubeData cubeData = cubeDataBuilder.build();
Map<Integer, List<Integer>> query = ImmutableMap.<Integer, List<Integer>>builder()
.put(0, Lists.newArrayList(1,3)).build();
Iterator<CubeEntry> it = cubeData.query(query);
List<CubeEntry> result = Lists.newArrayList(it);
assertArrayEquals(new int[]{1,1,1},result.get(0).vector);
assertArrayEquals(new String[]{"12006", "..."}, result.get(0).metrics);
assertArrayEquals(new int[]{3,3,3},result.get(1).vector);
assertArrayEquals(new String[]{"12003","..."},result.get(1).metrics);
assertEquals(2, result.size());
}