void storeBlock(long lobId,int seq,long pos,byte[] b,String compressAlgorithm) throws SQLException {
  long block;
  boolean blockExists=false;
  if (compressAlgorithm != null) {
    b=compress.compress(b,compressAlgorithm);
  }
  int hash=Arrays.hashCode(b);
  assertHoldsLock(conn.getSession());
  assertHoldsLock(database);
  block=getHashCacheBlock(hash);
  if (block != -1) {
    String sql="SELECT COMPRESSED, DATA FROM " + LOB_DATA + " WHERE BLOCK = ?";
    PreparedStatement prep=prepare(sql);
    prep.setLong(1,block);
    ResultSet rs=prep.executeQuery();
    if (rs.next()) {
      boolean compressed=rs.getInt(1) != 0;
      byte[] compare=rs.getBytes(2);
      if (compressed == (compressAlgorithm != null) && Arrays.equals(b,compare)) {
        blockExists=true;
      }
    }
    reuse(sql,prep);
  }
  if (!blockExists) {
    block=nextBlock++;
    setHashCacheBlock(hash,block);
    String sql="INSERT INTO " + LOB_DATA + "(BLOCK, COMPRESSED, DATA) VALUES(?, ?, ?)";
    PreparedStatement prep=prepare(sql);
    prep.setLong(1,block);
    prep.setInt(2,compressAlgorithm == null ? 0 : 1);
    prep.setBytes(3,b);
    prep.execute();
    reuse(sql,prep);
  }
  String sql="INSERT INTO " + LOB_MAP + "(LOB, SEQ, POS, HASH, BLOCK) VALUES(?, ?, ?, ?, ?)";
  PreparedStatement prep=prepare(sql);
  prep.setLong(1,lobId);
  prep.setInt(2,seq);
  prep.setLong(3,pos);
  prep.setLong(4,hash);
  prep.setLong(5,block);
  prep.execute();
  reuse(sql,prep);
}

void storeBlock ( long lobId , int seq , long pos , byte [ ] b , String compressAlgorithm ) throws SQLException { long block ; boolean blockExists = false ; if ( compressAlgorithm != null ) { b = compress . compress ( b , compressAlgorithm ) ; } int hash = Arrays . hashCode ( b ) ; assertHoldsLock ( conn . getSession ( ) ) ; assertHoldsLock ( database ) ; block = getHashCacheBlock ( hash ) ; if ( block != - 1 ) { String sql = "SELECT COMPRESSED, DATA FROM " + LOB_DATA + " WHERE BLOCK = ?" ; PreparedStatement prep = prepare ( sql ) ; prep . setLong ( 1 , block ) ; ResultSet rs = prep . executeQuery ( ) ; if ( rs . next ( ) ) { boolean compressed = rs . getInt ( 1 ) != 0 ; byte [ ] compare = rs . getBytes ( 2 ) ; if ( compressed == ( compressAlgorithm != null ) && Arrays . equals ( b , compare ) ) { blockExists = true ; } } reuse ( sql , prep ) ; } if ( ! blockExists ) { block = nextBlock ++ ; setHashCacheBlock ( hash , block ) ; String sql = "INSERT INTO " + LOB_DATA + "(BLOCK, COMPRESSED, DATA) VALUES(?, ?, ?)" ; PreparedStatement prep = prepare ( sql ) ; prep . setLong ( 1 , block ) ; prep . setInt ( 2 , compressAlgorithm == null ? 0 : 1 ) ; prep . setBytes ( 3 , b ) ; prep . execute ( ) ; reuse ( sql , prep ) ; } String sql = "INSERT INTO " + LOB_MAP + "(LOB, SEQ, POS, HASH, BLOCK) VALUES(?, ?, ?, ?, ?)" ; PreparedStatement prep = prepare ( sql ) ; prep . setLong ( 1 , lobId ) ; prep . setInt ( 2 , seq ) ; prep . setLong ( 3 , pos ) ; prep . setLong ( 4 , hash ) ; prep . setLong ( 5 , block ) ; prep . execute ( ) ; reuse ( sql , prep ) ; }
store a block in the lob storage .
