You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2006/10/26 11:11:20 UTC
svn commit: r467925 [2/6] - in /jackrabbit/trunk/jackrabbit:
applications/test/ applications/test/workspaces/default/
applications/test/workspaces/test/ src/main/config/
src/main/java/org/apache/jackrabbit/core/
src/main/java/org/apache/jackrabbit/core...
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java Thu Oct 26 02:11:18 2006
@@ -0,0 +1,83 @@
+/*
+ * 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.persistence.db;
+
+import org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+/**
+ * Database persistence manager that uses JNDI to acquire the database
+ * connection. The JNDI location of the {@link DataSource} to be used in
+ * given as the <code>dataSourceLocation</code> configuration property.
+ * See the {@link SimpleDbPersistenceManager} for more configuration
+ * details.
+ * <p>
+ * <strong>WARNING:</strong> The acquired database connection is kept
+ * for the entire lifetime of the persistence manager instance. The
+ * configured data source should be prepared for this.
+ */
+public class JNDIDatabasePersistenceManager extends DatabasePersistenceManager {
+
+ /**
+ * JNDI location of the data source used to acquire database connections.
+ */
+ private String dataSourceLocation;
+
+ //----------------------------------------------------< setters & getters >
+
+ /**
+ * Returns the JNDI location of the data source.
+ *
+ * @return data source location
+ */
+ public String getDataSourceLocation() {
+ return dataSourceLocation;
+ }
+
+ /**
+ * Sets the JNDI location of the data source.
+ *
+ * @param dataSourceLocation data source location
+ */
+ public void setDataSourceLocation(String dataSourceLocation) {
+ this.dataSourceLocation = dataSourceLocation;
+ }
+
+ //-------------------------------------------< DatabasePersistenceManager >
+
+ /**
+ * Returns a JDBC connection from a {@link DataSource} acquired from JNDI
+ * with the configured data source location.
+ *
+ * @return new database connection
+ * @throws NamingException if the given data source location does not exist
+ * @throws SQLException if a database access error occurs
+ * @see DatabasePersistenceManager#getConnection()
+ */
+ protected Connection getConnection() throws NamingException, SQLException {
+ InitialContext ic = new InitialContext();
+ DataSource dataSource = (DataSource) ic.lookup(dataSourceLocation);
+ return dataSource.getConnection();
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/JNDIDatabasePersistenceManager.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java Thu Oct 26 02:11:18 2006
@@ -0,0 +1,414 @@
+/*
+ * 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.persistence.db;
+
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.util.Serializer;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ItemState;
+import org.apache.jackrabbit.util.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.lang.reflect.Method;
+import java.sql.Blob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.DatabaseMetaData;
+import java.sql.Statement;
+
+/**
+ * <code>OraclePersistenceManager</code> is a JDBC-based
+ * <code>PersistenceManager</code> for Jackrabbit that persists
+ * <code>ItemState</code> and <code>NodeReferences</code> objects in Oracle
+ * database using a simple custom serialization format and a
+ * very basic non-normalized database schema (in essence tables with one 'key'
+ * and one 'data' column).
+ * <p/>
+ * It is configured through the following properties:
+ * <ul>
+ * <li><code>driver</code>: the FQN name of the JDBC driver class
+ * (default: <code>"oracle.jdbc.OracleDriver"</code>)</li>
+ * <li><code>schema</code>: type of schema to be used
+ * (default: <code>"oracle"</code>)</li>
+ * <li><code>url</code>: the database url (e.g.
+ * <code>"jdbc:oracle:thin:@[host]:[port]:[sid]"</code>)</li>
+ * <li><code>user</code>: the database user</li>
+ * <li><code>password</code>: the user's password</li>
+ * <li><code>schemaObjectPrefix</code>: prefix to be prepended to schema objects</li>
+ * <li><code>externalBLOBs</code>: if <code>true</code> (the default) BINARY
+ * values (BLOBs) are stored in the local file system;
+ * if <code>false</code> BLOBs are stored in the database</li>
+ * </ul>
+ * See also {@link SimpleDbPersistenceManager}.
+ * <p/>
+ * The following is a fragment from a sample configuration:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.OraclePersistenceManager">
+ * <param name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"/>
+ * <param name="user" value="scott"/>
+ * <param name="password" value="tiger"/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ */
+public class OraclePersistenceManager extends SimpleDbPersistenceManager {
+
+ /**
+ * Logger instance
+ */
+ private static Logger log = LoggerFactory.getLogger(OraclePersistenceManager.class);
+
+ private Class blobClass;
+ private Integer DURATION_SESSION_CONSTANT;
+ private Integer MODE_READWRITE_CONSTANT;
+
+ /**
+ * Creates a new <code>OraclePersistenceManager</code> instance.
+ */
+ public OraclePersistenceManager() {
+ // preset some attributes to reasonable defaults
+ schema = "oracle";
+ driver = "oracle.jdbc.OracleDriver";
+ schemaObjectPrefix = "";
+ user = "";
+ password = "";
+ initialized = false;
+ }
+
+ //---------------------------------< SimpleDbPersistenceManager overrides >
+ /**
+ * {@inheritDoc}
+ * <p/>
+ * Retrieve the <code>oracle.sql.BLOB</code> class via reflection, and
+ * initialize the values for the <code>DURATION_SESSION</code> and
+ * <code>MODE_READWRITE</code> constants defined there.
+ * @see oracle.sql.BLOB#DURATION_SESSION
+ * @see oracle.sql.BLOB#MODE_READWRITE
+ */
+ public void init(PMContext context) throws Exception {
+ super.init(context);
+
+ if (!externalBLOBs) {
+ blobStore = new OracleBLOBStore();
+ }
+
+ // initialize oracle.sql.BLOB class & constants
+
+ // use the Connection object for using the exact same
+ // class loader that the Oracle driver was loaded with
+ blobClass = con.getClass().getClassLoader().loadClass("oracle.sql.BLOB");
+ DURATION_SESSION_CONSTANT =
+ new Integer(blobClass.getField("DURATION_SESSION").getInt(null));
+ MODE_READWRITE_CONSTANT =
+ new Integer(blobClass.getField("MODE_READWRITE").getInt(null));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void store(NodeState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // check if insert or update
+ boolean update = state.getStatus() != ItemState.STATUS_NEW;
+ //boolean update = exists((NodeId) state.getId());
+ PreparedStatement stmt = (update) ? nodeStateUpdate : nodeStateInsert;
+
+ Blob blob = null;
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize node state
+ Serializer.serialize(state, out);
+
+ // we are synchronized on this instance, therefore we do not
+ // not have to additionally synchronize on the preparedStatement
+
+ blob = createTemporaryBlob(new ByteArrayInputStream(out.toByteArray()));
+ stmt.setBlob(1, blob);
+ stmt.setString(2, state.getId().toString());
+ stmt.executeUpdate();
+
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to write node state: " + state.getId();
+ log.error(msg, e);
+ throw new ItemStateException(msg, e);
+ } finally {
+ resetStatement(stmt);
+ if (blob != null) {
+ try {
+ freeTemporaryBlob(blob);
+ } catch (Exception e1) {
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void store(PropertyState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // check if insert or update
+ boolean update = state.getStatus() != ItemState.STATUS_NEW;
+ //boolean update = exists((PropertyId) state.getId());
+ PreparedStatement stmt = (update) ? propertyStateUpdate : propertyStateInsert;
+
+ Blob blob = null;
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize property state
+ Serializer.serialize(state, out, blobStore);
+
+ // we are synchronized on this instance, therefore we do not
+ // not have to additionally synchronize on the preparedStatement
+
+ blob = createTemporaryBlob(new ByteArrayInputStream(out.toByteArray()));
+ stmt.setBlob(1, blob);
+ stmt.setString(2, state.getId().toString());
+ stmt.executeUpdate();
+
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to write property state: " + state.getId();
+ log.error(msg, e);
+ throw new ItemStateException(msg, e);
+ } finally {
+ resetStatement(stmt);
+ if (blob != null) {
+ try {
+ freeTemporaryBlob(blob);
+ } catch (Exception e1) {
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void store(NodeReferences refs) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // check if insert or update
+ boolean update = exists(refs.getId());
+ PreparedStatement stmt = (update) ? nodeReferenceUpdate : nodeReferenceInsert;
+
+ Blob blob = null;
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize references
+ Serializer.serialize(refs, out);
+
+ // we are synchronized on this instance, therefore we do not
+ // not have to additionally synchronize on the preparedStatement
+
+ blob = createTemporaryBlob(new ByteArrayInputStream(out.toByteArray()));
+ stmt.setBlob(1, blob);
+ stmt.setString(2, refs.getId().toString());
+ stmt.executeUpdate();
+
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to write node references: " + refs.getId();
+ log.error(msg, e);
+ throw new ItemStateException(msg, e);
+ } finally {
+ resetStatement(stmt);
+ if (blob != null) {
+ try {
+ freeTemporaryBlob(blob);
+ } catch (Exception e1) {
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p/>
+ * Overridden in order to support multiple oracle schemas. Note that
+ * schema names in Oracle correspond to the username of the connection.
+ * See http://issues.apache.org/jira/browse/JCR-582
+ *
+ * @throws Exception if an error occurs
+ */
+ protected void checkSchema() throws Exception {
+ DatabaseMetaData metaData = con.getMetaData();
+ String tableName = schemaObjectPrefix + "NODE";
+ if (metaData.storesLowerCaseIdentifiers()) {
+ tableName = tableName.toLowerCase();
+ } else if (metaData.storesUpperCaseIdentifiers()) {
+ tableName = tableName.toUpperCase();
+ }
+ String userName = metaData.getUserName();
+
+ ResultSet rs = metaData.getTables(null, userName, tableName, null);
+ boolean schemaExists;
+ try {
+ schemaExists = rs.next();
+ } finally {
+ rs.close();
+ }
+
+ if (!schemaExists) {
+ // read ddl from resources
+ InputStream in = getClass().getResourceAsStream(schema + ".ddl");
+ if (in == null) {
+ String msg = "Configuration error: unknown schema '" + schema + "'";
+ log.debug(msg);
+ throw new RepositoryException(msg);
+ }
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ Statement stmt = con.createStatement();
+ try {
+ String sql = reader.readLine();
+ while (sql != null) {
+ // Skip comments and empty lines
+ if (!sql.startsWith("#") && sql.length() > 0) {
+ // replace prefix variable
+ sql = Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);
+ // execute sql stmt
+ stmt.executeUpdate(sql);
+ }
+ // read next sql stmt
+ sql = reader.readLine();
+ }
+ // commit the changes
+ con.commit();
+ } finally {
+ closeStream(in);
+ closeStatement(stmt);
+ }
+ }
+ }
+
+ //----------------------------------------< oracle-specific blob handling >
+ /**
+ * Creates a temporary oracle.sql.BLOB instance via reflection and spools
+ * the contents of the specified stream.
+ */
+ protected Blob createTemporaryBlob(InputStream in) throws Exception {
+ /*
+ BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
+ blob.open(BLOB.MODE_READWRITE);
+ OutputStream out = blob.getBinaryOutputStream();
+ ...
+ out.flush();
+ out.close();
+ blob.close();
+ return blob;
+ */
+ Method createTemporary = blobClass.getMethod("createTemporary",
+ new Class[]{Connection.class, Boolean.TYPE, Integer.TYPE});
+ Object blob = createTemporary.invoke(null,
+ new Object[]{con, Boolean.FALSE, DURATION_SESSION_CONSTANT});
+ Method open = blobClass.getMethod("open", new Class[]{Integer.TYPE});
+ open.invoke(blob, new Object[]{MODE_READWRITE_CONSTANT});
+ Method getBinaryOutputStream =
+ blobClass.getMethod("getBinaryOutputStream", new Class[0]);
+ OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null);
+ try {
+ int read;
+ byte[] buf = new byte[8192];
+ while ((read = in.read(buf, 0, buf.length)) > -1) {
+ out.write(buf, 0, read);
+ }
+ } finally {
+ try {
+ out.flush();
+ } catch (IOException ioe) {
+ }
+ out.close();
+ }
+ Method close = blobClass.getMethod("close", new Class[0]);
+ close.invoke(blob, null);
+ return (Blob) blob;
+ }
+
+ /**
+ * Frees a temporary oracle.sql.BLOB instance via reflection.
+ */
+ protected void freeTemporaryBlob(Object blob) throws Exception {
+ // blob.freeTemporary();
+ Method freeTemporary = blobClass.getMethod("freeTemporary", new Class[0]);
+ freeTemporary.invoke(blob, null);
+ }
+
+ //--------------------------------------------------------< inner classes >
+ class OracleBLOBStore extends DbBLOBStore {
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void put(String blobId, InputStream in, long size)
+ throws Exception {
+ PreparedStatement stmt = blobSelectExist;
+ Blob blob = null;
+ try {
+ stmt.setString(1, blobId);
+ stmt.execute();
+ ResultSet rs = stmt.getResultSet();
+ // a BLOB exists if the result has at least one entry
+ boolean exists = rs.next();
+ resetStatement(stmt);
+ closeResultSet(rs);
+
+ stmt = (exists) ? blobUpdate : blobInsert;
+
+ blob = createTemporaryBlob(in);
+ stmt.setBlob(1, blob);
+ stmt.setString(2, blobId);
+ stmt.executeUpdate();
+ } finally {
+ resetStatement(stmt);
+ if (blob != null) {
+ try {
+ freeTemporaryBlob(blob);
+ } catch (Exception e1) {
+ }
+ }
+ }
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java Thu Oct 26 02:11:18 2006
@@ -0,0 +1,168 @@
+/*
+ * 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.persistence.db;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.jackrabbit.core.persistence.util.Serializer;
+import org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager;
+
+/**
+ * <code>SimpleDbPersistenceManager</code> is a generic JDBC-based
+ * <code>PersistenceManager</code> for Jackrabbit that persists
+ * <code>ItemState</code> and <code>NodeReferences</code> objects using a
+ * simple custom binary serialization format (see {@link Serializer}) and a
+ * very basic non-normalized database schema (in essence tables with one 'key'
+ * and one 'data' column).
+ * <p/>
+ * It is configured through the following properties:
+ * <ul>
+ * <li><code>driver</code>: the FQN name of the JDBC driver class</li>
+ * <li><code>url</code>: the database url of the form <code>jdbc:subprotocol:subname</code></li>
+ * <li><code>user</code>: the database user</li>
+ * <li><code>password</code>: the user's password</li>
+ * <li><code>schema</code>: type of schema to be used
+ * (e.g. <code>mysql</code>, <code>mssql</code>, etc.); </li>
+ * <li><code>schemaObjectPrefix</code>: prefix to be prepended to schema objects</li>
+ * <li><code>externalBLOBs</code>: if <code>true</code> (the default) BINARY
+ * values (BLOBs) are stored in the local file system;
+ * if <code>false</code> BLOBs are stored in the database</li>
+ * </ul>
+ * The required schema objects are automatically created by executing the DDL
+ * statements read from the [schema].ddl file. The .ddl file is read from the
+ * resources by calling <code>getClass().getResourceAsStream(schema + ".ddl")</code>.
+ * Every line in the specified .ddl file is executed separatly by calling
+ * <code>java.sql.Statement.execute(String)</code> where every occurence of the
+ * the string <code>"${schemaObjectPrefix}"</code> has been replaced with the
+ * value of the property <code>schemaObjectPrefix</code>.
+ * <p/>
+ * The following is a fragment from a sample configuration using MySQL:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager">
+ * <param name="driver" value="com.mysql.jdbc.Driver"/>
+ * <param name="url" value="jdbc:mysql:///test?autoReconnect=true"/>
+ * <param name="schema" value="mysql"/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ * The following is a fragment from a sample configuration using Daffodil One$DB Embedded:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager">
+ * <param name="driver" value="in.co.daffodil.db.jdbc.DaffodilDBDriver"/>
+ * <param name="url" value="jdbc:daffodilDB_embedded:${wsp.name};path=${wsp.home}/../../databases;create=true"/>
+ * <param name="user" value="daffodil"/>
+ * <param name="password" value="daffodil"/>
+ * <param name="schema" value="daffodil"/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ * The following is a fragment from a sample configuration using DB2:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager">
+ * <param name="driver" value="com.ibm.db2.jcc.DB2Driver"/>
+ * <param name="url" value="jdbc:db2:test"/>
+ * <param name="schema" value="db2"/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ * The following is a fragment from a sample configuration using MSSQL:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager">
+ * <param name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
+ * <param name="url" value="jdbc:microsoft:sqlserver://localhost:1433;;DatabaseName=test;SelectMethod=Cursor;"/>
+ * <param name="schema" value="mssql"/>
+ * <param name="user" value="sa"/>
+ * <param name="password" value=""/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ * The following is a fragment from a sample configuration using PostgreSQL:
+ * <pre>
+ * <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.SimpleDbPersistenceManager">
+ * <param name="driver" value="org.postgresql.Driver"/>
+ * <param name="url" value="jdbc:postgresql://localhost/test"/>
+ * <param name="schema" value="postgresql"/>
+ * <param name="user" value="postgres"/>
+ * <param name="password" value="postgres"/>
+ * <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+ * <param name="externalBLOBs" value="false"/>
+ * </PersistenceManager>
+ * </pre>
+ * See also {@link DerbyPersistenceManager}, {@link OraclePersistenceManager}.
+ */
+public class SimpleDbPersistenceManager extends DatabasePersistenceManager {
+
+ protected String driver;
+ protected String url;
+ protected String user;
+ protected String password;
+
+ //----------------------------------------------------< setters & getters >
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getDriver() {
+ return driver;
+ }
+
+ public void setDriver(String driver) {
+ this.driver = driver;
+ }
+
+ //------------------------------------------< DatabasePersistenceManager >
+
+ /**
+ * Returns a JDBC connection acquired using the JDBC {@link DriverManager}.
+ *
+ * @throws ClassNotFoundException if the JDBC driver class is not found
+ * @throws SQLException if a database access error occurs
+ * @see DatabasePersistenceManager#getConnection()
+ */
+ protected Connection getConnection() throws ClassNotFoundException, SQLException {
+ Class.forName(driver);
+ Connection connection = DriverManager.getConnection(url, user, password);
+ return connection;
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/SimpleDbPersistenceManager.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/daffodil.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/daffodil.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/daffodil.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/daffodil.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA blob not null)
+create index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA blob not null)
+create index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/db2.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/db2.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/db2.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/db2.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1000) not null, PROP_DATA blob not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1000) not null, BINVAL_DATA blob(100M) not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/default.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/default.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/default.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/default.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA varbinary not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar not null, PROP_DATA varbinary not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA varbinary not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar not null, BINVAL_DATA varbinary not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/derby.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/derby.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/derby.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/derby.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA blob not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA blob(100M) not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mssql.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mssql.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mssql.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mssql.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA image not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA image not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mysql.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mysql.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mysql.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/mysql.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(255) not null, PROP_DATA blob not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(255) not null, BINVAL_DATA longblob not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/oracle.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/oracle.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/oracle.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/oracle.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA blob not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar2(1024) not null, PROP_DATA blob not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA blob not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar2(1024) not null, BINVAL_DATA blob null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/package.html
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/package.html?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/package.html (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/package.html Thu Oct 26 02:11:18 2006
@@ -0,0 +1,32 @@
+<!--
+ 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.
+-->
+<body>
+This package contains the class <code>{@link SimpleDbPersistenceManager}</code>,
+a simple generic JDBC-based <code>PersistenceManager</code> for Jackrabbit.
+<p/>
+It also contains [schemaName].ddl files which are read by
+<code>{@link SimpleDbPersistenceManager}</code> in order to automatically
+create the required schema objects on the target database. Every line in a
+[schemaName].ddl file is executed separatly by calling
+<code>java.sql.Statement.execute(String)</code> where every occurence of the
+the string <code>"${schemaObjectPrefix}"</code> has been replaced with the
+value of the property <code>schemaObjectPrefix</code> (see
+ <code>{@link SimpleDbPersistenceManager#setSchemaObjectPrefix(String)}</code>).
+The schema name is either set programmtically by calling
+<code>{@link SimpleDbPersistenceManager#setSchema(String)}</code> or configured
+through the <code>schema</code> bean property.
+</body>
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/postgresql.ddl
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/postgresql.ddl?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/postgresql.ddl (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/db/postgresql.ddl Thu Oct 26 02:11:18 2006
@@ -0,0 +1,22 @@
+# 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA bytea not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar not null, PROP_DATA bytea not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA bytea not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar not null, BINVAL_DATA bytea not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java?view=auto&rev=467925
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java Thu Oct 26 02:11:18 2006
@@ -0,0 +1,597 @@
+/*
+ * 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.persistence.mem;
+
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
+import org.apache.jackrabbit.core.fs.FileSystemResource;
+import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
+import org.apache.jackrabbit.core.persistence.AbstractPersistenceManager;
+import org.apache.jackrabbit.core.persistence.PMContext;
+import org.apache.jackrabbit.core.persistence.util.BLOBStore;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.NoSuchItemStateException;
+import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.NodeReferencesId;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
+import org.apache.jackrabbit.core.persistence.util.Serializer;
+import org.apache.jackrabbit.core.value.BLOBFileValue;
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.name.QName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.PropertyType;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * <code>InMemPersistenceManager</code> is a very simple <code>HashMap</code>-based
+ * <code>PersistenceManager</code> for Jackrabbit that keeps all data in memory
+ * and that is capable of storing and loading its contents using a simple custom
+ * binary serialization format (see {@link Serializer}).
+ * <p/>
+ * It is configured through the following properties:
+ * <ul>
+ * <li><code>initialCapacity</code>: initial capacity of the hash map used to store the data</li>
+ * <li><code>loadFactor</code>: load factor of the hash map used to store the data</li>
+ * <li><code>persistent</code>: if <code>true</code> the contents of the hash map
+ * is loaded on startup and stored on shutdown;
+ * if <code>false</code> nothing is persisted</li>
+ * </ul>
+ * <b>Please note that this class should only be used for testing purposes.</b>
+ */
+public class InMemPersistenceManager extends AbstractPersistenceManager {
+
+ private static Logger log = LoggerFactory.getLogger(InMemPersistenceManager.class);
+
+ protected boolean initialized;
+
+ protected Map stateStore;
+ protected Map refsStore;
+
+ // initial size of buffer used to serialize objects
+ protected static final int INITIAL_BUFFER_SIZE = 1024;
+
+ // some constants used in serialization
+ protected static final String STATE_FILE_PATH = "/data/.state.bin";
+ protected static final String REFS_FILE_PATH = "/data/.refs.bin";
+ protected static final byte NODE_ENTRY = 0;
+ protected static final byte PROP_ENTRY = 1;
+
+ // file system where BLOB data is stored
+ protected FileSystem blobFS;
+ // BLOBStore that manages BLOB data in the file system
+ protected BLOBStore blobStore;
+
+ /**
+ * file system where the content of the hash maps are read from/written to
+ * (if <code>persistent==true</code>)
+ */
+ protected FileSystem wspFS;
+
+ // initial capacity
+ protected int initialCapacity = 32768;
+ // load factor for the hash map
+ protected float loadFactor = 0.75f;
+ // should hash map be persisted?
+ protected boolean persistent = true;
+
+ /**
+ * Creates a new <code>InMemPersistenceManager</code> instance.
+ */
+ public InMemPersistenceManager() {
+ initialized = false;
+ }
+
+ public void setInitialCapacity(int initialCapacity) {
+ this.initialCapacity = initialCapacity;
+ }
+
+ public void setInitialCapacity(String initialCapacity) {
+ this.initialCapacity = Integer.valueOf(initialCapacity).intValue();
+ }
+
+ public String getInitialCapacity() {
+ return Integer.toString(initialCapacity);
+ }
+
+ public void setLoadFactor(float loadFactor) {
+ this.loadFactor = loadFactor;
+ }
+
+ public void setLoadFactor(String loadFactor) {
+ this.loadFactor = Float.valueOf(loadFactor).floatValue();
+ }
+
+ public String getLoadFactor() {
+ return Float.toString(loadFactor);
+ }
+
+ public boolean isPersistent() {
+ return persistent;
+ }
+
+ public void setPersistent(boolean persistent) {
+ this.persistent = persistent;
+ }
+
+ public void setPersistent(String persistent) {
+ this.persistent = Boolean.valueOf(persistent).booleanValue();
+ }
+
+ protected static String buildBlobFilePath(String parentUUID, QName propName, int index) {
+ StringBuffer sb = new StringBuffer();
+ char[] chars = parentUUID.toCharArray();
+ int cnt = 0;
+ for (int i = 0; i < chars.length; i++) {
+ if (chars[i] == '-') {
+ continue;
+ }
+ //if (cnt > 0 && cnt % 4 == 0) {
+ if (cnt == 2 || cnt == 4) {
+ sb.append(FileSystem.SEPARATOR_CHAR);
+ }
+ sb.append(chars[i]);
+ cnt++;
+ }
+ sb.append(FileSystem.SEPARATOR_CHAR);
+ sb.append(FileSystemPathUtil.escapeName(propName.toString()));
+ sb.append('.');
+ sb.append(index);
+ sb.append(".bin");
+ return sb.toString();
+ }
+
+ /**
+ * Reads the content of the hash maps from the file system
+ *
+ * @throws Exception if an error occurs
+ */
+ public synchronized void loadContents() throws Exception {
+ // read item states
+ FileSystemResource fsRes = new FileSystemResource(wspFS, STATE_FILE_PATH);
+ if (!fsRes.exists()) {
+ return;
+ }
+ BufferedInputStream bis = new BufferedInputStream(fsRes.getInputStream());
+ DataInputStream in = new DataInputStream(bis);
+
+ try {
+ int n = in.readInt(); // number of entries
+ while (n-- > 0) {
+ byte type = in.readByte(); // entry type
+ ItemId id;
+ if (type == NODE_ENTRY) {
+ // entry type: node
+ String s = in.readUTF(); // id
+ id = NodeId.valueOf(s);
+ } else {
+ // entry type: property
+ String s = in.readUTF(); // id
+ id = PropertyId.valueOf(s);
+ }
+ int length = in.readInt(); // data length
+ byte[] data = new byte[length];
+ in.readFully(data); // data
+ // store in map
+ stateStore.put(id, data);
+ }
+ } finally {
+ in.close();
+ }
+
+ // read references
+ fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
+ bis = new BufferedInputStream(fsRes.getInputStream());
+ in = new DataInputStream(bis);
+
+ try {
+ int n = in.readInt(); // number of entries
+ while (n-- > 0) {
+ String s = in.readUTF(); // target id
+ NodeReferencesId id = (NodeReferencesId) NodeReferencesId.valueOf(s);
+ int length = in.readInt(); // data length
+ byte[] data = new byte[length];
+ in.readFully(data); // data
+ // store in map
+ refsStore.put(id, data);
+ }
+ } finally {
+ in.close();
+ }
+ }
+
+ /**
+ * Writes the content of the hash maps to the file system
+ *
+ * @throws Exception if an error occurs
+ */
+ public synchronized void storeContents() throws Exception {
+ // write item states
+ FileSystemResource fsRes = new FileSystemResource(wspFS, STATE_FILE_PATH);
+ fsRes.makeParentDirs();
+ BufferedOutputStream bos = new BufferedOutputStream(fsRes.getOutputStream());
+ DataOutputStream out = new DataOutputStream(bos);
+
+ try {
+
+ out.writeInt(stateStore.size()); // number of entries
+ // entries
+ Iterator iterKeys = stateStore.keySet().iterator();
+ while (iterKeys.hasNext()) {
+ ItemId id = (ItemId) iterKeys.next();
+ if (id.denotesNode()) {
+ out.writeByte(NODE_ENTRY); // entry type
+ } else {
+ out.writeByte(PROP_ENTRY); // entry type
+ }
+ out.writeUTF(id.toString()); // id
+ byte[] data = (byte[]) stateStore.get(id);
+ out.writeInt(data.length); // data length
+ out.write(data); // data
+ }
+ } finally {
+ out.close();
+ }
+
+ // write references
+ fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
+ fsRes.makeParentDirs();
+ bos = new BufferedOutputStream(fsRes.getOutputStream());
+ out = new DataOutputStream(bos);
+
+ try {
+ out.writeInt(refsStore.size()); // number of entries
+ // entries
+ Iterator iterKeys = refsStore.keySet().iterator();
+ while (iterKeys.hasNext()) {
+ NodeReferencesId id = (NodeReferencesId) iterKeys.next();
+ out.writeUTF(id.toString()); // target id
+ byte[] data = (byte[]) refsStore.get(id);
+ out.writeInt(data.length); // data length
+ out.write(data); // data
+ }
+ } finally {
+ out.close();
+ }
+ }
+
+ //---------------------------------------------------< PersistenceManager >
+ /**
+ * {@inheritDoc}
+ */
+ public void init(PMContext context) throws Exception {
+ if (initialized) {
+ throw new IllegalStateException("already initialized");
+ }
+
+ stateStore = new HashMap(initialCapacity, loadFactor);
+ refsStore = new HashMap(initialCapacity, loadFactor);
+
+ wspFS = context.getFileSystem();
+
+ /**
+ * store BLOB data in local file system in a sub directory
+ * of the workspace home directory
+ */
+ LocalFileSystem blobFS = new LocalFileSystem();
+ blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
+ blobFS.init();
+ this.blobFS = blobFS;
+ blobStore = new FileSystemBLOBStore(blobFS);
+
+ if (persistent) {
+ // deserialize contents of state and refs stores
+ loadContents();
+ }
+
+ initialized = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized void close() throws Exception {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ try {
+ if (persistent) {
+ // serialize contents of state and refs stores
+ storeContents();
+ } else {
+ // clear out blob store
+ try {
+ String[] folders = blobFS.listFolders("/");
+ for (int i = 0; i < folders.length; i++) {
+ blobFS.deleteFolder(folders[i]);
+ }
+ String[] files = blobFS.listFiles("/");
+ for (int i = 0; i < files.length; i++) {
+ blobFS.deleteFile(files[i]);
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ // close BLOB file system
+ blobFS.close();
+ blobFS = null;
+ blobStore = null;
+
+ stateStore.clear();
+ stateStore = null;
+ refsStore.clear();
+ refsStore = null;
+ } finally {
+ initialized = false;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized NodeState load(NodeId id)
+ throws NoSuchItemStateException, ItemStateException {
+
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ byte[] data = (byte[]) stateStore.get(id);
+ if (data == null) {
+ throw new NoSuchItemStateException(id.toString());
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(data);
+ try {
+ NodeState state = createNew(id);
+ Serializer.deserialize(state, in);
+ return state;
+ } catch (Exception e) {
+ String msg = "failed to read node state: " + id;
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized PropertyState load(PropertyId id)
+ throws NoSuchItemStateException, ItemStateException {
+
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ byte[] data = (byte[]) stateStore.get(id);
+ if (data == null) {
+ throw new NoSuchItemStateException(id.toString());
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(data);
+ try {
+ PropertyState state = createNew(id);
+ Serializer.deserialize(state, in, blobStore);
+ return state;
+ } catch (Exception e) {
+ String msg = "failed to read property state: " + id;
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void store(NodeState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize node state
+ Serializer.serialize(state, out);
+
+ // store in serialized format in map for better memory efficiency
+ stateStore.put(state.getNodeId(), out.toByteArray());
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to write node state: " + state.getNodeId();
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void store(PropertyState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize property state
+ Serializer.serialize(state, out, blobStore);
+
+ // store in serialized format in map for better memory efficiency
+ stateStore.put(state.getPropertyId(), out.toByteArray());
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to store property state: " + state.getPropertyId();
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void destroy(NodeState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // remove node state
+ stateStore.remove(state.getNodeId());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void destroy(PropertyState state) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // delete binary values (stored as files)
+ InternalValue[] values = state.getValues();
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ InternalValue val = values[i];
+ if (val != null) {
+ if (val.getType() == PropertyType.BINARY) {
+ BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
+ // delete blob file and prune empty parent folders
+ blobVal.delete(true);
+ }
+ }
+ }
+ }
+
+ // remove property state
+ stateStore.remove(state.getPropertyId());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized NodeReferences load(NodeReferencesId id)
+ throws NoSuchItemStateException, ItemStateException {
+
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ byte[] data = (byte[]) refsStore.get(id);
+ if (data == null) {
+ throw new NoSuchItemStateException(id.toString());
+ }
+
+ ByteArrayInputStream in = new ByteArrayInputStream(data);
+ try {
+ NodeReferences refs = new NodeReferences(id);
+ Serializer.deserialize(refs, in);
+ return refs;
+ } catch (Exception e) {
+ String msg = "failed to load references: " + id;
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void store(NodeReferences refs) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ try {
+ ByteArrayOutputStream out =
+ new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
+ // serialize references
+ Serializer.serialize(refs, out);
+
+ // store in serialized format in map for better memory efficiency
+ refsStore.put(refs.getId(), out.toByteArray());
+ // there's no need to close a ByteArrayOutputStream
+ //out.close();
+ } catch (Exception e) {
+ String msg = "failed to store references: " + refs.getId();
+ log.debug(msg);
+ throw new ItemStateException(msg, e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void destroy(NodeReferences refs) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ // remove node references
+ refsStore.remove(refs.getId());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean exists(PropertyId id) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+ return stateStore.containsKey(id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean exists(NodeId id) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+ return stateStore.containsKey(id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean exists(NodeReferencesId id) throws ItemStateException {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+ return refsStore.containsKey(id);
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/persistence/mem/InMemPersistenceManager.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url rev