You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2008/10/02 14:33:36 UTC
svn commit: r701106 - in /jackrabbit/trunk/jackrabbit-core/src:
main/java/org/apache/jackrabbit/core/cluster/
main/java/org/apache/jackrabbit/core/journal/
test/java/org/apache/jackrabbit/core/journal/
Author: dpfister
Date: Thu Oct 2 05:33:36 2008
New Revision: 701106
URL: http://svn.apache.org/viewvc?rev=701106&view=rev
Log:
JCR-904 - non mantatory revision property in the Journal configuration
Added:
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
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/FileJournal.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=701106&r1=701105&r2=701106&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java Thu Oct 2 05:33:36 2008
@@ -23,6 +23,7 @@
import org.apache.jackrabbit.core.config.ConfigurationException;
import org.apache.jackrabbit.core.config.JournalConfig;
import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.journal.AbstractJournal;
import org.apache.jackrabbit.core.journal.Journal;
import org.apache.jackrabbit.core.journal.RecordConsumer;
import org.apache.jackrabbit.core.journal.Record;
@@ -46,10 +47,7 @@
import javax.jcr.Session;
import javax.jcr.observation.Event;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
@@ -71,13 +69,10 @@
*/
public static final String SYSTEM_PROPERTY_NODE_ID = "org.apache.jackrabbit.core.cluster.node_id";
- /** Cluster node id file. */
- private static final String CLUSTER_NODE_ID_FILE = "cluster_node.id";
-
/**
- * Used for padding short string representations.
+ * Cluster node id file.
*/
- private static final String SHORT_PADDING = "0000";
+ private static final String CLUSTER_NODE_ID_FILE = "cluster_node.id";
/**
* Producer identifier.
@@ -228,6 +223,7 @@
try {
JournalConfig jc = cc.getJournalConfig();
journal = (Journal) jc.newInstance();
+ setRepositoryHome(journal, clusterContext.getRepositoryHome());
journal.init(clusterNodeId, clusterContext.getNamespaceResolver());
instanceRevision = journal.getInstanceRevision();
journal.register(this);
@@ -239,6 +235,20 @@
}
/**
+ * Set a journal's repository home, if possible, i.e. if it is an
+ * <code>AbstractJournal</code>
+ *
+ * @param journal journal instance
+ * @param repHome repository home
+ */
+ private void setRepositoryHome(Journal journal, File repHome) {
+ if (journal instanceof AbstractJournal) {
+ AbstractJournal aj = (AbstractJournal) journal;
+ aj.setRepositoryHome(repHome);
+ }
+ }
+
+ /**
* Starts this cluster node.
*
* @throws ClusterException if an error occurs
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?rev=701106&r1=701105&r2=701106&view=diff
==============================================================================
--- 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 Thu Oct 2 05:33:36 2008
@@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
@@ -72,7 +73,7 @@
/**
* The path of the local revision file on disk. Configurable through the repository.xml.
- *
+ *
* Note: this field is not located in the FileJournal class for upgrade reasons (before
* JCR-1087 had been fixed all Journals used a revision file on the local file system.
* Also see {@link DatabaseJournal#initInstanceRevisionAndJanitor()}).
@@ -80,6 +81,11 @@
private String revision;
/**
+ * Repository home.
+ */
+ private File repHome;
+
+ /**
* {@inheritDoc}
*/
public void init(String id, NamespaceResolver resolver) throws JournalException {
@@ -345,11 +351,31 @@
public NamePathResolver getNamePathResolver() {
return npResolver;
}
-
+
+ /**
+ * Set the repository home.
+ *
+ * @param repHome repository home
+ * @since JR 1.5
+ */
+ public void setRepositoryHome(File repHome) {
+ this.repHome = repHome;
+ }
+
+ /**
+ * Return the repository home.
+ *
+ * @return the repository home
+ * @since JR 1.5
+ */
+ public File getRepositoryHome() {
+ return repHome;
+ }
+
/*
* Bean getters and setters.
- */
-
+ */
+
/**
* @return the path of the cluster node's local revision file
*/
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?rev=701106&r1=701105&r2=701106&view=diff
==============================================================================
--- 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 Thu Oct 2 05:33:36 2008
@@ -42,6 +42,11 @@
public class FileJournal extends AbstractJournal {
/**
+ * Default instance revision file name.
+ */
+ public static final String DEFAULT_INSTANCE_FILE_NAME = "revision.log";
+
+ /**
* Global revision counter name, located in the journal directory.
*/
private static final String REVISION_NAME = "revision";
@@ -103,8 +108,14 @@
super.init(id, resolver);
if (getRevision() == null) {
- String msg = "Revision not specified.";
- throw new JournalException(msg);
+ File repHome = getRepositoryHome();
+ if (repHome == null) {
+ String msg = "Revision not specified.";
+ throw new JournalException(msg);
+ }
+ String revision = new File(repHome, DEFAULT_INSTANCE_FILE_NAME).getPath();
+ log.info("Revision not specified, using: " + revision);
+ setRevision(revision);
}
if (directory == null) {
String msg = "Directory not specified.";
@@ -156,7 +167,7 @@
files[i] = logFiles[i].getFile();
}
}
- return new FileRecordIterator(files, startRevision, stopRevision,
+ return new FileRecordIterator(files, startRevision, stopRevision,
getResolver(), getNamePathResolver());
}
Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java?rev=701106&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java Thu Oct 2 05:33:36 2008
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.journal;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.cluster.ClusterNode;
+import org.apache.jackrabbit.core.cluster.SimpleClusterContext;
+import org.apache.jackrabbit.core.config.BeanConfig;
+import org.apache.jackrabbit.core.config.ClusterConfig;
+import org.apache.jackrabbit.core.config.JournalConfig;
+import org.apache.jackrabbit.test.JUnitTest;
+
+/**
+ * Test cases for file journal.
+ */
+public class FileJournalTest extends JUnitTest {
+
+ /**
+ * Repository home value.
+ */
+ private static final String REPOSITORY_HOME = "target/repository_for_test";
+
+ /**
+ * Repository home.
+ */
+ private File repositoryHome;
+
+ /**
+ * Journal directory.
+ */
+ private File journalDirectory;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception {
+ repositoryHome = new File(REPOSITORY_HOME);
+ repositoryHome.mkdirs();
+ FileUtils.cleanDirectory(repositoryHome);
+ journalDirectory = new File(repositoryHome, "journal");
+
+ super.setUp();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void tearDown() throws Exception {
+ if (repositoryHome != null) {
+ FileUtils.deleteDirectory(repositoryHome);
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Create a journal with no revision file name. Verify that the journal
+ * is created nonetheless, with a revision file in the repository home.
+ *
+ * @throws Exception
+ * @see http://issues.apache.org/jira/browse/JCR-904
+ */
+ public void testRevisionIsOptional() throws Exception {
+ Properties params = new Properties();
+ params.setProperty("directory", journalDirectory.getPath());
+
+ BeanConfig bc = new BeanConfig(FileJournal.class.getName(), params);
+ JournalConfig jc = new JournalConfig(bc);
+
+ ClusterConfig cc = new ClusterConfig(null, 0, jc);
+ SimpleClusterContext context = new SimpleClusterContext(cc, repositoryHome);
+
+ ClusterNode clusterNode = new ClusterNode();
+ clusterNode.init(context);
+
+ File revisionFile = new File(repositoryHome, FileJournal.DEFAULT_INSTANCE_FILE_NAME);
+ assertTrue(revisionFile.exists());
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/journal/FileJournalTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev Url