jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r703476 - in /jackrabbit/sandbox/jackrabbit-journalwalker: ./ src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java
Date Fri, 10 Oct 2008 13:41:45 GMT
Author: dpfister
Date: Fri Oct 10 06:41:44 2008
New Revision: 703476

URL: http://svn.apache.org/viewvc?rev=703476&view=rev
Log:
Allow walking a journal record log alone.

Modified:
    jackrabbit/sandbox/jackrabbit-journalwalker/   (props changed)
    jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java

Propchange: jackrabbit/sandbox/jackrabbit-journalwalker/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 10 06:41:44 2008
@@ -0,0 +1,13 @@
+
+target
+*.log
+*.iws
+*.ipr
+*.iml
+junit*.properties
+.settings
+.classpath
+.project
+*.xml.md5
+*-pom-snapshot-version
+.checkstyle

Modified: jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java?rev=703476&r1=703475&r2=703476&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java
(original)
+++ jackrabbit/sandbox/jackrabbit-journalwalker/src/main/java/org/apache/jackrabbit/journalwalker/JournalWalker.java
Fri Oct 10 06:41:44 2008
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.journalwalker;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -35,6 +38,7 @@
 import org.apache.jackrabbit.core.cluster.NamespaceRecord;
 import org.apache.jackrabbit.core.cluster.NodeTypeRecord;
 import org.apache.jackrabbit.core.journal.FileJournal;
+import org.apache.jackrabbit.core.journal.FileRecordLog;
 import org.apache.jackrabbit.core.journal.JournalException;
 import org.apache.jackrabbit.core.journal.Record;
 import org.apache.jackrabbit.core.journal.RecordConsumer;
@@ -44,6 +48,8 @@
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.slf4j.Logger;
@@ -77,6 +83,11 @@
     private String id;
 
     /**
+     * File record log.
+     */
+    private FileRecordLog recordLog;
+
+    /**
      * Revision.
      */
     private long revision;
@@ -100,6 +111,34 @@
     }
 
     /**
+     * Create a new instance of this class.
+     */
+    public JournalWalker(FileRecordLog recordLog, long revision) {
+        this.recordLog = recordLog;
+
+        if (revision == 0) {
+            revision = recordLog.getPreviousRevision();
+        }
+        this.revision = revision;
+    }
+
+    /**
+     * Walk a record log.
+     *
+     * @throws IOException if an I/O error occurs
+     */
+    public void walk() throws IOException {
+        recordLog.seek(revision);
+
+        NamePathResolver npResolver = new DefaultNamePathResolver(this, true);
+        while (revision < recordLog.getLastRevision()) {
+            Record record = recordLog.read(this, npResolver);
+            revision = record.getRevision();
+            consume(record);
+        }
+    }
+
+    /**
      * Log an operation.
      *
      * @param op operation identifier
@@ -110,7 +149,7 @@
         StringBuffer buf = new StringBuffer();
         buf.append(op);
         buf.append("    ");
-        buf.append(workspace);
+        buf.append(workspace != null ? workspace : "version");
         buf.append(':');
         buf.append(lookupPath(id));
         log(buf.toString());
@@ -159,6 +198,10 @@
         return revision;
     }
 
+    /**
+     * Walk
+     */
+
     //--------------------------------------------------- ClusterRecordProcessor
 
     /**
@@ -381,25 +424,63 @@
      * @param args program arguments
      */
     public static void main(String[] args) throws Exception {
-        if (args.length == 0) {
-            System.err.println("args: directory [revision]");
+        boolean noMoreArgs = false;
+        long revision = 0;
+
+        int argc = 0;
+        while (!noMoreArgs && argc < args.length) {
+            String arg = args[argc];
+            if (!arg.startsWith("-")) {
+                break;
+            }
+            argc++;
+            if (arg.length() != 2) {
+                System.err.println("Illegal option: " + arg);
+                System.exit(1);
+                return;
+            }
+            switch (arg.charAt(1)) {
+            case 'r':
+                if (argc == args.length) {
+                    System.err.println("Option -r requires argument.");
+                    System.exit(1);
+                    return;
+                }
+                revision = Long.parseLong(args[argc++]);
+                break;
+            case '-':
+                noMoreArgs = true;
+                break;
+            default:
+                System.err.println("Unknown option: " + arg);
+                System.exit(1);
+                return;
+            }
+        }
+        if (argc == args.length) {
+            System.err.println("args: [ -r revision ] directory | files");
             System.exit(1);
             return;
         }
 
-        FileJournal journal = new FileJournal();
-        journal.setRevision("revision.log");
-        journal.setDirectory(args[0]);
-
-        long revision = 0L;
-
-        if (args.length > 1) {
-            revision = Long.parseLong(args[1]);
-        }
-        JournalWalker walker = new JournalWalker(DEFAULT_PRODUCER, revision);
-        journal.init("", walker);
-        journal.register(walker);
-        journal.sync();
+        while (argc < args.length) {
+            File f = new File(args[argc++]);
+            if (f.isDirectory()) {
+                FileJournal journal = new FileJournal();
+                journal.setRevision("revision.log");
+                journal.setDirectory(args[0]);
+
+                JournalWalker walker = new JournalWalker(DEFAULT_PRODUCER, revision);
+                journal.init("", walker);
+                journal.register(walker);
+                journal.sync();
+            } else if (f.isFile()) {
+                FileRecordLog recordLog = new FileRecordLog(f);
+
+                JournalWalker walker = new JournalWalker(recordLog, revision);
+                walker.walk();
+            }
+        }
     }
 }
 



Mime
View raw message