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;
}
Aggregations