Java Code Examples for com.sleepycat.je.Database#count()

The following examples show how to use com.sleepycat.je.Database#count() . 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: CursorOperation.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void run(final Database sourceDatabase, final Database targetDatabase, final Transaction transaction)
{
    _rowCount = sourceDatabase.count();
    _template = new CursorTemplate(sourceDatabase, transaction, new DatabaseEntryCallback()
    {
        @Override
        public void processEntry(final Database database, final Transaction transaction, final DatabaseEntry key,
                final DatabaseEntry value)
        {
            _processedRowCount++;
            CursorOperation.this.processEntry(database, targetDatabase, transaction, key, value);
            if (getProcessedCount() % 1000 == 0)
            {
                LOGGER.info("Processed " + getProcessedCount() + " records of " + getRowCount() + ".");
            }
        }

    });
    _template.processEntries();
}
 
Example 2
Source File: UpgradeFrom6To7.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
{
    reportStarting(environment, 6);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);

    if(versionDb.count() == 0L)
    {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
        ByteBinding.byteToEntry((byte) 0, key);
        OperationStatus status = versionDb.put(null, key, value);
        if (status != OperationStatus.SUCCESS)
        {
            throw new StoreException("Error initialising config version: " + status);
        }
    }

    versionDb.close();

    reportFinished(environment, 7);
}
 
Example 3
Source File: AbstractStoreUpgrade.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private long getRowCount(String databaseName, Environment environment)
{
    DatabaseCallable<Long> operation = new DatabaseCallable<Long>()
    {
        @Override
        public Long call(Database sourceDatabase, Database targetDatabase, Transaction transaction)
        {
            return sourceDatabase.count();
        }
    };
    return new DatabaseTemplate(environment, databaseName, null).call(operation);
}
 
Example 4
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();
        }
    }
}