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/11/21 14:17:18 UTC
svn commit: r719573 - in /jackrabbit/branches/1.5: ./
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/
jackrabbit-core/src/main/java/org/apache/jackrabbi...
Author: jukka
Date: Fri Nov 21 05:17:17 2008
New Revision: 719573
URL: http://svn.apache.org/viewvc?rev=719573&view=rev
Log:
1.5: Merged revisions 718566, 718632 and 718981 (JCR-1852, JCR-1864 and JCR-1866)
Added:
jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
- copied unchanged from r718632, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/DataStoreTest.java
Removed:
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbResources.java
Modified:
jackrabbit/branches/1.5/ (props changed)
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/persistence/bundle/util/ConnectionRecoveryManager.java
jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
jackrabbit/branches/1.5/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
Propchange: jackrabbit/branches/1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 21 05:17:17 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,708598,708609,708613,708619,708634,708840,708863,708909,708929,708943,709115,709142,709207,709211,710047,711238,711566-711567,711595,711841-711843,712984-712985,713037,713059,713065,713072,713076,713162,713214,713956,713958,713964,713971,713975,714034,718218,718249-718250,718371,718376
+/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,708634,708840,708863,708909,708929,708943,709115,709142,709207,709211,710047,711238,711566-711567,711595,711841-711843,712984-712985,713037,713059,713065,713072,713076,713162,713214,713956,713958,713964,713971,713975,714034,718218,718249-718250,718371,718376,718566,718632,718981
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=719573&r1=719572&r2=719573&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 Fri Nov 21 05:17:17 2008
@@ -485,18 +485,17 @@
putBack(conn);
}
}
-
+
/**
- * getDatabaseResources() does NOT close the DB resources on success. It's up to the client of
- * the stream backed by these resources to close it and therefore close the DB resources.
- *
+ * Open the input stream. This method sets those fields of the caller
+ * that need to be closed once the input stream is read.
+ *
+ * @param inputStream the database input stream object
* @param identifier data identifier
- * @return database resources that will back the stream corresponding
- * to the passed data identifier
- * @throws DataStoreException if the data store could not be accessed,
- * or if the given identifier is invalid
- */
- public DbResources getDatabaseResources(DataIdentifier identifier) throws DataStoreException {
+ * @throws DataStoreException if the data store could not be accessed,
+ * or if the given identifier is invalid
+ */
+ InputStream openStream(DbInputStream inputStream, DataIdentifier identifier) throws DataStoreException {
ConnectionRecoveryManager conn = null;
ResultSet rs = null;
try {
@@ -508,32 +507,29 @@
throw new DataStoreException("Record not found: " + identifier);
}
InputStream stream = rs.getBinaryStream(2);
- DbResources dbResource = null;
if (stream == null) {
- // If the stream is null, go ahead and close resources
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 {
stream = new BufferedInputStream(stream);
- dbResource = new DbResources(conn, rs, stream, this);
+ inputStream.setConnection(conn);
+ inputStream.setResultSet(rs);
}
- return dbResource;
+ return stream;
} catch (Exception e) {
DatabaseHelper.closeSilently(rs);
putBack(conn);
- throw convert("Retrieving database resources ", e);
+ throw convert("Retrieving database resource ", e);
}
}
-
+
/**
* {@inheritDoc}
*/
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=719573&r1=719572&r2=719573&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 Fri Nov 21 05:17:17 2008
@@ -16,27 +16,35 @@
*/
package org.apache.jackrabbit.core.data.db;
-import java.io.FilterInputStream;
+import java.io.EOFException;
import java.io.IOException;
+import java.io.InputStream;
+import java.sql.ResultSet;
+
import org.apache.jackrabbit.core.data.DataIdentifier;
import org.apache.jackrabbit.core.data.DataStoreException;
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionRecoveryManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * This class represents an input stream backed by a database. It allows the stream to be used by
- * keeping the DB resources open until the stream is closed. When the stream is finished or
- * close()d, then the resources are freed.
+ * This class represents an input stream backed by a database. It allows the
+ * stream to be used by keeping the database objects open until the stream is
+ * closed. When the stream is finished or closed, then the database objects are
+ * freed.
*/
-public class DbInputStream extends FilterInputStream {
+public class DbInputStream extends InputStream {
private static Logger log = LoggerFactory.getLogger(DbInputStream.class);
- protected DbResources resources;
- protected boolean streamFinished;
- protected boolean streamClosed;
protected DbDataStore store;
protected DataIdentifier identifier;
+ protected boolean endOfStream;
+ protected InputStream in;
+
+ protected ConnectionRecoveryManager conn;
+ protected ResultSet rs;
+
/**
* Create a database input stream for the given identifier.
@@ -46,39 +54,42 @@
* @param identifier the data identifier
*/
protected DbInputStream(DbDataStore store, DataIdentifier identifier) {
- super(null);
- streamFinished = false;
- streamClosed = true;
this.store = store;
this.identifier = identifier;
}
- private void getStream() throws IOException {
- try {
- resources = store.getDatabaseResources(identifier);
- in = resources.getInputStream();
- streamClosed = false;
- } catch (DataStoreException e) {
- IOException e2 = new IOException(e.getMessage());
- e2.initCause(e);
- throw e2;
+ /**
+ * Open the stream if required.
+ *
+ * @throws IOException
+ */
+ protected void openStream() throws IOException {
+ if (endOfStream) {
+ throw new EOFException();
+ }
+ if (in == null) {
+ try {
+ in = store.openStream(this, identifier);
+ } catch (DataStoreException e) {
+ IOException e2 = new IOException(e.getMessage());
+ e2.initCause(e);
+ throw e2;
+ }
}
}
/**
* {@inheritDoc}
- * When the stream is consumed, the database resources held by the instance are closed.
+ * When the stream is consumed, the database objects held by the instance are closed.
*/
public int read() throws IOException {
- if (streamFinished) {
+ if (endOfStream) {
return -1;
}
- if (in == null) {
- getStream();
- }
+ openStream();
int c = in.read();
if (c == -1) {
- streamFinished = true;
+ endOfStream = true;
close();
}
return c;
@@ -86,7 +97,7 @@
/**
* {@inheritDoc}
- * When the stream is consumed, the database resources held by the instance are closed.
+ * When the stream is consumed, the database objects held by the instance are closed.
*/
public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
@@ -94,18 +105,16 @@
/**
* {@inheritDoc}
- * When the stream is consumed, the database resources held by the instance are closed.
+ * When the stream is consumed, the database objects held by the instance are closed.
*/
public int read(byte[] b, int off, int len) throws IOException {
- if (streamFinished) {
+ if (endOfStream) {
return -1;
}
- if (in == null) {
- getStream();
- }
+ openStream();
int c = in.read(b, off, len);
if (c == -1) {
- streamFinished = true;
+ endOfStream = true;
close();
}
return c;
@@ -113,19 +122,24 @@
/**
* {@inheritDoc}
- * When the stream is consumed, the database resources held by the instance are closed.
+ * When the stream is consumed, the database objects held by the instance are closed.
*/
public void close() throws IOException {
- if (!streamClosed) {
- streamClosed = true;
- // It may be null (see constructor)
- if (in != null) {
- in.close();
- super.close();
+ if (in != null) {
+ in.close();
+ in = null;
+ // some additional database objects
+ // may need to be closed
+ if (rs != null) {
+ DatabaseHelper.closeSilently(rs);
+ rs = null;
}
- // resources may be null (if getStream() was not called)
- if (resources != null) {
- resources.close();
+ if (conn != null) {
+ try {
+ store.putBack(conn);
+ } catch (DataStoreException e) {
+ log.info("Error closing DbResource", e);
+ }
}
}
}
@@ -134,9 +148,10 @@
* {@inheritDoc}
*/
public long skip(long n) throws IOException {
- if (in == null) {
- getStream();
- }
+ if (endOfStream) {
+ return -1;
+ }
+ openStream();
return in.skip(n);
}
@@ -144,9 +159,10 @@
* {@inheritDoc}
*/
public int available() throws IOException {
- if (in == null) {
- getStream();
- }
+ if (endOfStream) {
+ return 0;
+ }
+ openStream();
return in.available();
}
@@ -154,12 +170,13 @@
* {@inheritDoc}
*/
public void mark(int readlimit) {
- if (in == null) {
- try {
- getStream();
- } catch (IOException e) {
- log.info("Error getting underlying stream: ", e);
- }
+ if (endOfStream) {
+ return;
+ }
+ try {
+ openStream();
+ } catch (IOException e) {
+ log.info("Error getting underlying stream: ", e);
}
in.mark(readlimit);
}
@@ -168,9 +185,10 @@
* {@inheritDoc}
*/
public void reset() throws IOException {
- if (in == null) {
- getStream();
- }
+ if (endOfStream) {
+ throw new EOFException();
+ }
+ openStream();
in.reset();
}
@@ -178,14 +196,36 @@
* {@inheritDoc}
*/
public boolean markSupported() {
- if (in == null) {
- try {
- getStream();
- } catch (IOException e) {
- log.info("Error getting underlying stream: ", e);
- return false;
- }
+ if (endOfStream) {
+ return false;
+ }
+ try {
+ openStream();
+ } catch (IOException e) {
+ log.info("Error getting underlying stream: ", e);
+ return false;
}
return in.markSupported();
}
+
+ /**
+ * Set the database connection of this input stream. This object must be
+ * closed once the stream is closed.
+ *
+ * @param conn the connection
+ */
+ void setConnection(ConnectionRecoveryManager conn) {
+ this.conn = conn;
+ }
+
+ /**
+ * Set the result set of this input stream. This object must be closed once
+ * the stream is closed.
+ *
+ * @param rs the result set
+ */
+ void setResultSet(ResultSet rs) {
+ this.rs = rs;
+ }
+
}
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java?rev=719573&r1=719572&r2=719573&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java Fri Nov 21 05:17:17 2008
@@ -479,13 +479,4 @@
}
}
- public void closeSilently(ResultSet rs) {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- // ignore
- }
- }
- }
}
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java?rev=719573&r1=719572&r2=719573&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java Fri Nov 21 05:17:17 2008
@@ -471,7 +471,7 @@
return next();
}
} else {
- return true;
+ return false;
}
}
Modified: jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=719573&r1=719572&r2=719573&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java Fri Nov 21 05:17:17 2008
@@ -32,6 +32,7 @@
*/
public static Test suite() {
TestSuite suite = new TestSuite("Data tests");
+ suite.addTestSuite(DataStoreTest.class);
suite.addTestSuite(NodeTypeTest.class);
suite.addTestSuite(ExportImportTest.class);
suite.addTestSuite(GarbageCollectorTest.class);
Modified: jackrabbit/branches/1.5/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java?rev=719573&r1=719572&r2=719573&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java (original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/xml/Exporter.java Fri Nov 21 05:17:17 2008
@@ -61,7 +61,7 @@
private final AttributesImpl attributes = new AttributesImpl();
/**
- * Stack of namespace mappings.
+ * Stack of namespace mappings.
*/
private final LinkedList stack = new LinkedList();
@@ -158,7 +158,7 @@
* the abstract property export methods so the subclass can decide what
* SAX events to emit for each exported item.
*
- * @param uri node namespace, or <code>null</code>
+ * @param uri node namespace
* @param local node name
* @param node node
* @throws RepositoryException if a repository error occurs
@@ -171,7 +171,7 @@
* Called by {@link #processProperties(Node)} to process a single-valued
* property.
*
- * @param uri property namespace, or <code>null</code>
+ * @param uri property namespace
* @param local property name
* @param value property value
* @throws RepositoryException if a repository error occurs
@@ -185,7 +185,7 @@
* Called by {@link #processProperties(Node)} to process a multivalued
* property.
*
- * @param uri property namespace, or <code>null</code>
+ * @param uri property namespace
* @param local property name
* @param type property type
* @param value property values
@@ -292,7 +292,7 @@
String name = node.getName();
int colon = name.indexOf(':');
if (colon == -1) {
- exportNode(null, name, node);
+ exportNode("", name, node);
} else {
String uri = session.getNamespaceURI(name.substring(0, colon));
exportNode(uri, name.substring(colon + 1), node);
@@ -348,7 +348,7 @@
*/
private void exportProperty(String name, Property property)
throws RepositoryException, SAXException {
- String uri = null;
+ String uri = "";
String local = name;
int colon = name.indexOf(':');
if (colon != -1) {
@@ -468,14 +468,14 @@
* it is created based on the namespace mappings of the current JCR
* session.
*
- * @param uri namespace URI, or <code>null</code>
+ * @param uri namespace URI
* @param local local name
* @return prefixed XML name
* @throws RepositoryException if a JCR namespace mapping is not available
*/
protected String getXMLName(String uri, String local)
throws RepositoryException {
- if (uri == null) {
+ if (uri.length() == 0) {
return local;
} else {
String prefix = getPrefix(uri);