Java Code Examples for com.sleepycat.je.DatabaseConfig#setSortedDuplicates()

The following examples show how to use com.sleepycat.je.DatabaseConfig#setSortedDuplicates() . 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: JE_Repository.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
public Database getDatabase(String name, boolean isTmp, boolean isSortedDuplicates) {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    Environment _env = env;
    if (isTmp) {
        dbConfig.setTemporary(true);
        dbConfig.setSortedDuplicates(isSortedDuplicates);
        _env = getTmpEnv();
    } else {
        if (!config.isTransactional()) {
            dbConfig.setDeferredWrite(config.isCommitSync());
        } else {
            dbConfig.setTransactional(true);
        }
    }

    Database database = buildPrimaryIndex(dbConfig, _env, name);
    return database;
}
 
Example 2
Source File: DefaultIndexImpl.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public void open()
{
	try
	{
		DatabaseConfig dbConfig = storage.getConfiguration().getDatabaseConfig().clone();
		dbConfig.setSortedDuplicates(sort_duplicates);

		if (keyComparator != null)
		{
			dbConfig.setBtreeComparator((Comparator<byte[]>) keyComparator);
		}

		db = storage.getBerkleyEnvironment().openDatabase(null, DB_NAME_PREFIX + name, dbConfig);
	}
	catch (Throwable t)
	{
		throw new HGException("While attempting to open index ;" + name + "': " + t.toString(), t);
	}
}
 
Example 3
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already created");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(true);
		boolean finalTransactional = transactional && useTransactions;
		databaseConfig.setDeferredWrite(!finalTransactional);
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(false);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			return false;
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		
		return true;
	}
 
Example 4
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean createIndexTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already created");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(true);
		boolean finalTransactional = transactional && useTransactions;
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setDeferredWrite(!finalTransactional);
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(true);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			return false;
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		
		return true;
	}
 
Example 5
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already opened");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(false);
		boolean finalTransactional = transactional && useTransactions;
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setDeferredWrite(!finalTransactional);
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(false);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			throw new BimserverDatabaseException("Table " + tableName + " not found in database");
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
		return true;
	}
 
Example 6
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void openIndexTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
		if (tables.containsKey(tableName)) {
			throw new BimserverDatabaseException("Table " + tableName + " already opened");
		}
		DatabaseConfig databaseConfig = new DatabaseConfig();
		databaseConfig.setKeyPrefixing(keyPrefixing);
		databaseConfig.setAllowCreate(false);
		boolean finalTransactional = transactional && useTransactions;
//		if (!transactional) {
//			databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
//		}
		databaseConfig.setDeferredWrite(!finalTransactional);
		databaseConfig.setTransactional(finalTransactional);
		databaseConfig.setSortedDuplicates(true);
		Database database = environment.openDatabase(null, tableName, databaseConfig);
		if (database == null) {
			throw new BimserverDatabaseException("Table " + tableName + " not found in database");
		}
		tables.put(tableName, new TableWrapper(database, finalTransactional));
	}
 
Example 7
Source File: BdbNonPersistentEnvironmentCreator.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName,
                                                           boolean allowDuplicates, EntryBinding<KeyT> keyBinder,
                                                           EntryBinding<ValueT> valueBinder,
                                                           IsCleanHandler<KeyT, ValueT> isCleanHandler)
  throws BdbDbCreationException {
  try {
    DatabaseConfig config = new DatabaseConfig();
    config.setAllowCreate(true);
    config.setDeferredWrite(true);
    config.setSortedDuplicates(allowDuplicates);

    String environmentKey = environmentKey(userId, dataSetId);
    File envHome = new File(dbHome, environmentKey);
    envHome.mkdirs();
    Environment dataSetEnvironment = new Environment(envHome, configuration);
    Database database = dataSetEnvironment.openDatabase(null, databaseName, config);
    databases.put(environmentKey + "_" + databaseName, database);
    environmentMap.put(environmentKey, dataSetEnvironment);
    return new BdbWrapper<>(dataSetEnvironment, database, config, keyBinder, valueBinder, isCleanHandler);
  } catch (DatabaseException e) {
    throw new BdbDbCreationException(e);
  }
}
 
Example 8
Source File: OSMBDBNodeStore.java    From bboxdb with Apache License 2.0 5 votes vote down vote up
/**
 * Init a new BDB environment in the given folder
 * @param folder
 */
