jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r533019 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal: AbstractJournal.java AppendRecord.java DatabaseJournal.java DefaultRecordProducer.java FileJournal.java
Date Fri, 27 Apr 2007 08:49:26 GMT
Author: dpfister
Date: Fri Apr 27 01:49:25 2007
New Revision: 533019

URL: http://svn.apache.org/viewvc?view=rev&rev=533019
Log:
JCR-884 - DatabaseJournal assigns same revision id to different revisions

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DefaultRecordProducer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileJournal.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java?view=diff&rev=533019&r1=533018&r2=533019
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractJournal.java
Fri Apr 27 01:49:25 2007
@@ -272,16 +272,27 @@
     protected abstract void doLock() throws JournalException;
 
     /**
-     * Append a record backed by a file. Subclass responsibility.
+     * Notification method called by an appended record at creation time.
+     * May be overridden by subclasses to save some context information
+     * inside the appended record.
      *
-     * @param producerId producer identifier
+     * @param record record that was appended
+     */
+    protected void appending(AppendRecord record) {
+        // nothing to be done here
+    }
+
+    /**
+     * Append a record backed by a file. On exit, the new revision must have
+     * been set inside the appended record. Subclass responsibility.
+     *
+     * @param record record to append
      * @param in input stream
      * @param length number of bytes in input stream
-     * @return the new record's revision
      *
      * @throws JournalException if an error occurs
      */
-    protected abstract long append(String producerId, InputStream in, int length)
+    protected abstract void append(AppendRecord record, InputStream in, int length)
             throws JournalException;
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java?view=diff&rev=533019&r1=533018&r2=533019
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AppendRecord.java
Fri Apr 27 01:49:25 2007
@@ -138,6 +138,15 @@
     }
 
     /**
+     * Set the revision this record represents.
+     *
+     * @param revision revision
+     */
+    protected void setRevision(long revision) {
+        this.revision = revision;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public void writeByte(int n) throws JournalException {
@@ -239,7 +248,7 @@
             InputStream in = openInput();
 
             try {
-                revision = journal.append(producerId, in, length);
+                journal.append(this, in, length);
                 succeeded = true;
             } finally {
                 try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?view=diff&rev=533019&r1=533018&r2=533019
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
Fri Apr 27 01:49:25 2007
@@ -215,6 +215,11 @@
 
     /**
      * {@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;
@@ -278,22 +283,32 @@
 
     /**
      * {@inheritDoc}
+     * <p/>
+     * Save away the locked revision inside the newly appended record.
      */
-    protected long append(String producerId, InputStream in, int length)
+    protected void appending(AppendRecord record) {
+        record.setRevision(lockedRevision);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * We have already saved away the revision for this record.
+     */
+    protected void append(AppendRecord record, InputStream in, int length)
             throws JournalException {
 
         try {
             try {
                 insertRevisionStmt.clearParameters();
                 insertRevisionStmt.clearWarnings();
-                insertRevisionStmt.setLong(1, lockedRevision);
+                insertRevisionStmt.setLong(1, record.getRevision());
                 insertRevisionStmt.setString(2, getId());
-                insertRevisionStmt.setString(3, producerId);
+                insertRevisionStmt.setString(3, record.getProducerId());
                 insertRevisionStmt.setBinaryStream(4, in, length);
                 insertRevisionStmt.execute();
 
                 con.commit();
-                return lockedRevision;
             } finally {
                 try {
                     con.setAutoCommit(true);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DefaultRecordProducer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DefaultRecordProducer.java?view=diff&rev=533019&r1=533018&r2=533019
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DefaultRecordProducer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DefaultRecordProducer.java
Fri Apr 27 01:49:25 2007
@@ -46,12 +46,13 @@
      * {@inheritDoc}
      */
     public Record append() throws JournalException {
-        Record record = null;
+        AppendRecord record = null;
 
         journal.lockAndSync();
 
         try {
             record = createRecord();
+            journal.appending(record);
             return record;
         } finally {
             if (record == null) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileJournal.java?view=diff&rev=533019&r1=533018&r2=533019
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileJournal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileJournal.java
Fri Apr 27 01:49:25 2007
@@ -169,7 +169,7 @@
     /**
      * {@inheritDoc}
      */
-    protected long append(String producerId, InputStream in, int length)
+    protected void append(AppendRecord record, InputStream in, int length)
             throws JournalException {
 
         try {
@@ -181,9 +181,10 @@
             if (recordLog.isNew()) {
                 recordLog.init(globalRevision.get());
             }
-            long revision = recordLog.append(getId(), producerId, in, length);
+            long revision = recordLog.append(getId(),
+                    record.getProducerId(), in, length);
             globalRevision.set(revision);
-            return revision;
+            record.setRevision(revision);
 
         } catch (IOException e) {
             String msg = "Unable to append new record to journal '" + journalFile + "'.";



Mime
View raw message