exo-jcr SVN: r1708 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 8 other directories.
by do-not-reply@jboss.org
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
16 years, 5 months
exo-jcr SVN: r1707 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache: jdbc and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-02-05 12:00:14 -0500 (Fri, 05 Feb 2010)
New Revision: 1707
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
Log:
EXOJCR-472: LockJDBCConnection isLockDataExist added
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05 16:52:40 UTC (rev 1706)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05 17:00:14 UTC (rev 1707)
@@ -32,44 +32,17 @@
*/
public interface CacheableLockManager extends WorkspaceLockManager
{
-
- // Search constants
/**
- * The exact lock token.
- */
- public static final int SEARCH_EXECMATCH = 1;
-
- /**
- * Lock token of closed parent
- */
- public static final int SEARCH_CLOSEDPARENT = 2;
-
- /**
- * Lock token of closed child
- */
- public static final int SEARCH_CLOSEDCHILD = 4;
-
- /**
* Is lock live for node by nodeIdentifier.
*
* @param nodeIdentifier
*
* @return boolean
- * @throws LockException TODO
+ * @throws LockException
*/
boolean isLockLive(String nodeIdentifier) throws LockException;
/**
- * Search lock in storage. SearchType shows which locks should be returned.
- * See SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD. SearchTypes may be combined.
- *
- * @param node - base node to search locks
- * @param searchType - combination of SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD search types
- * @return LockData or null
- */
- // public LockData getLockData(NodeData node, int searchType) throws LockException;
-
- /**
* Replace old lockData with new one. Node ID, token can't be replaced.
*
* @param newLockData
@@ -92,9 +65,33 @@
*/
String getLockTokenHash(String lockToken);
- LockData getExactNodeLock(NodeData node) throws RepositoryException;
+ /**
+ * Return lock holding node.
+ *
+ * @param node NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
+ //LockData getExactNodeLock(NodeData node) throws RepositoryException;
+ /**
+ * Return Lock holding node or its parent.
+ *
+ * @param node - NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException;
+ /**
+ * Return Lock holding any nodes child.
+ *
+ * @param node - NodeData
+ * @return LockData for node or null;
+ * @throws RepositoryException
+ */
LockData getClosedChild(NodeData node) throws RepositoryException;
+
+ boolean lockExist(String nodeId) throws RepositoryException;
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05 16:52:40 UTC (rev 1706)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05 17:00:14 UTC (rev 1707)
@@ -709,7 +709,10 @@
}
};
- private boolean lockExist(String nodeId)
+ /**
+ * {@inheritDoc}
+ */
+ public boolean lockExist(String nodeId)
{
try
{
@@ -723,10 +726,7 @@
}
/**
- * Calculates md5 hash of string.
- *
- * @param token
- * @return
+ * {@inheritDoc}
*/
public String getLockTokenHash(String token)
{
@@ -744,6 +744,9 @@
return hash;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException
{
if (node == null)
@@ -761,6 +764,9 @@
return retval;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeLock(NodeData node) throws RepositoryException
{
LockData retval = null;
@@ -771,6 +777,9 @@
return retval;
}
+ /**
+ * {@inheritDoc}
+ */
public LockData getClosedChild(NodeData node) throws RepositoryException
{
LockData retval = null;
@@ -920,7 +929,6 @@
*/
public void closeSessionLockManager(String sessionID)
{
-
sessionLockManagers.remove(sessionID);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05 16:52:40 UTC (rev 1706)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05 17:00:14 UTC (rev 1707)
@@ -177,8 +177,7 @@
*/
public boolean holdsLock(NodeData node) throws RepositoryException
{
- //TODO optimise it
- return lockManager.getExactNodeLock(node) != null;
+ return lockManager.lockExist(node.getIdentifier());//.getExactNodeLock(node) != null;
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 16:52:40 UTC (rev 1706)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 17:00:14 UTC (rev 1707)
@@ -746,7 +746,10 @@
}
}
- private boolean lockExist(String nodeId) throws RepositoryException
+ /**
+ * {@inheritDoc}
+ */
+ public boolean lockExist(String nodeId) throws RepositoryException
{
//if present in cache - then exists
if (cache.get(makeLockFqn(nodeId), LOCK_DATA) != null)
@@ -760,7 +763,7 @@
try
{
connection = this.lockJDBCContainer.openConnection();
- return connection.getLockData(nodeId) != null;
+ return connection.isLockDataExist(nodeId);
}
finally
{
@@ -863,6 +866,9 @@
// return retval;
// }
+ /**
+ * {@inheritDoc}
+ */
public LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException
{
if (node == null)
@@ -880,16 +886,22 @@
return retval;
}
- public LockData getExactNodeLock(NodeData node) throws RepositoryException
- {
- LockData retval = null;
- if (node != null)
- {
- retval = getLockDataById(node.getIdentifier());
- }
- return retval;
- }
+ /**
+ * {@inheritDoc}
+ */
+ // public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ // {
+ // LockData retval = null;
+ // if (node != null)
+ // {
+ // retval = getLockDataById(node.getIdentifier());
+ // }
+ // return retval;
+ // }
+ /**
+ * {@inheritDoc}
+ */
public LockData getClosedChild(NodeData node) throws RepositoryException
{
LockData retval = null;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 16:52:40 UTC (rev 1706)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 17:00:14 UTC (rev 1707)
@@ -53,6 +53,8 @@
protected String GET_LOCK_DATA;
+ protected String IS_LOCK_DATA_EXIST;
+
// column names
protected static String COLUMN_WS_NAME = "WS_NAME";
@@ -81,6 +83,8 @@
private PreparedStatement getLockData;
+ private PreparedStatement isLockDataExist;
+
private Connection dbConnection;
private String wsName;
@@ -113,6 +117,9 @@
GET_LOCKED_NODES = "select NODE_ID from JCR_LOCKS where WS_NAME=?";
GET_LOCK_DATA = "select * from JCR_LOCKS where NODE_ID=? and WS_NAME=?";
+
+ IS_LOCK_DATA_EXIST = "select NODE_ID from JCR_LOCKS where NODE_ID=? and WS_NAME=?";
+
}
/**
@@ -311,9 +318,44 @@
}
/**
- * Check if connection is alive and opened
+ * Check is LockData by node identifier exist.
+ *
+ * @param identifier
* @return
+ * @throws RepositoryException
*/
+ public boolean isLockDataExist(String identifier) throws RepositoryException
+ {
+ if (!isOpened())
+ {
+ throw new IllegalStateException("Connection is closed");
+ }
+ try
+ {
+ if (isLockDataExist == null)
+ {
+ isLockDataExist = dbConnection.prepareStatement(IS_LOCK_DATA_EXIST);
+ }
+ else
+ {
+ isLockDataExist.clearParameters();
+ }
+ isLockDataExist.setString(1, identifier);
+ isLockDataExist.setString(2, wsName);
+ // get result set
+ ResultSet result = getLockData.executeQuery();
+ return result.next();
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * Check if connection is alive and opened
+ * @return boolean
+ */
public boolean isOpened()
{
try
16 years, 5 months
exo-jcr SVN: r1706 - in jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load: query and 1 other directories.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2010-02-05 11:52:40 -0500 (Fri, 05 Feb 2010)
New Revision: 1706
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/NodeInfo.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/WorkerResult.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/AbstractWebDavTestAgent.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java
Removed:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AvgResponceTimeTest.java
Log:
EXOJCR-395 : load test update
Copied: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java (from rev 1697, jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AvgResponceTimeTest.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2010 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.cluster.load;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractAvgResponceTimeTest
+{
+
+ private final int iterationGrowingPoll;
+
+ private final int iterationTime;
+
+ private final int initialSize;
+
+ private final int readValue;
+
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ */
+ public AbstractAvgResponceTimeTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
+ {
+ super();
+ this.iterationGrowingPoll = iterationGrowingPoll;
+ this.iterationTime = iterationTime;
+ this.initialSize = initialSize;
+ this.readValue = readValue;
+ }
+
+ public void testResponce() throws Exception
+ {
+ final List<NodeInfo> nodesPath = new ArrayList<NodeInfo>();
+ //start from 1 thread
+ int threadCount = initialSize;
+
+ Random random = new Random();
+
+ while (true)
+ {
+
+ final List<WorkerResult> responceResults = Collections.synchronizedList(new ArrayList<WorkerResult>());
+
+ ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
+ CountDownLatch startSignal = new CountDownLatch(1);
+ AbstractTestAgent[] testAgents = new AbstractTestAgent[threadCount];
+ //pool initialization
+ for (int i = 0; i < threadCount; i++)
+ {
+ testAgents[i] = getAgent(nodesPath, responceResults, startSignal, readValue, random);
+ threadPool.execute(testAgents[i]);
+
+ }
+ responceResults.clear();
+ startSignal.countDown();//let all threads proceed
+
+ Thread.sleep(iterationTime);
+
+ threadPool.shutdown();
+ for (int i = 0; i < testAgents.length; i++)
+ {
+ testAgents[i].setShouldStop(true);
+ }
+ //wait 10 minutes
+ threadPool.awaitTermination(60 * 10, TimeUnit.SECONDS);
+ dumpResults(responceResults, threadCount);
+ threadCount += iterationGrowingPoll;
+ }
+ }
+
+ /**
+ * Create new agent
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ * @return
+ */
+ protected abstract AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random);
+
+ private void dumpResults(List<WorkerResult> responceResults, int threadCount)
+ {
+ long sum_read = 0;
+ long sum_write = 0;
+ long read = 0;
+ long write = 0;
+ for (WorkerResult workerResult : responceResults)
+ {
+
+ if (workerResult.isRead())
+ {
+ read++;
+ sum_read += workerResult.getResponceTime();
+ }
+ else
+ {
+ write++;
+ sum_write += workerResult.getResponceTime();
+ }
+ }
+ if ((read + write) > 0)
+ {
+ System.out.println(" ThreadCount= " + threadCount + " Read=" + read + " Write=" + write + " value "
+ + (read * 100 / (read + write)) + " Avg read resp=" + (read > 0 ? (sum_read / read) : 0)
+ + " Avg write resp=" + (write > 0 ? (sum_write / write) : 0));
+ }
+ responceResults.clear();
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractAvgResponceTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2010 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.cluster.load;
+
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractTestAgent implements Runnable
+{
+
+ protected final Random random;
+
+ private final int readValue;
+
+ private final CountDownLatch startSignal;
+
+ private final List<NodeInfo> nodesPath;
+
+ private final List<WorkerResult> responceResults;
+
+ private boolean shouldStop = false;
+
+ /**
+ *
+ */
+ public AbstractTestAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults, CountDownLatch startSignal,
+ int readValue, Random random)
+ {
+ this.nodesPath = nodesPath;
+ this.responceResults = responceResults;
+ this.random = random;
+ this.startSignal = startSignal;
+ this.readValue = readValue;
+ }
+
+ /**
+ * Do read
+ * @return
+ */
+ public abstract List<WorkerResult> doRead(List<NodeInfo> nodesPath);
+
+ /**
+ * Do write
+ * @return
+ */
+ public abstract List<WorkerResult> doWrite(List<NodeInfo> nodesPath);
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ try
+ {
+ startSignal.await();
+ while (!shouldStop)
+ {
+ if (random.nextInt(100) > readValue)
+ {
+
+ responceResults.addAll(doWrite(nodesPath));
+ }
+ else
+ {
+ responceResults.addAll(doRead(nodesPath));
+ }
+ }
+ }
+ catch (InterruptedException e)
+ {
+ // exit
+ }
+ }
+
+ /**
+ * @return the shouldStop
+ */
+ protected boolean isShouldStop()
+ {
+ return shouldStop;
+ }
+
+ /**
+ * @param shouldStop the shouldStop to set
+ */
+ protected void setShouldStop(boolean shouldStop)
+ {
+ this.shouldStop = shouldStop;
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AbstractTestAgent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AvgResponceTimeTest.java 2010-02-05 16:16:16 UTC (rev 1705)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/AvgResponceTimeTest.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -1,350 +0,0 @@
-/*
- * Copyright (C) 2010 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.cluster.load;
-
-import junit.framework.TestCase;
-
-import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-import java.util.Timer;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
- * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
- *
- */
-public class AvgResponceTimeTest extends TestCase
-{
- /**
- * WebDav realm
- */
- private String WEBDAV_REALM = "eXo REST services";
-
- /**
- * WebDav path
- */
- private String WEBDAV_DEFAULT_PATH = "/rest/jcr/repository/production/";
-
- /**
- * 10 sec default sampling time.
- */
- private static final int SAMPLING_TIME = 14000;
-
- /**
- * 2min default time of work of one iteration.
- */
- private static final int ITERATION_TIME = 60 * 1000;
-
- /**
- * How much thread will be added on the next iteration.
- */
- private static final int ITERATION_GROWING_POLL = 5;
-
- /**
- * Number between 0 and 100 show % how many read operations.
- */
- private static final int READ_VALUE = 90;
-
- private static final Random random = new Random();
-
- private volatile static long l1FolderCount = 0;
-
- private static long lastCleanTime;
-
- /**
- * Statistic dumper task
- */
- private static final Timer STAT_TIMER = new Timer(true);
-
- public void testResponce() throws Exception
- {
- final List<NodeInfo> nodesPath = new ArrayList<NodeInfo>();
- //start from 1 thread
- int threadCount = 0;
- lastCleanTime = System.currentTimeMillis();
-
- while (true)
- {
-
- final List<WorkerResult> responceResults = Collections.synchronizedList(new ArrayList<WorkerResult>());
- threadCount += ITERATION_GROWING_POLL;
- ExecutorService tp = Executors.newFixedThreadPool(threadCount);
- WorkerThread[] workedThread = new WorkerThread[threadCount];
- for (int i = 0; i < threadCount; i++)
- {
- workedThread[i] = new WorkerThread(nodesPath, responceResults);
- tp.execute(workedThread[i]);
-
- }
- responceResults.clear();
- System.out.println("Thread started " + threadCount);
- Thread.sleep(ITERATION_TIME);
-
- for (int i = 0; i < workedThread.length; i++)
- {
- workedThread[i].setShoudRun(false);
- }
- tp.shutdown();
- //wait 10 minutes
- tp.awaitTermination(60 * 10, TimeUnit.SECONDS);
- dumpResults(responceResults);
- responceResults.clear();
-
- }
- }
-
- public static void dumpResults(List<WorkerResult> responceResults)
- {
- long sum_read = 0;
- long sum_write = 0;
- long read = 0;
- long write = 0;
- for (WorkerResult workerResult : responceResults)
- {
-
- if (workerResult.isRead)
- {
- read++;
- sum_read += workerResult.responceTime;
- }
- else
- {
- write++;
- sum_write += workerResult.responceTime;
- }
- }
- if ((read + write) > 0)
- {
- System.out.println("Read=" + read + " Write=" + write + " value " + (read * 100 / (read + write))
- + " Avg read resp=" + (read > 0 ? (sum_read / read) : 0) + " Avg write resp="
- + (write > 0 ? (sum_write / write) : 0));
- //System.out.println(responceResults);
- }
- responceResults.clear();
- }
-
- private class NodeInfo
- {
- private final String path;
-
- private final long created;
-
- /**
- * @param path
- * @param created
- */
- public NodeInfo(String path, long created)
- {
- super();
- this.path = path;
- this.created = created;
- }
-
- }
-
- private class WorkerResult
- {
- private final boolean isRead;
-
- private final long responceTime;
-
- /**
- * @param isRead
- * @param responceTime
- */
- public WorkerResult(boolean isRead, long responceTime)
- {
- super();
- this.isRead = isRead;
- this.responceTime = responceTime;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString()
- {
- return "WorkerResult [isRead=" + isRead + ", responceTime=" + responceTime + "]";
- }
-
- }
-
- private class WorkerThread implements Runnable
- {
-
- private final List<WorkerResult> responceResults;
-
- private final List<NodeInfo> nodesPath;
-
- private String l1FolderName;
-
- private long l2FolderCount;
-
- private boolean shoudRun;
-
- /**
- * @param nodesPath
- * @param resultsList
- */
- public WorkerThread(List<NodeInfo> nodesPath, List<WorkerResult> responceResults)
- {
- this.nodesPath = nodesPath;
- this.responceResults = responceResults;
- this.shoudRun = true;
- }
-
- /**
- * @see java.lang.Runnable#run()
- */
- public void run()
- {
-
- while (shoudRun)
- {
- if (random.nextInt(100) > READ_VALUE)
- {
-
- doWrite();
- }
- else
- {
- doRead();
- }
- }
-
- }
-
- /**
- * @return the shoudRun
- */
- protected boolean isShoudRun()
- {
- return shoudRun;
- }
-
- /**
- * @param shoudRun the shoudRun to set
- */
- protected void setShoudRun(boolean shoudRun)
- {
- this.shoudRun = shoudRun;
- }
-
- private JCRWebdavConnection getNewConnection()
- {
- return new JCRWebdavConnection("192.168.0.129", 80, "root", "exo", WEBDAV_REALM, WEBDAV_DEFAULT_PATH);
- }
-
- /**
- * Make write operation.
- */
- private void doWrite()
- {
- long start = 0;
- JCRWebdavConnection connection = null;
- try
- {
- connection = getNewConnection();
-
- if (l1FolderName == null || l2FolderCount == 100)
- {
- l1FolderName = "folder" + (l1FolderCount++);
- start = System.currentTimeMillis();
- connection.addDir(l1FolderName);
- l2FolderCount = 0;
- responceResults.add(new WorkerResult(false, System.currentTimeMillis() - start));
- }
- String path = l1FolderName + "/" + "node" + l2FolderCount++;
- start = System.currentTimeMillis();
- HTTPResponse response = connection.addNode(path, ("__the_data_in_nt+file__" + l2FolderCount).getBytes());
-
- if (response.getStatusCode() != 201)
- {
- System.out.println(Thread.currentThread().getName() + " : Can not add (response code "
- + response.getStatusCode() + new String(response.getData()) + " ) node with path : " + path);
- }
- responceResults.add(new WorkerResult(false, System.currentTimeMillis() - start));
- nodesPath.add(new NodeInfo(path, System.currentTimeMillis()));
- }
- catch (Exception e)
- {
- System.out.println(e.getLocalizedMessage());
- }
- finally
- {
- if (connection != null)
- {
- connection.stop();
- }
- }
-
- }
-
- /**
- * Make
- */
- private void doRead()
- {
- if (nodesPath.size() > 0)
- {
-
- String readNodePath = null;
- while (readNodePath == null)
- {
- NodeInfo nodeInfo = nodesPath.get(random.nextInt(nodesPath.size()));
- // if ((System.currentTimeMillis() - nodeInfo.created) > 30000)
- // {
- readNodePath = nodeInfo.path;
- // }
-
- }
- long start = System.currentTimeMillis();
- JCRWebdavConnection conn = getNewConnection();
- try
- {
- HTTPResponse response = conn.getNode(readNodePath);
- if (response.getStatusCode() != 200)
- {
- System.out.println("Can not get (response code " + response.getStatusCode()
- + new String(response.getData()) + " ) node with path : " + readNodePath);
- }
-
- }
- catch (Exception e)
- {
- System.out.println(e.getLocalizedMessage());
- }
- finally
- {
- conn.stop();
- }
- responceResults.add(new WorkerResult(true, System.currentTimeMillis() - start));
- }
- }
- }
-}
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/NodeInfo.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/NodeInfo.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/NodeInfo.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 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.cluster.load;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+
+public class NodeInfo
+{
+ private final String path;
+
+ private final long created;
+
+ /**
+ * @param path
+ * @param created
+ */
+ public NodeInfo(String path, long created)
+ {
+ super();
+ this.path = path;
+ this.created = created;
+ }
+
+ /**
+ * @return the created
+ */
+ public long getCreated()
+ {
+ return created;
+ }
+
+ /**
+ * @return the path
+ */
+ public String getPath()
+ {
+ return path;
+ }
+
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/NodeInfo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/WorkerResult.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/WorkerResult.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/WorkerResult.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010 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.cluster.load;
+
+public class WorkerResult
+{
+
+ private final boolean isRead;
+
+ private final long responceTime;
+
+ /**
+ * @param isRead
+ * @param responceTime
+ * @param abstractAvgResponceTimeTest TODO
+ */
+ public WorkerResult(boolean isRead, long responceTime)
+ {
+ super();
+ this.isRead = isRead;
+ this.responceTime = responceTime;
+ }
+
+ /**
+ * @return the isRead
+ */
+ public boolean isRead()
+ {
+ return isRead;
+ }
+
+ /**
+ * @return the responceTime
+ */
+ public long getResponceTime()
+ {
+ return responceTime;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return "WorkerResult [isRead=" + isRead + ", responceTime=" + responceTime + "]";
+ }
+
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/WorkerResult.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2010 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.cluster.load.query;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.version.VersionException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class JcrQueryAvgResponceTimeTest extends JcrImplBaseTest
+{
+
+ /**
+ * 2min default time of work of one iteration.
+ */
+ private static final int ITERATION_TIME = 60 * 1000;
+
+ /**
+ * How much thread will be added on the next iteration.
+ */
+ private static final int ITERATION_GROWING_POLL = 5;
+
+ /**
+ * Number between 0 and 100 show % how many read operations.
+ */
+ private static final int READ_VALUE = 90;
+
+ private static final String[] words =
+ new String[]{"private", "branch", "final", "string", "logging", "bottle", "property", "node", "repository",
+ "exception", "cycle", "value", "index", "meaning", "strange", "words", "hello", "outline", "finest",
+ "basetest", "writer"};
+
+ public static final String FIELDNAME_COUNT = "count";
+
+ public static final String FIELDNAME_CONTENT = "Content";
+
+ public static final String FIELDNAME_STATISTIC = "Statistic";
+
+ public void testname() throws Exception
+ {
+ QueryAvgResponceTimeTest test =
+ new QueryAvgResponceTimeTest(repository, ITERATION_GROWING_POLL, ITERATION_TIME, 1, READ_VALUE);
+ test.testResponce();
+
+ }
+
+ private class QueryAvgResponceTimeTest extends AbstractAvgResponceTimeTest
+ {
+
+ private final RepositoryImpl repository;
+
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ * @param readValue
+ */
+ public QueryAvgResponceTimeTest(RepositoryImpl repository, int iterationGrowingPoll, int iterationTime,
+ int initialSize, int readValue)
+ {
+ super(iterationGrowingPoll, iterationTime, initialSize, readValue);
+ this.repository = repository;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
+ */
+ @Override
+ protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ return new QueryTestAgent(repository, nodesPath, responceResults, startSignal, readValue, random);
+ }
+
+ }
+
+ private class QueryTestAgent extends AbstractTestAgent
+ {
+ private final RepositoryImpl repository;
+
+ private UUID threadUUID;
+
+ /**
+ * @param repository
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ */
+ public QueryTestAgent(RepositoryImpl repository, List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ super(nodesPath, responceResults, startSignal, readValue, random);
+ this.threadUUID = UUID.randomUUID();
+ this.repository = repository;
+ initRoot();
+ }
+
+ /**
+ * @param repository
+ * @throws LoginException
+ * @throws NoSuchWorkspaceException
+ * @throws RepositoryException
+ * @throws ItemExistsException
+ * @throws PathNotFoundException
+ * @throws VersionException
+ * @throws ConstraintViolationException
+ * @throws LockException
+ * @throws AccessDeniedException
+ * @throws InvalidItemStateException
+ * @throws NoSuchNodeTypeException
+ */
+ private void initRoot()
+ {
+ try
+ {
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+ Session sessionLocal = repository.login(credentials, "ws");
+ // prepare nodes
+ Node wsRoot = sessionLocal.getRootNode();
+ Node threadNode = wsRoot.addNode("Thread" + threadUUID);
+ sessionLocal.save();
+ sessionLocal.logout();
+ sessionLocal = null;
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doRead(java.util.List)
+ */
+ @Override
+ public List<WorkerResult> doRead(List<NodeInfo> nodesPath)
+ {
+ List<WorkerResult> result = new ArrayList<WorkerResult>();
+ Session sessionLocal = null;
+ try
+ {
+ // login
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+ sessionLocal = repository.login(credentials, "ws");
+ // prepare nodes
+ int i = random.nextInt(words.length);
+ String word = words[i];
+ Query q =
+ sessionLocal.getWorkspace().getQueryManager().createQuery(
+ "SELECT * FROM nt:base WHERE " + FIELDNAME_CONTENT + "='" + word + "'", Query.SQL);
+ long start = System.currentTimeMillis();
+ QueryResult res = q.execute();
+ long sqlsize = res.getNodes().getSize();
+ result.add(new WorkerResult(true, System.currentTimeMillis() - start));
+ //log.info(word + " found:" + sqlsize + " time=" + (System.currentTimeMillis() - start));
+
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ finally
+ {
+ if (sessionLocal != null)
+ {
+ sessionLocal.logout();
+ sessionLocal = null;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doWrite(java.util.List)
+ */
+ @Override
+ public List<WorkerResult> doWrite(List<NodeInfo> nodesPath)
+ {
+ List<WorkerResult> result = new ArrayList<WorkerResult>();
+ // get any word
+ int i = random.nextInt(words.length);
+ String word = words[i];
+
+ Session sessionLocal = null;
+ try
+ {
+ CredentialsImpl credentials = new CredentialsImpl("admin", "admin".toCharArray());
+ sessionLocal = repository.login(credentials, "ws");
+ long start = System.currentTimeMillis();
+ Node threadNode = sessionLocal.getRootNode().getNode("Thread" + threadUUID);
+ addCountent(threadNode, UUID.randomUUID(), word);
+ sessionLocal.save();
+ result.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ //log.info(word + " time : " + (System.currentTimeMillis() - start));
+ }
+ catch (Exception e1)
+ {
+ if (sessionLocal != null)
+ {
+ // discard session changes
+ try
+ {
+ sessionLocal.refresh(false);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("An error occurs", e);
+ }
+ }
+ log.error("An error occurs", e1);
+ }
+ finally
+ {
+ if (sessionLocal != null)
+ {
+ sessionLocal.logout();
+ sessionLocal = null;
+ }
+ }
+ return result;
+ }
+
+ private void addCountent(Node testRoot, UUID nodePath, String content) throws RepositoryException
+ {
+ String uuidPath = nodePath.toString();
+ Node l1 = addOrCreate(uuidPath.substring(0, 8), testRoot);
+ Node l2 = addOrCreate(uuidPath.substring(9, 13), l1);
+ Node l3 = addOrCreate(uuidPath.substring(14, 18), l2);
+ Node l4 = addOrCreate(uuidPath.substring(19, 23), l3);
+ Node l5 = addOrCreate(uuidPath.substring(24), l4);
+ l5.setProperty(FIELDNAME_CONTENT, content);
+ }
+
+ /**
+ * Gets or creates node
+ *
+ * @param name
+ * @param parent
+ * @return
+ * @throws RepositoryException
+ */
+ private Node addOrCreate(String name, Node parent) throws RepositoryException
+ {
+ if (parent.hasNode(name))
+ {
+ return parent.getNode(name);
+ }
+ return parent.addNode(name);
+ }
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/query/JcrQueryAvgResponceTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/AbstractWebDavTestAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/AbstractWebDavTestAgent.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/AbstractWebDavTestAgent.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 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.cluster.load.webdav;
+
+import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
+import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class AbstractWebDavTestAgent extends AbstractTestAgent
+{
+ /**
+ * WebDav realm
+ */
+ private static final String WEBDAV_REALM = "eXo REST services";
+
+ /**
+ * WebDav path
+ */
+ private static final String WEBDAV_DEFAULT_PATH = "/rest/jcr/repository/production/";
+
+ /**
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ */
+ public AbstractWebDavTestAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int READ_VALUE, Random random)
+ {
+ super(nodesPath, responceResults, startSignal, READ_VALUE, random);
+ }
+
+ protected JCRWebdavConnection getNewConnection()
+ {
+ return new JCRWebdavConnection("192.168.0.129", 80, "root", "exo", WEBDAV_REALM, WEBDAV_DEFAULT_PATH);
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/AbstractWebDavTestAgent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 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.cluster.load.webdav;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest;
+import org.exoplatform.services.jcr.cluster.load.AbstractTestAgent;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class WebDavAvgResponceTimeTest extends TestCase
+{
+
+ /**
+ * 2min default time of work of one iteration.
+ */
+ private static final int ITERATION_TIME = 60 * 1000;
+
+ /**
+ * How much thread will be added on the next iteration.
+ */
+ private static final int ITERATION_GROWING_POLL = 5;
+
+ /**
+ * Number between 0 and 100 show % how many read operations.
+ */
+ private static final int READ_VALUE = 90;
+
+ public void testWebDav() throws Exception
+ {
+ WebDavTest test = new WebDavTest(ITERATION_GROWING_POLL, ITERATION_TIME, 1, READ_VALUE);
+ test.testResponce();
+ }
+
+ private class WebDavTest extends AbstractAvgResponceTimeTest
+ {
+ /**
+ * @param iterationGrowingPoll
+ * @param iterationTime
+ * @param initialSize
+ * @param readValue
+ */
+ public WebDavTest(int iterationGrowingPoll, int iterationTime, int initialSize, int readValue)
+ {
+ super(iterationGrowingPoll, iterationTime, initialSize, readValue);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractAvgResponceTimeTest#getAgent(java.util.List, java.util.List, java.util.concurrent.CountDownLatch, int, java.util.Random)
+ */
+ @Override
+ protected AbstractTestAgent getAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults,
+ CountDownLatch startSignal, int readValue, Random random)
+ {
+ return new WebDavTestAgent(nodesPath, responceResults, startSignal, readValue, random);
+ }
+
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavAvgResponceTimeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java 2010-02-05 16:52:40 UTC (rev 1706)
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2010 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.cluster.load.webdav;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
+import org.exoplatform.services.jcr.cluster.load.NodeInfo;
+import org.exoplatform.services.jcr.cluster.load.WorkerResult;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class WebDavTestAgent extends AbstractWebDavTestAgent
+{
+
+ private volatile static long l1FolderCount = 0;
+
+ private String l1FolderName;
+
+ private long l2FolderCount;
+
+ /**
+ * @param nodesPath
+ * @param responceResults
+ * @param startSignal
+ * @param READ_VALUE
+ * @param random
+ */
+ public WebDavTestAgent(List<NodeInfo> nodesPath, List<WorkerResult> responceResults, CountDownLatch startSignal,
+ int READ_VALUE, Random random)
+ {
+ super(nodesPath, responceResults, startSignal, READ_VALUE, random);
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doRead(java.util.List)
+ */
+ @Override
+ public List<WorkerResult> doRead(List<NodeInfo> nodesPath)
+ {
+ List<WorkerResult> result = new ArrayList<WorkerResult>();
+ if (nodesPath.size() > 0)
+ {
+
+ String readNodePath = null;
+ while (readNodePath == null)
+ {
+ NodeInfo nodeInfo = nodesPath.get(random.nextInt(nodesPath.size()));
+ // if ((System.currentTimeMillis() - nodeInfo.created) > 30000)
+ // {
+ readNodePath = nodeInfo.getPath();
+ // }
+
+ }
+ long start = System.currentTimeMillis();
+ JCRWebdavConnection conn = getNewConnection();
+ try
+ {
+ HTTPResponse response = conn.getNode(readNodePath);
+ if (response.getStatusCode() != 200)
+ {
+ System.out.println("Can not get (response code " + response.getStatusCode()
+ + new String(response.getData()) + " ) node with path : " + readNodePath);
+ }
+
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.getLocalizedMessage());
+ }
+ finally
+ {
+ conn.stop();
+ }
+
+ result.add(new WorkerResult(true, System.currentTimeMillis() - start));
+
+ }
+ return result;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.cluster.load.AbstractTestAgent#doWrite(java.util.List)
+ */
+ @Override
+ public List<WorkerResult> doWrite(List<NodeInfo> nodesPath)
+ {
+ List<WorkerResult> result = new ArrayList<WorkerResult>();
+ long start = 0;
+ JCRWebdavConnection connection = null;
+ try
+ {
+ connection = getNewConnection();
+
+ if (l1FolderName == null || l2FolderCount == 100)
+ {
+ l1FolderName = "folder" + (l1FolderCount++);
+ start = System.currentTimeMillis();
+ connection.addDir(l1FolderName);
+ l2FolderCount = 0;
+ result.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ }
+ String path = l1FolderName + "/" + "node" + l2FolderCount++;
+ start = System.currentTimeMillis();
+ HTTPResponse response = connection.addNode(path, ("__the_data_in_nt+file__" + l2FolderCount).getBytes());
+
+ if (response.getStatusCode() != 201)
+ {
+ System.out.println(Thread.currentThread().getName() + " : Can not add (response code "
+ + response.getStatusCode() + new String(response.getData()) + " ) node with path : " + path);
+ }
+ result.add(new WorkerResult(false, System.currentTimeMillis() - start));
+ nodesPath.add(new NodeInfo(path, System.currentTimeMillis()));
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.getLocalizedMessage());
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.stop();
+ }
+ }
+ return result;
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/load/webdav/WebDavTestAgent.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 5 months
exo-jcr SVN: r1705 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache: jdbc and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-02-05 11:16:16 -0500 (Fri, 05 Feb 2010)
New Revision: 1705
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
Log:
EXOJCR-472: CacheableLockManager.getLockData splitted to three methods
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05 15:22:40 UTC (rev 1704)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-02-05 16:16:16 UTC (rev 1705)
@@ -19,6 +19,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.lock.WorkspaceLockManager;
+import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
/**
@@ -66,7 +67,7 @@
* @param searchType - combination of SEARCH_EXECMATCH, SEARCH_CLOSEDPARENT, SEARCH_CLOSEDCHILD search types
* @return LockData or null
*/
- public LockData getLockData(NodeData node, int searchType) throws LockException;
+ // public LockData getLockData(NodeData node, int searchType) throws LockException;
/**
* Replace old lockData with new one. Node ID, token can't be replaced.
@@ -90,4 +91,10 @@
* @return - hash string
*/
String getLockTokenHash(String lockToken);
+
+ LockData getExactNodeLock(NodeData node) throws RepositoryException;
+
+ LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException;
+
+ LockData getClosedChild(NodeData node) throws RepositoryException;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05 15:22:40 UTC (rev 1704)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-02-05 16:16:16 UTC (rev 1705)
@@ -744,63 +744,51 @@
return hash;
}
- /**
- * {@inheritDoc}
- */
- public LockData getLockData(NodeData data, int searchType)
+ public LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException
{
- if (data == null)
+ if (node == null)
return null;
LockData retval = null;
- try
+ retval = getLockDataById(node.getIdentifier());
+ if (retval == null)
{
- if ((searchType & SEARCH_EXECMATCH) != 0)
+ NodeData parentData = (NodeData)dataManager.getItemData(node.getParentIdentifier());
+ if (parentData != null)
{
- retval = getLockDataById(data.getIdentifier());
+ retval = getExactNodeOrCloseParentLock(parentData);
}
- if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
- {
+ }
+ return retval;
+ }
- NodeData parentData = (NodeData)dataManager.getItemData(data.getParentIdentifier());
- if (parentData != null)
- {
- retval = getLockDataById(parentData.getIdentifier());
- // parent not found try to fo upper
- if (retval == null)
- {
- retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
- }
- }
- }
- if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
- {
+ public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+ if (node != null)
+ {
+ retval = getLockDataById(node.getIdentifier());
+ }
+ return retval;
+ }
- List<NodeData> childData = dataManager.getChildNodesData(data);
- for (NodeData nodeData : childData)
- {
- retval = getLockDataById(nodeData.getIdentifier());
- if (retval != null)
- break;
- }
- if (retval == null)
- {
- // child not found try to find diper
- for (NodeData nodeData : childData)
- {
- retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
- if (retval != null)
- break;
- }
- }
- }
+ public LockData getClosedChild(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+
+ List<NodeData> childData = dataManager.getChildNodesData(node);
+ for (NodeData nodeData : childData)
+ {
+ retval = getLockDataById(nodeData.getIdentifier());
+ if (retval != null)
+ return retval;
}
- catch (RepositoryException e)
+ // child not found try to find dipper
+ for (NodeData nodeData : childData)
{
- //TODO
- log.error(e.getMessage(), e);
- return null;
+ retval = getClosedChild(nodeData);
+ if (retval != null)
+ return retval;
}
-
return retval;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05 15:22:40 UTC (rev 1704)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableSessionLockManager.java 2010-02-05 16:16:16 UTC (rev 1705)
@@ -106,9 +106,8 @@
NodeData data = (NodeData)node.getData();
- LockData lData =
- lockManager
- .getLockData(data, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ LockData lData = lockManager.getExactNodeOrCloseParentLock(data);
+ //.getLockData(data, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
if (lData != null)
{
if (lData.getNodeIdentifier().equals(node.getIdentifier()))
@@ -121,7 +120,7 @@
}
}
- if (isDeep && lockManager.getLockData(data, CacheableLockManager.SEARCH_CLOSEDCHILD) != null)
+ if (isDeep && lockManager.getClosedChild(data) != null)
{
throw new LockException("Some child node is locked.");
}
@@ -154,9 +153,7 @@
*/
public LockImpl getLock(NodeImpl node) throws LockException, RepositoryException
{
- LockData lData =
- lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
- | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ LockData lData = lockManager.getExactNodeOrCloseParentLock((NodeData)node.getData());
if (lData == null || (!node.getInternalIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
{
@@ -180,7 +177,8 @@
*/
public boolean holdsLock(NodeData node) throws RepositoryException
{
- return lockManager.getLockData(node, CacheableLockManager.SEARCH_EXECMATCH) != null;
+ //TODO optimise it
+ return lockManager.getExactNodeLock(node) != null;
}
/**
@@ -188,9 +186,15 @@
*/
public boolean isLocked(NodeData node) throws LockException
{
- LockData lData =
- lockManager
- .getLockData(node, CacheableLockManager.SEARCH_EXECMATCH | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ LockData lData = null;
+ try
+ {
+ lData = lockManager.getExactNodeOrCloseParentLock(node);
+ }
+ catch (RepositoryException e)
+ {
+ throw new LockException(e.getMessage(), e);
+ }
if (lData == null || (!node.getIdentifier().equals(lData.getNodeIdentifier()) && !lData.isDeep()))
{
@@ -204,9 +208,8 @@
*/
public boolean isLockHolder(NodeImpl node) throws RepositoryException
{
- LockData lData =
- lockManager.getLockData((NodeData)node.getData(), CacheableLockManager.SEARCH_EXECMATCH
- | CacheableLockManager.SEARCH_CLOSEDPARENT);
+ //TODO optimise it
+ LockData lData = lockManager.getExactNodeOrCloseParentLock((NodeData)node.getData());
return lData != null && isLockHolder(lData);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 15:22:40 UTC (rev 1704)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 16:16:16 UTC (rev 1705)
@@ -808,58 +808,106 @@
/**
* {@inheritDoc}
*/
- public LockData getLockData(NodeData data, int searchType) throws LockException
+ // public LockData getLockData(NodeData data, int searchType) throws LockException
+ // {
+ // if (data == null)
+ // return null;
+ // LockData retval = null;
+ // try
+ // {
+ // if ((searchType & SEARCH_EXECMATCH) != 0)
+ // {
+ // retval = getLockDataById(data.getIdentifier());
+ // }
+ // if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
+ // {
+ //
+ // NodeData parentData = (NodeData)dataManager.getItemData(data.getParentIdentifier());
+ // if (parentData != null)
+ // {
+ // retval = getLockDataById(parentData.getIdentifier());
+ // // parent not found try to fo upper
+ // if (retval == null)
+ // {
+ // retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
+ // }
+ // }
+ // }
+ // if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
+ // {
+ //
+ // List<NodeData> childData = dataManager.getChildNodesData(data);
+ // for (NodeData nodeData : childData)
+ // {
+ // retval = getLockDataById(nodeData.getIdentifier());
+ // if (retval != null)
+ // break;
+ // }
+ // if (retval == null)
+ // {
+ // // child not found try to find diper
+ // for (NodeData nodeData : childData)
+ // {
+ // retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
+ // if (retval != null)
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // catch (RepositoryException e)
+ // {
+ // throw new LockException(e.getMessage(), e);
+ // }
+ //
+ // return retval;
+ // }
+
+ public LockData getExactNodeOrCloseParentLock(NodeData node) throws RepositoryException
{
- if (data == null)
+ if (node == null)
return null;
LockData retval = null;
- try
+ retval = getLockDataById(node.getIdentifier());
+ if (retval == null)
{
- if ((searchType & SEARCH_EXECMATCH) != 0)
+ NodeData parentData = (NodeData)dataManager.getItemData(node.getParentIdentifier());
+ if (parentData != null)
{
- retval = getLockDataById(data.getIdentifier());
+ retval = getExactNodeOrCloseParentLock(parentData);
}
- if (retval == null && (searchType & SEARCH_CLOSEDPARENT) != 0)
- {
+ }
+ return retval;
+ }
- NodeData parentData = (NodeData)dataManager.getItemData(data.getParentIdentifier());
- if (parentData != null)
- {
- retval = getLockDataById(parentData.getIdentifier());
- // parent not found try to fo upper
- if (retval == null)
- {
- retval = getLockData(parentData, SEARCH_CLOSEDPARENT);
- }
- }
- }
- if (retval == null && (searchType & SEARCH_CLOSEDCHILD) != 0)
- {
+ public LockData getExactNodeLock(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+ if (node != null)
+ {
+ retval = getLockDataById(node.getIdentifier());
+ }
+ return retval;
+ }
- List<NodeData> childData = dataManager.getChildNodesData(data);
- for (NodeData nodeData : childData)
- {
- retval = getLockDataById(nodeData.getIdentifier());
- if (retval != null)
- break;
- }
- if (retval == null)
- {
- // child not found try to find diper
- for (NodeData nodeData : childData)
- {
- retval = getLockData(nodeData, SEARCH_CLOSEDCHILD);
- if (retval != null)
- break;
- }
- }
- }
+ public LockData getClosedChild(NodeData node) throws RepositoryException
+ {
+ LockData retval = null;
+
+ List<NodeData> childData = dataManager.getChildNodesData(node);
+ for (NodeData nodeData : childData)
+ {
+ retval = getLockDataById(nodeData.getIdentifier());
+ if (retval != null)
+ return retval;
}
- catch (RepositoryException e)
+ // child not found try to find dipper
+ for (NodeData nodeData : childData)
{
- throw new LockException(e.getMessage(), e);
+ retval = getClosedChild(nodeData);
+ if (retval != null)
+ return retval;
}
-
return retval;
}
16 years, 5 months
exo-jcr SVN: r1704 - ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2010-02-05 10:22:40 -0500 (Fri, 05 Feb 2010)
New Revision: 1704
Modified:
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-468
Modified: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-02-05 15:12:29 UTC (rev 1703)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-02-05 15:22:40 UTC (rev 1704)
@@ -55,7 +55,7 @@
/** The headers array. */
NVPair[] headers;
-
+
/** Logger. */
private static final Log LOG = ExoLogger.getLogger(BaseConnector.class);
@@ -63,24 +63,47 @@
* {@inheritDoc}
*/
@Override
- public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException
+ public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
{
URL url_obj = null;
url_obj = new URL(url);
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
- prepareFormParams(url_obj);
-
- resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+ prepareFormParams(url_obj);
+ resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+
+ byte[] body = new byte[httpRequest.getContentLength()];
+ new DataInputStream(httpRequest.getInputStream()).readFully(body);
+ resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
return resp;
}
@@ -88,28 +111,50 @@
* {@inheritDoc}
*/
@Override
- public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException
+ public HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
{
URL url_obj = null;
- url_obj = new URL(url);
+ url_obj = new URL(url);
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
- byte[] body = new byte[httpRequest.getContentLength()];;
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
- }
+ byte[] body = new byte[httpRequest.getContentLength()];
+ new DataInputStream(httpRequest.getInputStream()).readFully(body);
+ resp = conn.Put(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
return resp;
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+ resp = conn.Delete(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
+
+ /**
* Prepares request headers.
*
* @param httpRequest the http request
Modified: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-02-05 15:12:29 UTC (rev 1703)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-02-05 15:22:40 UTC (rev 1704)
@@ -58,5 +58,27 @@
*/
abstract HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
IOException, ModuleException,ParseException;
+
+
+ /**
+ * Do PUT proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
+
+
+ /**
+ * Do DELETE proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
}
Modified: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-02-05 15:12:29 UTC (rev 1703)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-02-05 15:22:40 UTC (rev 1704)
@@ -23,8 +23,10 @@
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
@@ -88,6 +90,7 @@
}
}
+
/**
* Handles POST proxy request.
*
@@ -132,6 +135,94 @@
}
/**
+ * Handles PUT proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @PUT
+ public Response doProxyPut(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.doPut(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+
+ }
+
+ /**
+ * Handles DELETE proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @DELETE
+ public Response doProxyDelete(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.doDelete(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+
+ }
+
+ /**
* Creates the response from HTTP response.
*
* @param httpResponse the http response
16 years, 5 months
exo-jcr SVN: r1703 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2010-02-05 10:12:29 -0500 (Fri, 05 Feb 2010)
New Revision: 1703
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-468 POST & PUT Added
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-02-05 15:00:41 UTC (rev 1702)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-02-05 15:12:29 UTC (rev 1703)
@@ -55,7 +55,7 @@
/** The headers array. */
NVPair[] headers;
-
+
/** Logger. */
private static final Log LOG = ExoLogger.getLogger(BaseConnector.class);
@@ -63,24 +63,47 @@
* {@inheritDoc}
*/
@Override
- public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException
+ public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
{
URL url_obj = null;
url_obj = new URL(url);
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
- prepareFormParams(url_obj);
-
- resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+ prepareFormParams(url_obj);
+ resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+
+ byte[] body = new byte[httpRequest.getContentLength()];
+ new DataInputStream(httpRequest.getInputStream()).readFully(body);
+ resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
return resp;
}
@@ -88,28 +111,50 @@
* {@inheritDoc}
*/
@Override
- public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException
+ public HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
{
URL url_obj = null;
- url_obj = new URL(url);
+ url_obj = new URL(url);
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
- byte[] body = new byte[httpRequest.getContentLength()];;
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(resp.getText());
- }
+ byte[] body = new byte[httpRequest.getContentLength()];
+ new DataInputStream(httpRequest.getInputStream()).readFully(body);
+ resp = conn.Put(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
return resp;
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException,
+ ProtocolNotSuppException, IOException, ModuleException, ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+ resp = conn.Delete(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
+
+ /**
* Prepares request headers.
*
* @param httpRequest the http request
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-02-05 15:00:41 UTC (rev 1702)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-02-05 15:12:29 UTC (rev 1703)
@@ -58,5 +58,27 @@
*/
abstract HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
IOException, ModuleException,ParseException;
+
+
+ /**
+ * Do PUT proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
+
+
+ /**
+ * Do DELETE proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
}
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-02-05 15:00:41 UTC (rev 1702)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-02-05 15:12:29 UTC (rev 1703)
@@ -23,8 +23,10 @@
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
@@ -88,6 +90,7 @@
}
}
+
/**
* Handles POST proxy request.
*
@@ -132,6 +135,94 @@
}
/**
+ * Handles PUT proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @PUT
+ public Response doProxyPut(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.doPut(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+
+ }
+
+ /**
+ * Handles DELETE proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @DELETE
+ public Response doProxyDelete(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.doDelete(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+
+ }
+
+ /**
* Creates the response from HTTP response.
*
* @param httpResponse the http response
16 years, 5 months
exo-jcr SVN: r1702 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/core/lock and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-02-05 10:00:41 -0500 (Fri, 05 Feb 2010)
New Revision: 1702
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.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/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java
Log:
EXOJCR-472: CacheableLockManager - exceptions throwing updated
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 15:00:41 UTC (rev 1702)
@@ -137,11 +137,6 @@
*/
private LockRemover lockRemover;
- /**
- * The current Transaction Manager
- */
- private TransactionManager tm;
-
private Cache<Serializable, Object> cache;
private LockJDBCContainer lockJDBCContainer;
@@ -231,7 +226,7 @@
// make cache
if (config.getLockManager() != null)
{
- this.tm = transactionManager;
+
String dataSourceName = config.getLockManager().getParameterValue(DATA_SOURCE);
lockJDBCContainer = new LockJDBCContainer(dataSourceName, config.getName());
@@ -273,15 +268,34 @@
public int getNumLocks()
{
int lockNum = -1;
+ LockJDBCConnection connection = null;
try
{
- LockJDBCConnection connection = this.lockJDBCContainer.openConnection();
+ connection = this.lockJDBCContainer.openConnection();
lockNum = connection.getLockedNodes().size();
}
- catch (LockException e)
+ catch (RepositoryException e)
{
// skip
}
+ finally
+ {
+ if (connection != null)
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (IllegalStateException e)
+ {
+ // do nothing
+ }
+ catch (RepositoryException e)
+ {
+ // do nothing
+ }
+ }
+ }
return lockNum;
}
@@ -303,7 +317,14 @@
*/
public boolean isLockLive(String nodeId) throws LockException
{
- return this.lockExist(nodeId);
+ try
+ {
+ return this.lockExist(nodeId);
+ }
+ catch (RepositoryException e)
+ {
+ throw new LockException(e.getMessage(), e);
+ }
}
/**
@@ -415,7 +436,7 @@
{
log.error(e.getLocalizedMessage(), e);
}
- catch (LockException e)
+ catch (RepositoryException e)
{
log.error(e.getLocalizedMessage(), e);
}
@@ -471,15 +492,22 @@
public void apply() throws LockException
{
- // invoke internalLock in LOCK operation
- if (type == ExtendedEvent.LOCK)
+ try
{
- internalLock(sessionId, identifier);
+ // invoke internalLock in LOCK operation
+ if (type == ExtendedEvent.LOCK)
+ {
+ internalLock(sessionId, identifier);
+ }
+ // invoke internalUnLock in UNLOCK operation
+ else if (type == ExtendedEvent.UNLOCK)
+ {
+ internalUnLock(sessionId, identifier);
+ }
}
- // invoke internalUnLock in UNLOCK operation
- else if (type == ExtendedEvent.UNLOCK)
+ catch (RepositoryException e)
{
- internalUnLock(sessionId, identifier);
+ throw new LockException(e.getMessage(), e);
}
}
@@ -499,7 +527,6 @@
*/
public void refreshLockData(LockData newLockData) throws LockException
{
- // TODO
// Write to DB
LockJDBCConnection connection = null;
try
@@ -541,7 +568,6 @@
*/
public synchronized void removeExpired()
{
- // TODO
final List<String> removeLockList = new ArrayList<String>();
try
{
@@ -561,8 +587,9 @@
removeLock(rLock);
}
}
- catch (LockException e)
+ catch (RepositoryException e)
{
+ // Used from LockRemover thread, so no exception must be thrown.
log.error("Exception removing expired locks", e);
}
}
@@ -589,10 +616,10 @@
}
/**
- * Copy <code>PropertyData prop<code> to new TransientItemData
+ * Copy <code>PropertyData prop<code> to new TransientItemData.
*
- * @param prop
- * @return
+ * @param prop - PropertyData
+ * @return TransientItemData
* @throws RepositoryException
*/
private TransientItemData copyItemData(PropertyData prop) throws RepositoryException
@@ -616,14 +643,13 @@
* @param nodeIdentifier
* @throws LockException
*/
- private synchronized void internalLock(String sessionId, String nodeIdentifier) throws LockException
+ private synchronized void internalLock(String sessionId, String nodeIdentifier) throws RepositoryException
{
CacheableSessionLockManager sessionLockManager = sessionLockManagers.get(sessionId);
if (sessionLockManager != null && sessionLockManager.cotainsPendingLock(nodeIdentifier))
{
LockData lockData = sessionLockManager.getPendingLock(nodeIdentifier);
- //TODO
// add to DB for first
LockJDBCConnection connection = null;
try
@@ -635,15 +661,11 @@
// if any SQL exception, that nothing should be placed to cache
Fqn<String> lockPath = makeLockFqn(lockData.getNodeIdentifier());
- Node<Serializable, Object> node = cache.getRoot().addChild(lockPath);
+
cache.put(lockPath, LOCK_DATA, lockData);
sessionLockManager.notifyLockPersisted(nodeIdentifier);
}
- catch (RepositoryException e)
- {
- throw new LockException(e);
- }
finally
{
if (connection != null)
@@ -677,13 +699,12 @@
* @param nodeIdentifier
* @throws LockException
*/
- private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws LockException
+ private synchronized void internalUnLock(String sessionId, String nodeIdentifier) throws RepositoryException
{
LockData lData = getLockDataById(nodeIdentifier);
if (lData != null)
{
- //TODO
LockJDBCConnection connection = null;
try
{
@@ -725,9 +746,8 @@
}
}
- private boolean lockExist(String nodeId) throws LockException
+ private boolean lockExist(String nodeId) throws RepositoryException
{
- //TODO
//if present in cache - then exists
if (cache.get(makeLockFqn(nodeId), LOCK_DATA) != null)
{
@@ -788,7 +808,7 @@
/**
* {@inheritDoc}
*/
- public LockData getLockData(NodeData data, int searchType)
+ public LockData getLockData(NodeData data, int searchType) throws LockException
{
if (data == null)
return null;
@@ -837,17 +857,14 @@
}
catch (RepositoryException e)
{
- //TODO
- log.error(e.getMessage(), e);
- return null;
+ throw new LockException(e.getMessage(), e);
}
return retval;
}
- protected LockData getLockDataById(String nodeId) throws LockException
+ protected LockData getLockDataById(String nodeId) throws RepositoryException
{
- //TODO
LockData lData = (LockData)cache.get(makeLockFqn(nodeId), LOCK_DATA);
if (lData != null)
@@ -883,11 +900,8 @@
}
}
- protected synchronized List<LockData> getLockList() throws LockException
+ protected synchronized List<LockData> getLockList() throws RepositoryException
{
-
- //TODO
-
LockJDBCConnection connection = null;
try
{
@@ -905,7 +919,6 @@
{
locksData.add(connection.getLockData(nodeId));
}
-
}
return locksData;
}
@@ -919,13 +932,11 @@
}
catch (IllegalStateException e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error(e.getMessage(), e);
}
catch (RepositoryException e)
{
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error(e.getMessage(), e);
}
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 15:00:41 UTC (rev 1702)
@@ -28,7 +28,6 @@
import java.util.Set;
import javax.jcr.RepositoryException;
-import javax.jcr.lock.LockException;
/**
* Created by The eXo Platform SAS.
@@ -121,9 +120,9 @@
*
* @param data
* @return
- * @throws LockException
+ * @throws RepositoryException
*/
- public int addLockData(LockData data) throws LockException
+ public int addLockData(LockData data) throws RepositoryException
{
if (!isOpened())
{
@@ -152,7 +151,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
@@ -161,9 +160,9 @@
*
* @param nodeID
* @return
- * @throws LockException
+ * @throws RepositoryException
*/
- public int removeLockData(String nodeID) throws LockException
+ public int removeLockData(String nodeID) throws RepositoryException
{
if (!isOpened())
{
@@ -187,7 +186,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
@@ -196,9 +195,9 @@
*
* @param data
* @return
- * @throws LockException
+ * @throws RepositoryException
*/
- public int refreshLockData(LockData data) throws LockException
+ public int refreshLockData(LockData data) throws RepositoryException
{
if (!isOpened())
{
@@ -224,7 +223,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
@@ -232,9 +231,9 @@
* Returns the set of locked nodes identifiers
*
* @return
- * @throws LockException
+ * @throws RepositoryException
*/
- public Set<String> getLockedNodes() throws LockException
+ public Set<String> getLockedNodes() throws RepositoryException
{
if (!isOpened())
{
@@ -264,7 +263,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
@@ -272,11 +271,11 @@
* Returns LockData for given node identifier from database
* or null if not exists
*
- * @param identifier
- * @return
- * @throws LockException
+ * @param identifier - locked node identifier
+ * @return LockData
+ * @throws RepositoryException
*/
- public LockData getLockData(String identifier) throws LockException
+ public LockData getLockData(String identifier) throws RepositoryException
{
if (!isOpened())
{
@@ -307,7 +306,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
@@ -338,7 +337,6 @@
{
if (isOpened())
{
-
try
{
dbConnection.close();
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 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCContainer.java 2010-02-05 15:00:41 UTC (rev 1702)
@@ -94,7 +94,7 @@
}
- public LockJDBCConnection openConnection() throws LockException
+ public LockJDBCConnection openConnection() throws RepositoryException
{
try
{
@@ -102,7 +102,7 @@
}
catch (SQLException e)
{
- throw new LockException(e);
+ throw new RepositoryException(e);
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java 2010-02-05 14:32:25 UTC (rev 1701)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestLockPerstistentDataManager.java 2010-02-05 15:00:41 UTC (rev 1702)
@@ -26,7 +26,6 @@
import java.util.Set;
import javax.jcr.RepositoryException;
-import javax.jcr.lock.LockException;
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
@@ -202,7 +201,7 @@
connection.addLockData(new LockData("identifier", "hash", false, false, "owner", 100));
fail("exception expected!");
}
- catch (LockException e)
+ catch (RepositoryException e)
{
// it's ok
}
16 years, 5 months
exo-jcr SVN: r1701 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-02-05 09:32:25 -0500 (Fri, 05 Feb 2010)
New Revision: 1701
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
Log:
EXOJCR-472: Fixed parameter name
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 14:23:14 UTC (rev 1700)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/CacheableJDBCLockManagerImpl.java 2010-02-05 14:32:25 UTC (rev 1701)
@@ -100,7 +100,7 @@
/**
* The name of data source's property
*/
- public static final String DATA_SOURCE = "data-source";
+ public static final String DATA_SOURCE = "datasource";
/**
* Default lock time out. 30min
16 years, 5 months
exo-jcr SVN: r1700 - in ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext: proxy and 1 other directory.
by do-not-reply@jboss.org
Author: max_shaposhnik
Date: 2010-02-05 09:23:14 -0500 (Fri, 05 Feb 2010)
New Revision: 1700
Added:
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-468
Added: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java (rev 0)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-02-05 14:23:14 UTC (rev 1700)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2010 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.rest.ext.proxy;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.exoplatform.common.http.client.Codecs;
+import org.exoplatform.common.http.client.HTTPConnection;
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.common.http.client.ModuleException;
+import org.exoplatform.common.http.client.NVPair;
+import org.exoplatform.common.http.client.ParseException;
+import org.exoplatform.common.http.client.ProtocolNotSuppException;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id$
+ */
+public class BaseConnector extends Connector
+{
+
+ /** The connection. */
+ private HTTPConnection conn;
+
+ /** The HTTPResponse. */
+ HTTPResponse resp = null;
+
+ /** The form_data array. */
+ NVPair[] form_data;
+
+ /** The headers array. */
+ NVPair[] headers;
+
+ /** Logger. */
+ private static final Log LOG = ExoLogger.getLogger(BaseConnector.class);
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+ prepareFormParams(url_obj);
+
+ resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
+
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException
+ {
+ URL url_obj = null;
+ url_obj = new URL(url);
+
+ conn = new HTTPConnection(url_obj);
+ conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
+ prepareRequestHeaders(httpRequest);
+
+ byte[] body = new byte[httpRequest.getContentLength()];;
+ new DataInputStream(httpRequest.getInputStream()).readFully(body);
+ resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
+ if (resp.getStatusCode() >= 300)
+ {
+ LOG.error("Received Error: " + resp.getReasonLine());
+ LOG.error(resp.getText());
+ }
+ return resp;
+ }
+
+ /**
+ * Prepares request headers.
+ *
+ * @param httpRequest the http request
+ */
+ private void prepareRequestHeaders(HttpServletRequest httpRequest)
+ {
+ ArrayList<NVPair> hds = new ArrayList<NVPair>();
+ for (Enumeration<String> en = httpRequest.getHeaderNames(); en.hasMoreElements();)
+ {
+ NVPair pair = null;
+ String headerName = (String)en.nextElement();
+ for (Enumeration<String> en2 = httpRequest.getHeaders(headerName); en2.hasMoreElements();)
+ {
+ pair = new NVPair(headerName, en2.nextElement());
+ }
+ hds.add(pair);
+ this.headers = new NVPair[hds.size()];
+ this.headers = hds.toArray(headers);
+ }
+ }
+
+ /**
+ * Prepares form params.
+ *
+ * @param url the url
+ */
+ private void prepareFormParams(URL url)
+ {
+ String query = url.getQuery();
+ if (query != null)
+ {
+ try
+ {
+ this.form_data = Codecs.query2nv(query);
+ }
+ catch (ParseException e)
+ {
+ LOG.error(e.getMessage());
+ }
+ }
+ }
+}
Property changes on: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java (rev 0)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-02-05 14:23:14 UTC (rev 1700)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 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.rest.ext.proxy;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.common.http.client.ModuleException;
+import org.exoplatform.common.http.client.ParseException;
+import org.exoplatform.common.http.client.ProtocolNotSuppException;
+
+/**
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id$
+ */
+public abstract class Connector
+{
+
+ /** The connect timeout. */
+ protected static final int DEFAULT_CONNECT_TIMEOUT_MS = 5000;
+
+
+ /**
+ * Do GET proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
+
+ /**
+ * Do POST proxy request.
+ *
+ * @param httpRequest the HttpServletRequest
+ * @param url the url to request
+ * @return response HTTPResponse
+ */
+ abstract HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
+ IOException, ModuleException,ParseException;
+
+}
Property changes on: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java (rev 0)
+++ ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-02-05 14:23:14 UTC (rev 1700)
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2010 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.rest.ext.proxy;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Enumeration;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.common.http.client.ModuleException;
+import org.exoplatform.common.http.client.ParseException;
+import org.exoplatform.common.http.client.ProtocolNotSuppException;
+import org.exoplatform.services.rest.resource.ResourceContainer;
+
+/**
+ * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
+ * @version $Id$
+ */
+@Path("proxy")
+public class ProxyService implements ResourceContainer
+{
+ /**
+ * Handles GET proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @GET
+ public Response doProxyGet(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.fetchGet(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+
+ }
+ /**
+ * Handles POST proxy request.
+ *
+ * @param httpRequestHttpServletRequest
+ * @param url the url to request
+ * @return response Response
+ */
+ @POST
+ public Response doProxyPost(@Context HttpServletRequest httpRequest, @QueryParam("url") String url)
+ {
+ BaseConnector conn = new BaseConnector();
+ if (url == null)
+ {
+ Throwable e = new Throwable("Necessary URL parameter not found in proxy request");
+ throw new WebApplicationException(e, createErrorResponse(e, 404));
+ }
+ try
+ {
+ HTTPResponse resp = conn.fetchPost(httpRequest, url);
+ return createResponse(resp);
+ }
+ catch (MalformedURLException mue)
+ {
+ throw new WebApplicationException(mue, createErrorResponse(mue, 400));
+ }
+ catch (ProtocolNotSuppException pnse)
+ {
+ throw new WebApplicationException(pnse, createErrorResponse(pnse, 400));
+ }
+ catch (IOException ioe)
+ {
+ throw new WebApplicationException(ioe, createErrorResponse(ioe, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 500));
+ }
+ catch (ParseException pe)
+ {
+ throw new WebApplicationException(pe, createErrorResponse(pe, 400));
+ }
+ }
+
+ /**
+ * Creates the response from HTTP response.
+ *
+ * @param httpResponse the http response
+ * @return response Response
+ */
+ private Response createResponse(HTTPResponse httpResponse)
+ {
+ ResponseBuilder responseBuilder;
+ try
+ {
+ responseBuilder = Response.status(httpResponse.getStatusCode());
+ for (Enumeration<String> en = httpResponse.listHeaders(); en.hasMoreElements();)
+ {
+ String headerName = (String)en.nextElement();
+ responseBuilder.header(headerName, httpResponse.getHeader(headerName));
+ }
+ return responseBuilder.entity(httpResponse.getInputStream()).build();
+ }
+ catch (IOException e)
+ {
+ throw new WebApplicationException(e, createErrorResponse(e, 500));
+ }
+ catch (ModuleException me)
+ {
+ throw new WebApplicationException(me, createErrorResponse(me, 400));
+ }
+ }
+
+ /**
+ * Creates the error response.
+ *
+ * @param t Throwable
+ * @param status integer response status
+ * @return response Response
+ */
+ private Response createErrorResponse(Throwable t, int status)
+ {
+ return Response.status(status).entity(t.getMessage()).type("text/plain").build();
+ }
+}
Property changes on: ws/tags/2.1.0-CR1/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
16 years, 5 months
exo-jcr SVN: r1699 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-02-05 08:53:28 -0500 (Fri, 05 Feb 2010)
New Revision: 1699
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
Log:
EXOJCR-472: Fix LockJDBCConnection.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 13:29:35 UTC (rev 1698)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/jdbc/LockJDBCConnection.java 2010-02-05 13:53:28 UTC (rev 1699)
@@ -336,19 +336,18 @@
*/
public final void close() throws IllegalStateException, RepositoryException
{
- if (!isOpened())
+ if (isOpened())
{
- throw new IllegalStateException("Connection is closed");
- }
- try
- {
- dbConnection.close();
+ try
+ {
+ dbConnection.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
}
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
}
/**
16 years, 5 months