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

The following examples show how to use com.sleepycat.je.DatabaseConfig#setAllowCreate() . 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: 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 2
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 3
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 4
Source File: AbstractFrontier.java    From codes-scratch-crawler with Apache License 2.0 6 votes vote down vote up
public AbstractFrontier(String homeDirectory) {
  EnvironmentConfig envConfig = new EnvironmentConfig();
  envConfig.setTransactional(true);
  envConfig.setAllowCreate(true);
  env = new Environment(new File(homeDirectory), envConfig);
  // 设置databaseconfig
  DatabaseConfig dbConfig = new DatabaseConfig();
  dbConfig.setTransactional(true);
  dbConfig.setAllowCreate(true);
  // 打开
  catalogdatabase = env.openDatabase(null, CLASS_CATALOG, dbConfig);
  javaCatalog = new StoredClassCatalog(catalogdatabase);
  // 设置databaseconfig
  DatabaseConfig dbConfig0 = new DatabaseConfig();
  dbConfig0.setTransactional(true);
  dbConfig0.setAllowCreate(true);
  database = env.openDatabase(null, "URL", dbConfig0);
}
 
Example 5
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 6
Source File: UpgraderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private int getStoreVersion(Environment environment)
{
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try(Database versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor cursor = versionDb.openCursor(null, null))
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
        {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version)
            {
                storeVersion = version;
            }
        }
    }
    return storeVersion;
}
 
Example 7
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 8
Source File: DatabaseTemplate.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
public <T> T call(DatabaseCallable<T> databaseCallable)
{
    Database sourceDatabase = null;
    Database targetDatabase = null;
    try
    {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);

        sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig);

        if (_targetDatabaseName != null)
        {
            targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig);
        }

        return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction);
    }
    finally
    {
        closeDatabase(sourceDatabase);
        closeDatabase(targetDatabase);
    }
}
 
Example 9
Source File: BDBPreferenceStoreTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void populateTestData(final List<PreferenceRecord> records, final String modelVersion)
{
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(false);
    try (Environment environment = new Environment(_storeFile, envConfig))
    {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
             Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig))
        {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            MapBinding valueBinding = MapBinding.getInstance();
            for (PreferenceRecord record : records)
            {
                keyBinding.objectToEntry(record.getId(), key);
                valueBinding.objectToEntry(record.getAttributes(), value);
                preferencesDb.put(null, key, value);
            }

            ByteBinding.byteToEntry((byte) 0, value);
            StringBinding.stringToEntry(modelVersion, key);
            versionDb.put(null, key, value);
        }
    }
}
 
Example 10
Source File: CompressedStorage.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method is invoked by the kernel to initialize the storage.
 *
 * @param arguments The arguments with which this storage is to be
 *                  initialized.
 * @return True if the storage was initialized successfully.
 */
public boolean initialize(String filePath) {
	//clock = System.currentTimeMillis();
	countUpdates = 0;
	annotationsTime = 0;
	scaffoldTime = 0;
	clockScaffold = 0;
	clockAnnotations = 0;
	scaffoldInMemory = new HashMap<Integer, Pair<SortedSet<Integer>, SortedSet<Integer>>>();
	edgesInMemory = 0;
	hashToID = new HashMap<String, Integer>();
	idToHash = new HashMap<Integer, String>();
	alreadyRenamed = new Vector<String>();
	compresser = new Deflater(Deflater.BEST_COMPRESSION);
	W=10;
	L=5;
	nextVertexID = 0;
	try {
		benchmarks = new PrintWriter("/Users/melanie/Documents/benchmarks/compression_time_berkeleyDB.txt", "UTF-8");
		// Open the environment. Create it if it does not already exist.
		EnvironmentConfig envConfig = new EnvironmentConfig();
		envConfig.setAllowCreate(true);
		DatabaseEnvironment1 = new Environment(new File(filePath + "/scaffold"), 
				envConfig);
		DatabaseEnvironment2 = new Environment(new File(filePath + "/annotations"), 
				envConfig);
		// Open the databases. Create it if it does not already exist.
		DatabaseConfig DatabaseConfig1 = new DatabaseConfig();
		DatabaseConfig1.setAllowCreate(true);
		scaffoldDatabase = DatabaseEnvironment1.openDatabase(null, "spade_scaffold", DatabaseConfig1); 
		annotationsDatabase = DatabaseEnvironment2.openDatabase(null, "spade_annotations", DatabaseConfig1); 

		return true;

	} catch (Exception ex) {
		// Exception handling goes here
		logger.log(Level.SEVERE, "Compressed Storage Initialized not successful!", ex);
		return false;
	}
}
 
Example 11
Source File: BDBTupleStore.java    From bboxdb with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws Exception {
	final EnvironmentConfig envConfig = new EnvironmentConfig();
	envConfig.setTransactional(USE_TRANSACTIONS);
	envConfig.setAllowCreate(true);

	environment = new Environment(dir, envConfig);

	Transaction txn = null;
	if(USE_TRANSACTIONS) {
		txn = environment.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);

	database = environment.openDatabase(txn, "test", dbConfig);

	if(txn != null) {
		txn.commit();
	}	
}
 
