deflate(new File(DB_ARCHIVE), DB_FILE_NAME, dbFile1, true);
final SqlJetDb db1 = SqlJetDb.open(dbFile1, false);
final SqlJetDb db2 = SqlJetDb.open(dbFile2, true);
db2.runWriteTransaction(new ISqlJetTransaction() {
public Object run(SqlJetDb db) throws SqlJetException {
db.createTable("create table rep_cache (hash text not null primary key, "
+ " revision integer not null, "
+ " offset integer not null, "
+ " size integer not null, "
+ " expanded_size integer not null); ");
return null;
}
});
db1.runReadTransaction(new ISqlJetTransaction() {
public Object run(SqlJetDb db) throws SqlJetException {
ISqlJetCursor c = null;
final Collection<Object> values = new ArrayList<Object>();
final Collection<Collection<Object>> block = new LinkedList<Collection<Object>>();
try {
c = db.getTable("rep_cache").open();
long currentRev = 0;
while (!c.eof()) {
values.clear();
for (int i = 0; i < c.getFieldsCount(); i++) {
values.add(c.getValue(i));
}
long rev = c.getInteger(1);
if (rev != currentRev) {
db2.runWriteTransaction(new ISqlJetTransaction() {
public Object run(SqlJetDb db) throws SqlJetException {
for (Collection<Object> row : block) {
db2.getTable("rep_cache").insert(row.toArray());
}
return null;
}
});
currentRev = rev;
block.clear();
}
block.add(new ArrayList<Object>(values));
c.next();
}
if (!block.isEmpty()) {
db2.runWriteTransaction(new ISqlJetTransaction() {
public Object run(SqlJetDb db) throws SqlJetException {
for (Collection<Object> row : block) {
db2.getTable("rep_cache").insert(row.toArray());
}
return null;