com.sleepycat.persist.StoreConfig Java Examples

The following examples show how to use com.sleepycat.persist.StoreConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebGraph.java    From codes-scratch-crawler with Apache License 2.0 6 votes vote down vote up
/**
 * 构造函数
 */
public WebGraph(String dbDir) throws DatabaseException {
  File envDir = new File(dbDir);
  EnvironmentConfig envConfig = new EnvironmentConfig();
  envConfig.setTransactional(false);
  envConfig.setAllowCreate(true);
  Environment env = new Environment(envDir, envConfig);

  StoreConfig storeConfig = new StoreConfig();
  storeConfig.setAllowCreate(true);
  storeConfig.setTransactional(false);

  store = new EntityStore(env, "classDb", storeConfig);
  outLinkIndex = store.getPrimaryIndex(String.class, Link.class);
  inLinkIndex = store.getSecondaryIndex(outLinkIndex, String.class, "toURL");
}
 
Example #2
Source File: Migrator.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 构建仓储的映射
 * 
 * @param environment
 * @param entityStoreNameMap
 * @return 仓储名称与仓储实例的映射
 */
private Map<String, RawStore> bulidRawStoreMap(Environment environment, Map<String, String> entityStoreNameMap) {
    final StoreConfig storeConfiguration = new StoreConfig();
    final Map<String, RawStore> rawStoreMap = new HashMap<String, RawStore>();
    for (String storeName : entityStoreNameMap.values()) {
        if (!rawStoreMap.containsKey(storeName)) {
            rawStoreMap.put(storeName, new RawStore(environment, storeName, storeConfiguration));
        }
    }
    return rawStoreMap;
}
 
Example #3
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates and/or opens the BDB databases with the appropriate parameters.
 * 
 * @throws Exception
 */
private void createOrOpenBDBDbs() throws Exception {
	// configuration for the mapping dbs
	DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setAllowCreate(true); // db will be created if it does not exist
	dbConfig.setReadOnly(readOnly);
	dbConfig.setTransactional(transactional);
	// create/open mapping dbs using config
	iidToIdDB = dbEnv.openDatabase(null, "idToName", dbConfig);

	// if countSizeOnLoad is true, the id-name mappings are counted and the loadCounter is initialized
	if (countSizeOnLoad) {
		System.out.println(new Date() + " counting index size started ");
		int idToNameMappings = (int) iidToIdDB.count();
		loadCounter = Math.min(idToNameMappings, maxNumVectors);
		System.out.println(new Date() + " counting index size ended ");
		System.out.println("Index size: " + loadCounter);
	}

	idToIidDB = dbEnv.openDatabase(null, "nameToId", dbConfig);

	if (useGeolocation) {// create/open geolocation db using config
		iidToGeolocationDB = dbEnv.openDatabase(null, "idToGeolocation", dbConfig);
	}

	if (useMetaData) {
		StoreConfig storeConfig = new StoreConfig(); // configuration of the entity store
		storeConfig.setAllowCreate(true); // store will be created if it does not exist
		storeConfig.setReadOnly(readOnly);
		storeConfig.setTransactional(transactional);
		iidToMetadataDB = new EntityStore(dbEnv, "idToMetadata", storeConfig);
		// int nameToMetadataMappings = (int) nameToMetadataBDB.getPrimaryIndex(String.class,
		// MediaFeedData.class).count(); // counting the size of an EntityStore
	}
}
 
Example #4
Source File: BerkeleyDBWiktionaryEdition.java    From dkpro-jwktl with Apache License 2.0 4 votes vote down vote up
protected void connect(boolean isReadOnly, boolean allowCreateNew,
		boolean overwriteExisting, final Long cacheSize) throws DatabaseException {
	// Configure DB environment.
	EnvironmentConfig envConfig = new EnvironmentConfig();
	envConfig.setAllowCreate(allowCreateNew);
	envConfig.setReadOnly(isReadOnly);
	envConfig.setTransactional(false);
	if (cacheSize != null)
		envConfig.setCacheSize(cacheSize);
	env = new Environment(dbPath, envConfig);

	// Configure store.
	StoreConfig storeConfig = new StoreConfig();
	storeConfig.setAllowCreate(allowCreateNew);
	storeConfig.setTransactional(false);
	storeConfig.setReadOnly(isReadOnly);
	store = new EntityStore(env, DATABASE_NAME, storeConfig);

	// Load properties.
	properties = new Properties();
	File propFile = new File(dbPath, PROPERTY_FILE_NAME);
	if (propFile.exists()) {
		try {
			try (Reader reader = new InputStreamReader(new FileInputStream(propFile), "UTF-8")) {
				properties.load(reader);
			}
		} catch (IOException e) {
			throw new DatabaseException("Unable to load property file", e){};
		}

		String lang = properties.getProperty("wiktionary.language");
		if (lang == null)
			lang = properties.getProperty("entry_language");
		language = Language.get(lang);
	}

	// Load index.
	pageById = store.getPrimaryIndex(Long.class, WiktionaryPage.class);
	pageByTitle = store.getSecondaryIndex(pageById, String.class, "title");
	pageByNormalizedTitle = store.getSecondaryIndex(pageById, String.class, "normalizedTitle");

	entryByKey = store.getPrimaryIndex(String.class, WiktionaryEntryProxy.class);
	entryById = store.getSecondaryIndex(entryByKey, Long.class, "entryId");
	senseByKey = store.getPrimaryIndex(String.class, WiktionarySenseProxy.class);

	openCursors = new HashSet<>();
}