db.createTable(TABLE_DDL);
db.createIndex(INDEX_DDL);
db.commit();
SecureRandom rnd = new SecureRandom();
ISqlJetTable table = db.getTable("tiles");
for (int i = 0; i < INSERTS_COUNT; i++) {
byte[] blob = new byte[1024 + rnd.nextInt(4096)];
rnd.nextBytes(blob);
int x = rnd.nextInt(2048);
int y = 0;
int zoom = 10;
db.beginTransaction(SqlJetTransactionMode.WRITE);
try {
table.insert(x, y, zoom, 0, blob);
} catch (SqlJetException e) {
if (SqlJetErrorCode.CONSTRAINT.equals(e.getErrorCode())) {
// insert failed because record already exists -> update
// it
Object[] key = new Object[] { x, y, zoom, 0 };
ISqlJetCursor updateCursor = table.lookup("IND", key);
do {
updateCursor.update(x, y, zoom, 0, blob);
} while (updateCursor.next());
updateCursor.close();