Author: sergiykarpenko
Date: 2010-02-04 04:49:11 -0500 (Thu, 04 Feb 2010)
New Revision: 1673
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockPersistentDataManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/OracleLockDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.default.sql
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.ora.sql
Log:
EXOJCR-472: LockPersisterDataManager - multi and single db support added
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockDBInitializer.java 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockDBInitializer.java 2010-02-04
09:49:11 UTC (rev 1673)
@@ -88,12 +88,8 @@
protected final Pattern dbTriggerNamePattern;
- private final String tableName;
-
- public LockDBInitializer(String containerName, Connection connection, String
scriptPath, String tableName)
- throws IOException
+ public LockDBInitializer(String containerName, Connection connection, String
scriptPath) throws IOException
{
- this.tableName = tableName;
this.connection = connection;
this.script = script(scriptPath);
this.containerName = containerName;
@@ -110,12 +106,7 @@
protected String script(String scriptPath) throws IOException
{
- String script = readScriptResource(scriptPath);
-
- //replace table name pattern
- // TODO make correct replacement
- script.replaceAll(SQL_TABLE_NAME_PATTERN, tableName);
- return script;
+ return readScriptResource(scriptPath);
}
protected String readScriptResource(String path) throws IOException
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockJDBCConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockJDBCConnection.java 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockJDBCConnection.java 2010-02-04
09:49:11 UTC (rev 1673)
@@ -24,6 +24,7 @@
import java.sql.SQLException;
import javax.jcr.RepositoryException;
+import javax.jcr.lock.LockException;
/**
* Created by The eXo Platform SAS.
@@ -48,7 +49,7 @@
private Connection dbConnection;
- public LockJDBCConnection(Connection dbConnection, String tableName) throws
SQLException
+ public LockJDBCConnection(Connection dbConnection, String wsName) throws SQLException
{
this.dbConnection = dbConnection;
@@ -58,13 +59,14 @@
dbConnection.setAutoCommit(false);
}
- prepareQueries(tableName);
+ prepareQueries(wsName);
}
- protected void prepareQueries(String tableName) throws SQLException
+ protected void prepareQueries(String wsName) throws SQLException
{
// Table structure
- // CREATE TABLE ${table.name}(
+ // CREATE TABLE JCR_LOCKS(
+ // WS_NAME VARCHAR(96) NOT NULL,
// NODE_ID VARCHAR(96) NOT NULL,
// TOKEN_HASH VARCHAR(32) NOT NULL,
// OWNER VARCHAR(96) NOT NULL,
@@ -75,14 +77,15 @@
// )
ADD_LOCK_DATA =
- "insert into " + tableName
- + "(NODE_ID, TOKEN_HASH, OWNER, IS_SESSIONSCOPED, IS_DEEP, BIRTHDAY,
TIMEOUT) VALUES(?,?,?,?,?,?,?)";
+ "insert into JCR_LOCKS"
+ + "(WS_NAME, NODE_ID, TOKEN_HASH, OWNER, IS_SESSIONSCOPED, IS_DEEP,
BIRTHDAY, TIMEOUT) VALUES( " + wsName
+ + " ,?,?,?,?,?,?,?)";
- REMOVE_LOCK_DATA = "delete from " + tableName + " where
NODE_ID=?";
+ REMOVE_LOCK_DATA = "delete from JCR_LOCKS where WS_NAME=" + wsName +
" and NODE_ID=?";
}
- public int addLockData(LockData data) throws RepositoryException
+ public int addLockData(LockData data) throws LockException
{
if (!isOpened())
@@ -108,11 +111,11 @@
}
catch (SQLException e)
{
- throw new RepositoryException(e);
+ throw new LockException(e);
}
}
- public int removeLockData(String nodeID) throws RepositoryException
+ public int removeLockData(String nodeID) throws LockException
{
if (!isOpened())
{
@@ -131,13 +134,13 @@
}
catch (SQLException e)
{
- throw new RepositoryException(e);
+ throw new LockException(e);
}
}
/**
- * {@inheritDoc}
- */
+ * {@inheritDoc}
+ */
public boolean isOpened()
{
try
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockPersistentDataManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockPersistentDataManager.java 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/LockPersistentDataManager.java 2010-02-04
09:49:11 UTC (rev 1673)
@@ -44,16 +44,16 @@
private DataSource dataSource;
- private String tableName;
+ private String wsName;
/**
* @param dataSourceName DataSource name
* @param tableName Name of DB table
* @throws RepositoryException
*/
- public LockPersistentDataManager(String dataSourceName, String tableName) throws
RepositoryException, IOException
+ public LockPersistentDataManager(String dataSourceName, String wsName) throws
RepositoryException, IOException
{
- this.tableName = tableName;
+ this.wsName = wsName;
// try to resolve DataSource
try
@@ -69,7 +69,7 @@
jdbcConn = dataSource.getConnection();
String dialect = DialectDetecter.detect(jdbcConn.getMetaData());
// if table not exists, create it
- initDatabase(dataSourceName, jdbcConn, dialect, tableName);
+ initDatabase(dataSourceName, jdbcConn, dialect);
}
catch (SQLException e)
{
@@ -107,7 +107,7 @@
{
try
{
- return new LockJDBCConnection(getJDBCConnection(readOnly), tableName);
+ return new LockJDBCConnection(getJDBCConnection(), wsName);
}
catch (SQLException e)
{
@@ -123,19 +123,12 @@
* @throws RepositoryException
* @throws RepositoryException
*/
- private Connection getJDBCConnection(boolean readOnly) throws RepositoryException
+ private Connection getJDBCConnection() throws RepositoryException
{
try
{
//TODO make connection as in GenericConnectionFactory
final Connection conn = dataSource.getConnection();
-
- if (readOnly)
- {
- // set this feature only if it asked
- conn.setReadOnly(readOnly);
- }
-
return conn;
}
catch (SQLException e)
@@ -154,8 +147,8 @@
* @throws IOException
* @throws DBInitializerException
*/
- protected void initDatabase(String dataSource, Connection jdbcConn, String dialect,
String tableName)
- throws IOException, DBInitializerException
+ protected void initDatabase(String dataSource, Connection jdbcConn, String dialect)
throws IOException,
+ DBInitializerException
{
LockDBInitializer dbInitializer = null;
@@ -164,13 +157,13 @@
{
// oracle preparation script
String sqlPath = "/conf/storage/lock-jdbc.ora.sql";
- dbInitializer = new OracleLockDBInitializer(dataSource, jdbcConn, sqlPath,
tableName);
+ dbInitializer = new OracleLockDBInitializer(dataSource, jdbcConn, sqlPath);
}
else
{
// generic preparation script
String sqlPath = "/conf/storage/lock-jdbc.default.sql";
- dbInitializer = new LockDBInitializer(dataSource, jdbcConn, sqlPath,
tableName);
+ dbInitializer = new LockDBInitializer(dataSource, jdbcConn, sqlPath);
}
// init DB
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/OracleLockDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/OracleLockDBInitializer.java 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/OracleLockDBInitializer.java 2010-02-04
09:49:11 UTC (rev 1673)
@@ -32,10 +32,9 @@
public class OracleLockDBInitializer extends LockDBInitializer
{
- public OracleLockDBInitializer(String containerName, Connection connection, String
script, String tableName)
- throws IOException
+ public OracleLockDBInitializer(String containerName, Connection connection, String
script) throws IOException
{
- super(containerName, connection, script, tableName);
+ super(containerName, connection, script);
}
@Override
Modified:
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.default.sql
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.default.sql 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.default.sql 2010-02-04
09:49:11 UTC (rev 1673)
@@ -1,4 +1,5 @@
-CREATE TABLE ${table.name}(
+CREATE TABLE JCR_LOCKS(
+ WS_NAME VARCHAR(96) NOT NULL,
NODE_ID VARCHAR(96) NOT NULL,
TOKEN_HASH VARCHAR(32) NOT NULL,
OWNER VARCHAR(96) NOT NULL,
Modified:
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.ora.sql
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.ora.sql 2010-02-04
09:16:48 UTC (rev 1672)
+++
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.ora.sql 2010-02-04
09:49:11 UTC (rev 1673)
@@ -1,5 +1,6 @@
/*$DELIMITER:/ */
CREATE TABLE ${table.name}(
+ WS_NAME VARCHAR(96) NOT NULL,
NODE_ID VARCHAR(96) NOT NULL,
TOKEN_HASH VARCHAR(32) NOT NULL,
OWNER VARCHAR(96) NOT NULL,