/**
   * {@inheritDoc}
   *
   * <p>This journal is locked by incrementing the current value in the table named <code>
   * GLOBAL_REVISION</code>, which effectively write-locks this table. The updated value is then
   * saved away and remembered in the appended record, because a save may entail multiple appends
   * (JCR-884).
   */
  protected void doLock() throws JournalException {
    ResultSet rs = null;
    boolean succeeded = false;

    try {
      startBatch();
    } catch (SQLException e) {
      throw new JournalException("Unable to set autocommit to false.", e);
    }

    try {
      conHelper.exec(updateGlobalStmtSQL);
      rs = conHelper.exec(selectGlobalStmtSQL, null, false, 0);
      if (!rs.next()) {
        throw new JournalException("No revision available.");
      }
      lockedRevision = rs.getLong(1);
      succeeded = true;
    } catch (SQLException e) {
      throw new JournalException("Unable to lock global revision table.", e);
    } finally {
      DbUtility.close(rs);
      if (!succeeded) {
        doUnlock(false);
      }
    }
  }
 /** {@inheritDoc} */
 public RecordIterator getRecords() throws JournalException {
   try {
     return new DatabaseRecordIterator(
         conHelper.exec(selectRevisionsStmtSQL, new Object[] {new Long(Long.MIN_VALUE)}, false, 0),
         getResolver(),
         getNamePathResolver());
   } catch (SQLException e) {
     throw new JournalException("Unable to return record iterator.", e);
   }
 }
  /**
   * {@inheritDoc}
   *
   * <p>We have already saved away the revision for this record.
   */
  protected void append(AppendRecord record, InputStream in, int length) throws JournalException {

    try {
      conHelper.exec(
          insertRevisionStmtSQL,
          record.getRevision(),
          getId(),
          record.getProducerId(),
          new StreamWrapper(in, length));

    } catch (SQLException e) {
      String msg = "Unable to append revision " + lockedRevision + ".";
      throw new JournalException(msg, e);
    }
  }