Example 12
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 13
Source File: PQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Advanced constructor.
 * 
 * @param vectorLength
 *            The dimensionality of the VLAD vectors being indexed
 * @param maxNumVectors
 *            The maximum allowable size (number of vectors) of the index
 * @param readOnly
 *            If true the persistent store will opened only for read access (allows multiple opens)
 * @param BDBEnvHome
 *            The BDB environment home directory
 * @param numSubVectors
 *            The number of subvectors
 * @param numProductCentroids
 *            The number of centroids used to quantize each sub-vector
 * @param transformation
 *            The type of transformation to perform on each vector
 * @param countSizeOnLoad
 *            Whether the load counter will be initialized by the size of the persistent store
 * @param loadCounter
 *            The initial value of the load counter
 * @param loadIndexInMemory
 *            Whether to load the index in memory, we can avoid loading the index in memory when we only
 *            want to perform indexing
 * @throws Exception
 */
public PQ(int vectorLength, int maxNumVectors, boolean readOnly, String BDBEnvHome, int numSubVectors,
		int numProductCentroids, TransformationType transformation, boolean countSizeOnLoad,
		int loadCounter, boolean loadIndexInMemory, long cacheSize) throws Exception {
	super(vectorLength, maxNumVectors, readOnly, countSizeOnLoad, loadCounter, loadIndexInMemory,
			cacheSize);
	this.numSubVectors = numSubVectors;
	if (vectorLength % numSubVectors > 0) {
		throw new Exception("The given number of subvectors is not valid!");
	}
	this.subVectorLength = vectorLength / numSubVectors;
	this.numProductCentroids = numProductCentroids;
	this.transformation = transformation;

	if (transformation == TransformationType.RandomRotation) {
		this.rr = new RandomRotation(seed, vectorLength);
	} else if (transformation == TransformationType.RandomPermutation) {
		this.rp = new RandomPermutation(seed, vectorLength);
	}

	createOrOpenBDBEnvAndDbs(BDBEnvHome);

	// configuration of the persistent index
	DatabaseConfig dbConf = new DatabaseConfig();
	dbConf.setReadOnly(readOnly);
	dbConf.setTransactional(transactional);
	dbConf.setAllowCreate(true); // db will be created if it does not exist
	iidToPqDB = dbEnv.openDatabase(null, "adc", dbConf); // create/open the db using config

	if (loadIndexInMemory) {
		// initialize the in-memory data structures and load any existing persistent index in memory
		loadIndexInMemory();
	}
}
 
Example 14
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
boolean checkIndexExisting(String name)
{
	if (openIndices.get(name) != null)
	{
		return true;
	}
	else
	{
		DatabaseConfig cfg = new DatabaseConfig();
		cfg.setAllowCreate(false);
		Database db = null;

		try
		{
			db = env.openDatabase(null, DefaultIndexImpl.DB_NAME_PREFIX + name, cfg);
		}
		catch (Exception ex)
		{
		}

		if (db != null)
		{
			try
			{
				db.close();
			}
			catch (Throwable t)
			{
				t.printStackTrace();
			}
			return true;
		}
		else
		{
			return false;
		}
	}
}
 
Example 15
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 16
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 17
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 4 votes vote down vote up
/**
 * Advanced constructor.
 * 
 * @param vectorLength
 *            The dimensionality of the VLAD vectors being indexed
 * @param maxNumVectors
 *            The maximum allowable size (number of vectors) of the index
 * @param readOnly
 *            If true the persistent store will opened only for read access (allows multiple opens)
 * @param BDBEnvHome
 *            The BDB environment home directory
 * @param numSubVectors
 *            The number of subvectors
 * @param numProductCentroids
 *            The number of centroids used to quantize each sub-vector
 * @param transformation
 *            The type of transformation to perform on each vector
 * @param numCoarseCentroids
 *            The number of centroids of the coarse quantizer
 * @param countSizeOnLoad
 *            Whether the load counter will be initialized by the size of the persistent store
 * @param loadCounter
 *            The initial value of the load counter
 * @param loadIndexInMemory
 *            Whether to load the index in memory, we can avoid loading the index in memory when we only
 *            want to perform indexing
 * @param cacheSize
 *            the size of the cache in Megabytes
 * @throws Exception
 */
