當前位置: 首頁>>代碼示例>>Java>>正文


Java DBMaker.newFileDB方法代碼示例

本文整理匯總了Java中org.mapdb.DBMaker.newFileDB方法的典型用法代碼示例。如果您正苦於以下問題:Java DBMaker.newFileDB方法的具體用法?Java DBMaker.newFileDB怎麽用?Java DBMaker.newFileDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mapdb.DBMaker的用法示例。


在下文中一共展示了DBMaker.newFileDB方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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;
        }
    }
 
開發者ID:conveyal,項目名稱:gtfs-lib,代碼行數:18,代碼來源:GTFSFeed.java

示例2: createDBMakerInstance

import org.mapdb.DBMaker; //導入方法依賴的package包/類
private DBMaker createDBMakerInstance(Map<String, String> configuration) throws StorageBackendException {
    String modeProperty = configuration.get(PROPERTY_KEY_OPERATION_MODE);
    String filepathProperty = configuration.get(PROPERTY_KEY_DB_FILE);

    checkNotNull(filepathProperty, "Database file must be specified with property" + PROPERTY_KEY_DB_FILE);

    OperationMode operationMode = OperationMode.valueOf(StringUtils.upperCase(modeProperty));

    LOGGER.info("Initializing MapDB storage backend in {} mode", operationMode);

    switch (operationMode) {
        case FILE:
            Path path = Paths.get(filepathProperty);
            LOGGER.info("Using MapDB database file '{}'", path.toAbsolutePath().toString());
            return DBMaker.newFileDB(path.toFile());
        case TEMPORARY:
            return DBMaker.newMemoryDB();
        default:
            throw new StorageBackendException("Unknown operation mode: " + operationMode);
    }
}
 
開發者ID:jhendess,項目名稱:metadict,代碼行數:22,代碼來源:MapdbStorageEngineFactory.java

示例3: init

import org.mapdb.DBMaker; //導入方法依賴的package包/類
private void init() {
  DBMaker maker;
  if (file == null)
    maker = DBMaker.newMemoryDB();
  else {
    if (overwrite)
      wipe(file);
    maker = DBMaker.newFileDB(new File(file));
    maker = maker.cacheSize(cache_size);
    if (async) {
      maker = maker.asyncWriteEnable();
      maker = maker.asyncWriteFlushDelay(10000);
    }
    if (mmap)
      maker = maker.mmapFileEnableIfSupported();
    if (compression)
      maker = maker.compressionEnable();
    if (snapshot)
      maker = maker.snapshotEnable();
    if (notxn)
      maker = maker.transactionDisable();
  }

  db = maker.make();

  if (!db.exists("idmap"))
    idmap = db.createHashMap("idmap")
      .valueSerializer(new RecordSerializer())
      .make();
  else
    idmap = db.getHashMap("idmap");
}
 
開發者ID:enricopal,項目名稱:STEM,代碼行數:33,代碼來源:MapDBBlockingDatabase.java

示例4: build

import org.mapdb.DBMaker; //導入方法依賴的package包/類
public MicroDB build(File path) throws IOException {
    DBMaker mapdbBuilder = DBMaker.newFileDB(path);
    if(mCacheSize != null) {
        mapdbBuilder.cacheSize(mCacheSize);
    }
    DB db = mapdbBuilder.make();

    MapDBDriver driver = new MapDBDriver(db);

    return new MicroDB(driver, mSchemaVersion, mCallback, mConstructorMap);

}
 
開發者ID:dinocore1,項目名稱:MicroDb,代碼行數:13,代碼來源:DBBuilder.java

示例5: onInit

import org.mapdb.DBMaker; //導入方法依賴的package包/類
@Override
public void onInit() {
	if (LOG.isTraceEnabled()) {
		LOG.trace("Initializing the '"
				+ MapDbAuthorizingRealm.class.getSimpleName() + "'.");
	}

	super.onInit();

	// create the maker of the database and create it
	final DBMaker<?> maker = DBMaker.newFileDB(location);
	maker.cacheHardRefEnable();
	maker.cacheLRUEnable();
	maker.cacheSize(1000);
	maker.closeOnJvmShutdown();
	db = maker.make();

	// create the maker for the specific maps of users and roles
	final HTreeMapMaker usersMapMaker = db.createHashMap("users");
	final HTreeMapMaker rolesMapMaker = db.createHashMap("roles");
	this.users = usersMapMaker.makeOrGet();
	this.roles = rolesMapMaker.makeOrGet();

	// disable any caching
	setCachingEnabled(false);
	setCacheManager(null);

	// add a role resolver
	setRolePermissionResolver(new RolePermissionResolver() {

		@Override
		public Collection<Permission> resolvePermissionsInRole(
				final String role) {

			final SimpleRole r = roles.get(role);
			if (r == null) {
				return null;
			} else {
				return r.getPermissions();
			}
		}
	});

	checkAdministrator();
}
 
開發者ID:pmeisen,項目名稱:dis-timeintervaldataanalyzer,代碼行數:46,代碼來源:MapDbAuthorizingRealm.java

示例6: CachingRemoteConnector

import org.mapdb.DBMaker; //導入方法依賴的package包/類
/**
 * Creates a connector that caches items read from the server
 * @param delegate the underlying connector
 * @param cacheFile a file used to cache items
 */
public CachingRemoteConnector(RemoteConnector delegate, File cacheFile) {
	super(delegate);
	
	DB db = null;
	Set<String> itemIds = null;
	Map<String, String> items = null;
	int retry = 2;
	while (retry >= 1) {
		try {
			DBMaker<?> dbMaker = DBMaker.newFileDB(cacheFile);
			dbMaker.closeOnJvmShutdown();
			db = dbMaker.make();
			
			itemIds = db.getTreeSet("itemIds");
			items = db.getHashMap("items");
			
			break;
		} catch (Throwable e) {
			--retry;
			if (retry == 1 && cacheFile.exists()) {
				//unable to open disk cache. remove it and try again.
				try {
					//close db first
					if (db != null) {
						db.close();
						db = null;
					}
				} catch (Throwable t) {
					//ignore
				}
				cacheFile.delete();
				continue;
			}
			
			//disk cache is not available. use in-memory cache
			db = null;
			itemIds = new HashSet<>();
			items = new HashMap<>();
			break;
		}
	}
	
	_db = db;
	_itemIds = itemIds;
	_items = items;
}
 
開發者ID:michel-kraemer,項目名稱:citeproc-java,代碼行數:52,代碼來源:CachingRemoteConnector.java


注:本文中的org.mapdb.DBMaker.newFileDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。