Author: pnedonosko
Date: 2010-02-05 12:20:02 -0500 (Fri, 05 Feb 2010)
New Revision: 1708
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/StorageDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerException.java
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-lock-jdbc.sql
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/OracleLockDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializerException.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
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/IngresSQLDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/OracleDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/PgSQLDBInitializer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCConnectionTestBase.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestSingleDbJDBCConnection.java
Log:
EXOJCR-472 rework of DB initializer; oracle dialect removed to use one for all Dbs (rely
on ANSI SQL)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockDBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -16,19 +16,10 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.jbosscache.jdbc;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializerException;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializer;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Created by The eXo Platform SAS.
@@ -36,356 +27,14 @@
* <br/>Date:
*
* @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: LockDBInitializer.java 111 2008-11-11 11:11:11Z serg $
+ * @version $Id$
*/
-public class LockDBInitializer
+public class LockDBInitializer extends DBInitializer
{
- static public String SQL_DELIMITER = ";";
- static public String SQL_DELIMITER_COMMENT_PREFIX = "/*$DELIMITER:";
-
- static public String SQL_TABLE_NAME_PATTERN = "${table.name}";
-
- static public String SQL_CREATETABLE =
"^(CREATE(\\s)+TABLE(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
-
- static public String SQL_CREATEVIEW =
"^(CREATE(\\s)+VIEW(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
-
- static public String SQL_OBJECTNAME =
"((JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
-
- static public String SQL_CREATEINDEX =
"^(CREATE(\\s)+(UNIQUE(\\s)+)*INDEX(\\s)+){1}";
-
- static public String SQL_ONTABLENAME =
"(ON(\\s)+(JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+){1}";
-
- static public String SQL_CREATESEQUENCE =
"^(CREATE(\\s)+SEQUENCE(\\s)+){1}";
-
- static public String SQL_CREATETRIGGER =
"^(CREATE(\\s)+(OR(\\s){1}REPLACE(\\s)+)*TRIGGER(\\s)+){1}";
-
- static public String SQL_TRIGGERNAME =
"(([A-Z_]+JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
-
- protected final Log log = ExoLogger.getLogger("jcr.LockDBInitializer");
-
- protected final Connection connection;
-
- protected final String containerName;
-
- protected final String script;
-
- //protected final boolean multiDb;
-
- protected final Pattern creatTablePattern;
-
- protected final Pattern creatViewPattern;
-
- protected final Pattern dbObjectNamePattern;
-
- protected final Pattern creatIndexPattern;
-
- protected final Pattern onTableNamePattern;
-
- protected final Pattern creatSequencePattern;
-
- protected final Pattern creatTriggerPattern;
-
- protected final Pattern dbTriggerNamePattern;
-
public LockDBInitializer(String containerName, Connection connection, String
scriptPath) throws IOException
{
- this.connection = connection;
- this.script = script(scriptPath);
- this.containerName = containerName;
-
- this.creatTablePattern = Pattern.compile(SQL_CREATETABLE,
Pattern.CASE_INSENSITIVE);
- this.creatViewPattern = Pattern.compile(SQL_CREATEVIEW, Pattern.CASE_INSENSITIVE);
- this.dbObjectNamePattern = Pattern.compile(SQL_OBJECTNAME,
Pattern.CASE_INSENSITIVE);
- this.creatIndexPattern = Pattern.compile(SQL_CREATEINDEX,
Pattern.CASE_INSENSITIVE);
- this.onTableNamePattern = Pattern.compile(SQL_ONTABLENAME,
Pattern.CASE_INSENSITIVE);
- this.creatSequencePattern = Pattern.compile(SQL_CREATESEQUENCE,
Pattern.CASE_INSENSITIVE);
- this.creatTriggerPattern = Pattern.compile(SQL_CREATETRIGGER,
Pattern.CASE_INSENSITIVE);
- this.dbTriggerNamePattern = Pattern.compile(SQL_TRIGGERNAME,
Pattern.CASE_INSENSITIVE);
+ super(containerName, connection, scriptPath);
}
- protected String script(String scriptPath) throws IOException
- {
- return readScriptResource(scriptPath);
- }
-
- protected String readScriptResource(String path) throws IOException
- {
- InputStream is = this.getClass().getResourceAsStream(path);
- InputStreamReader isr = new InputStreamReader(is);
- try
- {
- StringBuilder sbuff = new StringBuilder();
- char[] buff = new char[is.available()];
- int r = 0;
- while ((r = isr.read(buff)) > 0)
- {
- sbuff.append(buff, 0, r);
- }
-
- return sbuff.toString();
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- }
- }
- }
-
- public String cleanWhitespaces(String string)
- {
- if (string != null)
- {
- char[] cc = string.toCharArray();
- for (int ci = cc.length - 1; ci > 0; ci--)
- {
- if (Character.isWhitespace(cc[ci]))
- {
- cc[ci] = ' ';
- }
- }
- return new String(cc);
- }
- return string;
- }
-
- protected boolean isTableExists(Connection conn, String tableName) throws
SQLException
- {
- ResultSet trs = conn.getMetaData().getTables(null, null, tableName, null);
- boolean res = false;
- while (trs.next())
- {
- res = true; // check for columns/table type matching etc.
- }
- return res;
- }
-
- protected boolean isIndexExists(Connection conn, String tableName, String indexName)
throws SQLException
- {
- ResultSet irs = conn.getMetaData().getIndexInfo(null, null, tableName, false,
true);
- boolean res = false;
- while (irs.next())
- {
- if (irs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic
- &&
irs.getString("INDEX_NAME").equalsIgnoreCase(indexName))
- res = true; // check for index params matching etc.
- }
- return res;
- }
-
- protected boolean isSequenceExists(Connection conn, String sequenceName) throws
SQLException
- {
- return false;
- }
-
- protected boolean isTriggerExists(Connection conn, String triggerName) throws
SQLException
- {
- return false;
- }
-
- public boolean isObjectExists(Connection conn, String sql) throws SQLException
- {
- Matcher tMatcher = creatTablePattern.matcher(sql);
- if (tMatcher.find())
- {
- // CREATE TABLE
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got table name
- String tableName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTableExists(conn, tableName))
- {
- if (log.isDebugEnabled())
- log.debug("Table is already exists " + tableName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatViewPattern.matcher(sql)).find())
- {
- // CREATE VIEW
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got view name
- String tableName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTableExists(conn, tableName))
- {
- if (log.isDebugEnabled())
- log.debug("View is already exists " + tableName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatIndexPattern.matcher(sql)).find())
- {
- // CREATE INDEX
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got index name
- String indexName = sql.substring(tMatcher.start(), tMatcher.end());
- if ((tMatcher = onTableNamePattern.matcher(sql)).find())
- {
- String onTableName = sql.substring(tMatcher.start(), tMatcher.end());
- if ((tMatcher = dbObjectNamePattern.matcher(onTableName)).find())
- {
- String tableName = onTableName.substring(tMatcher.start(),
tMatcher.end());
- if (isIndexExists(conn, tableName, indexName))
- {
- if (log.isDebugEnabled())
- log.debug("Index is already exists " + indexName);
- return true;
- }
- }
- else
- {
- log.warn("Index found but $TABLE_NAME is not detected '"
+ sql + "'");
- }
- }
- else
- {
- log.warn("Index found but ON $TABLE_NAME clause is not detected
'" + sql + "'");
- }
- }
- else
- {
- log.warn("Create index clause found but $INDEX_NAME is not detected
'" + sql + "'");
- }
- }
- else if ((tMatcher = creatSequencePattern.matcher(sql)).find())
- {
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got sequence name
- String sequenceName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isSequenceExists(conn, sequenceName))
- {
- if (log.isDebugEnabled())
- log.debug("Sequence is already exists " + sequenceName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatTriggerPattern.matcher(sql)).find())
- {
- tMatcher = dbTriggerNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got trigger name
- String triggerName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTriggerExists(conn, triggerName))
- {
- if (log.isDebugEnabled())
- log.debug("Trigger is already exists " + triggerName);
- return true;
- }
- }
- }
- else
- {
- if (log.isDebugEnabled())
- log.debug("Command is not detected for check '" + sql +
"'");
- }
-
- return false;
- }
-
- public void init() throws DBInitializerException
- {
- String[] scripts = null;
- if (script.startsWith(SQL_DELIMITER_COMMENT_PREFIX))
- {
- // read custom prefix
- try
- {
- String s = script.substring(SQL_DELIMITER_COMMENT_PREFIX.length());
- int endOfDelimIndex = s.indexOf("*/");
- String delim = s.substring(0, endOfDelimIndex).trim();
- s = s.substring(endOfDelimIndex + 2).trim();
- scripts = s.split(delim);
- }
- catch (IndexOutOfBoundsException e)
- {
- log.warn("Error of parse SQL-script file. Invalid DELIMITER
configuration. Valid format is '"
- + SQL_DELIMITER_COMMENT_PREFIX + "XXX*/' at begin of the
SQL-script file, where XXX - DELIMITER string."
- + " Spaces will be trimed. ", e);
- log.info("Using DELIMITER:[" + SQL_DELIMITER + "]");
- scripts = script.split(SQL_DELIMITER);
- }
- }
- else
- {
- scripts = script.split(SQL_DELIMITER);
- }
-
- String sql = null;
- try
- {
- connection.setAutoCommit(false);
-
- for (String scr : scripts)
- {
- String s = cleanWhitespaces(scr.trim());
- if (s.length() > 0)
- {
- if (isObjectExists(connection, sql = s))
- continue;
-
- if (log.isDebugEnabled())
- log.debug("Execute script: \n[" + sql + "]");
-
- connection.createStatement().executeUpdate(sql);
- }
- }
-
- //rootInit(connection);
-
- connection.commit();
- log.info("DB schema of DataSource: '" + containerName +
"' initialized succesfully");
- }
- catch (SQLException e)
- {
- try
- {
- connection.rollback();
- }
- catch (SQLException re)
- {
- log.error("Rollback error " + e, e);
- }
-
- SQLException next = e.getNextException();
- String errorTrace = "";
- while (next != null)
- {
- errorTrace += next.getMessage() + "; ";
- next = e.getNextException();
- }
- Throwable cause = e.getCause();
- String msg =
- "Could not create db schema of DataSource: '" + containerName +
"'. Reason: " + e.getMessage() + "; "
- + errorTrace + (cause != null ? " (Cause: " + cause.getMessage()
+ ")" : "") + ". Last command: " + sql;
-
- throw new DBInitializerException(msg, e);
- }
- finally
- {
- try
- {
- connection.close();
- }
- catch (SQLException e)
- {
- log.error("Error of a connection closing. " + e, e);
- }
- }
- }
}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockDBInitializer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -20,7 +20,8 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializerException;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializer;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -64,14 +65,14 @@
if (dataSource != null)
{
// initialize DB table if needed
+ Connection jdbcConn = null;
try
{
log.info("Creating LockManager DB tables.");
- Connection jdbcConn = dataSource.getConnection();
- String dialect = DialectDetecter.detect(jdbcConn.getMetaData());
+ jdbcConn = dataSource.getConnection();
// if table not exists, create it
// connection is closed by DB initializer
- initDatabase(dataSourceName, jdbcConn, dialect);
+ initDatabase(dataSourceName, jdbcConn,
DialectDetecter.detect(jdbcConn.getMetaData()));
}
catch (SQLException e)
{
@@ -81,6 +82,20 @@
{
throw new RepositoryException(e);
}
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ log.error("Error of connection close", e);
+ }
+ }
+ }
}
else
{
@@ -141,22 +156,8 @@
protected void initDatabase(String dataSource, Connection jdbcConn, String dialect)
throws IOException,
DBInitializerException
{
- LockDBInitializer dbInitializer = null;
+ DBInitializer dbInitializer = new DBInitializer(dataSource, jdbcConn,
"/conf/storage/jcr-lock-jdbc.sql");
- // prepare DB
- if (DBConstants.DB_DIALECT_ORACLE.equals(dialect))
- {
- // oracle preparation script
- String sqlPath = "/conf/storage/lock-jdbc.ora.sql";
- dbInitializer = new OracleLockDBInitializer(dataSource, jdbcConn, sqlPath);
- }
- else
- {
- // generic preparation script
- String sqlPath = "/conf/storage/lock-jdbc.default.sql";
- dbInitializer = new LockDBInitializer(dataSource, jdbcConn, sqlPath);
- }
-
// init DB
dbInitializer.init();
}
Deleted:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/OracleLockDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/OracleLockDBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/OracleLockDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not,
see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.core.lock.jbosscache.jdbc;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date:
- *
- * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: OracleLockDBInitializer.java 111 2008-11-11 11:11:11Z serg $
- */
-public class OracleLockDBInitializer extends LockDBInitializer
-{
-
- public OracleLockDBInitializer(String containerName, Connection connection, String
script) throws IOException
- {
- super(containerName, connection, script);
- }
-
- @Override
- protected boolean isSequenceExists(Connection conn, String sequenceName) throws
SQLException
- {
- try
- {
- ResultSet srs = conn.createStatement().executeQuery("SELECT " +
sequenceName + ".nextval FROM DUAL");
- if (srs.next())
- {
- return true;
- }
- srs.close();
- return false;
- }
- catch (SQLException e)
- {
- // check: ORA-02289: sequence does not exist
- if (e.getMessage().indexOf("ORA-02289") >= 0)
- return false;
- throw e;
- }
- }
-
- @Override
- protected boolean isTriggerExists(Connection conn, String triggerName) throws
SQLException
- {
- String sql = "SELECT COUNT(trigger_name) FROM all_triggers WHERE trigger_name
= '" + triggerName + "'";
- ResultSet r = conn.createStatement().executeQuery(sql);
- if (r.next())
- return r.getInt(1) > 0;
- else
- return false;
- }
-
- @Override
- protected boolean isTableExists(Connection conn, String tableName) throws
SQLException
- {
- try
- {
- conn.createStatement().executeUpdate("SELECT 1 FROM " + tableName);
- return true;
- }
- catch (SQLException e)
- {
- // check: ORA-00942: table or view does not exist
- if (e.getMessage().indexOf("ORA-00942") >= 0)
- return false;
- throw e;
- }
- }
-
- @Override
- protected boolean isIndexExists(Connection conn, String tableName, String indexName)
throws SQLException
- {
- // use of oracle system view
- String sql = "SELECT COUNT(index_name) FROM all_indexes WHERE
index_name='" + indexName + "'";
- ResultSet r = conn.createStatement().executeQuery(sql);
- if (r.next())
- return r.getInt(1) > 0;
- else
- return false;
- }
-}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -554,7 +554,7 @@
else
{
// check in persistence
- final WorkspaceStorageConnection acon = dataContainer.openConnection();
+ final WorkspaceStorageConnection acon = con;
//dataContainer.openConnection();
try
{
NodeData parent = (NodeData)acon.getItemData(node.getParentIdentifier());
@@ -570,7 +570,7 @@
}
finally
{
- acon.close();
+ //acon.close();
}
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -27,13 +27,13 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.db.MySQLConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.OracleConnectionFactory;
import
org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializerException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.init.StorageDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.IngresSQLDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.OracleDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.PgSQLDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.update.StorageUpdateManager;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerException;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
@@ -409,7 +409,7 @@
*
* @param sqlPath
* - path to SQL script (database creation script)
- * @return DBInitializer instance
+ * @return StorageDBInitializer instance
* @throws NamingException
* on JNDI error
* @throws RepositoryException
@@ -417,10 +417,10 @@
* @throws IOException
* on I/O error
*/
- protected DBInitializer defaultDBInitializer(String sqlPath) throws NamingException,
RepositoryException,
+ protected StorageDBInitializer defaultDBInitializer(String sqlPath) throws
NamingException, RepositoryException,
IOException
{
- return new DBInitializer(containerName, this.connFactory.getJdbcConnection(),
sqlPath, multiDb);
+ return new StorageDBInitializer(containerName,
this.connFactory.getJdbcConnection(), sqlPath, multiDb);
}
/**
@@ -538,7 +538,7 @@
protected void initDatabase() throws NamingException, RepositoryException,
IOException
{
- DBInitializer dbInitilizer = null;
+ StorageDBInitializer dbInitilizer = null;
String sqlPath = null;
if (dbDialect == DBConstants.DB_DIALECT_ORACLEOCI)
{
Deleted:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -1,424 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.init;
-
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Created by The eXo Platform SAS 12.03.2007 Generic db initializer.
- *
- * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
- * @version $Id: DBInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
- */
-public class DBInitializer
-{
-
- static public String SQL_DELIMITER = ";";
-
- static public String SQL_DELIMITER_COMMENT_PREFIX = "/*$DELIMITER:";
-
- static public String SQL_CREATETABLE =
"^(CREATE(\\s)+TABLE(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
-
- static public String SQL_CREATEVIEW =
"^(CREATE(\\s)+VIEW(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
-
- static public String SQL_OBJECTNAME =
"((JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
-
- static public String SQL_CREATEINDEX =
"^(CREATE(\\s)+(UNIQUE(\\s)+)*INDEX(\\s)+){1}";
-
- static public String SQL_ONTABLENAME =
"(ON(\\s)+(JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+){1}";
-
- static public String SQL_CREATESEQUENCE =
"^(CREATE(\\s)+SEQUENCE(\\s)+){1}";
-
- static public String SQL_CREATETRIGGER =
"^(CREATE(\\s)+(OR(\\s){1}REPLACE(\\s)+)*TRIGGER(\\s)+){1}";
-
- static public String SQL_TRIGGERNAME =
"(([A-Z_]+JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
-
- protected final Log log = ExoLogger.getLogger("jcr.DBInitializer");
-
- protected final Connection connection;
-
- protected final String containerName;
-
- protected final String script;
-
- protected final boolean multiDb;
-
- protected final Pattern creatTablePattern;
-
- protected final Pattern creatViewPattern;
-
- protected final Pattern dbObjectNamePattern;
-
- protected final Pattern creatIndexPattern;
-
- protected final Pattern onTableNamePattern;
-
- protected final Pattern creatSequencePattern;
-
- protected final Pattern creatTriggerPattern;
-
- protected final Pattern dbTriggerNamePattern;
-
- public DBInitializer(String containerName, Connection connection, String scriptPath,
boolean multiDb)
- throws IOException
- {
- this.connection = connection;
- this.containerName = containerName;
- this.script = script(scriptPath);
- this.multiDb = multiDb;
-
- this.creatTablePattern = Pattern.compile(SQL_CREATETABLE,
Pattern.CASE_INSENSITIVE);
- this.creatViewPattern = Pattern.compile(SQL_CREATEVIEW, Pattern.CASE_INSENSITIVE);
- this.dbObjectNamePattern = Pattern.compile(SQL_OBJECTNAME,
Pattern.CASE_INSENSITIVE);
- this.creatIndexPattern = Pattern.compile(SQL_CREATEINDEX,
Pattern.CASE_INSENSITIVE);
- this.onTableNamePattern = Pattern.compile(SQL_ONTABLENAME,
Pattern.CASE_INSENSITIVE);
- this.creatSequencePattern = Pattern.compile(SQL_CREATESEQUENCE,
Pattern.CASE_INSENSITIVE);
- this.creatTriggerPattern = Pattern.compile(SQL_CREATETRIGGER,
Pattern.CASE_INSENSITIVE);
- this.dbTriggerNamePattern = Pattern.compile(SQL_TRIGGERNAME,
Pattern.CASE_INSENSITIVE);
- }
-
- protected String script(String scriptPath) throws IOException
- {
- return readScriptResource(scriptPath);
- }
-
- protected String readScriptResource(String path) throws IOException
- {
- InputStream is = this.getClass().getResourceAsStream(path);
- InputStreamReader isr = new InputStreamReader(is);
- try
- {
- StringBuilder sbuff = new StringBuilder();
- char[] buff = new char[is.available()];
- int r = 0;
- while ((r = isr.read(buff)) > 0)
- {
- sbuff.append(buff, 0, r);
- }
-
- return sbuff.toString();
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- }
- }
- }
-
- public String cleanWhitespaces(String string)
- {
- if (string != null)
- {
- char[] cc = string.toCharArray();
- for (int ci = cc.length - 1; ci > 0; ci--)
- {
- if (Character.isWhitespace(cc[ci]))
- {
- cc[ci] = ' ';
- }
- }
- return new String(cc);
- }
- return string;
- }
-
- protected boolean isTableExists(Connection conn, String tableName) throws
SQLException
- {
- ResultSet trs = conn.getMetaData().getTables(null, null, tableName, null);
- boolean res = false;
- while (trs.next())
- {
- res = true; // check for columns/table type matching etc.
- }
- return res;
- }
-
- protected boolean isIndexExists(Connection conn, String tableName, String indexName)
throws SQLException
- {
- ResultSet irs = conn.getMetaData().getIndexInfo(null, null, tableName, false,
true);
- boolean res = false;
- while (irs.next())
- {
- if (irs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic
- &&
irs.getString("INDEX_NAME").equalsIgnoreCase(indexName))
- res = true; // check for index params matching etc.
- }
- return res;
- }
-
- protected boolean isSequenceExists(Connection conn, String sequenceName) throws
SQLException
- {
- return false;
- }
-
- protected boolean isTriggerExists(Connection conn, String triggerName) throws
SQLException
- {
- return false;
- }
-
- public boolean isObjectExists(Connection conn, String sql) throws SQLException
- {
- Matcher tMatcher = creatTablePattern.matcher(sql);
- if (tMatcher.find())
- {
- // CREATE TABLE
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got table name
- String tableName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTableExists(conn, tableName))
- {
- if (log.isDebugEnabled())
- log.debug("Table is already exists " + tableName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatViewPattern.matcher(sql)).find())
- {
- // CREATE VIEW
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got view name
- String tableName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTableExists(conn, tableName))
- {
- if (log.isDebugEnabled())
- log.debug("View is already exists " + tableName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatIndexPattern.matcher(sql)).find())
- {
- // CREATE INDEX
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got index name
- String indexName = sql.substring(tMatcher.start(), tMatcher.end());
- if ((tMatcher = onTableNamePattern.matcher(sql)).find())
- {
- String onTableName = sql.substring(tMatcher.start(), tMatcher.end());
- if ((tMatcher = dbObjectNamePattern.matcher(onTableName)).find())
- {
- String tableName = onTableName.substring(tMatcher.start(),
tMatcher.end());
- if (isIndexExists(conn, tableName, indexName))
- {
- if (log.isDebugEnabled())
- log.debug("Index is already exists " + indexName);
- return true;
- }
- }
- else
- {
- log.warn("Index found but $TABLE_NAME is not detected '"
+ sql + "'");
- }
- }
- else
- {
- log.warn("Index found but ON $TABLE_NAME clause is not detected
'" + sql + "'");
- }
- }
- else
- {
- log.warn("Create index clause found but $INDEX_NAME is not detected
'" + sql + "'");
- }
- }
- else if ((tMatcher = creatSequencePattern.matcher(sql)).find())
- {
- tMatcher = dbObjectNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got sequence name
- String sequenceName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isSequenceExists(conn, sequenceName))
- {
- if (log.isDebugEnabled())
- log.debug("Sequence is already exists " + sequenceName);
- return true;
- }
- }
- }
- else if ((tMatcher = creatTriggerPattern.matcher(sql)).find())
- {
- tMatcher = dbTriggerNamePattern.matcher(sql);
- if (tMatcher.find())
- {
- // got trigger name
- String triggerName = sql.substring(tMatcher.start(), tMatcher.end());
- if (isTriggerExists(conn, triggerName))
- {
- if (log.isDebugEnabled())
- log.debug("Trigger is already exists " + triggerName);
- return true;
- }
- }
- }
- else
- {
- if (log.isDebugEnabled())
- log.debug("Command is not detected for check '" + sql +
"'");
- }
-
- return false;
- }
-
- public void init() throws DBInitializerException
- {
- String[] scripts = null;
- if (script.startsWith(SQL_DELIMITER_COMMENT_PREFIX))
- {
- // read custom prefix
- try
- {
- String s = script.substring(SQL_DELIMITER_COMMENT_PREFIX.length());
- int endOfDelimIndex = s.indexOf("*/");
- String delim = s.substring(0, endOfDelimIndex).trim();
- s = s.substring(endOfDelimIndex + 2).trim();
- scripts = s.split(delim);
- }
- catch (IndexOutOfBoundsException e)
- {
- log.warn("Error of parse SQL-script file. Invalid DELIMITER
configuration. Valid format is '"
- + SQL_DELIMITER_COMMENT_PREFIX + "XXX*/' at begin of the
SQL-script file, where XXX - DELIMITER string."
- + " Spaces will be trimed. ", e);
- log.info("Using DELIMITER:[" + SQL_DELIMITER + "]");
- scripts = script.split(SQL_DELIMITER);
- }
- }
- else
- {
- scripts = script.split(SQL_DELIMITER);
- }
-
- String sql = null;
- try
- {
- connection.setAutoCommit(false);
-
- for (String scr : scripts)
- {
- String s = cleanWhitespaces(scr.trim());
- if (s.length() > 0)
- {
- if (isObjectExists(connection, sql = s))
- continue;
-
- if (log.isDebugEnabled())
- log.debug("Execute script: \n[" + sql + "]");
-
- connection.createStatement().executeUpdate(sql);
- }
- }
-
- rootInit(connection);
-
- optionalInit();
-
- connection.commit();
- log.info("DB schema of DataSource: '" + containerName +
"' initialized succesfully");
- }
- catch (SQLException e)
- {
- try
- {
- connection.rollback();
- }
- catch (SQLException re)
- {
- log.error("Rollback error " + e, e);
- }
-
- SQLException next = e.getNextException();
- String errorTrace = "";
- while (next != null)
- {
- errorTrace += next.getMessage() + "; ";
- next = e.getNextException();
- }
- Throwable cause = e.getCause();
- String msg =
- "Could not create db schema of DataSource: '" + containerName +
"'. Reason: " + e.getMessage() + "; "
- + errorTrace + (cause != null ? " (Cause: " + cause.getMessage()
+ ")" : "") + ". Last command: " + sql;
-
- throw new DBInitializerException(msg, e);
- }
- finally
- {
- try
- {
- connection.close();
- }
- catch (SQLException e)
- {
- log.error("Error of a connection closing. " + e, e);
- }
- }
- }
-
- /**
- * Empty here but may be overriden
- */
- protected void optionalInit() throws DBInitializerException
- {
-
- }
-
- /**
- * Init root node parent record
- */
- protected void rootInit(Connection connection) throws SQLException
- {
- final String MDB = (multiDb ? "M" : "S");
- String select =
- "select * from JCR_" + MDB + "ITEM where ID='" +
Constants.ROOT_PARENT_UUID + "' and PARENT_ID='"
- + Constants.ROOT_PARENT_UUID + "'";
-
- if (!connection.createStatement().executeQuery(select).next())
- {
- String insert =
- "insert into JCR_" + MDB + "ITEM(ID, PARENT_ID, NAME, " +
(multiDb ? "" : "CONTAINER_NAME, ")
- + "VERSION, I_CLASS, I_INDEX, N_ORDER_NUM)" + "
VALUES('" + Constants.ROOT_PARENT_UUID + "', '"
- + Constants.ROOT_PARENT_UUID + "', '__root_parent',
" + (multiDb ? "" : "'__root_parent_container', ")
- + "0, 0, 0, 0)";
-
- connection.createStatement().executeUpdate(insert);
- }
- }
-}
Deleted:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializerException.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializerException.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializerException.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.init;
-
-/**
- * Created by The eXo Platform SAS
- *
- * 12.03.2007
- *
- * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
- * @version $Id: DBInitializerException.java 34801 2009-07-31 15:44:50Z dkatayev $
- */
-public class DBInitializerException extends Exception
-{
-
- public DBInitializerException(String message, Throwable e)
- {
- super(message, e);
- }
-
-}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/IngresSQLDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/IngresSQLDBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/IngresSQLDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -34,7 +34,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id: IngresSQLDBInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-public class IngresSQLDBInitializer extends DBInitializer
+public class IngresSQLDBInitializer extends StorageDBInitializer
{
public IngresSQLDBInitializer(String containerName, Connection connection, String
scriptPath, boolean multiDb)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/OracleDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/OracleDBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/OracleDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -34,7 +34,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id: OracleDBInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-public class OracleDBInitializer extends DBInitializer
+public class OracleDBInitializer extends StorageDBInitializer
{
public OracleDBInitializer(String containerName, Connection connection, String
scriptPath, boolean multiDb)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/PgSQLDBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/PgSQLDBInitializer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/PgSQLDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -33,7 +33,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id: PgSQLDBInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-public class PgSQLDBInitializer extends DBInitializer
+public class PgSQLDBInitializer extends StorageDBInitializer
{
public PgSQLDBInitializer(String containerName, Connection connection, String
scriptPath, boolean multiDb)
Copied:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/StorageDBInitializer.java
(from rev 1701,
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializer.java)
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/StorageDBInitializer.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/StorageDBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.init;
+
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializer;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * JCR Storage DB initializer.
+ *
+ * Created by The eXo Platform SAS 12.03.2007.
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id$
+ */
+public class StorageDBInitializer extends DBInitializer
+{
+
+ protected final boolean multiDb;
+
+ public StorageDBInitializer(String containerName, Connection connection, String
scriptPath, boolean multiDb)
+ throws IOException
+ {
+ super(containerName, connection, scriptPath);
+ this.multiDb = multiDb;
+ }
+
+ /**
+ * Init root node parent record.
+ */
+ protected void postInit(Connection connection) throws SQLException
+ {
+ final String MDB = (multiDb ? "M" : "S");
+ String select =
+ "select * from JCR_" + MDB + "ITEM where ID='" +
Constants.ROOT_PARENT_UUID + "' and PARENT_ID='"
+ + Constants.ROOT_PARENT_UUID + "'";
+
+ if (!connection.createStatement().executeQuery(select).next())
+ {
+ String insert =
+ "insert into JCR_" + MDB + "ITEM(ID, PARENT_ID, NAME, " +
(multiDb ? "" : "CONTAINER_NAME, ")
+ + "VERSION, I_CLASS, I_INDEX, N_ORDER_NUM)" + "
VALUES('" + Constants.ROOT_PARENT_UUID + "', '"
+ + Constants.ROOT_PARENT_UUID + "', '__root_parent',
" + (multiDb ? "" : "'__root_parent_container', ")
+ + "0, 0, 0, 0)";
+
+ connection.createStatement().executeUpdate(insert);
+ }
+ }
+}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/StorageDBInitializer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -24,8 +24,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializerException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.init.StorageDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.IngresSQLDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.OracleDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.PgSQLDBInitializer;
@@ -33,6 +32,7 @@
import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.HSQLDBConnectionFactory;
import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.MySQLConnectionFactory;
import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.OracleConnectionFactory;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerException;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import org.exoplatform.services.naming.InitialContextInitializer;
import org.picocontainer.Startable;
@@ -85,7 +85,7 @@
protected void initDatabase() throws NamingException, RepositoryException,
IOException
{
- DBInitializer dbInitilizer = null;
+ StorageDBInitializer dbInitilizer = null;
String sqlPath = null;
if (dbDialect == DBConstants.DB_DIALECT_ORACLEOCI)
{
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -0,0 +1,399 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.util.jdbc;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Generic DB initializer.
+ * Created by The eXo Platform SAS 12.03.2007.
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id: StorageDBInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class DBInitializer
+{
+
+ static public String SQL_DELIMITER = ";";
+
+ static public String SQL_DELIMITER_COMMENT_PREFIX = "/*$DELIMITER:";
+
+ static public String SQL_CREATETABLE =
"^(CREATE(\\s)+TABLE(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
+
+ static public String SQL_CREATEVIEW =
"^(CREATE(\\s)+VIEW(\\s)+(IF(\\s)+NOT(\\s)+EXISTS(\\s)+)*){1}";
+
+ static public String SQL_OBJECTNAME =
"((JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
+
+ static public String SQL_CREATEINDEX =
"^(CREATE(\\s)+(UNIQUE(\\s)+)*INDEX(\\s)+){1}";
+
+ static public String SQL_ONTABLENAME =
"(ON(\\s)+(JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+){1}";
+
+ static public String SQL_CREATESEQUENCE =
"^(CREATE(\\s)+SEQUENCE(\\s)+){1}";
+
+ static public String SQL_CREATETRIGGER =
"^(CREATE(\\s)+(OR(\\s){1}REPLACE(\\s)+)*TRIGGER(\\s)+){1}";
+
+ static public String SQL_TRIGGERNAME =
"(([A-Z_]+JCR_[A-Z_]+){1}(\\s*?|(\\(\\))*?)+)+?";
+
+ protected final Log LOG = ExoLogger.getLogger("jcr.DBInitializer");
+
+ protected final Connection connection;
+
+ protected final String containerName;
+
+ protected final String script;
+
+ protected final Pattern creatTablePattern;
+
+ protected final Pattern creatViewPattern;
+
+ protected final Pattern dbObjectNamePattern;
+
+ protected final Pattern creatIndexPattern;
+
+ protected final Pattern onTableNamePattern;
+
+ protected final Pattern creatSequencePattern;
+
+ protected final Pattern creatTriggerPattern;
+
+ protected final Pattern dbTriggerNamePattern;
+
+ public DBInitializer(String containerName, Connection connection, String scriptPath)
+ throws IOException
+ {
+ this.connection = connection;
+ this.containerName = containerName;
+ this.script = script(scriptPath);
+
+ this.creatTablePattern = Pattern.compile(SQL_CREATETABLE,
Pattern.CASE_INSENSITIVE);
+ this.creatViewPattern = Pattern.compile(SQL_CREATEVIEW, Pattern.CASE_INSENSITIVE);
+ this.dbObjectNamePattern = Pattern.compile(SQL_OBJECTNAME,
Pattern.CASE_INSENSITIVE);
+ this.creatIndexPattern = Pattern.compile(SQL_CREATEINDEX,
Pattern.CASE_INSENSITIVE);
+ this.onTableNamePattern = Pattern.compile(SQL_ONTABLENAME,
Pattern.CASE_INSENSITIVE);
+ this.creatSequencePattern = Pattern.compile(SQL_CREATESEQUENCE,
Pattern.CASE_INSENSITIVE);
+ this.creatTriggerPattern = Pattern.compile(SQL_CREATETRIGGER,
Pattern.CASE_INSENSITIVE);
+ this.dbTriggerNamePattern = Pattern.compile(SQL_TRIGGERNAME,
Pattern.CASE_INSENSITIVE);
+ }
+
+ protected String script(String scriptPath) throws IOException
+ {
+ return readScriptResource(scriptPath);
+ }
+
+ protected String readScriptResource(String path) throws IOException
+ {
+ InputStream is = this.getClass().getResourceAsStream(path);
+ InputStreamReader isr = new InputStreamReader(is);
+ try
+ {
+ StringBuilder sbuff = new StringBuilder();
+ char[] buff = new char[is.available()];
+ int r = 0;
+ while ((r = isr.read(buff)) > 0)
+ {
+ sbuff.append(buff, 0, r);
+ }
+
+ return sbuff.toString();
+ }
+ finally
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException e)
+ {
+ }
+ }
+ }
+
+ public String cleanWhitespaces(String string)
+ {
+ if (string != null)
+ {
+ char[] cc = string.toCharArray();
+ for (int ci = cc.length - 1; ci > 0; ci--)
+ {
+ if (Character.isWhitespace(cc[ci]))
+ {
+ cc[ci] = ' ';
+ }
+ }
+ return new String(cc);
+ }
+ return string;
+ }
+
+ protected boolean isTableExists(Connection conn, String tableName) throws
SQLException
+ {
+ ResultSet trs = conn.getMetaData().getTables(null, null, tableName, null);
+ boolean res = false;
+ while (trs.next())
+ {
+ res = true; // check for columns/table type matching etc.
+ }
+ return res;
+ }
+
+ protected boolean isIndexExists(Connection conn, String tableName, String indexName)
throws SQLException
+ {
+ ResultSet irs = conn.getMetaData().getIndexInfo(null, null, tableName, false,
true);
+ boolean res = false;
+ while (irs.next())
+ {
+ if (irs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic
+ &&
irs.getString("INDEX_NAME").equalsIgnoreCase(indexName))
+ res = true; // check for index params matching etc.
+ }
+ return res;
+ }
+
+ protected boolean isSequenceExists(Connection conn, String sequenceName) throws
SQLException
+ {
+ return false;
+ }
+
+ protected boolean isTriggerExists(Connection conn, String triggerName) throws
SQLException
+ {
+ return false;
+ }
+
+ public boolean isObjectExists(Connection conn, String sql) throws SQLException
+ {
+ Matcher tMatcher = creatTablePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // CREATE TABLE
+ tMatcher = dbObjectNamePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // got table name
+ String tableName = sql.substring(tMatcher.start(), tMatcher.end());
+ if (isTableExists(conn, tableName))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Table is already exists " + tableName);
+ return true;
+ }
+ }
+ }
+ else if ((tMatcher = creatViewPattern.matcher(sql)).find())
+ {
+ // CREATE VIEW
+ tMatcher = dbObjectNamePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // got view name
+ String tableName = sql.substring(tMatcher.start(), tMatcher.end());
+ if (isTableExists(conn, tableName))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("View is already exists " + tableName);
+ return true;
+ }
+ }
+ }
+ else if ((tMatcher = creatIndexPattern.matcher(sql)).find())
+ {
+ // CREATE INDEX
+ tMatcher = dbObjectNamePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // got index name
+ String indexName = sql.substring(tMatcher.start(), tMatcher.end());
+ if ((tMatcher = onTableNamePattern.matcher(sql)).find())
+ {
+ String onTableName = sql.substring(tMatcher.start(), tMatcher.end());
+ if ((tMatcher = dbObjectNamePattern.matcher(onTableName)).find())
+ {
+ String tableName = onTableName.substring(tMatcher.start(),
tMatcher.end());
+ if (isIndexExists(conn, tableName, indexName))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Index is already exists " + indexName);
+ return true;
+ }
+ }
+ else
+ {
+ LOG.warn("Index found but $TABLE_NAME is not detected '"
+ sql + "'");
+ }
+ }
+ else
+ {
+ LOG.warn("Index found but ON $TABLE_NAME clause is not detected
'" + sql + "'");
+ }
+ }
+ else
+ {
+ LOG.warn("Create index clause found but $INDEX_NAME is not detected
'" + sql + "'");
+ }
+ }
+ else if ((tMatcher = creatSequencePattern.matcher(sql)).find())
+ {
+ tMatcher = dbObjectNamePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // got sequence name
+ String sequenceName = sql.substring(tMatcher.start(), tMatcher.end());
+ if (isSequenceExists(conn, sequenceName))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Sequence is already exists " + sequenceName);
+ return true;
+ }
+ }
+ }
+ else if ((tMatcher = creatTriggerPattern.matcher(sql)).find())
+ {
+ tMatcher = dbTriggerNamePattern.matcher(sql);
+ if (tMatcher.find())
+ {
+ // got trigger name
+ String triggerName = sql.substring(tMatcher.start(), tMatcher.end());
+ if (isTriggerExists(conn, triggerName))
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Trigger is already exists " + triggerName);
+ return true;
+ }
+ }
+ }
+ else
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("Command is not detected for check '" + sql +
"'");
+ }
+
+ return false;
+ }
+
+ public void init() throws DBInitializerException
+ {
+ String[] scripts = null;
+ if (script.startsWith(SQL_DELIMITER_COMMENT_PREFIX))
+ {
+ // read custom prefix
+ try
+ {
+ String s = script.substring(SQL_DELIMITER_COMMENT_PREFIX.length());
+ int endOfDelimIndex = s.indexOf("*/");
+ String delim = s.substring(0, endOfDelimIndex).trim();
+ s = s.substring(endOfDelimIndex + 2).trim();
+ scripts = s.split(delim);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ LOG.warn("Error of parse SQL-script file. Invalid DELIMITER
configuration. Valid format is '"
+ + SQL_DELIMITER_COMMENT_PREFIX + "XXX*/' at begin of the
SQL-script file, where XXX - DELIMITER string."
+ + " Spaces will be trimed. ", e);
+ LOG.info("Using DELIMITER:[" + SQL_DELIMITER + "]");
+ scripts = script.split(SQL_DELIMITER);
+ }
+ }
+ else
+ {
+ scripts = script.split(SQL_DELIMITER);
+ }
+
+ String sql = null;
+ try
+ {
+ connection.setAutoCommit(false);
+
+ for (String scr : scripts)
+ {
+ String s = cleanWhitespaces(scr.trim());
+ if (s.length() > 0)
+ {
+ if (isObjectExists(connection, sql = s))
+ continue;
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Execute script: \n[" + sql + "]");
+ }
+
+ connection.createStatement().executeUpdate(sql);
+ }
+ }
+
+ postInit(connection);
+
+ connection.commit();
+ LOG.info("DB schema of DataSource: '" + containerName +
"' initialized succesfully");
+ }
+ catch (SQLException e)
+ {
+ try
+ {
+ connection.rollback();
+ }
+ catch (SQLException re)
+ {
+ LOG.error("Rollback error " + e, e);
+ }
+
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = e.getNextException();
+ }
+ Throwable cause = e.getCause();
+ String msg =
+ "Could not create db schema of DataSource: '" + containerName +
"'. Reason: " + e.getMessage() + "; "
+ + errorTrace + (cause != null ? " (Cause: " + cause.getMessage()
+ ")" : "") + ". Last command: " + sql;
+
+ throw new DBInitializerException(msg, e);
+ }
+ finally
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Error of a connection closing. " + e, e);
+ }
+ }
+ }
+
+ /**
+ * Place to perform additional operations in overriden classes.
+ */
+ protected void postInit(Connection connection) throws SQLException
+ {
+
+ }
+}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerException.java
(from rev 1701,
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/init/DBInitializerException.java)
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerException.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.util.jdbc;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 12.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id: DBInitializerException.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class DBInitializerException extends Exception
+{
+
+ public DBInitializerException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+
+}
Copied: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-lock-jdbc.sql
(from rev 1701,
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/jcr-lock-jdbc.sql
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-lock-jdbc.sql 2010-02-05
17:20:02 UTC (rev 1708)
@@ -0,0 +1,13 @@
+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,
+ IS_SESSIONSCOPED CHAR NOT NULL,
+ IS_DEEP CHAR NOT NULL,
+ BIRTHDAY BIGINT NOT NULL,
+ TIMEOUT BIGINT NOT NULL,
+ CONSTRAINT JCR_PK_LOCK PRIMARY KEY(NODE_ID, WS_NAME)
+);
+CREATE INDEX JCR_ALL_WS_LOCKS ON JCR_LOCKS(WS_NAME, NODE_ID);
+CREATE INDEX JCR_LOCKS_BY_ID ON JCR_LOCKS(NODE_ID);
Deleted:
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-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.default.sql 2010-02-05
17:20:02 UTC (rev 1708)
@@ -1,14 +0,0 @@
-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,
- IS_SESSIONSCOPED CHAR NOT NULL,
- IS_DEEP CHAR NOT NULL,
- BIRTHDAY BIGINT NOT NULL,
- TIMEOUT BIGINT NOT NULL,
- CONSTRAINT JCR_PK_LOCK PRIMARY KEY(NODE_ID, WS_NAME)
-);
-
-CREATE INDEX JCR_ALL_WS_LOCKS ON JCR_LOCKS(WS_NAME, NODE_ID);
-CREATE INDEX JCR_LOCKS_BY_ID ON JCR_LOCKS(NODE_ID);
Deleted:
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-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/lock-jdbc.ora.sql 2010-02-05
17:20:02 UTC (rev 1708)
@@ -1,17 +0,0 @@
-/*$DELIMITER:/ */
-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,
- IS_SESSIONSCOPED CHAR NOT NULL,
- IS_DEEP CHAR NOT NULL,
- BIRTHDAY LONG NOT NULL,
- TIMEOUT LONG NOT NULL,
- CONSTRAINT JCR_PK_LOCK PRIMARY KEY(NODE_ID, WS_NAME)
-)
-/
-CREATE INDEX JCR_ALL_WS_LOCKS ON JCR_LOCKS(WS_NAME, NODE_ID)
-/
-CREATE INDEX JCR_LOCKS_BY_ID ON JCR_LOCKS(NODE_ID)
-/
\ No newline at end of file
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCConnectionTestBase.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCConnectionTestBase.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCConnectionTestBase.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -21,7 +21,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.init.StorageDBInitializer;
import java.io.ByteArrayInputStream;
import java.sql.Connection;
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestMultiDbJDBCConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestMultiDbJDBCConnection.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestMultiDbJDBCConnection.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -17,7 +17,7 @@
package org.exoplatform.services.jcr.impl.storage.jdbc.db;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCConnectionTestBase;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.init.StorageDBInitializer;
import java.sql.SQLException;
import java.sql.Statement;
@@ -36,7 +36,7 @@
private void setUp(String scriptPath, boolean multiDB) throws Exception
{
super.setUp();
- new DBInitializer("ws3", getJNDIConnection(), scriptPath,
multiDB).init();
+ new StorageDBInitializer("ws3", getJNDIConnection(), scriptPath,
multiDB).init();
}
@Override
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestSingleDbJDBCConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestSingleDbJDBCConnection.java 2010-02-05
17:00:14 UTC (rev 1707)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/TestSingleDbJDBCConnection.java 2010-02-05
17:20:02 UTC (rev 1708)
@@ -17,7 +17,7 @@
package org.exoplatform.services.jcr.impl.storage.jdbc.db;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCConnectionTestBase;
-import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.init.StorageDBInitializer;
import java.sql.SQLException;
import java.sql.Statement;
@@ -36,7 +36,7 @@
private void setUp(String scriptPath, boolean multiDB) throws Exception
{
super.setUp();
- new DBInitializer("ws3", getJNDIConnection(), scriptPath,
multiDB).init();
+ new StorageDBInitializer("ws3", getJNDIConnection(), scriptPath,
multiDB).init();
}
@Override