public IVFPQ(int vectorLength, int maxNumVectors, boolean readOnly, String BDBEnvHome, int numSubVectors,
		int numProductCentroids, TransformationType transformation, int numCoarseCentroids,
		boolean countSizeOnLoad, int loadCounter, boolean loadIndexInMemory, long cacheSize)
				throws Exception {
	super(vectorLength, maxNumVectors, readOnly, countSizeOnLoad, loadCounter, loadIndexInMemory,
			cacheSize);
	this.numSubVectors = numSubVectors;
	if (vectorLength % numSubVectors > 0) {
		throw new Exception("The given number of subvectors is not valid!");
	}
	this.subVectorLength = vectorLength / numSubVectors;
	this.numProductCentroids = numProductCentroids;
	this.transformation = transformation;
	this.numCoarseCentroids = numCoarseCentroids;
	w = (int) (numCoarseCentroids * 0.1); // by default set w to 10% of the lists

	if (transformation == TransformationType.RandomRotation) {
		this.rr = new RandomRotation(seed, vectorLength);
	} else if (transformation == TransformationType.RandomPermutation) {
		this.rp = new RandomPermutation(seed, vectorLength);
	}

	createOrOpenBDBEnvAndDbs(BDBEnvHome);

	// configuration of the persistent index
	DatabaseConfig dbConf = new DatabaseConfig();
	dbConf.setReadOnly(readOnly);
	dbConf.setTransactional(transactional);
	dbConf.setAllowCreate(true); // db will be created if it does not exist
	iidToIvfpqDB = dbEnv.openDatabase(null, "ivfadc", dbConf); // create/open the db using config

	if (loadIndexInMemory) {// load the existing persistent index in memory
		// create the memory objects with the appropriate initial size
		invertedLists = new TIntArrayList[numCoarseCentroids];

		if (numProductCentroids <= 256) {
			pqByteCodes = new TByteArrayList[numCoarseCentroids];
		} else {
			pqShortCodes = new TShortArrayList[numCoarseCentroids];
		}

		int initialListCapacity = (int) ((double) maxNumVectors / numCoarseCentroids);
		System.out.println("Calculated list size " + initialListCapacity);

		for (int i = 0; i < numCoarseCentroids; i++) {
			if (numProductCentroids <= 256) {
				// fixed initial size allows space efficiency measurements
				// pqByteCodes[i] = new TByteArrayList(initialListCapacity * numSubVectors);
				pqByteCodes[i] = new TByteArrayList();

			} else {
				// fixed initial size allows space efficiency measurements
				// pqShortCodes[i] = new TShortArrayList(initialListCapacity * numSubVectors);
				pqShortCodes[i] = new TShortArrayList();

			}
			// fixed initial size for each list, allows space efficiency measurements
			// invertedLists[i] = new TIntArrayList(initialListCapacity);
			invertedLists[i] = new TIntArrayList();
		}
		// load any existing persistent index in memory
		loadIndexInMemory();
	}
}
 
Example 18
Source File: UpgradeFrom8To9.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
public void performUpgrade(final Environment environment,
                           final UpgradeInteractionHandler handler,
                           final ConfiguredObject<?> parent)
{
    reportStarting(environment, 8);

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    final Transaction transaction = environment.beginTransaction(null, null);
    try
    {
        Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
        userPreferencesDb.close();

        try (Database userPreferencesVersionDb = environment.openDatabase(transaction,
                                                                          "USER_PREFERENCES_VERSION",
                                                                          dbConfig))
        {
            if (userPreferencesVersionDb.count() == 0L)
            {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry value = new DatabaseEntry();
                StringBinding.stringToEntry(DEFAULT_VERSION, key);
                LongBinding.longToEntry(System.currentTimeMillis(), value);
                OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
                if (status != OperationStatus.SUCCESS)
                {
                    throw new StoreException("Error initialising user preference version: " + status);
                }
            }
        }

        transaction.commit();
        reportFinished(environment, 9);
    }
    catch (RuntimeException e)
    {
        try
        {
            if (transaction.isValid())
            {
                transaction.abort();
            }
        }
        finally
        {
            throw e;
        }
    }
}
 
Example 19
Source File: BerkeleyDBUtils.java    From WebCollector with GNU General Public License v3.0 4 votes vote down vote up
public static DatabaseConfig  createDefaultDBConfig(){
        DatabaseConfig databaseConfig=new DatabaseConfig();
        databaseConfig.setAllowCreate(true);
//        databaseConfig.setDeferredWrite(true);
        return databaseConfig;
    }
 
Example 20
Source File: Upgrader.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public void upgradeIfNecessary()
{
    boolean isEmpty = _environment.getDatabaseNames().isEmpty();
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    Database versionDb = null;
    try
    {
        versionDb = _environment.openDatabase(null, VERSION_DB_NAME, dbConfig);

        if(versionDb.count() == 0L)
        {

            int sourceVersion = isEmpty ? BDBConfigurationStore.VERSION: identifyOldStoreVersion();
            DatabaseEntry key = new DatabaseEntry();
            IntegerBinding.intToEntry(sourceVersion, key);
            DatabaseEntry value = new DatabaseEntry();
            LongBinding.longToEntry(System.currentTimeMillis(), value);

            versionDb.put(null, key, value);
        }

        int version = getSourceVersion(versionDb);

        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Source message store version is " + version);
        }

        if(version > BDBConfigurationStore.VERSION)
        {
            throw new StoreException("Database version " + version
                                        + " is higher than the most recent known version: "
                                        + BDBConfigurationStore.VERSION);
        }
        performUpgradeFromVersion(version, versionDb);
    }
    finally
    {
        if (versionDb != null)
        {
            versionDb.close();
        }
    }
}