Ejemplo n.º 1
0
  /**
   * {@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);
      }
    }
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  public void init(String id, NamespaceResolver resolver) throws JournalException {

    super.init(id, resolver);

    init();

    try {
      conHelper = createConnectionHelper(getDataSource());

      // make sure schemaObjectPrefix consists of legal name characters only
      schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);

      // check if schema objects exist and create them if necessary
      if (isSchemaCheckEnabled()) {
        createCheckSchemaOperation().run();
      }

      // Make sure that the LOCAL_REVISIONS table exists (see JCR-1087)
      if (isSchemaCheckEnabled()) {
        checkLocalRevisionSchema();
      }

      buildSQLStatements();
      initInstanceRevisionAndJanitor();
    } catch (Exception e) {
      String msg = "Unable to create connection.";
      throw new JournalException(msg, e);
    }
    log.info("DatabaseJournal initialized.");
  }
Ejemplo n.º 3
0
 private void endBatch(boolean successful) {
   if (--lockLevel == 0) {
     try {
       conHelper.endBatch(successful);
       ;
     } catch (SQLException e) {
       log.error("failed to end batch", e);
     }
   }
 }
Ejemplo n.º 4
0
 /** {@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);
   }
 }
Ejemplo n.º 5
0
  /**
   * {@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);
    }
  }
Ejemplo n.º 6
0
 private void startBatch() throws SQLException {
   if (lockLevel++ == 0) {
     conHelper.startBatch();
   }
 }