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)");
// stat.execute("SET UNDO_LOG 0");
// stat.execute("SET REDO_LOG_BINARY 0");
stat.execute("CREATE TABLE IF NOT EXISTS "+LOBS+"(ID BIGINT PRIMARY KEY, LENGTH BIGINT, TABLE INT)");
stat.execute("CREATE TABLE IF NOT EXISTS "+LOB_MAP+"(LOB BIGINT, SEQ INT, BLOCK BIGINT, PRIMARY KEY(LOB, SEQ))");
stat.execute("CREATE INDEX INFORMATION_SCHEMA.INDEX_LOB_MAP_DATA_LOB ON "+LOB_MAP+"(BLOCK, LOB)");
stat.execute("CREATE TABLE IF NOT EXISTS "+LOB_DATA+"(BLOCK BIGINT PRIMARY KEY, DATA BINARY)");
ResultSetrs;
rs=stat.executeQuery("select max(id) from block");
rs=stat.executeQuery("SELECT MAX(BLOCK) FROM "+LOB_DATA);
rs.next();
nextBlock=rs.getLong(1)+1;
if(HASH){
nextBlock=Math.max(UNIQUE+1,nextLob);
}
rs=stat.executeQuery("select max(id) from lob");
rs=stat.executeQuery("SELECT MAX(ID) FROM "+LOBS);
rs.next();
nextLob=rs.getLong(1)+1;
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 = ?");
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 <> ?)");