stat.execute("create table if not exists block(id bigint primary key, next bigint, data binary)");
stat.execute("create table if not exists lob(id bigint primary key, length bigint, block bigint, table int)");
stat.execute("create table if not exists lob(id bigint primary key, length bigint, table int)");
stat.execute("create table if not exists map(lob bigint, seq int, block bigint, primary key(lob, seq))");
stat.execute("create index idx_map_block on map(block, lob)");
stat.execute("create table if not exists block(id bigint primary key, data binary)");
ResultSetrs;
rs=stat.executeQuery("select max(id) from block");
rs.next();
nextBlock=rs.getLong(1)+1;
if(HASH){
nextBlock=Math.max(UNIQUE+1,nextLob);
}
rs=stat.executeQuery("select max(id) from lob");
rs.next();
nextLob=rs.getLong(1)+1;
prepInsertBlock=conn.prepareStatement("insert into block(id, next, data) values(?, ?, ?)");
prepDeleteBlock=conn.prepareStatement("delete from block where id = ?");
prepInsertLob=conn.prepareStatement("insert into lob(id, length, table) values(?, ?, ?)");
prepInsertMap=conn.prepareStatement("insert into map(lob, seq, block) values(?, ?, ?)");
prepInsertBlock=conn.prepareStatement("insert into block(id, data) values(?, ?)");
prepSelectMapBlock=conn.prepareStatement("select data from map m inner join block b on m.block = b.id where m.lob = ? and m.seq = ?");
prepSelectBlock=conn.prepareStatement("select data from block where id = ?");
prepDeleteLob=conn.prepareStatement("delete from lob where id = ?");
prepInsertLob=conn.prepareStatement("insert into lob(id, length, block, table) values(?, ?, ?, ?)");
prepSelectBlock=conn.prepareStatement("select id, next, data from block where id = ?");
prepDeleteMap=conn.prepareStatement("delete from map where lob = ?");
prepDeleteBlockUnused=conn.prepareStatement("delete from block where id in(select block from map where lob = ?) and not exists(select 1 from map where block = id and lob <> ?)");
}
privatevoiddeleteLob(intlobId){
//
privatevoiddeleteLob(longlob)throwsSQLException{
// delete from map where lob = ?
prepDeleteMap.setLong(1,lob);
prepDeleteMap.execute();
// delete from block where id in(select block from map where lob = ?)
// and not exists(select 1 from map where block = id and lob <> ?)