File source = new File(args[0]);
File env = new File(args[1]);
FileUtils.ensureWriteableDirectory(env);
// setup target environment
EnhancedEnvironment targetEnv = PersistProcessor.setupCopyEnvironment(env);
StoredClassCatalog classCatalog = targetEnv.getClassCatalog();
Database historyDB = targetEnv.openDatabase(
null,
PersistProcessor.URI_HISTORY_DBNAME,
PersistProcessor.HISTORY_DB_CONFIG.toDatabaseConfig());
@SuppressWarnings({ "rawtypes", "unchecked" })
StoredSortedMap<String, Object> historyMap = new StoredSortedMap<String, Object>(historyDB,
new StringBinding(), new SerialBinding(classCatalog, Map.class), true);
int count = 0;
if(source.isFile()) {
// scan log, writing to database
BufferedReader br = ArchiveUtils.getBufferedReader(source);
Iterator<String> iter = new LineReadingIterator(br);
while(iter.hasNext()) {
String line = (String) iter.next();
String[] splits = line.split("\\s");
String uri = splits[0];
if(!uri.matches("\\w+:.*")) {
// prepend "http://"
uri = "http://"+uri;
}
String key = PersistProcessor.persistKeyFor(uri);
int precedence = Integer.parseInt(splits[1]);
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>)historyMap.get(key);
if (map==null) {
map = new HashMap<String, Object>();
}
map.put(A_PRECALC_PRECEDENCE, precedence);
historyMap.put(key,map);
count++;
if(count % 100000 == 0) {
System.out.print(count+"... ");
}
}
br.close();
System.out.println();
System.out.println(count+" entries loaded");
} else {
// error
System.err.println("unacceptable source file");
return;
}
// cleanup
historyDB.sync();
historyDB.close();
targetEnv.close();
System.out.println(count+" records imported from "+source+" to BDB env "+env);
}