exo-jcr SVN: r3924 - jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 11:53:00 -0500 (Fri, 04 Feb 2011)
New Revision: 3924
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/query-handler-config.xml
Log:
EXOJCR-1104: make pagesize to be configurable
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/query-handler-config.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/query-handler-config.xml 2011-02-04 16:52:33 UTC (rev 3923)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/query-handler-config.xml 2011-02-04 16:53:00 UTC (rev 3924)
@@ -100,6 +100,7 @@
<property name="jgroups-multiplexer-stack" value="true" />
<property name="jbosscache-cluster-name" value="JCR-cluster-indexer-ws" />
<property name="max-volatile-time" value="60" />
+ <property name="reindexing-page-size" value="10000" />
</properties>
</query-handler>
</workspace></programlisting> <table>
@@ -154,6 +155,14 @@
<entry>max time to live for Volatile Index</entry>
</row>
+
+ <row>
+ <entry>reindexing-page-size</entry>
+
+ <entry>maximum amount of nodes which can be retrieved from
+ storage for re-indexing purpose, the default value is
+ 1000</entry>
+ </row>
</tbody>
</tgroup>
</table></para>
15 years, 2 months
exo-jcr SVN: r3923 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/core/query and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 11:52:33 -0500 (Fri, 04 Feb 2011)
New Revision: 3923
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchIndexConfigurationHelper.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1104: make pagesize to be configurable, using order by with limit and offset only for HSQLDB
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -108,4 +108,6 @@
public static final String PARAM_ANALYZER_CLASS = "analyzer";
public static final String PARAM_CHANGES_FILTER_CLASS = "changesfilter-class";
+
+ public static final String PARAM_REINDEXING_PAGE_SIZE = "reindexing-page-size";
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchIndexConfigurationHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchIndexConfigurationHelper.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchIndexConfigurationHelper.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -186,5 +186,9 @@
{
searchIndex.setSpellCheckerMinDistance(StringNumberParser.parseNumber(value).floatValue());
}
+ else if (QueryHandlerParams.PARAM_REINDEXING_PAGE_SIZE.equals(name))
+ {
+ searchIndex.setReindexingPageSize(StringNumberParser.parseNumber(value).intValue());
+ }
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -1479,7 +1479,8 @@
private long createIndex(Indexable indexableComponent, NodeData rootNode, ItemDataConsumer stateMgr, long count)
throws IOException, RepositoryException
{
- NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(10000);
+ NodeDataIndexingIterator iterator =
+ indexableComponent.getNodeDataIndexingIterator(handler.getReindexingPageSize());
while (iterator.hasNext())
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -171,6 +171,11 @@
public static final int DEFAULT_TERM_INFOS_INDEX_DIVISOR = 1;
/**
+ * The default value for {@link #reindexingPageSize}.
+ */
+ public static final int DEFAULT_REINDEXING_PAGE_SIZE = 1000;
+
+ /**
* Default name of the error log file
*/
private static final String ERROR_LOG = "error.log";
@@ -456,6 +461,11 @@
private final ConfigurationManager cfm;
/**
+ * Maximum amount of nodes which can be retrieved from storage for re-indexing purpose.
+ */
+ private int reindexingPageSize = DEFAULT_REINDEXING_PAGE_SIZE;
+
+ /**
* Working constructor.
*
* @throws RepositoryConfigurationException
@@ -2650,6 +2660,14 @@
}
/**
+ * @return the current value for reindexingPageSize
+ */
+ public int getReindexingPageSize()
+ {
+ return reindexingPageSize;
+ }
+
+ /**
* Sets a new value for termInfosIndexDivisor.
*
* @param termInfosIndexDivisor
@@ -2681,6 +2699,17 @@
this.initializeHierarchyCache = initializeHierarchyCache;
}
+ /**
+ * Set a new value for reindexingPageSize.
+ *
+ * @param reindexingPageSize
+ * the new value
+ */
+ public void setReindexingPageSize(int reindexingPageSize)
+ {
+ this.reindexingPageSize = reindexingPageSize;
+ }
+
// ----------------------------< internal
// >----------------------------------
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -83,6 +83,12 @@
FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1" + " order by N_ORDER_NUM";
FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1";
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=2" + " order by ID";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
+ + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
@Override
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -91,6 +91,12 @@
"select count(ID) from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=1 and CONTAINER_NAME=?";
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=2 and CONTAINER_NAME=?" + " order by ID";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -157,7 +157,7 @@
"select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
- + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where I.I_CLASS=1 LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -165,7 +165,7 @@
"select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
- + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -94,6 +94,12 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED,"
+ " V.ORDER_NUM, V.DATA, V.STORAGE_DESC from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID)"
+ " where I.PARENT_ID=? and I.I_CLASS=2 order by I.NAME";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
+ + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -49,7 +49,7 @@
* HSQLDB Singledatabase JDBC Connection constructor.
*
* @param dbConnection
- * JDBC connection, shoudl be opened before
+ * JDBC connection, should be opened before
* @param readOnly
* boolean if true the dbConnection was marked as READ-ONLY.
* @param containerName
@@ -105,6 +105,12 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED, V.ORDER_NUM,"
+ " V.DATA, V.STORAGE_DESC from JCR_SITEM I LEFT OUTER JOIN JCR_SVALUE V ON (V.PROPERTY_ID=I.ID)"
+ " where I.PARENT_ID=? and I.I_CLASS=2 and I.CONTAINER_NAME=? order by I.NAME";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -184,7 +184,7 @@
"select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
- + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where I.I_CLASS=1 LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-04 15:02:54 UTC (rev 3922)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-04 16:52:33 UTC (rev 3923)
@@ -191,7 +191,7 @@
"select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
- + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
15 years, 2 months
exo-jcr SVN: r3922 - in ws/trunk: exo.ws.rest.core and 6 other directories.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2011-02-04 10:02:54 -0500 (Fri, 04 Feb 2011)
New Revision: 3922
Added:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/DependencySupplier.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/InjectionProvider.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/InjectAnnotationTest.java
Modified:
ws/trunk/exo.ws.rest.core/pom.xml
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationRegistry.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityProviderTest.java
ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml
ws/trunk/pom.xml
Log:
EXOJCR-1181
Modified: ws/trunk/exo.ws.rest.core/pom.xml
===================================================================
--- ws/trunk/exo.ws.rest.core/pom.xml 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/pom.xml 2011-02-04 15:02:54 UTC (rev 3922)
@@ -104,6 +104,10 @@
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
</dependencies>
<build>
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ApplicationContext.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.rest;
+import org.exoplatform.services.rest.impl.DependencySupplier;
import org.exoplatform.services.rest.impl.ProviderBinder;
import org.exoplatform.services.rest.uri.UriPattern;
@@ -33,7 +34,7 @@
/**
* Provides access to ContainerRequest, ContainerResponse and other context
* information information.
- *
+ *
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
@@ -45,14 +46,14 @@
* in matching at
* {@link org.exoplatform.services.rest.uri.UriPattern#match(String, List)} .
* List will be cleared during matching.
- *
+ *
* @return the list for template values
*/
List<String> getParameterValues();
/**
* Pass in context list of path template parameters .
- *
+ *
* @param parameterNames list of templates parameters
* @see UriPattern
*/
@@ -65,9 +66,9 @@
* the root resource last.
* </p>
* So add each new resource at the begin of list.
- *
+ *
* @param resource the resource e. g. resource class, sub-resource method or
- * sub-resource locator
+ * sub-resource locator
*/
void addMatchedResource(Object resource);
@@ -78,9 +79,9 @@
* resource URI last.
* </p>
* So add each new URI at the begin of list.
- *
+ *
* @param uri the partial part of that matched to resource class,
- * sub-resource method or sub-resource locator
+ * sub-resource method or sub-resource locator
*/
void addMatchedURI(String uri);
@@ -132,6 +133,13 @@
GenericContainerResponse getContainerResponse();
/**
+ * @return instance of actual dependency resolver. It will be used for
+ * injection fields annotated with 'inject' annotation and
+ * constructor parameters not annotated with JAX-RS annotations
+ */
+ DependencySupplier getDependencySupplier();
+
+ /**
* @return set of providers
* @see Providers
*/
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/ContainerObjectFactory.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -28,7 +28,6 @@
* @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
* @version $Id: $
*/
-
public class ContainerObjectFactory<T extends ObjectModel> implements ObjectFactory<T>
{
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationContextImpl.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -60,7 +60,7 @@
/**
* Set ApplicationContext for current thread.
- *
+ *
* @param context the ApplicationContext.
*/
public static void setCurrent(ApplicationContext context)
@@ -158,21 +158,30 @@
*/
private MultivaluedMap<String, String> queryParameters;
+ private DependencySupplier dependencySupplier;
+
/**
* Constructs new instance of ApplicationContext.
- *
+ *
* @param request See {@link GenricContainerRequest}
* @param response See {@link GenericContainerResponse}
* @param providerBinder
*/
public ApplicationContextImpl(GenericContainerRequest request, GenericContainerResponse response,
- ProviderBinder providers)
+ ProviderBinder providers, DependencySupplier dependencySupplier)
{
this.request = request;
this.response = response;
this.providers = providers;
+ this.dependencySupplier = dependencySupplier;
}
+ public ApplicationContextImpl(GenericContainerRequest request, GenericContainerResponse response,
+ ProviderBinder providers)
+ {
+ this(request, response, providers, new DependencySupplier());
+ }
+
/**
* {@inheritDoc}
*/
@@ -253,6 +262,19 @@
/**
* {@inheritDoc}
*/
+ public DependencySupplier getDependencySupplier()
+ {
+ return dependencySupplier;
+ }
+
+ public void setDependencySupplier(DependencySupplier dependencySupplier)
+ {
+ this.dependencySupplier = dependencySupplier;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public HttpHeaders getHttpHeaders()
{
return request;
@@ -355,8 +377,8 @@
{
if (!pathParameters.containsKey(key))
{
- pathParameters.putSingle(UriComponent.decode(key, UriComponent.PATH_SEGMENT), UriComponent.decode(
- encodedPathParameters.getFirst(key), UriComponent.PATH));
+ pathParameters.putSingle(UriComponent.decode(key, UriComponent.PATH_SEGMENT),
+ UriComponent.decode(encodedPathParameters.getFirst(key), UriComponent.PATH));
}
}
}
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationRegistry.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationRegistry.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ApplicationRegistry.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -86,7 +86,7 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
public void addApplication(Application app)
{
String applicationId = app.getClass().getName();
@@ -167,5 +167,4 @@
public void stop()
{
}
-
}
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/ConstructorDescriptorImpl.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.rest.impl;
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.ApplicationContext;
@@ -54,26 +52,15 @@
*/
public class ConstructorDescriptorImpl implements ConstructorDescriptor
{
-
- /**
- * Logger.
- */
+ /** Logger. */
private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.core.ConstructorDescriptorImpl");
- /**
- * ConstructorDescriptor comparator.
- */
+ /** ConstructorDescriptor comparator. */
public static final Comparator<ConstructorDescriptor> CONSTRUCTOR_COMPARATOR = new ConstructorComparator();
- /**
- * Compare two ConstructorDescriptor in number parameters order.
- */
+ /** Compare two ConstructorDescriptor in number parameters order. */
private static class ConstructorComparator implements Comparator<ConstructorDescriptor>
{
-
- /**
- * {@inheritDoc}
- */
public int compare(ConstructorDescriptor o1, ConstructorDescriptor o2)
{
int r = o2.getParameters().size() - o1.getParameters().size();
@@ -83,19 +70,13 @@
}
}
- /**
- * Constructor.
- */
+ /** Constructor. */
private final Constructor<?> constructor;
- /**
- * Collection of constructor's parameters.
- */
+ /** Collection of constructor's parameters. */
private final List<ConstructorParameter> parameters;
- /**
- * Resource class.
- */
+ /** Resource class. */
private final Class<?> resourceClass;
/**
@@ -111,20 +92,16 @@
if (paramTypes.length == 0)
{
-
parameters = java.util.Collections.emptyList();
-
}
else
{
-
Type[] getParamTypes = constructor.getGenericParameterTypes();
Annotation[][] annotations = constructor.getParameterAnnotations();
List<ConstructorParameter> params = new ArrayList<ConstructorParameter>(paramTypes.length);
for (int i = 0; i < paramTypes.length; i++)
{
-
String defaultValue = null;
Annotation annotation = null;
boolean encoded = false;
@@ -142,7 +119,6 @@
Class<?> ac = a.annotationType();
if (allowedAnnotation.contains(ac.getName()))
{
-
if (annotation == null)
{
annotation = a;
@@ -154,15 +130,12 @@
+ annotation + " and " + a + " can't be applied to one parameter.";
throw new RuntimeException(msg);
}
-
- // @Encoded has not sense for Provider. Provider may use only
- // @Context annotation for constructor parameters
+ // @Encoded has not sense for Provider. Provider may use only @Context annotation for constructor parameters
}
else if (ac == Encoded.class && !provider)
{
encoded = true;
- // @Default has not sense for Provider. Provider may use only
- // @Context annotation for constructor parameters
+ // @Default has not sense for Provider. Provider may use only @Context annotation for constructor parameters
}
else if (ac == DefaultValue.class && !provider)
{
@@ -186,7 +159,6 @@
parameters = java.util.Collections.unmodifiableList(params);
}
-
}
/**
@@ -218,7 +190,6 @@
*/
public Object createInstance(ApplicationContext context)
{
- ExoContainer container = ExoContainerContext.getCurrentContainer();
Object[] p = new Object[parameters.size()];
int i = 0;
for (ConstructorParameter cp : parameters)
@@ -236,18 +207,18 @@
String msg = "Not able resolve constructor parameter " + cp;
Class<?> ac = a.annotationType();
if (ac == MatrixParam.class || ac == QueryParam.class || ac == PathParam.class)
- throw new WebApplicationException(e, Response.status(Response.Status.NOT_FOUND).entity(msg).type(
- MediaType.TEXT_PLAIN).build());
+ throw new WebApplicationException(e, Response.status(Response.Status.NOT_FOUND).entity(msg)
+ .type(MediaType.TEXT_PLAIN).build());
- throw new WebApplicationException(e, Response.status(Response.Status.BAD_REQUEST).entity(msg).type(
- MediaType.TEXT_PLAIN).build());
+ throw new WebApplicationException(e, Response.status(Response.Status.BAD_REQUEST).entity(msg)
+ .type(MediaType.TEXT_PLAIN).build());
}
}
else
{
// If parameter not has not annotation then get constructor parameter
- // from container, this is out of scope JAX-RS specification.
- Object tmp = container.getComponentInstanceOfType(cp.getParameterClass());
+ // try to find it via DependencySupplier, this is out of scope JAX-RS specification.
+ Object tmp = context.getDependencySupplier().getComponent(cp);
if (tmp == null)
{
@@ -314,5 +285,4 @@
sb.append(" ]");
return sb.toString();
}
-
}
Added: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/DependencySupplier.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/DependencySupplier.java (rev 0)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/DependencySupplier.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2011 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.impl;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+import org.exoplatform.services.rest.FieldInjector;
+import org.exoplatform.services.rest.Parameter;
+
+import java.lang.annotation.Annotation;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Provide objects that required for constructors or fields of Resource or
+ * Provider.
+ *
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class DependencySupplier
+{
+ protected final Class<? extends Annotation> injectAnnotationClass;
+
+ protected DependencySupplier(Class<? extends Annotation> injectAnnotationClass)
+ {
+ this.injectAnnotationClass = injectAnnotationClass;
+ }
+
+ // Default.
+ public DependencySupplier()
+ {
+ this(javax.inject.Inject.class);
+ }
+
+ // For eXo Container usage.
+ public DependencySupplier(InitParams params)
+ {
+ this(findInjectAnnotationClass(params));
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static Class<? extends Annotation> findInjectAnnotationClass(InitParams params)
+ {
+ Class<? extends Annotation> injectAnnotationClass = null;
+ if (params != null)
+ {
+ final ValueParam injectAnnotationParameter = params.getValueParam("inject.annotation.class");
+ try
+ {
+ injectAnnotationClass = AccessController.doPrivileged(new PrivilegedExceptionAction<Class>() {
+ public Class run() throws ClassNotFoundException
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(injectAnnotationParameter.getValue());
+ }
+ });
+ }
+ catch (PrivilegedActionException pe)
+ {
+ ClassNotFoundException c = (ClassNotFoundException)pe.getCause();
+ throw new RuntimeException(c.getMessage());
+ }
+ }
+ if (injectAnnotationClass == null)
+ injectAnnotationClass = javax.inject.Inject.class;
+ return injectAnnotationClass;
+ }
+
+ /**
+ * Instance for initialization <code>parameter</code>.
+ *
+ * @param parameter parameter
+ * @return instance or <code>null</code> if required instance can't be
+ * provided
+ */
+ public final Object getComponent(Parameter parameter)
+ {
+ if (parameter instanceof FieldInjector)
+ {
+ for (Annotation a : parameter.getAnnotations())
+ if (injectAnnotationClass.isInstance(a))
+ return getComponent(parameter.getParameterClass());
+ return null;
+ }
+ // Annotation required for fields only.
+ return getComponent(parameter.getParameterClass());
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ protected Object getComponent(Class<?> parameterClass)
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ List injectionProviders = container.getComponentInstancesOfType(InjectionProvider.class);
+ if (injectionProviders != null && injectionProviders.size() > 0)
+ {
+ for (Iterator i = injectionProviders.iterator(); i.hasNext();)
+ {
+ InjectionProvider provider = (InjectionProvider)i.next();
+ if (provider.isSupported(parameterClass))
+ return javax.inject.Provider.class.isAssignableFrom(parameterClass) ? provider : provider.get();
+ }
+ }
+ // Directly look up component in container by class,
+ return container.getComponentInstanceOfType(parameterClass);
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/DependencySupplier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/FieldInjectorImpl.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -49,20 +49,13 @@
*/
public class FieldInjectorImpl implements FieldInjector
{
-
- /**
- * Logger.
- */
+ /** Logger. */
private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.core.FieldInjectorImpl");
- /**
- * All annotations including JAX-RS annotation.
- */
+ /** All annotations including JAX-RS annotation. */
private final Annotation[] annotations;
- /**
- * JAX-RS annotation.
- */
+ /** JAX-RS annotation. */
private final Annotation annotation;
/**
@@ -72,9 +65,7 @@
*/
private final String defaultValue;
- /**
- * See {@link javax.ws.rs.Encoded}.
- */
+ /** See {@link javax.ws.rs.Encoded}. */
private final boolean encoded;
/** See {@link java.lang.reflect.Field} . */
@@ -86,7 +77,6 @@
*/
public FieldInjectorImpl(Class<?> resourceClass, java.lang.reflect.Field jfield)
{
-
this.jfield = jfield;
this.annotations = jfield.getDeclaredAnnotations();
@@ -119,15 +109,12 @@
+ annotation.toString() + " and " + a.toString() + " can't be applied to one field.";
throw new RuntimeException(msg);
}
-
- // @Encoded has not sense for Provider. Provider may use only @Context
- // annotation for fields
+ // @Encoded has not sense for Provider. Provider may use only @Context annotation for fields
}
else if (ac == Encoded.class && !provider)
{
encoded = true;
- // @Default has not sense for Provider. Provider may use only @Context
- // annotation for fields
+ // @Default has not sense for Provider. Provider may use only @Context annotation for fields
}
else if (ac == DefaultValue.class && !provider)
{
@@ -143,7 +130,6 @@
this.defaultValue = defaultValue;
this.annotation = annotation;
this.encoded = encoded || resourceClass.getAnnotation(Encoded.class) != null;
-
}
/**
@@ -221,22 +207,43 @@
return null;
}
});
-
}
-
jfield.set(resource, pr.resolve(this, context));
}
catch (Throwable e)
{
-
Class<?> ac = annotation.annotationType();
if (ac == MatrixParam.class || ac == QueryParam.class || ac == PathParam.class)
throw new WebApplicationException(e, Response.status(Response.Status.NOT_FOUND).build());
-
throw new WebApplicationException(e, Response.status(Response.Status.BAD_REQUEST).build());
}
}
-
+ else
+ {
+ Object tmp = context.getDependencySupplier().getComponent(this);
+ if (tmp != null)
+ {
+ try
+ {
+ if (!Modifier.isPublic(jfield.getModifiers()))
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run()
+ {
+ jfield.setAccessible(true);
+ return null;
+ }
+ });
+ }
+ jfield.set(resource, tmp);
+ }
+ catch (Throwable e)
+ {
+ throw new WebApplicationException(e, Response.status(Response.Status.INTERNAL_SERVER_ERROR).build());
+ }
+ // TODO Need to throw exception ?????
+ }
+ }
}
/**
@@ -259,5 +266,4 @@
.append("; encoded: " + isEncoded()).append(" ]");
return sb.toString();
}
-
}
Added: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/InjectionProvider.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/InjectionProvider.java (rev 0)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/InjectionProvider.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 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.impl;
+
+import javax.inject.Provider;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ * @see Provider
+ */
+public interface InjectionProvider<O> extends Provider<O>
+{
+ /**
+ * Check is InjectionProvider able to produce instance of class
+ * <code>clazz</code>.
+ *
+ * @param clazz class to be checked
+ * @return <code>true</code> if able to produce class and <code>false</code>
+ * otherwise
+ * @see #get()
+ */
+ boolean isSupported(Class<O> clazz);
+}
Property changes on: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/InjectionProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestHandlerImpl.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -80,6 +80,8 @@
*/
private final RequestDispatcher dispatcher;
+ private final DependencySupplier dependencySupplier;
+
public static final String getProperty(String name)
{
return properties.get(name);
@@ -88,23 +90,15 @@
public static final void setProperty(String name, String value)
{
if (value == null)
- {
properties.remove(name);
- }
else
- {
properties.put(name, value);
- }
}
- /**
- * Constructs new instance of {@link RequestHandler}.
- *
- * @param dispatcher See {@link RequestDispatcher}
- * @param params init parameters
- */
- public RequestHandlerImpl(RequestDispatcher dispatcher, InitParams params)
+ public RequestHandlerImpl(RequestDispatcher dispatcher, DependencySupplier dependencySupplier, InitParams params)
{
+ this.dispatcher = dispatcher;
+ this.dependencySupplier = dependencySupplier;
if (params != null)
{
for (Iterator<ValueParam> i = params.getValueParamIterator(); i.hasNext();)
@@ -113,21 +107,32 @@
properties.put(vp.getName(), vp.getValue());
}
}
- this.dispatcher = dispatcher;
}
+ /**
+ * Constructs new instance of {@link RequestHandler}.
+ *
+ * @param dispatcher See {@link RequestDispatcher}
+ * @param params init parameters
+ */
+ public RequestHandlerImpl(RequestDispatcher dispatcher, InitParams params)
+ {
+ this(dispatcher, new DependencySupplier(), params);
+ }
+
// RequestHandler
/**
* {@inheritDoc}
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "rawtypes"})
public void handleRequest(GenericContainerRequest request, GenericContainerResponse response) throws Exception
{
try
{
ProviderBinder defaultProviders = ProviderBinder.getInstance();
- ApplicationContextImpl context = new ApplicationContextImpl(request, response, defaultProviders);
+ ApplicationContextImpl context =
+ new ApplicationContextImpl(request, response, defaultProviders, dependencySupplier);
context.getProperties().putAll(properties);
ApplicationContextImpl.setCurrent(context);
@@ -252,7 +257,7 @@
/**
* Create error response with specified status and body message.
- *
+ *
* @param status response status
* @param message response message
* @return response
@@ -271,7 +276,7 @@
/**
* Get JAXR header for response status.
- *
+ *
* @param status response status
* @return JAXRS header or null.
*/
@@ -361,12 +366,10 @@
}
// Register Shutdown Hook for cleaning temporary files.
- SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
- {
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>() {
public Void run()
{
- Runtime.getRuntime().addShutdownHook(new Thread()
- {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run()
{
@@ -388,10 +391,10 @@
/**
* Processing {@link ComponentPlugin} for injection external components.
- *
+ *
* @param plugin See {@link ComponentPlugin}
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"rawtypes"})
public void addPlugin(ComponentPlugin plugin)
{
// NOTE!!! ProviderBinder should be already initialized by ResourceBinder
@@ -426,7 +429,8 @@
}
else if (ExceptionMapperComponentPlugin.class.isAssignableFrom(plugin.getClass()))
{
- Set<Class<? extends ExceptionMapper<?>>> emaps = ((ExceptionMapperComponentPlugin)plugin).getExceptionMappers();
+ Set<Class<? extends ExceptionMapper<?>>> emaps =
+ ((ExceptionMapperComponentPlugin)plugin).getExceptionMappers();
for (Class<? extends ExceptionMapper<?>> mapper : emaps)
providers.addExceptionMapper(mapper);
}
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/BaseTest.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -23,6 +23,7 @@
import org.exoplatform.container.StandaloneContainer;
import org.exoplatform.services.rest.impl.ApplicationContextImpl;
import org.exoplatform.services.rest.impl.ApplicationRegistry;
+import org.exoplatform.services.rest.impl.DependencySupplier;
import org.exoplatform.services.rest.impl.ProviderBinder;
import org.exoplatform.services.rest.impl.ProvidersRegistry;
import org.exoplatform.services.rest.impl.RequestHandlerImpl;
@@ -61,6 +62,8 @@
binder = (ResourceBinder)container.getComponentInstanceOfType(ResourceBinder.class);
requestHandler = (RequestHandlerImpl)container.getComponentInstanceOfType(RequestHandlerImpl.class);
providersRegistry = (ProvidersRegistry)container.getComponentInstanceOfType(ProvidersRegistry.class);
+ DependencySupplier dependencySupplier =
+ (DependencySupplier)container.getComponentInstanceOfType(DependencySupplier.class);
// reset default providers to be sure it is clean.
ProviderBinder.setInstance(new ProviderBinder());
@@ -68,7 +71,8 @@
binder.clear();
- ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
+ ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers, dependencySupplier));
+
launcher = new ResourceLauncher(requestHandler);
}
Added: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/InjectAnnotationTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/InjectAnnotationTest.java (rev 0)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/InjectAnnotationTest.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 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.impl;
+
+import org.exoplatform.services.rest.BaseTest;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+/**
+ * @author <a href="mailto:andrey.parfonov@exoplatform.com">Andrey Parfonov</a>
+ * @version $Id$
+ */
+public class InjectAnnotationTest extends BaseTest
+{
+ public static class InjectableComponent
+ {
+ public String message = "injected from container";
+ }
+
+ public static class InjectionProvider0 implements InjectionProvider<InjectableComponent>
+ {
+ public InjectableComponent get()
+ {
+ InjectableComponent injectable = new InjectableComponent();
+ injectable.message = "injected from provider";
+ return injectable;
+ }
+
+ public boolean isSupported(Class<InjectableComponent> clazz)
+ {
+ return InjectableComponent.class.isAssignableFrom(clazz);
+ }
+ }
+
+ @Path("a")
+ public static class Resource1
+ {
+ @Inject
+ private InjectableComponent injected;
+
+ @GET
+ public String m()
+ {
+ assertNotNull(injected);
+ return injected.message;
+ }
+ }
+
+ @Path("b")
+ public static class Resource2
+ {
+ @Inject
+ private Provider<InjectableComponent> injected;
+
+ @GET
+ public String m()
+ {
+ assertNotNull(injected);
+ InjectableComponent inst = injected.get();
+ return inst.message;
+ }
+ }
+
+ public void testInjectFromContainer() throws Exception
+ {
+ container.registerComponentInstance(InjectableComponent.class.getName(), new InjectableComponent());
+ registry(Resource1.class);
+ ContainerResponse response = launcher.service("GET", "/a", "", null, null, null);
+ assertEquals(200, response.getStatus());
+ assertEquals("injected from container", response.getEntity());
+ unregistry(Resource1.class);
+ container.unregisterComponent(InjectableComponent.class.getName());
+ }
+
+ public void testInjectFromProvider() throws Exception
+ {
+ container.registerComponentInstance(InjectionProvider0.class.getName(), new InjectionProvider0());
+ registry(Resource1.class);
+ ContainerResponse response = launcher.service("GET", "/a", "", null, null, null);
+ assertEquals(200, response.getStatus());
+ assertEquals("injected from provider", response.getEntity());
+ unregistry(Resource1.class);
+ container.unregisterComponent(InjectionProvider0.class.getName());
+ }
+
+ public void testInjectProvider() throws Exception
+ {
+ container.registerComponentInstance(InjectionProvider0.class.getName(), new InjectionProvider0());
+ registry(Resource2.class);
+ ContainerResponse response = launcher.service("GET", "/b", "", null, null, null);
+ assertEquals(200, response.getStatus());
+ assertEquals("injected from provider", response.getEntity());
+ unregistry(Resource2.class);
+ container.unregisterComponent(InjectionProvider0.class.getName());
+ }
+}
Property changes on: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/InjectAnnotationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityProviderTest.java
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityProviderTest.java 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/provider/JsonEntityProviderTest.java 2011-02-04 15:02:54 UTC (rev 3922)
@@ -19,7 +19,6 @@
package org.exoplatform.services.rest.impl.provider;
import org.exoplatform.services.rest.BaseTest;
-import org.exoplatform.services.rest.RequestHandler;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import java.io.ByteArrayInputStream;
@@ -40,14 +39,14 @@
private static final String DATA = "{\"name\":\"andrew\", \"password\":\"hello\"}";
- private RequestHandler requestHandler;
+ //private RequestHandler requestHandler;
private MediaType mediaType;
public void setUp() throws Exception
{
super.setUp();
- requestHandler = (RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
+ //requestHandler = (RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
assertNotNull(requestHandler);
mediaType = new MediaType("application", "json");
}
Modified: ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/exo.ws.rest.core/src/test/resources/conf/standalone/test-configuration.xml 2011-02-04 15:02:54 UTC (rev 3922)
@@ -64,6 +64,9 @@
<type>org.exoplatform.services.rest.impl.RequestHandlerImpl</type>
</component>
<component>
+ <type>org.exoplatform.services.rest.impl.DependencySupplier</type>
+ </component>
+ <component>
<type>org.exoplatform.services.rest.impl.RequestDispatcher</type>
</component>
<component>
Modified: ws/trunk/pom.xml
===================================================================
--- ws/trunk/pom.xml 2011-02-04 13:39:49 UTC (rev 3921)
+++ ws/trunk/pom.xml 2011-02-04 15:02:54 UTC (rev 3922)
@@ -184,6 +184,11 @@
<artifactId>groovy-all</artifactId>
<version>1.6.5</version>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<dependencies>
15 years, 2 months
exo-jcr SVN: r3921 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/core/query/lucene and 4 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 08:39:49 -0500 (Fri, 04 Feb 2011)
New Revision: 3921
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/NodeDataIndexing.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1104: using new queries
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/NodeDataIndexing.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/NodeDataIndexing.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/NodeDataIndexing.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -142,6 +142,6 @@
*/
public AccessControlList getACL()
{
- throw new UnsupportedOperationException("getACL() method is not supported");
+ return nodeData.getACL();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -1479,7 +1479,7 @@
private long createIndex(Indexable indexableComponent, NodeData rootNode, ItemDataConsumer stateMgr, long count)
throws IOException, RepositoryException
{
- NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(100000);
+ NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(10000);
while (iterator.hasNext())
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -1020,10 +1020,10 @@
* @throws RepositoryException
* @throws IllegalStateException
*/
- public int getNodesAndProperties(int offset, int limit, List<NodeDataIndexing> result) throws RepositoryException,
+ public List<NodeDataIndexing> getNodesAndProperties(int offset, int limit) throws RepositoryException,
IllegalStateException
{
- int read = 0;
+ List<NodeDataIndexing> result = new ArrayList<NodeDataIndexing>();
checkIfOpened();
try
@@ -1056,8 +1056,6 @@
}
values.add(new ExtendedTempPropertyData(resultSet));
-
- ++read;
}
if (tempNodeData != null)
@@ -1090,7 +1088,7 @@
throw new RepositoryException(e);
}
- return read;
+ return result;
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -153,12 +153,12 @@
DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
- FIND_NODES_AND_PROPERTIES =
- "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
- + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
- + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
- + " where I.I_CLASS=1 and P.I_CLASS=2 and P.PARENT_ID=I.ID and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
+ + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -161,13 +161,12 @@
DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
- FIND_NODES_AND_PROPERTIES =
- "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
- + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
- + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V"
- + " where I.I_CLASS=1 and I.CONTAINER_NAME=? and P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID"
- + " and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
@@ -560,9 +559,9 @@
}
findNodesAndProperties.setString(1, containerName);
- findNodesAndProperties.setString(2, containerName);
- findNodesAndProperties.setInt(3, limit);
- findNodesAndProperties.setInt(4, offset);
+ findNodesAndProperties.setInt(2, limit);
+ findNodesAndProperties.setInt(3, offset);
+ findNodesAndProperties.setString(4, containerName);
return findNodesAndProperties.executeQuery();
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -18,23 +18,14 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.indexing;
-import org.exoplatform.services.jcr.dataflow.persistent.PersistedNodeData;
-import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
-import org.exoplatform.services.jcr.datamodel.PropertyData;
-import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.core.query.NodeDataIndexingIterator;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import javax.jcr.RepositoryException;
@@ -77,18 +68,6 @@
private List<NodeDataIndexing> current;
/**
- * Node data which may not contains all its properties. It is the last
- * data in the resulted list in readNext() method. Should be merged with
- * first one during next invoking readNext() method.
- */
- private NodeDataIndexing unCompletedNode;
-
- /**
- * Indicates if all rows has been read and no need more access to database.
- */
- private boolean isReadAll = false;
-
- /**
* Constructor JdbcIndexingDataIterator.
*
*/
@@ -126,69 +105,12 @@
*/
private List<NodeDataIndexing> readNext() throws RepositoryException
{
- if (isReadAll)
- {
- return new ArrayList<NodeDataIndexing>();
- }
-
- List<NodeDataIndexing> result = getNodesAndProperties();
-
- if (result.isEmpty())
- {
- if (unCompletedNode != null)
- {
- result.add(unCompletedNode);
- unCompletedNode = null;
- }
- }
- else
- {
- if (unCompletedNode != null)
- {
- NodeDataIndexing node = result.get(0);
- if (unCompletedNode.getIdentifier().equals(node.getIdentifier()))
- {
- result.set(0, mergeWithUnCompletedNode(node));
- unCompletedNode = null;
- }
- else
- {
- result.add(0, unCompletedNode);
- }
- }
-
- if (!isReadAll)
- {
- unCompletedNode = result.remove(result.size() - 1);
- }
-
- if (result.isEmpty())
- {
- return readNext();
- }
- }
-
- return result;
- }
-
- /**
- * Read next nodes from database.
- *
- * @return List
- * @throws RepositoryException
- */
- private List<NodeDataIndexing> getNodesAndProperties() throws RepositoryException
- {
JDBCStorageConnection conn = (JDBCStorageConnection)connFactory.openConnection();
try
{
- List<NodeDataIndexing> result = new ArrayList<NodeDataIndexing>();
-
- int read = conn.getNodesAndProperties(offset, pageSize, result);
+ List<NodeDataIndexing> result = conn.getNodesAndProperties(offset, pageSize);
offset += pageSize;
- isReadAll = read != pageSize;
-
return result;
}
finally
@@ -196,60 +118,5 @@
conn.close();
}
}
-
- /**
- * Merge two nodes.
- */
- private NodeDataIndexing mergeWithUnCompletedNode(NodeDataIndexing node)
- {
- InternalQName primaryType = unCompletedNode.getPrimaryTypeName();
- if (primaryType == null)
- {
- primaryType = node.getPrimaryTypeName();
- }
-
- List<InternalQName> mixins = new ArrayList<InternalQName>();
- for (InternalQName mixin : unCompletedNode.getMixinTypeNames())
- {
- mixins.add(mixin);
- }
-
- for (InternalQName mixin : node.getMixinTypeNames())
- {
- mixins.add(mixin);
- }
-
- NodeData nodeData =
- new PersistedNodeData(unCompletedNode.getIdentifier(), unCompletedNode.getQPath(),
- unCompletedNode.getParentIdentifier(), unCompletedNode.getPersistedVersion(),
- unCompletedNode.getOrderNumber(), primaryType, mixins.toArray(new InternalQName[mixins.size()]), null);
-
- Map<String, PropertyData> props = new HashMap<String, PropertyData>();
- for (PropertyData prop : unCompletedNode.getChildPropertiesData())
- {
- props.put(prop.getIdentifier(), prop);
- }
-
- for (PropertyData prop : node.getChildPropertiesData())
- {
- if (props.containsKey(prop.getIdentifier()))
- {
- List<ValueData> values = new ArrayList<ValueData>(props.get(prop.getIdentifier()).getValues());
- values.addAll(prop.getValues());
-
- PropertyData propertyData =
- new PersistedPropertyData(prop.getIdentifier(), prop.getQPath(), prop.getParentIdentifier(),
- prop.getPersistedVersion(), prop.getType(), prop.isMultiValued(), values);
-
- props.put(prop.getIdentifier(), propertyData);
- }
- else
- {
- props.put(prop.getIdentifier(), prop);
- }
- }
-
- return new NodeDataIndexing(nodeData, new ArrayList<PropertyData>(props.values()));
- }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -180,12 +180,12 @@
DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
- FIND_NODES_AND_PROPERTIES =
- "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
- + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
- + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
- + " where I.I_CLASS=1 and P.I_CLASS=2 and P.PARENT_ID=I.ID and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_MITEM I"
+ + " where I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-04 11:10:15 UTC (rev 3920)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-04 13:39:49 UTC (rev 3921)
@@ -187,13 +187,12 @@
DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
- FIND_NODES_AND_PROPERTIES =
- "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
- + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
- + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V"
- + " where I.I_CLASS=1 and I.CONTAINER_NAME=? and P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID"
- + " and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
+ FIND_NODES_AND_PROPERTIES =
+ "select J.*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P"
+ + " join (select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM from JCR_SITEM I"
+ + " where I.CONTAINER_NAME=? AND I.I_CLASS=1 order by I.ID LIMIT ? OFFSET ?) J on P.PARENT_ID = J.ID"
+ + " where P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by J.ID";
}
/**
@@ -648,9 +647,9 @@
}
findNodesAndProperties.setString(1, containerName);
- findNodesAndProperties.setString(2, containerName);
- findNodesAndProperties.setInt(3, limit);
- findNodesAndProperties.setInt(4, offset);
+ findNodesAndProperties.setInt(2, limit);
+ findNodesAndProperties.setInt(3, offset);
+ findNodesAndProperties.setString(4, containerName);
return findNodesAndProperties.executeQuery();
}
15 years, 2 months
exo-jcr SVN: r3920 - kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 06:10:15 -0500 (Fri, 04 Feb 2011)
New Revision: 3920
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
Log:
EXOJCR-1182: apply remarks
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-04 11:07:28 UTC (rev 3919)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-04 11:10:15 UTC (rev 3920)
@@ -42,7 +42,7 @@
{
public Void run() throws Exception
{
- Scanner scanner = new Scanner(getClass().getResourceAsStream("mimetypes.properties"));
+ Scanner scanner = new Scanner(getClass().getResourceAsStream("mimetypes.properties"), "ISO-8859-1");
try
{
while (scanner.hasNextLine())
15 years, 2 months
exo-jcr SVN: r3919 - kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 06:07:28 -0500 (Fri, 04 Feb 2011)
New Revision: 3919
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
Log:
EXOJCR-1182: apply remarks
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-04 10:05:50 UTC (rev 3918)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-04 11:07:28 UTC (rev 3919)
@@ -36,7 +36,6 @@
public MimeTypeResolver()
{
- Scanner scanner = null;
try
{
SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
@@ -44,10 +43,18 @@
public Void run() throws Exception
{
Scanner scanner = new Scanner(getClass().getResourceAsStream("mimetypes.properties"));
- while (scanner.hasNextLine())
+ try
{
- processLine(scanner.nextLine());
+ while (scanner.hasNextLine())
+ {
+ processLine(scanner.nextLine());
+ }
}
+ finally
+ {
+ scanner.close();
+ }
+
return null;
}
});
@@ -56,13 +63,6 @@
{
throw new InternalError("Unable to load mimetypes: " + e.toString());
}
- finally
- {
- if (scanner != null)
- {
- scanner.close();
- }
- }
}
/**
@@ -97,7 +97,7 @@
public String getMimeType(String filename)
{
String ext = filename.substring(filename.lastIndexOf(".") + 1);
- if (ext.equals(""))
+ if (ext.isEmpty())
{
ext = filename;
}
@@ -141,7 +141,7 @@
if (resultExt.isEmpty())
{
- resultExt = new String(ext);
+ resultExt = ext;
}
}
return resultExt;
@@ -154,30 +154,27 @@
*/
protected void processLine(String aLine)
{
- Scanner scanner = new Scanner(aLine);
- scanner.useDelimiter("=");
- while (scanner.hasNext())
- {
- String ext = scanner.next();
- String mimetype = scanner.next();
+ int p = aLine.indexOf("=");
- // add mimetype
- List<String> values = mimeTypes.get(ext);
- if (values == null)
- {
- values = new ArrayList<String>();
- mimeTypes.put(ext, values);
- }
- values.add(mimetype);
+ String ext = aLine.substring(0, p);
+ String mimetype = aLine.substring(p + 1);
- // add extension
- values = extentions.get(mimetype);
- if (values == null)
- {
- values = new ArrayList<String>();
- extentions.put(mimetype, values);
- }
- values.add(ext);
+ // add mimetype
+ List<String> values = mimeTypes.get(ext);
+ if (values == null)
+ {
+ values = new ArrayList<String>();
+ mimeTypes.put(ext, values);
}
+ values.add(mimetype);
+
+ // add extension
+ values = extentions.get(mimetype);
+ if (values == null)
+ {
+ values = new ArrayList<String>();
+ extentions.put(mimetype, values);
+ }
+ values.add(ext);
}
}
15 years, 2 months
exo-jcr SVN: r3918 - jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 05:05:50 -0500 (Fri, 04 Feb 2011)
New Revision: 3918
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
Log:
EXOJCR-1078: fix doc
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2011-02-04 09:26:44 UTC (rev 3917)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/exojcr-backup-service.xml 2011-02-04 10:05:50 UTC (rev 3918)
@@ -941,7 +941,7 @@
<properties-param>
<name>backup-properties</name>
<property name="default-incremental-job-period" value="3600" /> <!-- set default incremental period = 60 minutes -->
- <property name="full-backup-type" value="org.exoplatform.services.jcr.ext.backup.impl.fs..rdbms.FullBackupJob" />
+ <property name="full-backup-type" value="org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob" />
<property name="incremental-backup-type" value="org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob" />
<property name="backup-dir" value="target/backup" />
</properties-param>
15 years, 2 months
exo-jcr SVN: r3917 - in kernel/trunk/exo.kernel.commons/src: main/resources/org/exoplatform/commons/utils and 1 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-04 04:26:44 -0500 (Fri, 04 Feb 2011)
New Revision: 3917
Added:
kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
kernel/trunk/exo.kernel.commons/src/main/resources/org/exoplatform/commons/utils/mimetypes.properties
Log:
EXOJCR-1182: MimeTypeResolver does not work well with IE7
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-03 20:40:43 UTC (rev 3916)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-02-04 09:26:44 UTC (rev 3917)
@@ -20,25 +20,34 @@
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
-import java.util.Iterator;
-import java.util.Properties;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
public class MimeTypeResolver
{
+ private Map<String, List<String>> mimeTypes = new HashMap<String, List<String>>();
- private Properties mimeTypes = new Properties();
+ private Map<String, List<String>> extentions = new HashMap<String, List<String>>();
private String defaultMimeType = "application/octet-stream";
public MimeTypeResolver()
{
+ Scanner scanner = null;
try
{
SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
{
public Void run() throws Exception
{
- mimeTypes.load(getClass().getResourceAsStream("mimetypes.properties"));
+ Scanner scanner = new Scanner(getClass().getResourceAsStream("mimetypes.properties"));
+ while (scanner.hasNextLine())
+ {
+ processLine(scanner.nextLine());
+ }
return null;
}
});
@@ -47,18 +56,44 @@
{
throw new InternalError("Unable to load mimetypes: " + e.toString());
}
+ finally
+ {
+ if (scanner != null)
+ {
+ scanner.close();
+ }
+ }
}
+ /**
+ * Returns default MIMEType.
+ *
+ * @return String
+ */
public String getDefaultMimeType()
{
return defaultMimeType;
}
+ /**
+ * Set default MIMEType.
+ *
+ * @param defaultMimeType
+ * String, default MIMEType
+ */
public void setDefaultMimeType(String defaultMimeType)
{
this.defaultMimeType = defaultMimeType;
}
+ /**
+ * Get MIMEType which corresponds to file extension. If file extension is unknown the default
+ * MIMEType will be returned. If there are more than one MIMETypes for specific extension the
+ * first occurred in the list will be returned.
+ *
+ * @param filename
+ * @return String MIMEType
+ */
public String getMimeType(String filename)
{
String ext = filename.substring(filename.lastIndexOf(".") + 1);
@@ -66,28 +101,83 @@
{
ext = filename;
}
- return mimeTypes.getProperty(ext.toLowerCase(), defaultMimeType);
+
+ List<String> values = mimeTypes.get(ext);
+ return values == null ? defaultMimeType : values.get(0);
}
+ /**
+ * Get file extension corresponds to MIMEType. If MIMEType is empty or equals
+ * default MIMEType empty string will be returned. If there is no file extension
+ * for specific MIMEType the empty string will be returned also. In case when
+ * there are more than one extension for specific MIMEType the first occurred
+ * extension in the list will be returned if MIMEType ends with this extension
+ * otherwise just first occurred.
+ *
+ * @param mimeType
+ * MIMEType
+ * @return file extension
+ */
public String getExtension(String mimeType)
{
- if (mimeType.equals("") || mimeType.equals(defaultMimeType))
+ if (mimeType.isEmpty() || mimeType.equals(defaultMimeType))
+ {
return "";
- Iterator iterator = mimeTypes.keySet().iterator();
- // if true than this flag define multiple mimetypes for different extensions
- // exists
- String ext = "";
- while (iterator.hasNext())
+ }
+
+ List<String> values = extentions.get(mimeType);
+ if (values == null)
{
- String key = (String)iterator.next();
- String value = (String)mimeTypes.get(key);
- if (value.equals(mimeType) && mimeType.endsWith(key))
- return key;
- if (value.equals(mimeType) && ext.equals(""))
- ext = new String(key);
- else if (value.equals(mimeType) && (!ext.equals("")))
+ return "";
+ }
+
+ String resultExt = "";
+ for (String ext : values)
+ {
+ if (mimeType.endsWith(ext))
+ {
return ext;
+ }
+
+ if (resultExt.isEmpty())
+ {
+ resultExt = new String(ext);
+ }
}
- return ext;
+ return resultExt;
}
+
+ /**
+ * Load MIMEType and corresponding extension.
+ *
+ * @param aLine
+ */
+ protected void processLine(String aLine)
+ {
+ Scanner scanner = new Scanner(aLine);
+ scanner.useDelimiter("=");
+ while (scanner.hasNext())
+ {
+ String ext = scanner.next();
+ String mimetype = scanner.next();
+
+ // add mimetype
+ List<String> values = mimeTypes.get(ext);
+ if (values == null)
+ {
+ values = new ArrayList<String>();
+ mimeTypes.put(ext, values);
+ }
+ values.add(mimetype);
+
+ // add extension
+ values = extentions.get(mimetype);
+ if (values == null)
+ {
+ values = new ArrayList<String>();
+ extentions.put(mimetype, values);
+ }
+ values.add(ext);
+ }
+ }
}
Modified: kernel/trunk/exo.kernel.commons/src/main/resources/org/exoplatform/commons/utils/mimetypes.properties
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/resources/org/exoplatform/commons/utils/mimetypes.properties 2011-02-03 20:40:43 UTC (rev 3916)
+++ kernel/trunk/exo.kernel.commons/src/main/resources/org/exoplatform/commons/utils/mimetypes.properties 2011-02-04 09:26:44 UTC (rev 3917)
@@ -42,6 +42,7 @@
iges=model/iges
igs=model/iges
jpeg=image/jpeg
+jpeg=image/pjpeg
jpe=image/jpeg
jpg=image/jpeg
bmp=image/bmp
@@ -55,7 +56,7 @@
mesh=model/mesh
mid=audio/midi
midi=audio/midi
-mif=application/vnd=mif
+mif=application/vnd.mif
mov=video/quicktime
m4v=video/x-m4v
m4a=audio/x-m4a
@@ -77,6 +78,7 @@
pgm=image/x-portable-graymap
pgn=application/x-chess-pgn
png=image/png
+png=image/x-png
pnm=image/x-portable-anymap
ppm=image/x-portable-pixmap
ppt=application/ppt
Added: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java (rev 0)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java 2011-02-04 09:26:44 UTC (rev 3917)
@@ -0,0 +1,68 @@
+/*
+ * 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.commons.utils;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 3 02 2011
+ *
+ * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: TestMimeTypeResolver.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public class TestMimeTypeResolver extends TestCase
+{
+
+ private MimeTypeResolver resolver = new MimeTypeResolver();
+
+ public void testGetMimeType()
+ {
+ assertEquals(resolver.getDefaultMimeType(), resolver.getMimeType("file.unknown-file-extension"));
+ assertEquals(resolver.getDefaultMimeType(), resolver.getMimeType("unknown-file-extension"));
+ assertEquals(resolver.getDefaultMimeType(), resolver.getMimeType(""));
+
+ // there are two MIMETypes for jpeg extension [image/jpeg, image/pjpeg], check the first one
+ assertEquals("image/jpeg", resolver.getMimeType("image.jpeg"));
+ assertEquals("image/jpeg", resolver.getMimeType("jpeg"));
+
+ assertEquals("application/vnd.ms-outlook", resolver.getMimeType("my.msg"));
+ }
+
+ public void testGetExtension()
+ {
+ assertEquals("jpeg", resolver.getExtension("image/jpeg"));
+ assertEquals("jpeg", resolver.getExtension("image/pjpeg"));
+
+ assertEquals("", resolver.getExtension(""));
+ assertEquals("", resolver.getExtension("unknown-mimetype"));
+ assertEquals("", resolver.getExtension(resolver.getDefaultMimeType()));
+
+ assertEquals("msg", resolver.getExtension("application/vnd.ms-outlook"));
+
+ // there are two file extension for audio/midi MIMEType [mid, midi]
+ // should be returned "midi" as MIMEType ends with "midi"
+ assertEquals("midi", resolver.getExtension("audio/midi"));
+
+ // there are two file extension for application/x-director MIMEType [dcr, dir]
+ // should be returned "dcr" as first occurred
+ assertEquals("dcr", resolver.getExtension("application/x-director"));
+ }
+}
15 years, 2 months
exo-jcr SVN: r3916 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: core/query/lucene and 4 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-03 15:40:43 -0500 (Thu, 03 Feb 2011)
New Revision: 3916
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.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/db/HSQLDBMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1104: using paging
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -30,5 +30,14 @@
*/
public interface Indexable
{
- NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize) throws RepositoryException;
+ /**
+ * Returns NodeDataIndexingIterator.
+ *
+ * @param pageSize
+ * the maximum amount of the rows which can be retrieved from database per once
+ * @return NodeDataIndexingIterator
+ * @throws RepositoryException
+ */
+ NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize)
+ throws RepositoryException;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -1479,7 +1479,8 @@
private long createIndex(Indexable indexableComponent, NodeData rootNode, ItemDataConsumer stateMgr, long count)
throws IOException, RepositoryException
{
- NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(1000);
+ NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(100000);
+
while (iterator.hasNext())
{
for (NodeDataIndexing node : iterator.next())
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -60,7 +60,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -1012,20 +1011,29 @@
}
/**
- * {@inheritDoc}
+ * GetNodesAndProperties.
+ *
+ * @param offset
+ * @param limit
+ * @param result
+ * @return
+ * @throws RepositoryException
+ * @throws IllegalStateException
*/
- public List<NodeDataIndexing> getNodesAndProperties(int offset, int limit) throws RepositoryException,
+ public int getNodesAndProperties(int offset, int limit, List<NodeDataIndexing> result) throws RepositoryException,
IllegalStateException
{
- List<NodeDataIndexing> result = new ArrayList<NodeDataIndexing>();
+ int read = 0;
checkIfOpened();
try
{
ResultSet resultSet = findNodesAndProperties(offset, limit);
+
try
{
TempNodeData tempNodeData = null;
+
while (resultSet.next())
{
if (tempNodeData == null)
@@ -1034,8 +1042,7 @@
}
else if (!resultSet.getString(COLUMN_ID).equals(tempNodeData.cid))
{
- result.add(createNodeData(tempNodeData));
-
+ result.add(createNodeDataIndexing(tempNodeData));
tempNodeData = new TempNodeData(resultSet);
}
@@ -1049,11 +1056,13 @@
}
values.add(new ExtendedTempPropertyData(resultSet));
+
+ ++read;
}
if (tempNodeData != null)
{
- result.add(createNodeData(tempNodeData));
+ result.add(createNodeDataIndexing(tempNodeData));
}
}
finally
@@ -1081,7 +1090,7 @@
throw new RepositoryException(e);
}
- return result;
+ return read;
}
/**
@@ -2540,84 +2549,92 @@
* @throws SQLException
* @throws IllegalNameException
*/
- protected NodeDataIndexing createNodeData(TempNodeData tempNode) throws RepositoryException, SQLException,
+ protected NodeDataIndexing createNodeDataIndexing(TempNodeData tempNode) throws RepositoryException, SQLException,
IOException, IllegalNameException
{
+ String parentCid;
QPath parentPath;
- String parentCid;
if (tempNode.cpid.equals(Constants.ROOT_PARENT_UUID))
{
// root node
+ parentCid = null;
parentPath = Constants.ROOT_PATH;
- parentCid = null;
}
else
{
+ parentCid = tempNode.cpid;
parentPath =
QPath.makeChildPath(traverseQPath(tempNode.cpid), InternalQName.parse(tempNode.cname), tempNode.cindex);
- parentCid = tempNode.cpid;
}
- // primary type
- SortedSet<TempPropertyData> primaryTypeTempProp =
- tempNode.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
- if (primaryTypeTempProp == null)
+ // primary type if exists in the list of properties
+ InternalQName ptName = null;
+ ValueData ptValue = null;
+
+ SortedSet<TempPropertyData> ptTempProp = tempNode.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
+ if (ptTempProp != null)
{
- throw new PrimaryTypeNotFoundException("FATAL ERROR primary type record not found. Node "
- + parentPath.getAsString() + ", id " + tempNode.cid + ", container " + this.containerName, null);
+ byte[] data = ptTempProp.first().getAsByteArray();
+
+ ptValue = new ByteArrayPersistedValueData(ptTempProp.first().orderNum, data);
+ ptName = InternalQName.parse(new String((data != null ? data : new byte[]{}), Constants.DEFAULT_ENCODING));
}
- byte[] data = primaryTypeTempProp.first().getAsByteArray();
- primaryTypeTempProp.first().data = new ByteArrayInputStream(data);
+ // mixins if exist in the list of properties
+ List<ValueData> mixinsData = new ArrayList<ValueData>();
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
- InternalQName ptName =
- InternalQName.parse(new String((data != null ? data : new byte[]{}), Constants.DEFAULT_ENCODING));
-
- // mixins
- List<InternalQName> mixins = new ArrayList<InternalQName>();
Set<TempPropertyData> mixinsTempProps = tempNode.properties.get(Constants.JCR_MIXINTYPES.getAsString());
if (mixinsTempProps != null)
{
-
for (TempPropertyData mxnb : mixinsTempProps)
{
- data = mxnb.getAsByteArray();
- mxnb.data = new ByteArrayInputStream(data);
+ byte[] data = mxnb.getAsByteArray();
+ mixinsData.add(new ByteArrayPersistedValueData(mxnb.orderNum, data));
mixins.add(InternalQName.parse(new String(data, Constants.DEFAULT_ENCODING)));
}
}
// build node data
NodeData nodeData =
- new PersistedNodeData(getIdentifier(tempNode.cid), parentPath, getIdentifier(parentCid), tempNode.cversion,
- tempNode.cnordernumb, ptName, mixins.toArray(new InternalQName[mixins.size()]), null);
+ new PersistedNodeData(getIdentifier(tempNode.cid), parentPath, getIdentifier(parentCid),
+ tempNode.cversion, tempNode.cnordernumb, ptName, mixins.toArray(new InternalQName[mixins.size()]), null);
List<PropertyData> childProps = new ArrayList<PropertyData>();
-
for (String propName : tempNode.properties.keySet())
{
ExtendedTempPropertyData prop = (ExtendedTempPropertyData)tempNode.properties.get(propName).first();
+
String identifier = getIdentifier(prop.id);
+ QPath qpath = QPath.makeChildPath(parentPath, InternalQName.parse(prop.name));
- // read values
List<ValueData> valueData = new ArrayList<ValueData>();
- for (TempPropertyData tempProp : tempNode.properties.get(propName))
+
+ if (propName.equals(Constants.JCR_PRIMARYTYPE.getAsString()))
{
- ExtendedTempPropertyData extTempProp = (ExtendedTempPropertyData)tempProp;
+ valueData.add(ptValue);
+ }
+ else if (propName.equals(Constants.JCR_MIXINTYPES.getAsString()))
+ {
+ valueData = mixinsData;
+ }
+ else
+ {
+ for (TempPropertyData tempProp : tempNode.properties.get(propName))
+ {
+ ExtendedTempPropertyData extTempProp = (ExtendedTempPropertyData)tempProp;
- ValueData vdata =
- extTempProp.storage_desc == null ? readValueData(extTempProp.id, extTempProp.orderNum,
- extTempProp.version, extTempProp.data) : readValueData(identifier, extTempProp.orderNum,
- extTempProp.storage_desc);
+ ValueData vdata =
+ extTempProp.storage_desc == null ? readValueData(extTempProp.id, extTempProp.orderNum,
+ extTempProp.version, extTempProp.data) : readValueData(identifier, extTempProp.orderNum,
+ extTempProp.storage_desc);
- valueData.add(vdata);
+ valueData.add(vdata);
+ }
}
- Collections.sort(valueData, COMPARATOR_VALUE_DATA);
- QPath qpath = QPath.makeChildPath(parentPath, InternalQName.parse(prop.name));
-
// build property data
PropertyData pdata =
new PersistedPropertyData(identifier, qpath, tempNode.cid, prop.version, prop.type, prop.multi,
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 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -1425,37 +1425,9 @@
/**
* {@inheritDoc}
*/
- public NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize) throws RepositoryException
+ public NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize)
+ throws RepositoryException
{
- try
- {
- final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
-
- if (ds != null)
- {
- Connection jdbcConn =
- SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
- }
- });
-
- return new JdbcNodeDataIndexingIterator(connFactory, pageSize);
- }
- else
- {
- throw new NameNotFoundException("Data source " + dbSourceName + " not found");
- }
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- catch (NamingException e)
- {
- throw new RepositoryException(e);
- }
+ return new JdbcNodeDataIndexingIterator(connFactory, pageSize);
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBMultiDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -25,7 +25,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -42,7 +41,51 @@
public class HSQLDBMultiDbJDBCConnection extends MultiDbJDBCConnection
{
+ /**
+ * HSQLDB Multidatabase JDBC Connection constructor.
+ *
+ * @param dbConnection
+ * JDBC connection, shoudl be opened before
+ * @param readOnly
+ * boolean if true the dbConnection was marked as READ-ONLY.
+ * @param containerName
+ * Workspace Storage Container name (see configuration)
+ * @param valueStorageProvider
+ * External Value Storages provider
+ * @param maxBufferSize
+ * Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * Swap directory File (see configuration)
+ * @param swapCleaner
+ * Swap cleaner (internal FileCleaner).
+ * @throws SQLException
+ *
+ * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
+ */
+ public HSQLDBMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ throws SQLException
+ {
+ super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
+ protected void prepareQueries() throws SQLException
+ {
+
+ super.prepareQueries();
+ FIND_PROPERTY_BY_NAME =
+ "select V.DATA" + " from JCR_MITEM I, JCR_MVALUE V"
+ + " where I.PARENT_ID=? and I.I_CLASS=2 and I.NAME=? and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
+ FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1" + " order by N_ORDER_NUM";
+ FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1";
+ FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=2" + " order by ID";
+ }
+
+ @Override
protected int addNodeRecord(final NodeData data) throws SQLException
{
return SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
@@ -290,46 +333,18 @@
}
/**
- * HSQLDB Multidatabase JDBC Connection constructor.
- *
- * @param dbConnection
- * JDBC connection, shoudl be opened before
- * @param readOnly
- * boolean if true the dbConnection was marked as READ-ONLY.
- * @param containerName
- * Workspace Storage Container name (see configuration)
- * @param valueStorageProvider
- * External Value Storages provider
- * @param maxBufferSize
- * Maximum buffer size (see configuration)
- * @param swapDirectory
- * Swap directory File (see configuration)
- * @param swapCleaner
- * Swap cleaner (internal FileCleaner).
- * @throws SQLException
- *
- * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
- */
- public HSQLDBMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
- ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
- throws SQLException
- {
- super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
- }
-
- /**
* {@inheritDoc}
*/
@Override
- protected void prepareQueries() throws SQLException
+ protected ResultSet findNodesAndProperties(final int offset, final int limit) throws SQLException
{
-
- super.prepareQueries();
- FIND_PROPERTY_BY_NAME =
- "select V.DATA" + " from JCR_MITEM I, JCR_MVALUE V"
- + " where I.PARENT_ID=? and I.I_CLASS=2 and I.NAME=? and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
- FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1" + " order by N_ORDER_NUM";
- FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1";
- FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=2" + " order by ID";
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findNodesAndProperties(offset, limit);
+ }
+ };
+ return SecurityHelper.doPrivilegedSQLExceptionAction(action);
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -459,4 +459,20 @@
};
return SecurityHelper.doPrivilegedSQLExceptionAction(action);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(final int offset, final int limit) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findNodesAndProperties(offset, limit);
+ }
+ };
+ return SecurityHelper.doPrivilegedSQLExceptionAction(action);
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -157,8 +157,8 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V where I.I_CLASS=1 and"
- + " P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by ID";
+ + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
+ + " where I.I_CLASS=1 and P.I_CLASS=2 and P.PARENT_ID=I.ID and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
}
/**
@@ -537,6 +537,9 @@
findNodesAndProperties.clearParameters();
}
+ findNodesAndProperties.setInt(1, limit);
+ findNodesAndProperties.setInt(2, offset);
+
return findNodesAndProperties.executeQuery();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -165,8 +165,9 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V where I.I_CLASS=1 and I.CONTAINER_NAME=? and"
- + " P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID" + " and V.PROPERTY_ID=P.ID order by ID";
+ + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V"
+ + " where I.I_CLASS=1 and I.CONTAINER_NAME=? and P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID"
+ + " and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
}
/**
@@ -560,6 +561,8 @@
findNodesAndProperties.setString(1, containerName);
findNodesAndProperties.setString(2, containerName);
+ findNodesAndProperties.setInt(3, limit);
+ findNodesAndProperties.setInt(4, offset);
return findNodesAndProperties.executeQuery();
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -18,7 +18,13 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.indexing;
+import org.exoplatform.services.jcr.dataflow.persistent.PersistedNodeData;
+import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.core.query.NodeDataIndexingIterator;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
@@ -26,7 +32,9 @@
import org.exoplatform.services.log.Log;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.jcr.RepositoryException;
@@ -69,6 +77,18 @@
private List<NodeDataIndexing> current;
/**
+ * Node data which may not contains all its properties. It is the last
+ * data in the resulted list in readNext() method. Should be merged with
+ * first one during next invoking readNext() method.
+ */
+ private NodeDataIndexing unCompletedNode;
+
+ /**
+ * Indicates if all rows has been read and no need more access to database.
+ */
+ private boolean isReadAll = false;
+
+ /**
* Constructor JdbcIndexingDataIterator.
*
*/
@@ -93,29 +113,143 @@
public List<NodeDataIndexing> next() throws RepositoryException
{
List<NodeDataIndexing> next = this.current;
- this.current = new ArrayList<NodeDataIndexing>();//readNext();
+ this.current = readNext();
return next;
}
/**
- * Read next nodes from database.
+ * Read nodes from database.
*
* @return List<NodeDataIndexing>
* @throws RepositoryException
*/
private List<NodeDataIndexing> readNext() throws RepositoryException
{
+ if (isReadAll)
+ {
+ return new ArrayList<NodeDataIndexing>();
+ }
+
+ List<NodeDataIndexing> result = getNodesAndProperties();
+
+ if (result.isEmpty())
+ {
+ if (unCompletedNode != null)
+ {
+ result.add(unCompletedNode);
+ unCompletedNode = null;
+ }
+ }
+ else
+ {
+ if (unCompletedNode != null)
+ {
+ NodeDataIndexing node = result.get(0);
+ if (unCompletedNode.getIdentifier().equals(node.getIdentifier()))
+ {
+ result.set(0, mergeWithUnCompletedNode(node));
+ unCompletedNode = null;
+ }
+ else
+ {
+ result.add(0, unCompletedNode);
+ }
+ }
+
+ if (!isReadAll)
+ {
+ unCompletedNode = result.remove(result.size() - 1);
+ }
+
+ if (result.isEmpty())
+ {
+ return readNext();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Read next nodes from database.
+ *
+ * @return List
+ * @throws RepositoryException
+ */
+ private List<NodeDataIndexing> getNodesAndProperties() throws RepositoryException
+ {
JDBCStorageConnection conn = (JDBCStorageConnection)connFactory.openConnection();
try
{
- return conn.getNodesAndProperties(offset, pageSize);
- // TODO offset + ?
+ List<NodeDataIndexing> result = new ArrayList<NodeDataIndexing>();
+
+ int read = conn.getNodesAndProperties(offset, pageSize, result);
+ offset += pageSize;
+
+ isReadAll = read != pageSize;
+
+ return result;
}
finally
{
conn.close();
}
}
+
+ /**
+ * Merge two nodes.
+ */
+ private NodeDataIndexing mergeWithUnCompletedNode(NodeDataIndexing node)
+ {
+ InternalQName primaryType = unCompletedNode.getPrimaryTypeName();
+ if (primaryType == null)
+ {
+ primaryType = node.getPrimaryTypeName();
+ }
+
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
+ for (InternalQName mixin : unCompletedNode.getMixinTypeNames())
+ {
+ mixins.add(mixin);
+ }
+
+ for (InternalQName mixin : node.getMixinTypeNames())
+ {
+ mixins.add(mixin);
+ }
+
+ NodeData nodeData =
+ new PersistedNodeData(unCompletedNode.getIdentifier(), unCompletedNode.getQPath(),
+ unCompletedNode.getParentIdentifier(), unCompletedNode.getPersistedVersion(),
+ unCompletedNode.getOrderNumber(), primaryType, mixins.toArray(new InternalQName[mixins.size()]), null);
+
+ Map<String, PropertyData> props = new HashMap<String, PropertyData>();
+ for (PropertyData prop : unCompletedNode.getChildPropertiesData())
+ {
+ props.put(prop.getIdentifier(), prop);
+ }
+
+ for (PropertyData prop : node.getChildPropertiesData())
+ {
+ if (props.containsKey(prop.getIdentifier()))
+ {
+ List<ValueData> values = new ArrayList<ValueData>(props.get(prop.getIdentifier()).getValues());
+ values.addAll(prop.getValues());
+
+ PropertyData propertyData =
+ new PersistedPropertyData(prop.getIdentifier(), prop.getQPath(), prop.getParentIdentifier(),
+ prop.getPersistedVersion(), prop.getType(), prop.isMultiValued(), values);
+
+ props.put(prop.getIdentifier(), propertyData);
+ }
+ else
+ {
+ props.put(prop.getIdentifier(), prop);
+ }
+ }
+
+ return new NodeDataIndexing(nodeData, new ArrayList<PropertyData>(props.values()));
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBMultiDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -44,8 +44,68 @@
*/
public class HSQLDBMultiDbJDBCConnection extends MultiDbJDBCConnection
{
+ /**
+ * HSQLDB Multidatabase JDBC Connection constructor.
+ *
+ * @param dbConnection
+ * JDBC connection, shoudl be opened before
+ * @param readOnly
+ * boolean if true the dbConnection was marked as READ-ONLY.
+ * @param containerName
+ * Workspace Storage Container name (see configuration)
+ * @param valueStorageProvider
+ * External Value Storages provider
+ * @param maxBufferSize
+ * Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * Swap directory File (see configuration)
+ * @param swapCleaner
+ * Swap cleaner (internal FileCleaner).
+ * @throws SQLException
+ *
+ * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
+ */
+ public HSQLDBMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ throws SQLException
+ {
+ super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+ /**
+ * {@inheritDoc}
+ */
@Override
+ protected void prepareQueries() throws SQLException
+ {
+ super.prepareQueries();
+ FIND_PROPERTY_BY_NAME =
+ "select V.DATA" + " from JCR_MITEM I, JCR_MVALUE V"
+ + " where I.PARENT_ID=? and I.I_CLASS=2 and I.NAME=? and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
+ FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1" + " order by N_ORDER_NUM";
+ FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1";
+ FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=2" + " order by ID";
+ FIND_NODES_BY_PARENTID_CQ =
+ "select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA"
+ + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
+ + " where I.PARENT_ID=? and I.I_CLASS=1 and (P.PARENT_ID=I.ID and P.I_CLASS=2 and (P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or P.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions') and V.PROPERTY_ID=P.ID)"
+ + " order by I.N_ORDER_NUM, I.ID";
+ FIND_PROPERTIES_BY_PARENTID_CQ =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED,"
+ + " V.ORDER_NUM, V.DATA, V.STORAGE_DESC from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID)"
+ + " where I.PARENT_ID=? and I.I_CLASS=2 order by I.NAME";
+ }
+
+ /**
+ * Use simple queries since it is much faster
+ */
+ @Override
+ protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
+ {
+ return traverseQPathSQ(cpid);
+ }
+
+ @Override
protected int addNodeRecord(final NodeData data) throws SQLException
{
return SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Integer>()
@@ -337,64 +397,18 @@
}
/**
- * HSQLDB Multidatabase JDBC Connection constructor.
- *
- * @param dbConnection
- * JDBC connection, shoudl be opened before
- * @param readOnly
- * boolean if true the dbConnection was marked as READ-ONLY.
- * @param containerName
- * Workspace Storage Container name (see configuration)
- * @param valueStorageProvider
- * External Value Storages provider
- * @param maxBufferSize
- * Maximum buffer size (see configuration)
- * @param swapDirectory
- * Swap directory File (see configuration)
- * @param swapCleaner
- * Swap cleaner (internal FileCleaner).
- * @throws SQLException
- *
- * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
- */
- public HSQLDBMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
- ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
- throws SQLException
- {
- super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
- }
-
- /**
* {@inheritDoc}
*/
@Override
- protected void prepareQueries() throws SQLException
+ protected ResultSet findNodesAndProperties(final int offset, final int limit) throws SQLException
{
-
- super.prepareQueries();
- FIND_PROPERTY_BY_NAME =
- "select V.DATA" + " from JCR_MITEM I, JCR_MVALUE V"
- + " where I.PARENT_ID=? and I.I_CLASS=2 and I.NAME=? and I.ID=V.PROPERTY_ID order by V.ORDER_NUM";
- FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1" + " order by N_ORDER_NUM";
- FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=1";
- FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where PARENT_ID=? and I_CLASS=2" + " order by ID";
- FIND_NODES_BY_PARENTID_CQ =
- "select I.*, P.NAME AS PROP_NAME, V.ORDER_NUM, V.DATA"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
- + " where I.PARENT_ID=? and I.I_CLASS=1 and (P.PARENT_ID=I.ID and P.I_CLASS=2 and (P.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or P.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner' or P.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions') and V.PROPERTY_ID=P.ID)"
- + " order by I.N_ORDER_NUM, I.ID";
- FIND_PROPERTIES_BY_PARENTID_CQ =
- "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_CLASS, I.I_INDEX, I.N_ORDER_NUM, I.P_TYPE, I.P_MULTIVALUED,"
- + " V.ORDER_NUM, V.DATA, V.STORAGE_DESC from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID)"
- + " where I.PARENT_ID=? and I.I_CLASS=2 order by I.NAME";
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBMultiDbJDBCConnection.super.findNodesAndProperties(offset, limit);
+ }
+ };
+ return SecurityHelper.doPrivilegedSQLExceptionAction(action);
}
-
- /**
- * Use simple queries since it is much faster
- */
- @Override
- protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
- {
- return traverseQPathSQ(cpid);
- }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/HSQLDBSingleDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -563,4 +563,20 @@
};
return SecurityHelper.doPrivilegedSQLExceptionAction(action);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(final int offset, final int limit) throws SQLException
+ {
+ PrivilegedExceptionAction<ResultSet> action = new PrivilegedExceptionAction<ResultSet>()
+ {
+ public ResultSet run() throws Exception
+ {
+ return HSQLDBSingleDbJDBCConnection.super.findNodesAndProperties(offset, limit);
+ }
+ };
+ return SecurityHelper.doPrivilegedSQLExceptionAction(action);
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -184,8 +184,8 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V where I.I_CLASS=1 and"
- + " P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by ID";
+ + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V"
+ + " where I.I_CLASS=1 and P.I_CLASS=2 and P.PARENT_ID=I.ID and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
}
/**
@@ -625,6 +625,9 @@
findNodesAndProperties.clearParameters();
}
+ findNodesAndProperties.setInt(1, limit);
+ findNodesAndProperties.setInt(2, offset);
+
return findNodesAndProperties.executeQuery();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-03 20:40:43 UTC (rev 3916)
@@ -191,8 +191,9 @@
"select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V where I.I_CLASS=1 and I.CONTAINER_NAME=? and"
- + " P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID" + " and V.PROPERTY_ID=P.ID order by ID";
+ + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V"
+ + " where I.I_CLASS=1 and I.CONTAINER_NAME=? and P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID"
+ + " and V.PROPERTY_ID=P.ID order by ID LIMIT ? OFFSET ?";
}
/**
@@ -648,6 +649,8 @@
findNodesAndProperties.setString(1, containerName);
findNodesAndProperties.setString(2, containerName);
+ findNodesAndProperties.setInt(3, limit);
+ findNodesAndProperties.setInt(4, offset);
return findNodesAndProperties.executeQuery();
}
15 years, 2 months
exo-jcr SVN: r3915 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: core/query/lucene and 5 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-03 02:32:17 -0500 (Thu, 03 Feb 2011)
New Revision: 3915
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/NodeDataIndexingIterator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.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/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1104: rely on JDBCStorageConnection class
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexable.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -18,9 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.core.query;
-import java.io.IOException;
+import javax.jcr.RepositoryException;
-
/**
* Created by The eXo Platform SAS.
*
@@ -31,5 +30,5 @@
*/
public interface Indexable
{
- NodeDataIndexingIterator getNodeDataIndexingIterator() throws IOException;
+ NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize) throws RepositoryException;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/NodeDataIndexingIterator.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/NodeDataIndexingIterator.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/NodeDataIndexingIterator.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -20,9 +20,10 @@
import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
-import java.io.IOException;
-import java.util.NoSuchElementException;
+import java.util.List;
+import javax.jcr.RepositoryException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -33,10 +34,9 @@
*/
public interface NodeDataIndexingIterator
{
-
/**
* Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if <tt>next</tt> would return an element
+ * words, returns <tt>true</tt> if <tt>next</tt> would return element
* rather than throwing an exception.)
*
* @return <tt>true</tt> if the iterator has more elements.
@@ -44,15 +44,10 @@
boolean hasNext();
/**
- * Returns the next element in the iteration.
+ * Returns the next list of elements in the iteration.
*
- * @return the next element in the iteration.
- * @exception NoSuchElementException iteration has no more elements.
+ * @return the next list of elements in the iteration
+ * @throws RepositoryException if any exception occurred
*/
- NodeDataIndexing next() throws IOException;
-
- /**
- * Closes the iterator and releases all resources.
- */
- void close() throws IOException;
+ List<NodeDataIndexing> next() throws RepositoryException;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -1479,13 +1479,11 @@
private long createIndex(Indexable indexableComponent, NodeData rootNode, ItemDataConsumer stateMgr, long count)
throws IOException, RepositoryException
{
- NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator();
- try
+ NodeDataIndexingIterator iterator = indexableComponent.getNodeDataIndexingIterator(1000);
+ while (iterator.hasNext())
{
- while (iterator.hasNext())
+ for (NodeDataIndexing node : iterator.next())
{
- NodeDataIndexing node = iterator.next();
-
if (indexingTree.isExcluded(node))
{
continue;
@@ -1509,10 +1507,6 @@
checkVolatileCommit();
}
}
- finally
- {
- iterator.close();
- }
return count;
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -189,6 +189,11 @@
*/
protected String DELETE_REF;
+ /**
+ * FIND_NODES.
+ */
+ protected String FIND_NODES_AND_PROPERTIES;
+
// ======================== ITEMS table ========================
/**
* COLUMN_ID.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -30,6 +30,7 @@
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.ItemType;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -59,8 +60,15 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
import java.util.StringTokenizer;
+import java.util.TreeSet;
import javax.jcr.InvalidItemStateException;
import javax.jcr.PropertyType;
@@ -185,6 +193,8 @@
protected PreparedStatement renameNode;
+ protected PreparedStatement findNodesAndProperties;
+
/**
* Read-only flag, if true the connection is marked as READ-ONLY.
*/
@@ -543,6 +553,11 @@
{
renameNode.close();
}
+
+ if (findNodesAndProperties != null)
+ {
+ findNodesAndProperties.close();
+ }
}
catch (SQLException e)
{
@@ -999,6 +1014,79 @@
/**
* {@inheritDoc}
*/
+ public List<NodeDataIndexing> getNodesAndProperties(int offset, int limit) throws RepositoryException,
+ IllegalStateException
+ {
+ List<NodeDataIndexing> result = new ArrayList<NodeDataIndexing>();
+
+ checkIfOpened();
+ try
+ {
+ ResultSet resultSet = findNodesAndProperties(offset, limit);
+ try
+ {
+ TempNodeData tempNodeData = null;
+ while (resultSet.next())
+ {
+ if (tempNodeData == null)
+ {
+ tempNodeData = new TempNodeData(resultSet);
+ }
+ else if (!resultSet.getString(COLUMN_ID).equals(tempNodeData.cid))
+ {
+ result.add(createNodeData(tempNodeData));
+
+ tempNodeData = new TempNodeData(resultSet);
+ }
+
+ String key = resultSet.getString("P_NAME");
+
+ SortedSet<TempPropertyData> values = tempNodeData.properties.get(key);
+ if (values == null)
+ {
+ values = new TreeSet<TempPropertyData>();
+ tempNodeData.properties.put(key, values);
+ }
+
+ values.add(new ExtendedTempPropertyData(resultSet));
+ }
+
+ if (tempNodeData != null)
+ {
+ result.add(createNodeData(tempNodeData));
+ }
+ }
+ finally
+ {
+ try
+ {
+ resultSet.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Can't close the ResultSet: " + e);
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (IllegalNameException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public List<PropertyData> listChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
{
checkIfOpened();
@@ -2443,6 +2531,205 @@
}
}
+ /**
+ * Build node data and its properties data from temporary stored info.
+ *
+ * @return NodeDataIndexing
+ * @throws RepositoryException
+ * @throws IOException
+ * @throws SQLException
+ * @throws IllegalNameException
+ */
+ protected NodeDataIndexing createNodeData(TempNodeData tempNode) throws RepositoryException, SQLException,
+ IOException, IllegalNameException
+ {
+ QPath parentPath;
+ String parentCid;
+
+ if (tempNode.cpid.equals(Constants.ROOT_PARENT_UUID))
+ {
+ // root node
+ parentPath = Constants.ROOT_PATH;
+ parentCid = null;
+ }
+ else
+ {
+ parentPath =
+ QPath.makeChildPath(traverseQPath(tempNode.cpid), InternalQName.parse(tempNode.cname), tempNode.cindex);
+ parentCid = tempNode.cpid;
+ }
+
+ // primary type
+ SortedSet<TempPropertyData> primaryTypeTempProp =
+ tempNode.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
+ if (primaryTypeTempProp == null)
+ {
+ throw new PrimaryTypeNotFoundException("FATAL ERROR primary type record not found. Node "
+ + parentPath.getAsString() + ", id " + tempNode.cid + ", container " + this.containerName, null);
+ }
+
+ byte[] data = primaryTypeTempProp.first().getAsByteArray();
+ primaryTypeTempProp.first().data = new ByteArrayInputStream(data);
+
+ InternalQName ptName =
+ InternalQName.parse(new String((data != null ? data : new byte[]{}), Constants.DEFAULT_ENCODING));
+
+ // mixins
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
+ Set<TempPropertyData> mixinsTempProps = tempNode.properties.get(Constants.JCR_MIXINTYPES.getAsString());
+ if (mixinsTempProps != null)
+ {
+
+ for (TempPropertyData mxnb : mixinsTempProps)
+ {
+ data = mxnb.getAsByteArray();
+ mxnb.data = new ByteArrayInputStream(data);
+
+ mixins.add(InternalQName.parse(new String(data, Constants.DEFAULT_ENCODING)));
+ }
+ }
+
+ // build node data
+ NodeData nodeData =
+ new PersistedNodeData(getIdentifier(tempNode.cid), parentPath, getIdentifier(parentCid), tempNode.cversion,
+ tempNode.cnordernumb, ptName, mixins.toArray(new InternalQName[mixins.size()]), null);
+
+ List<PropertyData> childProps = new ArrayList<PropertyData>();
+
+ for (String propName : tempNode.properties.keySet())
+ {
+ ExtendedTempPropertyData prop = (ExtendedTempPropertyData)tempNode.properties.get(propName).first();
+ String identifier = getIdentifier(prop.id);
+
+ // read values
+ List<ValueData> valueData = new ArrayList<ValueData>();
+ for (TempPropertyData tempProp : tempNode.properties.get(propName))
+ {
+ ExtendedTempPropertyData extTempProp = (ExtendedTempPropertyData)tempProp;
+
+ ValueData vdata =
+ extTempProp.storage_desc == null ? readValueData(extTempProp.id, extTempProp.orderNum,
+ extTempProp.version, extTempProp.data) : readValueData(identifier, extTempProp.orderNum,
+ extTempProp.storage_desc);
+
+ valueData.add(vdata);
+ }
+ Collections.sort(valueData, COMPARATOR_VALUE_DATA);
+
+ QPath qpath = QPath.makeChildPath(parentPath, InternalQName.parse(prop.name));
+
+ // build property data
+ PropertyData pdata =
+ new PersistedPropertyData(identifier, qpath, tempNode.cid, prop.version, prop.type, prop.multi,
+ valueData);
+
+ childProps.add(pdata);
+ }
+
+ return new NodeDataIndexing(nodeData, childProps);
+ }
+
+ /**
+ * Class needed temporary to store node data info.
+ */
+ protected class TempNodeData
+ {
+ public String cid;
+
+ public String cname;
+
+ public int cversion;
+
+ public String cpid;
+
+ public int cindex;
+
+ public int cnordernumb;
+
+ public Map<String, SortedSet<TempPropertyData>> properties = new HashMap<String, SortedSet<TempPropertyData>>();
+
+ public TempNodeData(ResultSet item) throws SQLException
+ {
+ cid = item.getString(COLUMN_ID);
+ cname = item.getString(COLUMN_NAME);
+ cversion = item.getInt(COLUMN_VERSION);
+ cpid = item.getString(COLUMN_PARENTID);
+ cindex = item.getInt(COLUMN_INDEX);
+ cnordernumb = item.getInt(COLUMN_NORDERNUM);
+ }
+ }
+
+ /**
+ * Class needs temporary to store value info.
+ */
+ protected class TempPropertyData implements Comparable<TempPropertyData>
+ {
+ public int orderNum;
+
+ public InputStream data;
+
+ public TempPropertyData(ResultSet item) throws SQLException
+ {
+ orderNum = item.getInt(COLUMN_VORDERNUM);
+ data = item.getBinaryStream(COLUMN_VDATA);
+ }
+
+ public byte[] getAsByteArray() throws IOException
+ {
+ byte[] readBuffer = new byte[data.available()];
+ data.read(readBuffer);
+
+ return readBuffer;
+ }
+
+ public int compareTo(TempPropertyData o)
+ {
+ return orderNum - o.orderNum;
+ }
+ }
+
+ /**
+ * Class needs temporary to store whole property data info.
+ */
+ protected class ExtendedTempPropertyData extends TempPropertyData
+ {
+ public String id;
+
+ public String name;
+
+ public int version;
+
+ public int type;
+
+ boolean multi;
+
+ public String storage_desc;
+
+ public ExtendedTempPropertyData(ResultSet item) throws SQLException
+ {
+ super(item);
+
+ id = item.getString("P_ID");
+ name = item.getString("P_NAME");
+ version = item.getInt("P_VERSION");
+ type = item.getInt("P_TYPE");
+ multi = item.getBoolean("P_MULTIVALUED");
+ storage_desc = item.getString(COLUMN_VSTORAGE_DESC);
+ }
+ }
+
+ /**
+ * The comparator used to sort the value data
+ */
+ protected static Comparator<ValueData> COMPARATOR_VALUE_DATA = new Comparator<ValueData>()
+ {
+
+ public int compare(ValueData vd1, ValueData vd2)
+ {
+ return vd1.getOrderNumber() - vd2.getOrderNumber();
+ }
+ };
+
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
@@ -2459,6 +2746,8 @@
protected abstract ResultSet findChildPropertiesByParentIdentifier(String parentIdentifier) throws SQLException;
+ protected abstract ResultSet findNodesAndProperties(int offset, int limit) throws SQLException;
+
protected abstract int addReference(PropertyData data) throws SQLException, IOException;
protected abstract int renameNode(NodeData data) throws SQLException;
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 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -1425,7 +1425,7 @@
/**
* {@inheritDoc}
*/
- public NodeDataIndexingIterator getNodeDataIndexingIterator() throws IOException
+ public NodeDataIndexingIterator getNodeDataIndexingIterator(int pageSize) throws RepositoryException
{
try
{
@@ -1441,17 +1441,21 @@
return ds.getConnection();
}
});
- return new JdbcNodeDataIndexingIterator(jdbcConn, multiDb, containerName, swapCleaner, maxBufferSize,
- swapDirectory, valueStorageProvider);
+
+ return new JdbcNodeDataIndexingIterator(connFactory, pageSize);
}
else
{
throw new NameNotFoundException("Data source " + dbSourceName + " not found");
}
}
- catch (Exception e)
+ catch (SQLException e)
{
- throw new IOException(e);
+ throw new RepositoryException(e);
}
+ catch (NamingException e)
+ {
+ throw new RepositoryException(e);
+ }
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -74,6 +74,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getIdentifier(final String internalId)
{
return internalId;
@@ -82,6 +83,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getInternalId(final String identifier)
{
return identifier;
@@ -150,6 +152,13 @@
DELETE_ITEM = "delete from JCR_MITEM where ID=?";
DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
+ + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V where I.I_CLASS=1 and"
+ + " P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by ID";
}
/**
@@ -293,6 +302,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findItemByName(String parentId, String name, int index) throws SQLException
{
if (findItemByName == null)
@@ -402,6 +412,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
throws SQLException
{
@@ -431,6 +442,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int deleteValueData(String cid) throws SQLException
{
if (deleteValue == null)
@@ -445,6 +457,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValuesByPropertyId(String cid) throws SQLException
{
if (findValuesByPropertyId == null)
@@ -459,6 +472,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException
{
if (findValueByPropertyIdOrderNumber == null)
@@ -507,4 +521,22 @@
findValuesStorageDescriptorsByPropertyId.setString(1, cid);
return findValuesStorageDescriptorsByPropertyId.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(int offset, int limit) throws SQLException
+ {
+ if (findNodesAndProperties == null)
+ {
+ findNodesAndProperties = dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES);
+ }
+ else
+ {
+ findNodesAndProperties.clearParameters();
+ }
+
+ return findNodesAndProperties.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -72,6 +72,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getInternalId(final String identifier)
{
return containerName + identifier;
@@ -80,6 +81,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getIdentifier(final String internalId)
{
@@ -158,6 +160,13 @@
DELETE_ITEM = "delete from JCR_SITEM where ID=?";
DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
+ + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V where I.I_CLASS=1 and I.CONTAINER_NAME=? and"
+ + " P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID" + " and V.PROPERTY_ID=P.ID order by ID";
}
/**
@@ -416,6 +425,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
throws SQLException
{
@@ -445,6 +455,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int deleteValueData(String cid) throws SQLException
{
if (deleteValue == null)
@@ -459,6 +470,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValuesByPropertyId(String cid) throws SQLException
{
if (findValuesByPropertyId == null)
@@ -489,6 +501,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException
{
if (findValueByPropertyIdOrderNumber == null)
@@ -529,4 +542,25 @@
renameNode.setString(6, getInternalId(data.getIdentifier()));
return renameNode.executeUpdate();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(int offset, int limit) throws SQLException
+ {
+ if (findNodesAndProperties == null)
+ {
+ findNodesAndProperties = dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES);
+ }
+ else
+ {
+ findNodesAndProperties.clearParameters();
+ }
+
+ findNodesAndProperties.setString(1, containerName);
+ findNodesAndProperties.setString(2, containerName);
+
+ return findNodesAndProperties.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/indexing/JdbcNodeDataIndexingIterator.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -18,52 +18,17 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.indexing;
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.jcr.dataflow.persistent.PersistedNodeData;
-import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
-import org.exoplatform.services.jcr.datamodel.IllegalNameException;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
-import org.exoplatform.services.jcr.datamodel.PropertyData;
-import org.exoplatform.services.jcr.datamodel.QPath;
-import org.exoplatform.services.jcr.datamodel.QPathEntry;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.query.NodeDataIndexingIterator;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.CleanableFilePersistedValueData;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.PrimaryTypeNotFoundException;
-import org.exoplatform.services.jcr.impl.storage.value.ValueStorageNotFoundException;
-import org.exoplatform.services.jcr.impl.storage.value.fs.operations.ValueFileIOHelper;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.impl.util.io.SwapFile;
-import org.exoplatform.services.jcr.storage.value.ValueIOChannel;
-import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
/**
* Created by The eXo Platform SAS.
@@ -75,122 +40,43 @@
* @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy Bazko</a>
* @version $Id: JdbcIndexingDataIterator.java 34360 2010-11-11 11:11:11Z tolusha $
*/
-public class JdbcNodeDataIndexingIterator extends DBConstants implements NodeDataIndexingIterator
+public class JdbcNodeDataIndexingIterator implements NodeDataIndexingIterator
{
/**
- * Logger.
+ * Connection factory. Allows to open jdbc storage connection.
*/
- protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.JdbcIndexingDataIterator");
+ private final GenericConnectionFactory connFactory;
/**
- * Connection to the database. Should be released on close.
+ * The amount of the rows which could be retrieved from database for once.
*/
- private final Connection jdbcConn;
+ private final int pageSize;
/**
- * Temporary used prepared statement for query execution. Should be released on close.
+ * The current offset in database.
*/
- private PreparedStatement st = null;
+ private int offset = 0;
/**
- * Temporary used prepared statement. Should be released on close.
+ * Logger.
*/
- private PreparedStatement findItemQPathByIdentifierCQ;
+ protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.JdbcIndexingDataIterator");
/**
- * Temporary used result set during fetching data. Should be released on close.
+ * The list of nodes to return in next() method.
*/
- private ResultSet resultSet = null;
+ private List<NodeDataIndexing> current;
/**
- * Connection to the database. Should be released on close.
- */
- private TempNodeData data = null;
-
- /**
- * Indicates if mulit db is used or not.
- */
- private final boolean multiDb;
-
- /**
- * Container name.
- */
- private final String containerName;
-
- /**
- * The File Cleaner.
- */
- private final FileCleaner swapCleaner;
-
- /**
- * Maximum buffer size.
- */
- private final int maxBufferSize;
-
- /**
- * Swap directory.
- */
- private final File swapDirectory;
-
- /**
- * Value storage provider.
- */
- private final ValueStoragePluginProvider valueStorageProvider;
-
- /**
- * The next node data to return in next() method.
- */
- private NodeDataIndexing nextNode = null;
-
- /**
- * Search query for single db.
- */
- private static final String FIND_NODES_SINGLE_DB =
- "select I.ID AS N_ID, I.PARENT_ID AS N_PARENT_ID, I.NAME AS N_NAME, I.VERSION AS N_VERSION, I.I_INDEX AS N_I_INDEX, I.N_ORDER_NUM, "
- + "P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED, "
- + "V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V where I.I_CLASS=1 and I.CONTAINER_NAME=? and"
- + " P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID" + " and V.PROPERTY_ID=P.ID order by N_ID";
-
- /**
- * Search query for multi db.
- */
- private static final String FIND_NODES_MULTI_DB =
- "select I.ID AS N_ID, I.PARENT_ID AS N_PARENT_ID, I.NAME AS N_NAME, I.VERSION AS N_VERSION, I.I_INDEX AS N_I_INDEX, I.N_ORDER_NUM, "
- + "P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED, "
- + "V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
- + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V where I.I_CLASS=1 and"
- + " P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by N_ID";
-
- /**
* Constructor JdbcIndexingDataIterator.
*
*/
- public JdbcNodeDataIndexingIterator(Connection jdbcConn, boolean multiDb, String containerName, FileCleaner swapCleaner,
- int maxBufferSize, File swapDirectory, ValueStoragePluginProvider valueStorageProvider) throws SQLException,
- PrimaryTypeNotFoundException, InvalidItemStateException, ValueStorageNotFoundException, IllegalNameException,
- IOException
+ public JdbcNodeDataIndexingIterator(GenericConnectionFactory connFactory, int pageSize) throws RepositoryException
{
- this.jdbcConn = jdbcConn;
- this.multiDb = multiDb;
- this.containerName = containerName;
- this.swapCleaner = swapCleaner;
- this.maxBufferSize = maxBufferSize;
- this.swapDirectory = swapDirectory;
- this.valueStorageProvider = valueStorageProvider;
-
- String sql = multiDb ? FIND_NODES_MULTI_DB : FIND_NODES_SINGLE_DB;
- st = jdbcConn.prepareStatement(sql);
-
- if (!multiDb)
- {
- st.setString(1, containerName);
- st.setString(2, containerName);
- }
- resultSet = st.executeQuery();
-
- this.nextNode = readNext();
+ this.connFactory = connFactory;
+ this.pageSize = pageSize;
+ this.current = readNext();
}
/**
@@ -198,573 +84,38 @@
*/
public boolean hasNext()
{
- return this.nextNode != null;
+ return this.current.size() != 0;
}
/**
* {@inheritDoc}
*/
- public NodeDataIndexing next() throws IOException
+ public List<NodeDataIndexing> next() throws RepositoryException
{
- NodeDataIndexing current = this.nextNode;
+ List<NodeDataIndexing> next = this.current;
+ this.current = new ArrayList<NodeDataIndexing>();//readNext();
- try
- {
- this.nextNode = readNext();
- }
- catch (PrimaryTypeNotFoundException e)
- {
- throw new IOException(e);
- }
- catch (InvalidItemStateException e)
- {
- throw new IOException(e);
- }
- catch (ValueStorageNotFoundException e)
- {
- throw new IOException(e);
- }
- catch (SQLException e)
- {
- throw new IOException(e);
- }
- catch (IllegalNameException e)
- {
- throw new IOException(e);
- }
-
- return current;
+ return next;
}
/**
- * {@inheritDoc}
- */
- public void close() throws IOException
- {
- try
- {
- if (resultSet != null)
- {
- resultSet.close();
- }
-
- if (st != null)
- {
- st.close();
- }
-
- if (findItemQPathByIdentifierCQ != null)
- {
- findItemQPathByIdentifierCQ.close();
- }
-
- jdbcConn.close();
- }
- catch (SQLException e)
- {
- throw new IOException(e);
- }
- }
-
- /**
- * Read next node from database.
+ * Read next nodes from database.
*
- * @return NodeDataIndexing
+ * @return List<NodeDataIndexing>
+ * @throws RepositoryException
*/
- private NodeDataIndexing readNext() throws PrimaryTypeNotFoundException, InvalidItemStateException,
- ValueStorageNotFoundException, SQLException, IllegalNameException, IOException
+ private List<NodeDataIndexing> readNext() throws RepositoryException
{
- while (resultSet.next())
- {
- if (data == null)
- {
- data = new TempNodeData(resultSet);
- readTempPropertyData();
- }
- else if (!resultSet.getString("N_ID").equals(data.cid))
- {
- NodeDataIndexing node = createNodeData(data);
-
- data = new TempNodeData(resultSet);
- readTempPropertyData();
-
- return node;
- }
- else
- {
- readTempPropertyData();
- }
- }
-
- if (data != null)
- {
- NodeDataIndexing node = createNodeData(data);
- data = null;
-
- return node;
- }
-
- return null;
- }
-
- /**
- * Read temporary property data.
- *
- * @throws SQLException
- */
- private void readTempPropertyData() throws SQLException
- {
- String key = resultSet.getString("P_NAME");
-
- SortedSet<TempPropertyData> values = data.properties.get(key);
- if (values == null)
- {
- values = new TreeSet<TempPropertyData>();
- data.properties.put(key, values);
- }
-
- values.add(new TempPropertyData(resultSet));
- }
-
- /**
- * Build node data and its properties data from temporary stored info.
- *
- * @return NodeDataIndexing
- */
- private NodeDataIndexing createNodeData(TempNodeData tempNode) throws IllegalNameException,
- InvalidItemStateException, SQLException, PrimaryTypeNotFoundException, IOException, ValueStorageNotFoundException
- {
- QPath parentPath;
- String parentCid;
-
- if (tempNode.cpid.equals(Constants.ROOT_PARENT_UUID))
- {
- // root node
- parentPath = Constants.ROOT_PATH;
- parentCid = null;
- }
- else
- {
- parentPath =
- QPath.makeChildPath(traverseQPath(tempNode.cpid), InternalQName.parse(tempNode.cname), tempNode.cindex);
- parentCid = tempNode.cpid;
- }
-
- // primary type
- SortedSet<TempPropertyData> primaryTypeTempProp = tempNode.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
- if (primaryTypeTempProp == null)
- {
- throw new PrimaryTypeNotFoundException("FATAL ERROR primary type record not found. Node "
- + parentPath.getAsString() + ", id " + tempNode.cid + ", container " + this.containerName, null);
- }
-
- ByteArrayInputStream ba = ((ByteArrayInputStream)primaryTypeTempProp.first().cdata);
- byte[] data = new byte[ba.available()];
- ba.read(data);
-
- primaryTypeTempProp.first().cdata = new ByteArrayInputStream(data);
-
- InternalQName ptName =
- InternalQName.parse(new String((data != null ? data : new byte[]{}), Constants.DEFAULT_ENCODING));
-
- // mixins
- List<InternalQName> mixins = new ArrayList<InternalQName>();
- Set<TempPropertyData> mixinsTempProps = tempNode.properties.get(Constants.JCR_MIXINTYPES.getAsString());
- if (mixinsTempProps != null)
- {
-
- for (TempPropertyData mxnb : mixinsTempProps)
- {
- ba = ((ByteArrayInputStream)mxnb.cdata);
- data = new byte[ba.available()];
- ba.read(data);
-
- mxnb.cdata = new ByteArrayInputStream(data);
-
- mixins.add(InternalQName.parse(new String(data, Constants.DEFAULT_ENCODING)));
- }
- }
-
- // build node data
- NodeData nodeData =
- new PersistedNodeData(getIdentifier(tempNode.cid), parentPath, getIdentifier(parentCid), tempNode.cversion,
- tempNode.cnordernumb, ptName, mixins.toArray(new InternalQName[mixins.size()]), null);
-
- List<PropertyData> childProps = new ArrayList<PropertyData>();
-
- for (String propName : tempNode.properties.keySet())
- {
- TempPropertyData prop = tempNode.properties.get(propName).first();
- String identifier = getIdentifier(prop.cid);
-
- // read values
- List<ValueData> valueData = new ArrayList<ValueData>();
- for (TempPropertyData tempProp : tempNode.properties.get(propName))
- {
- ValueData vdata =
- tempProp.cstorage_desc == null ? readValueData(tempProp.cid, tempProp.corderNum, tempProp.cversion,
- tempProp.cdata) : readValueData(identifier, tempProp.corderNum, tempProp.cstorage_desc);
-
- valueData.add(vdata);
- }
- Collections.sort(valueData, COMPARATOR_VALUE_DATA);
-
- QPath qpath = QPath.makeChildPath(parentPath, InternalQName.parse(prop.cname));
-
- // build property data
- PropertyData pdata =
- new PersistedPropertyData(identifier, qpath, tempNode.cid, prop.cversion, prop.ctype, prop.cmulti,
- valueData);
-
- childProps.add(pdata);
- }
-
- return new NodeDataIndexing(nodeData, childProps);
- }
-
- /**
- * Build Item path by id.
- *
- * @param cpid
- * - Item id (container id)
- * @return Item QPath
- * @throws SQLException
- * - if database error occurs
- * @throws InvalidItemStateException
- * - if parent not found
- * @throws IllegalNameException
- * - if name on the path is wrong
- */
- private QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
- {
- String id = getIdentifier(cpid);
- if (id.equals(Constants.ROOT_UUID))
- {
- return Constants.ROOT_PATH;
- }
-
- // get item by Identifier usecase
- List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
- String caid = cpid; // container ancestor id
- boolean isRoot = false;
- do
- {
- ResultSet result = null;
- try
- {
- result = findItemQPathByIdentifier(caid);
- if (!result.next())
- throw new InvalidItemStateException("Parent not found, uuid: " + getIdentifier(caid));
-
- QPathEntry qpe1 =
- new QPathEntry(InternalQName.parse(result.getString(COLUMN_NAME)), result.getInt(COLUMN_INDEX));
- boolean isChild = caid.equals(result.getString(COLUMN_ID));
- caid = result.getString(COLUMN_PARENTID);
- if (result.next())
- {
- QPathEntry qpe2 =
- new QPathEntry(InternalQName.parse(result.getString(COLUMN_NAME)), result.getInt(COLUMN_INDEX));
- if (isChild)
- {
- // The child is the first result then we have the parent
- qrpath.add(qpe1);
- qrpath.add(qpe2);
- // We need to take the value of the parent node
- caid = result.getString(COLUMN_PARENTID);
- }
- else
- {
- // The parent is the first result then we have the child
- qrpath.add(qpe2);
- qrpath.add(qpe1);
- }
- }
- else
- {
- qrpath.add(qpe1);
- }
- }
- finally
- {
- if (result != null)
- {
- try
- {
- result.close();
- }
- catch (SQLException e)
- {
- LOG.error("Can't close the ResultSet: " + e);
- }
- }
- }
-
- if (caid.equals(Constants.ROOT_PARENT_UUID) || (id = getIdentifier(caid)).equals(Constants.ROOT_UUID))
- {
- if (id.equals(Constants.ROOT_UUID))
- {
- qrpath.add(Constants.ROOT_PATH.getEntries()[0]);
- }
- isRoot = true;
- }
- }
- while (!isRoot);
-
- QPathEntry[] qentries = new QPathEntry[qrpath.size()];
- int qi = 0;
- for (int i = qrpath.size() - 1; i >= 0; i--)
- {
- qentries[qi++] = qrpath.get(i);
- }
- return new QPath(qentries);
- }
-
- /**
- * Invoke item identifier from internalId. In case of single db need to
- * remove prefix from internalId.
- *
- * @param internalId
- * the internal identifier
- */
- private String getIdentifier(final String internalId)
- {
- if (internalId == null)
- return null;
-
- return multiDb ? internalId : internalId.substring(containerName.length());
- }
-
- /**
- *
- * @param identifier
- * @return
- * @throws SQLException
- */
- private ResultSet findItemQPathByIdentifier(String identifier) throws SQLException
- {
- String findItemQPathByIdentifier;
- if (multiDb)
- {
- findItemQPathByIdentifier =
- "select I.ID, I.PARENT_ID, I.NAME, I.I_INDEX"
- + " from JCR_MITEM I, (SELECT ID, PARENT_ID from JCR_MITEM where ID=?) J"
- + " where I.ID = J.ID or I.ID = J.PARENT_ID";
- }
- else
- {
- findItemQPathByIdentifier =
- "select I.ID, I.PARENT_ID, I.NAME, I.I_INDEX"
- + " from JCR_SITEM I, (SELECT ID, PARENT_ID from JCR_SITEM where ID=?) J"
- + " where I.ID = J.ID or I.ID = J.PARENT_ID";
- }
-
- if (findItemQPathByIdentifierCQ == null)
- {
- findItemQPathByIdentifierCQ = jdbcConn.prepareStatement(findItemQPathByIdentifier);
- }
- else
- {
- findItemQPathByIdentifierCQ.clearParameters();
- }
-
- findItemQPathByIdentifierCQ.setString(1, identifier);
- return findItemQPathByIdentifierCQ.executeQuery();
- }
-
- /**
- * Read ValueData from database.
- *
- * @param cid
- * property id
- * @param orderNumber
- * value order number
- * @param version
- * persistent version (used for BLOB swapping)
- * @param content
- * input stream
- * @return ValueData
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error (swap)
- */
- private ValueData readValueData(String cid, int orderNumber, int version, final InputStream content)
- throws SQLException, IOException
- {
-
- byte[] buffer = new byte[0];
- byte[] spoolBuffer = new byte[ValueFileIOHelper.IOBUFFER_SIZE];
- int read;
- int len = 0;
- OutputStream out = null;
-
- SwapFile swapFile = null;
+ JDBCStorageConnection conn = (JDBCStorageConnection)connFactory.openConnection();
try
{
- // stream from database
- if (content != null)
- while ((read = content.read(spoolBuffer)) >= 0)
- {
- if (out != null)
- {
- // spool to temp file
- out.write(spoolBuffer, 0, read);
- len += read;
- }
- else if (len + read > maxBufferSize)
- {
- // threshold for keeping data in memory exceeded;
- // create temp file and spool buffer contents
- swapFile = SwapFile.get(swapDirectory, cid + orderNumber + "." + version);
- if (swapFile.isSpooled())
- {
- // break, value already spooled
- buffer = null;
- break;
- }
- out = PrivilegedFileHelper.fileOutputStream(swapFile);
- out.write(buffer, 0, len);
- out.write(spoolBuffer, 0, read);
- buffer = null;
- len += read;
- }
- else
- {
- // reallocate new buffer and spool old buffer contents
- byte[] newBuffer = new byte[len + read];
- System.arraycopy(buffer, 0, newBuffer, 0, len);
- System.arraycopy(spoolBuffer, 0, newBuffer, len, read);
- buffer = newBuffer;
- len += read;
- }
- }
+ return conn.getNodesAndProperties(offset, pageSize);
+ // TODO offset + ?
}
finally
{
- if (out != null)
- {
- out.close();
- swapFile.spoolDone();
- }
+ conn.close();
}
-
- if (buffer == null)
- {
- return new CleanableFilePersistedValueData(orderNumber, swapFile, swapCleaner);
- }
-
- return new ByteArrayPersistedValueData(orderNumber, buffer);
}
-
- /**
- * Read ValueData from external storage.
- *
- * @param identifier
- * property identifier
- * @param orderNumber
- * value order number
- * @param storageId
- * external Value storage id
- * @return ValueData
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error
- * @throws ValueStorageNotFoundException
- * if no such storage found with Value storageId
- */
- private ValueData readValueData(String identifier, int orderNumber, String storageId) throws SQLException,
- IOException, ValueStorageNotFoundException
- {
- ValueIOChannel channel = valueStorageProvider.getChannel(storageId);
- try
- {
- return channel.read(identifier, orderNumber, maxBufferSize);
- }
- finally
- {
- channel.close();
- }
- }
-
- /**
- * The comparator used to sort the value data
- */
- private static Comparator<ValueData> COMPARATOR_VALUE_DATA = new Comparator<ValueData>()
- {
- public int compare(ValueData vd1, ValueData vd2)
- {
- return vd1.getOrderNumber() - vd2.getOrderNumber();
- }
- };
-
- /**
- * Class needed to store temporary node data.
- */
- private class TempNodeData
- {
- String cid;
-
- String cname;
-
- int cversion;
-
- String cpid;
-
- int cindex;
-
- int cnordernumb;
-
- Map<String, SortedSet<TempPropertyData>> properties = new HashMap<String, SortedSet<TempPropertyData>>();
-
- public TempNodeData(ResultSet item) throws SQLException
- {
- cid = item.getString("N_ID");
- cname = item.getString("N_NAME");
- cversion = item.getInt("N_VERSION");
- cpid = item.getString("N_PARENT_ID");
- cindex = item.getInt("N_I_INDEX");
- cnordernumb = item.getInt("N_ORDER_NUM");
- }
- }
-
- /**
- * Class needs to store temporary property data.
- */
- private class TempPropertyData implements Comparable<TempPropertyData>
- {
- String cid;
-
- String cname;
-
- int cversion;
-
- int ctype;
-
- boolean cmulti;
-
- int corderNum;
-
- InputStream cdata;
-
- String cstorage_desc;
-
- public TempPropertyData(ResultSet item) throws SQLException
- {
- cid = item.getString("P_ID");
- cname = item.getString("P_NAME");
- cversion = item.getInt("P_VERSION");
- ctype = item.getInt("P_TYPE");
- cmulti = item.getBoolean("P_MULTIVALUED");
- cdata = item.getBinaryStream(COLUMN_VDATA);
- cstorage_desc = item.getString(COLUMN_VSTORAGE_DESC);
- corderNum = item.getInt(COLUMN_VORDERNUM);
- }
-
- public int compareTo(TempPropertyData o)
- {
- return corderNum - o.corderNum;
- }
- }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -46,7 +46,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -101,69 +100,6 @@
protected PreparedStatement findItemQPathByIdentifierCQ;
/**
- * The comparator used to sort the value data
- */
- private static Comparator<ValueData> COMPARATOR_VALUE_DATA = new Comparator<ValueData>()
- {
-
- public int compare(ValueData vd1, ValueData vd2)
- {
- return vd1.getOrderNumber() - vd2.getOrderNumber();
- }
- };
-
- /**
- * Class needed to store node details (property also) since result set is not sorted in valid way.
- */
- private static class TempNodeData
- {
- String cid;
-
- String cname;
-
- int cversion;
-
- String cpid;
-
- int cindex;
-
- int cnordernumb;
-
- Map<String, SortedSet<TempPropertyData>> properties = new HashMap<String, SortedSet<TempPropertyData>>();
-
- public TempNodeData(ResultSet item) throws SQLException
- {
- cid = item.getString(COLUMN_ID);
- cname = item.getString(COLUMN_NAME);
- cversion = item.getInt(COLUMN_VERSION);
- cpid = item.getString(COLUMN_PARENTID);
- cindex = item.getInt(COLUMN_INDEX);
- cnordernumb = item.getInt(COLUMN_NORDERNUM);
- }
- }
-
- /**
- * store temporary property data to allow to sort it manually
- */
- private static class TempPropertyData implements Comparable<TempPropertyData>
- {
- int orderNum;
-
- byte[] data;
-
- public TempPropertyData(ResultSet item) throws SQLException
- {
- orderNum = item.getInt(COLUMN_VORDERNUM);
- data = item.getBytes(COLUMN_VDATA);
- }
-
- public int compareTo(TempPropertyData o)
- {
- return orderNum - o.orderNum;
- }
- }
-
- /**
* JDBCStorageConnection constructor.
*
* @param dbConnection
@@ -191,6 +127,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
{
checkIfOpened();
@@ -257,6 +194,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public List<PropertyData> getChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
{
checkIfOpened();
@@ -363,9 +301,10 @@
* @return list ACL
* @throws SQLException
* @throws IllegalACLException
+ * @throws IOException
*/
protected List<AccessControlEntry> readACLPermisions(String cid, Map<String, SortedSet<TempPropertyData>> properties)
- throws SQLException, IllegalACLException
+ throws SQLException, IllegalACLException, IOException
{
List<AccessControlEntry> naPermissions = new ArrayList<AccessControlEntry>();
Set<TempPropertyData> permValues = properties.get(Constants.EXO_PERMISSIONS.getAsString());
@@ -374,7 +313,8 @@
{
for (TempPropertyData value : permValues)
{
- StringTokenizer parser = new StringTokenizer(new String(value.data), AccessControlEntry.DELIMITER);
+ StringTokenizer parser =
+ new StringTokenizer(new String(value.getAsByteArray()), AccessControlEntry.DELIMITER);
naPermissions.add(new AccessControlEntry(parser.nextToken(), parser.nextToken()));
}
@@ -391,13 +331,14 @@
* @param properties - Property name and property values
* @return ACL owner
* @throws IllegalACLException
+ * @throws IOException
*/
protected String readACLOwner(String cid, Map<String, SortedSet<TempPropertyData>> properties)
- throws IllegalACLException
+ throws IllegalACLException, IOException
{
SortedSet<TempPropertyData> ownerValues = properties.get(Constants.EXO_OWNER.getAsString());
if (ownerValues != null)
- return new String(ownerValues.first().data);
+ return new String(ownerValues.first().getAsByteArray());
else
throw new IllegalACLException("Property exo:owner is not found for node with id: " + getIdentifier(cid));
}
@@ -405,6 +346,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected PersistedNodeData loadNodeRecord(QPath parentPath, String cname, String cid, String cpid, int cindex,
int cversion, int cnordernumb, AccessControlList parentACL) throws RepositoryException, SQLException
{
@@ -426,6 +368,10 @@
return loadNodeRecord(parentPath, cname, cid, cpid, cindex, cversion, cnordernumb, properties, parentACL);
}
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
finally
{
try
@@ -459,10 +405,11 @@
/**
* Create a new node from the given parameter.
+ * @throws IOException
*/
private PersistedNodeData loadNodeRecord(QPath parentPath, String cname, String cid, String cpid, int cindex,
int cversion, int cnordernumb, Map<String, SortedSet<TempPropertyData>> properties, AccessControlList parentACL)
- throws RepositoryException, SQLException
+ throws RepositoryException, SQLException, IOException
{
try
{
@@ -500,7 +447,7 @@
+ qpath.getAsString() + ", id " + cid + ", container " + this.containerName, null);
}
- byte[] data = primaryType.first().data;
+ byte[] data = primaryType.first().getAsByteArray();
InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
// MIXIN
@@ -513,7 +460,7 @@
List<InternalQName> mNames = new ArrayList<InternalQName>();
for (TempPropertyData mxnb : mixTypes)
{
- InternalQName mxn = InternalQName.parse(new String(mxnb.data));
+ InternalQName mxn = InternalQName.parse(new String(mxnb.getAsByteArray()));
mNames.add(mxn);
if (!privilegeable && Constants.EXO_PRIVILEGEABLE.equals(mxn))
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -86,6 +86,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getIdentifier(final String internalId)
{
return internalId;
@@ -94,6 +95,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getInternalId(final String identifier)
{
return identifier;
@@ -177,6 +179,13 @@
DELETE_ITEM = "delete from JCR_MITEM where ID=?";
DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
+ + " from JCR_MITEM I, JCR_MITEM P, JCR_MVALUE V where I.I_CLASS=1 and"
+ + " P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by ID";
}
/**
@@ -320,6 +329,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findItemByName(String parentId, String name, int index) throws SQLException
{
if (findItemByName == null)
@@ -444,6 +454,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
throws SQLException
{
@@ -473,6 +484,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int deleteValueData(String cid) throws SQLException
{
if (deleteValue == null)
@@ -487,6 +499,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValuesByPropertyId(String cid) throws SQLException
{
if (findValuesByPropertyId == null)
@@ -501,6 +514,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException
{
if (findValueByPropertyIdOrderNumber == null)
@@ -596,4 +610,21 @@
return findItemQPathByIdentifierCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(int offset, int limit) throws SQLException
+ {
+ if (findNodesAndProperties == null)
+ {
+ findNodesAndProperties = dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES);
+ }
+ else
+ {
+ findNodesAndProperties.clearParameters();
+ }
+
+ return findNodesAndProperties.executeQuery();
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-02 16:15:14 UTC (rev 3914)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2011-02-03 07:32:17 UTC (rev 3915)
@@ -84,6 +84,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getInternalId(final String identifier)
{
return containerName + identifier;
@@ -92,6 +93,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected String getIdentifier(final String internalId)
{
@@ -184,6 +186,13 @@
DELETE_ITEM = "delete from JCR_SITEM where ID=?";
DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM,"
+ + " P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC"
+ + " from JCR_SITEM I, JCR_SITEM P, JCR_SVALUE V where I.I_CLASS=1 and I.CONTAINER_NAME=? and"
+ + " P.I_CLASS=2 and P.CONTAINER_NAME=? and P.PARENT_ID=I.ID" + " and V.PROPERTY_ID=P.ID order by ID";
}
/**
@@ -442,6 +451,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
throws SQLException
{
@@ -471,6 +481,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected int deleteValueData(String cid) throws SQLException
{
if (deleteValue == null)
@@ -485,6 +496,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValuesByPropertyId(String cid) throws SQLException
{
if (findValuesByPropertyId == null)
@@ -515,6 +527,7 @@
/**
* {@inheritDoc}
*/
+ @Override
protected ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException
{
if (findValueByPropertyIdOrderNumber == null)
@@ -617,4 +630,25 @@
findItemQPathByIdentifierCQ.setString(1, identifier);
return findItemQPathByIdentifierCQ.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodesAndProperties(int offset, int limit) throws SQLException
+ {
+ if (findNodesAndProperties == null)
+ {
+ findNodesAndProperties = dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES);
+ }
+ else
+ {
+ findNodesAndProperties.clearParameters();
+ }
+
+ findNodesAndProperties.setString(1, containerName);
+ findNodesAndProperties.setString(2, containerName);
+
+ return findNodesAndProperties.executeQuery();
+ }
}
15 years, 2 months