Java Code Examples for com.sleepycat.persist.EntityStore#getSecondaryIndex()

The following examples show how to use com.sleepycat.persist.EntityStore#getSecondaryIndex() . 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: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
/**
 * 构造方法
 * 
 * @param entityInfo
 * @param accessor
 */
public BerkeleyManager(BerkeleyMetadata metadata, EntityStore store) {
	this.metadata = metadata;
	this.store = store;

	// 通过获取主键索引准备Berkeley环境(有意义,别删除)
	primaryIndex = this.store.getPrimaryIndex(metadata.getPrimaryClass(), metadata.getStoreClass());
	for (String name : metadata.getIndexNames()) {
		Field field = metadata.getSecondaryField(name);
		Class<?> clazz = ClassUtility.primitiveToWrapper(field.getType());
		SecondaryIndex secondaryIndex;
		if (metadata.getOrmClass() == metadata.getStoreClass()) {
			secondaryIndex = store.getSecondaryIndex(primaryIndex, clazz, name);
		} else {
			secondaryIndex = store.getSubclassIndex(getPrimaryIndex(), metadata.getOrmClass(), clazz, name);
		}
		secondaryIndexes.put(name, secondaryIndex);
	}
}
 
Example 2
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 3
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<>();
}