private Data getNextBlock() {
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        try {
            con = DbConnectionManager.getConnection();
            // Get the current ID from the database.
            pstmt = con.prepareStatement(LOAD_ID);
            pstmt.setInt(1, type);
            rs = pstmt.executeQuery();

            long currentID = 1;
            if (rs.next()) {
                currentID = rs.getLong(1);
            }
            else {
                createNewID(con, type);
            }
            DbConnectionManager.fastcloseStmt(rs, pstmt);

            // Increment the id to define our block.
            long newID = currentID + blockSize;
            // The WHERE clause includes the last value of the id. This ensures
            // that an update will occur only if nobody else has performed an
            // update first.
            pstmt = con.prepareStatement(UPDATE_ID);
            pstmt.setLong(1, newID);
            pstmt.setInt(2, type);
            pstmt.setLong(3, currentID);
            // Check to see if the row was affected. If not, some other process
            // already changed the original id that we read. This code should be
            // called under a lock, so this is not supposed to happen. Throw a
            // very verbose error if it does.
            if (pstmt.executeUpdate() == 1) {
                final Data result = new Data(currentID, newID);
                sequenceBlocks.put(type, result);
                return result;
            } else {
                throw new IllegalStateException("Failed at attempt to obtain an ID, aborting...");
            }
        }
        catch (SQLException e) {
            Log.error("An exception occurred while trying to obtain new sequence values from the database for type {}", type, e);
            throw new IllegalStateException("Failed at attempt to obtain an ID, aborting...", e);
        }
        finally {
            DbConnectionManager.closeConnection(rs, pstmt, con);
        }
    }
Performs a lookup to get the next available ID block. The algorithm is as follows:
<ol>
<li> Select currentID from appropriate db row.
<li> Increment id returned from db.
<li> Update db row with new id where id=old_id.
</ol>

Calls to this method should only occur while a lock has already been acquired.

@return the next available ID block
xmppserver/src/main/java/org/jivesoftware/database/SequenceManager.java