You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2008/10/28 18:57:21 UTC
svn commit: r708622 - in /jackrabbit/branches/1.5: ./
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/
Author: jukka
Date: Tue Oct 28 10:57:20 2008
New Revision: 708622
URL: http://svn.apache.org/viewvc?rev=708622&view=rev
Log:
1.5: Merged revisions 708598, 709609 and 709619 (JCR-1825 and JCR-1813). Ignored revision 708613.
Modified:
jackrabbit/branches/1.5/ (props changed)
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbInputStream.java
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
Propchange: jackrabbit/branches/1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Oct 28 10:57:20 2008
@@ -1,2 +1,2 @@
/jackrabbit/branches/1.3:631261
-/jackrabbit/trunk:703899-704158,704165,704167,704324,704358,704361,704864,704933,704939,705010,705033,705243,705496,705522,705579,705925,705932,705934,705937-705938,705961,706242,706273,706285-706286,706562,706606,706649,706655,706660,706697,706918,707303-707304,707307,707310,707630,708206
+/jackrabbit/trunk:703899-704158,704165,704167,704324,704358,704361,704864,704933,704939,705010,705033,705243,705496,705522,705579,705925,705932,705934,705937-705938,705961,706242,706273,706285-706286,706562,706606,706649,706655,706660,706697,706918,707303-707304,707307,707310,707630,708206,708598,708609,708613,708619
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java?rev=708622&r1=708621&r2=708622&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java Tue Oct 28 10:57:20 2008
@@ -55,9 +55,21 @@
clusterRecord = new NodeTypeRecord(record);
clusterRecord.read();
break;
+ case ClusterRecord.END_MARKER:
+ // JCR-1813: Invalid journal records during XATransactions
+ // Some journal records may be empty due to JCR-1813 and other
+ // issues. We handle such cases with this dummy sentinel record.
+ clusterRecord = new ClusterRecord(record) {
+ protected void doRead() {
+ }
+ protected void doWrite() {
+ }
+ public void process(ClusterRecordProcessor processor) {
+ }
+ };
+ break;
default:
- String msg = "Unknown record identifier: " + c;
- throw new JournalException(msg);
+ throw new JournalException("Unknown record identifier: " + c);
}
return clusterRecord;
}
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=708622&r1=708621&r2=708622&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java Tue Oct 28 10:57:20 2008
@@ -62,7 +62,7 @@
* <param name="{@link #setDriver(String) driver}" value="org.postgresql.Driver"/>
* <param name="{@link #setMinRecordLength(int) minRecordLength}" value="1024"/>
* <param name="{@link #setMaxConnections(int) maxConnections}" value="2"/>
- * <param name="{@link #setCopyWhenReading(int) copyWhenReading}" value="true"/>
+ * <param name="{@link #setCopyWhenReading(boolean) copyWhenReading}" value="true"/>
* <param name="{@link #setTablePrefix(int) tablePrefix}" value=""/>
* </DataStore>
* </pre>
@@ -93,24 +93,45 @@
public class DbDataStore implements DataStore {
/**
- * The digest algorithm used to uniquely identify records.
+ * The default value for the minimum object size.
*/
- protected static final String DIGEST = "SHA-1";
+ public static final int DEFAULT_MIN_RECORD_LENGTH = 100;
/**
- * Logger instance
+ * The default value for the maximum connections.
*/
- private static Logger log = LoggerFactory.getLogger(DbDataStore.class);
+ public static final int DEFAULT_MAX_CONNECTIONS = 3;
+
+ /**
+ * Write to a temporary file to get the length (slow, but always works).
+ * This is the default setting.
+ */
+ public static final String STORE_TEMP_FILE = "tempFile";
/**
- * The default value for the minimum object size.
+ * Call PreparedStatement.setBinaryStream(..., -1)
*/
- public static final int DEFAULT_MIN_RECORD_LENGTH = 100;
+ public static final String STORE_SIZE_MINUS_ONE = "-1";
/**
- * The default value for the maximum connections.
+ * Call PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)
*/
- public static final int DEFAULT_MAX_CONNECTIONS = 3;
+ public static final String STORE_SIZE_MAX = "max";
+
+ /**
+ * The digest algorithm used to uniquely identify records.
+ */
+ protected static final String DIGEST = "SHA-1";
+
+ /**
+ * The prefix used for temporary objects.
+ */
+ protected static final String TEMP_PREFIX = "TEMP_";
+
+ /**
+ * Logger instance
+ */
+ private static Logger log = LoggerFactory.getLogger(DbDataStore.class);
/**
* The minimum modified date. If a file is accessed (read or write) with a modified date
@@ -159,11 +180,6 @@
protected Pool connectionPool;
/**
- * The prefix used for temporary objects.
- */
- protected static final String TEMP_PREFIX = "TEMP_";
-
- /**
* The prefix for the datastore table, empty by default.
*/
protected String tablePrefix = "";
@@ -251,26 +267,10 @@
protected String storeStream = STORE_TEMP_FILE;
/**
- * Write to a temporary file to get the length (slow, but always works).
- * This is the default setting.
- */
- public static final String STORE_TEMP_FILE = "tempFile";
-
- /**
- * Call PreparedStatement.setBinaryStream(..., -1)
- */
- public static final String STORE_SIZE_MINUS_ONE = "-1";
-
- /**
- * Call PreparedStatement.setBinaryStream(..., Integer.MAX_VALUE)
- */
- public static final String STORE_SIZE_MAX = "max";
-
- /**
* Copy the stream to a temp file before returning it.
* Enabled by default to support concurrent reads.
*/
- private boolean copyWhenReading = true;
+ protected boolean copyWhenReading = true;
/**
* All data identifiers that are currently in use are in this set until they are garbage collected.
@@ -366,7 +366,7 @@
} catch (Exception e) {
throw convert("Can not insert new record", e);
} finally {
- conn.closeSilently(rs);
+ DatabaseHelper.closeSilently(rs);
putBack(conn);
if (fileInput != null) {
try {
@@ -437,7 +437,7 @@
} catch (Exception e) {
throw convert("Can not read records", e);
} finally {
- conn.closeSilently(rs);
+ DatabaseHelper.closeSilently(rs);
putBack(conn);
}
}
@@ -481,7 +481,7 @@
} catch (Exception e) {
throw convert("Can not read identifier " + identifier, e);
} finally {
- conn.closeSilently(rs);
+ DatabaseHelper.closeSilently(rs);
putBack(conn);
}
}
@@ -507,23 +507,26 @@
if (!rs.next()) {
throw new DataStoreException("Record not found: " + identifier);
}
- InputStream result = null;
InputStream stream = rs.getBinaryStream(2);
+ DbResources dbResource = null;
if (stream == null) {
// If the stream is null, go ahead and close resources
- result = new ByteArrayInputStream(new byte[0]);
+ stream = new ByteArrayInputStream(new byte[0]);
+ dbResource = new DbResources(stream);
+ DatabaseHelper.closeSilently(rs);
+ putBack(conn);
+ } else if (copyWhenReading) {
+ // If we copy while reading, create a temp file and close the stream
+ File temp = moveToTempFile(stream);
+ stream = new TempFileInputStream(temp);
+ dbResource = new DbResources(stream);
DatabaseHelper.closeSilently(rs);
putBack(conn);
} else {
- result = new BufferedInputStream(stream);
- if (copyWhenReading) {
- File temp = moveToTempFile(result);
- result = new TempFileInputStream(temp);
- }
+ stream = new BufferedInputStream(stream);
+ dbResource = new DbResources(conn, rs, stream, this);
}
-
- DbResources dbResources = new DbResources(conn, rs, prep, result, this);
- return dbResources;
+ return dbResource;
} catch (Exception e) {
DatabaseHelper.closeSilently(rs);
putBack(conn);
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbInputStream.java?rev=708622&r1=708621&r2=708622&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbInputStream.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbInputStream.java Tue Oct 28 10:57:20 2008
@@ -39,10 +39,11 @@
protected DataIdentifier identifier;
/**
- * @param in the stream obtained by a call to ResultSet.getBinaryStream().
- * @param con the connection to the DB. It must not be closed.
- * @param rs the result set from wich the stream is obtained. It must not be closed.
- * @param stmt the statemen that produced the result set. It must not be closed.
+ * Create a database input stream for the given identifier.
+ * Database access is delayed until the first byte is read from the stream.
+ *
+ * @param store the database data store
+ * @param identifier the data identifier
*/
protected DbInputStream(DbDataStore store, DataIdentifier identifier) {
super(null);
@@ -88,15 +89,7 @@
* When the stream is consumed, the database resources held by the instance are closed.
*/
public int read(byte[] b) throws IOException {
- if (streamFinished) {
- return -1;
- }
- int c = read(b, 0, b.length);
- if (c == -1) {
- streamFinished = true;
- close();
- }
- return c;
+ return read(b, 0, b.length);
}
/**
@@ -127,6 +120,7 @@
streamClosed = true;
// It may be null (see constructor)
if (in != null) {
+ in.close();
super.close();
}
// resources may be null (if getStream() was not called)
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java?rev=708622&r1=708621&r2=708622&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java Tue Oct 28 10:57:20 2008
@@ -18,7 +18,6 @@
import java.io.InputStream;
import java.sql.ResultSet;
-import java.sql.Statement;
import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionRecoveryManager;
import org.slf4j.Logger;
@@ -33,36 +32,52 @@
protected final ConnectionRecoveryManager conn;
protected final ResultSet rs;
- protected final Statement stmt;
protected final InputStream in;
protected final DbDataStore store;
protected boolean closed;
-
- public DbResources(ConnectionRecoveryManager conn, ResultSet rs, Statement stmt, InputStream in, DbDataStore store) {
+
+ /**
+ * Construct a db resource using the specified input stream.
+ *
+ * @param in the input stream
+ */
+ public DbResources(InputStream in) {
+ this(null, null, in, null);
+ }
+
+ /**
+ * Construct a db resource using the specified connection. The connection
+ * will be returned to the data store once the resource is fully read. If
+ * the connection is null, then this class is just a container for the input
+ * stream. This is to support other kinds of input streams as well.
+ *
+ * @param conn the connection (may be null)
+ * @param rs the result set (may be null)
+ * @param in the input stream
+ * @param store the data store
+ */
+ public DbResources(ConnectionRecoveryManager conn, ResultSet rs, InputStream in, DbDataStore store) {
this.conn = conn;
this.rs = rs;
- this.stmt = stmt;
this.in = in;
this.store = store;
- this.closed = false;
- }
-
- public ConnectionRecoveryManager getConnection() {
- return conn;
+ if (conn == null) {
+ closed = true;
+ }
}
+ /**
+ * Get the input stream.
+ *
+ * @return the input stream
+ */
public InputStream getInputStream() {
return in;
}
- public ResultSet getResultSet() {
- return rs;
- }
-
- public Statement getStatement() {
- return stmt;
- }
-
+ /**
+ * Close the stream, and return the connection to the data store.
+ */
public void close() {
if (!closed) {
closed = true;
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?rev=708622&r1=708621&r2=708622&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java Tue Oct 28 10:57:20 2008
@@ -307,8 +307,11 @@
if (!editMode) {
throw new IllegalStateException("Not in edit mode");
}
- update(changeLog);
- changeLog.reset();
+ // JCR-1813: Only execute the update when there are some changes
+ if (changeLog.hasUpdates()) {
+ update(changeLog);
+ changeLog.reset();
+ }
editMode = false;
}