@SuppressWarnings("unused")
protected void initNewBDBEnvironment(final File folder, final EnvironmentConfig envConfig) {

	final Environment dbEnv = new Environment(folder, envConfig);

	Transaction txn = null;
	if(USE_TRANSACTIONS) {
		txn = dbEnv.beginTransaction(null, null);
	}
	
	final DatabaseConfig dbConfig = new DatabaseConfig();
	dbConfig.setTransactional(USE_TRANSACTIONS);
	dbConfig.setAllowCreate(true);
	dbConfig.setSortedDuplicates(true);
	dbConfig.setDeferredWrite(true);
	//dbConfig.setKeyPrefixing(true);
	//dbConfig.setNodeMaxEntries(128);

	final Database database = dbEnv.openDatabase(txn, "osm", dbConfig);

	if(txn != null) {
		txn.commit();
	}
	
	environments.add(dbEnv);
	databases.add(database);
}
 
Example 9
Source File: BerkeleyDBStore.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
@Override
public void init(HazelcastInstance hazelcastInstance, Properties properties, String mapName) {
    _hazelcastInstance = hazelcastInstance;
    _properties = properties;
    _mapName = mapName;

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setAllowCreate(true);
    dbConfig.setDeferredWrite(true); //延迟写
    dbConfig.setSortedDuplicates(false);
    dbConfig.setTransactional(false);
    _db = _env.openDatabase(null, _mapName, dbConfig);
    _dbMap.put(_mapName, _db);

    if (_scheduleSync == null) {
        try {
            _syncinterval = Integer.parseInt(_properties.getProperty("syncinterval"));
        } catch (Exception e) {
            _syncinterval = 3;
            _logger.log(Level.WARNING, e.getMessage(), e);
        }
        if (_syncinterval > 0) {
            _scheduleSync = Executors.newSingleThreadScheduledExecutor(); //同步磁盘的Scheduled
            _scheduleSync.scheduleWithFixedDelay(this, 1, _syncinterval, TimeUnit.SECONDS);
        }
    }
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":count:" + _db.count());
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":初始化完成!");

    //预先把数据加载进Hazelcast集群中
    IMap map = _hazelcastInstance.getMap(mapName);
    Set<K> keySet = privateLoadAllKeys();
    for (K key : keySet) {
        map.putTransient(key, load(key), 0, TimeUnit.SECONDS);
    }
    _logger.log(Level.INFO, this.getClass().getCanonicalName() + ":" + _mapName + ":预先加载数据完成!");

}
 
Example 10
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 4 votes vote down vote up
public void startup(HGStore store, HGConfiguration config)
{
	this.store = store;
	this.handleFactory = config.getHandleFactory();
	this.linkBinding = new LinkBinding(handleFactory);
	EnvironmentConfig envConfig = configuration.getEnvironmentConfig();
	envConfig.setConfigParam(EnvironmentConfig.CLEANER_THREADS, "5");
	envConfig.setClassLoader(new HGClassLoaderDelegate(config));
	if (config.isTransactional())
	{
		configuration.configureTransactional();
	}

	File envDir = new File(store.getDatabaseLocation());
	envDir.mkdirs();

	try
	{
		env = new Environment(envDir, envConfig);
		data_db = env.openDatabase(null, DATA_DB_NAME, configuration.getDatabaseConfig().clone());
		primitive_db = env.openDatabase(null, PRIMITIVE_DB_NAME, configuration.getDatabaseConfig().clone());

		DatabaseConfig incConfig = configuration.getDatabaseConfig().clone();
		incConfig.setSortedDuplicates(true);
		incidence_db = env.openDatabase(null, INCIDENCE_DB_NAME, incConfig);

		openIndices = new HashMap<String, HGIndex<?, ?>>(); // force reset
															// since startup
															// can follow a
															// shutdown on
															// same opened
															// class

		if (config.isTransactional())
		{
			CheckpointConfig ckptConfig = new CheckpointConfig();
			// System.out.println("checkpoint kbytes:" +
			// ckptConfig.getKBytes());
			// System.out.println("checkpoint minutes:" +
			// ckptConfig.getMinutes());
			env.checkpoint(null);
			checkPointThread = new CheckPointThread();
			checkPointThread.start();
		}
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to initialize HyperGraph data store: " + ex.toString(), ex);
	}
}