Search in sources :

Example 6 with EnhancedEnvironment

use of org.archive.util.bdbje.EnhancedEnvironment in project heritrix3 by internetarchive.

the class PersistProcessor method populatePersistEnv.

/**
 * Populates a new environment db from an old environment db or a persist
 * log. If path to new environment is not provided, only logs the entries
 * that would have been populated.
 *
 * @param sourcePath
 *            source of old entries: can be a path to an existing
 *            environment db, or a URL or path to a persist log
 * @param envFile
 *            path to new environment db (or null for a dry run)
 * @return number of records
 * @throws DatabaseException
 * @throws IOException
 */
public static int populatePersistEnv(String sourcePath, File envFile) throws IOException {
    int count = 0;
    StoredSortedMap<String, Map> historyMap = null;
    EnhancedEnvironment targetEnv = null;
    StoredClassCatalog classCatalog = null;
    Database historyDB = null;
    if (envFile != null) {
        // set up target environment
        FileUtils.ensureWriteableDirectory(envFile);
        targetEnv = setupCopyEnvironment(envFile);
        classCatalog = targetEnv.getClassCatalog();
        historyDB = targetEnv.openDatabase(null, URI_HISTORY_DBNAME, HISTORY_DB_CONFIG.toDatabaseConfig());
        historyMap = new StoredSortedMap<String, Map>(historyDB, new StringBinding(), new SerialBinding<Map>(classCatalog, Map.class), true);
    }
    try {
        count = copyPersistSourceToHistoryMap(new File(sourcePath), historyMap);
    } finally {
        // failed to populate it
        if (envFile != null) {
            logger.info(count + " records imported from " + sourcePath + " to BDB env " + envFile);
            historyDB.sync();
            historyDB.close();
            targetEnv.close();
        } else {
            logger.info(count + " records found in " + sourcePath);
        }
    }
    return count;
}
Also used : StringBinding(com.sleepycat.bind.tuple.StringBinding) StoredClassCatalog(com.sleepycat.bind.serial.StoredClassCatalog) Database(com.sleepycat.je.Database) SerialBinding(com.sleepycat.bind.serial.SerialBinding) Map(java.util.Map) StoredSortedMap(com.sleepycat.collections.StoredSortedMap) EnhancedEnvironment(org.archive.util.bdbje.EnhancedEnvironment) File(java.io.File)

Aggregations

EnhancedEnvironment (org.archive.util.bdbje.EnhancedEnvironment)6 StoredClassCatalog (com.sleepycat.bind.serial.StoredClassCatalog)3 StringBinding (com.sleepycat.bind.tuple.StringBinding)3 StoredSortedMap (com.sleepycat.collections.StoredSortedMap)3 Database (com.sleepycat.je.Database)3 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)3 File (java.io.File)3 Map (java.util.Map)3 SerialBinding (com.sleepycat.bind.serial.SerialBinding)2 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 DatabaseException (com.sleepycat.je.DatabaseException)1 DbBackup (com.sleepycat.je.util.DbBackup)1 BufferedReader (java.io.BufferedReader)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 BdbModule (org.archive.bdb.BdbModule)1 Checkpoint (org.archive.checkpointing.Checkpoint)1 LineReadingIterator (org.archive.util.iterator.LineReadingIterator)1 JSONObject (org.json.JSONObject)1