exo-jcr SVN: r1304 - jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-05 16:56:12 -0500 (Tue, 05 Jan 2010)
New Revision: 1304
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
Log:
EXOJCR-302 traverseQPath() and getInternalId() in JDBCStorageConnection methods made public (for load test)
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2010-01-05 21:52:56 UTC (rev 1303)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2010-01-05 21:56:12 UTC (rev 1304)
@@ -218,7 +218,7 @@
* Item id
* @return String with container internal id
*/
- protected abstract String getInternalId(String identifier);
+ public abstract String getInternalId(String identifier);
/**
* Used in loadXYZRecord methods for extract real Identifier from container value.
@@ -849,7 +849,7 @@
* @throws IllegalNameException
* - if name on the path is wrong
*/
- protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
+ public QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
{
// get item by Identifier usecase
List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
16 years, 4 months
exo-jcr SVN: r1303 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr: load/storage and 1 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-05 16:52:56 -0500 (Tue, 05 Jan 2010)
New Revision: 1303
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/jdbc/
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/jdbc/SQLBenchmarkTest.java
Removed:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLBenchmarkTest.java
Log:
EXOJCR-302 SQLBenchmarkTest moved to load-package
Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLBenchmarkTest.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLBenchmarkTest.java 2010-01-05 17:49:40 UTC (rev 1302)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLBenchmarkTest.java 2010-01-05 21:52:56 UTC (rev 1303)
@@ -1,705 +0,0 @@
-package org.exoplatform.services.jcr.impl.storage.jdbc;
-
-import org.exoplatform.container.StandaloneContainer;
-import org.exoplatform.services.jcr.BaseStandaloneTest;
-import org.exoplatform.services.jcr.RepositoryService;
-import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
-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.ItemData;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-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.RepositoryImpl;
-import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
-import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
-
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-
-/*
- * Copyright (C) 2003-2009 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-
-/**
- * This benchmark only works with mysql with the dump that you can find in src/test/resources/SQLBenchmark/exodb_data.sql.zip
- *
- *
- * Created by The eXo Platform SAS
- * Author : Nicolas Filotto
- * nicolas.filotto(a)exoplatform.com
- * 18 nov. 2009
- */
-public class SQLBenchmarkTest
-{
-/*
- static
- {
- try
- {
- Class.forName("com.jdbmonitor.MonitorDriver");
- System.out.println("Driver Loaded");
- }
- catch (ClassNotFoundException e)
- {
- e.printStackTrace();
- }
-
- }
-*/
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception
- {
- String containerConf =
- BaseStandaloneTest.class.getResource("/conf/standalone/sql-benchmark-configuration.xml").toString();
- String loginConf = BaseStandaloneTest.class.getResource("/login.conf").toString();
-
- StandaloneContainer.addConfigurationURL(containerConf);
-
- StandaloneContainer container = StandaloneContainer.getInstance();
-
- if (System.getProperty("java.security.auth.login.config") == null)
- System.setProperty("java.security.auth.login.config", loginConf);
-
- benchmark(1, container);
- benchmark(10, container);
- benchmark(20, container);
- benchmark(50, container);
- benchmark(100, container);
- }
-
- private static void benchmark(int threads, StandaloneContainer container) throws Exception
- {
- RepositoryService repositoryService =
- (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
- RepositoryImpl repository1 = (RepositoryImpl)repositoryService.getRepository("repository1");
- WorkspaceContainerFacade wsc1 = repository1.getWorkspaceContainer("collaboration");
- final WorkspaceDataContainer dataContainer1 =
- (WorkspaceDataContainer)wsc1.getComponent(WorkspaceDataContainer.class);
- WorkspaceContainerFacade wsc1s = repository1.getWorkspaceContainer("system");
- final WorkspaceDataContainer dataContainer1s =
- (WorkspaceDataContainer)wsc1s.getComponent(WorkspaceDataContainer.class);
- RepositoryImpl repository2 = (RepositoryImpl)repositoryService.getRepository("repository2");
- WorkspaceContainerFacade wsc2 = repository2.getWorkspaceContainer("collaboration");
- final WorkspaceDataContainer dataContainer2 =
- (WorkspaceDataContainer)wsc2.getComponent(WorkspaceDataContainer.class);
- WorkspaceContainerFacade wsc2s = repository2.getWorkspaceContainer("system");
- final WorkspaceDataContainer dataContainer2s =
- (WorkspaceDataContainer)wsc2s.getComponent(WorkspaceDataContainer.class);
-
- System.out.println("########################################");
-
- int totalTimes;
- long time;
- NodeData parent;
-
- totalTimes = 5000 / threads;
- QPath path1 = null;
- Task<QPath> traverseQPath = new Task<QPath>()
- {
- public QPath execute(Object... args) throws Exception
- {
- return traverseQPath((WorkspaceDataContainer)args[0], (String)args[1]);
- }
-
- };
- Result<QPath> rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer1, Constants.ROOT_UUID);
- path1 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 0, thread " + threads
- + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- QPath path2 = null;
- rTraverseQPath = executeTask(traverseQPath, totalTimes, threads, dataContainer2, Constants.ROOT_UUID);
- path2 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 0, thread " + threads + ": Total time with the new strategy 0 = "
- + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("path1 == path2 = " + equals(path1, path2));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbd34bc0a8010b006357806c7f108d");
- path1 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 1, thread " + threads
- + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbd34bc0a8010b006357806c7f108d");
- path2 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 1, thread " + threads
- + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("path1 == path2 = " + equals(path1, path2));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbe240c0a8010b00ff024d54e46b9f");
- path1 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 2, thread " + threads
- + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbe240c0a8010b00ff024d54e46b9f");
- path2 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 2, thread " + threads
- + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("path1 == path2 = " + equals(path1, path2));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbffaec0a8010b00ed7dad7cb43540");
- path1 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 5, thread " + threads
- + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbffaec0a8010b00ed7dad7cb43540");
- path2 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 5, thread " + threads
- + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("path1 == path2 = " + equals(path1, path2));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer1, "83cb7ebeac1b00a400bf3596e43c8f18");
- path1 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 9, thread " + threads
- + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rTraverseQPath =
- executeTask(traverseQPath, totalTimes, threads, dataContainer2, "83cb7ebeac1b00a400bf3596e43c8f18");
- path2 = rTraverseQPath.getResult();
- time = rTraverseQPath.getTime();
- System.out.println("traverseQPath with deep 9, thread " + threads
- + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("path1 == path2 = " + equals(path1, path2));
-
- totalTimes = 1;
- parent =
- new PersistedNodeData("83cb2a36ac1b00a400bdbe4f3f4f6e0e", Constants.ROOT_PATH, null, 0, 0, null, null, null);
-
- Task<List<NodeData>> getChildNodesData = new Task<List<NodeData>>()
- {
- public List<NodeData> execute(Object... args) throws Exception
- {
- return getChildNodesData((WorkspaceDataContainer)args[0], (NodeData)args[1]);
- }
-
- };
- List<NodeData> nodesData1 = null;
-
- Result<List<NodeData>> rGetChildNodesData =
- executeTask(getChildNodesData, totalTimes, threads, dataContainer1, parent);
- nodesData1 = rGetChildNodesData.getResult();
- time = rGetChildNodesData.getTime();
- System.out.println("getChildNodesData with 1034 subnodes, thread " + threads
- + ": Total time with the old strategy (4*n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
- List<NodeData> nodesData2 = null;
- rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer2, parent);
- nodesData2 = rGetChildNodesData.getResult();
- time = rGetChildNodesData.getTime();
- System.out.println("getChildNodesData with 1034 subnodes, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- try
- {
- System.out.println("length = " + nodesData1.size());
- System.out.println("nodesData1 == nodesData2 = " + equals(nodesData1, nodesData2) + " length = "
- + nodesData1.size());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- totalTimes = 100 / threads;
- parent =
- new PersistedNodeData("83c6e36cac1b00a400688aeb844539b2", Constants.ROOT_PATH, null, 0, 0, null, null, null);
- rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer1, parent);
- nodesData1 = rGetChildNodesData.getResult();
- time = rGetChildNodesData.getTime();
- System.out.println("getChildNodesData with 4 subnodes, thread " + threads
- + ": Total time with the old strategy (4*n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
-
- rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer2, parent);
- nodesData2 = rGetChildNodesData.getResult();
- time = rGetChildNodesData.getTime();
- System.out.println("getChildNodesData with 4 subnodes, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("nodesData1 == nodesData2 = " + equals(nodesData1, nodesData2) + " length = "
- + nodesData1.size());
-
- totalTimes = 1000 / threads;
-
- Task<ItemData> getItemData = new Task<ItemData>()
- {
- public ItemData execute(Object... args) throws Exception
- {
- return getItemData((WorkspaceDataContainer)args[0], (String)args[1]);
- }
-
- };
- PersistedNodeData nodeData1 = null;
- Result<ItemData> rGetItemData =
- executeTask(getItemData, totalTimes, threads, dataContainer1, "83c6e36cac1b00a400688aeb844539b2");
- nodeData1 = (PersistedNodeData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by Id for a node, thread " + threads
- + ": Total time with the old strategy (5 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- PersistedNodeData nodeData2 = null;
- rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer2, "83c6e36cac1b00a400688aeb844539b2");
- nodeData2 = (PersistedNodeData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by Id for a node, thread " + threads
- + ": Total time with the new strategy (2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("nodeData1 == nodeData2 = " + equals(nodeData1, nodeData2));
-
- PersistedPropertyData propertyData1 = null;
- rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer1, "83c6e36cac1b00a40038e9e950ecff39");
- propertyData1 = (PersistedPropertyData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by Id for a property, thread " + threads
- + ": Total time with the old strategy (2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- PersistedPropertyData propertyData2 = null;
- rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer2, "83c6e36cac1b00a40038e9e950ecff39");
- propertyData2 = (PersistedPropertyData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by Id for a property, thread " + threads
- + ": Total time with the new strategy (2 queries) (=old strategy) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
- System.out.println("propertyData1 == propertyData2 = " + equals(propertyData1, propertyData2));
-
- NodeData parent2 =
- new PersistedNodeData("00exo0jcr0root0uuid0000000000000", Constants.ROOT_PATH, null, 0, 0, null, null, null);
- QPathEntry name2 = new QPathEntry(null, "Documents", 1);
-
- Task<ItemData> getItemData2 = new Task<ItemData>()
- {
- public ItemData execute(Object... args) throws Exception
- {
- return getItemData((WorkspaceDataContainer)args[0], (NodeData)args[1], (QPathEntry)args[2]);
- }
-
- };
- rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer1, parent2, name2);
- nodeData1 = (PersistedNodeData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by QPathEntry for a node, thread " + threads
- + ": Total time with the old strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer2, parent2, name2);
- nodeData2 = (PersistedNodeData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by QPathEntry for a node, thread " + threads
- + ": Total time with the new strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("nodeData1 == nodeData2 = " + equals(nodeData1, nodeData2));
-
- NodeData parent3 = nodeData1;
- QPathEntry name3 = new QPathEntry("http://www.exoplatform.com/jcr/exo/1.0", "permissions", 1);
-
- rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer1, parent3, name3);
- propertyData1 = (PersistedPropertyData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by QPathEntry for a property, thread " + threads
- + ": Total time with the old strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
-
- rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer2, parent3, name3);
- propertyData2 = (PersistedPropertyData)rGetItemData.getResult();
- time = rGetItemData.getTime();
- System.out.println("getItemData by QPathEntry for a property, thread " + threads
- + ": Total time with the new strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("propertyData1 == propertyData2 = " + equals(propertyData1, propertyData2));
-
- parent =
- new PersistedNodeData("83c7507eac1b00a400cf6d951b948e23", Constants.ROOT_PATH, null, 0, 0, null, null, null);
-
- totalTimes = 100 / threads;
- Task<List<PropertyData>> getChildPropertiesData = new Task<List<PropertyData>>()
- {
- public List<PropertyData> execute(Object... args) throws Exception
- {
- return getChildPropertiesData((WorkspaceDataContainer)args[0], (NodeData)args[1]);
- }
-
- };
- List<PropertyData> propertiesData1 = null;
- Result<List<PropertyData>> rGetChildPropertiesData =
- executeTask(getChildPropertiesData, totalTimes, threads, dataContainer1, parent);
- propertiesData1 = rGetChildPropertiesData.getResult();
- time = rGetChildPropertiesData.getTime();
- System.out.println("getChildPropertiesData with 20 properties, thread " + threads
- + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
- List<PropertyData> propertiesData2 = null;
- rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer2, parent);
- propertiesData2 = rGetChildPropertiesData.getResult();
- time = rGetChildPropertiesData.getTime();
- System.out.println("getChildPropertiesData with 20 properties, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- try
- {
- System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
- + " length = " + propertiesData1.size());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- totalTimes = 100 / threads;
- parent =
- new PersistedNodeData("83c6e36cac1b00a400688aeb844539b2", Constants.ROOT_PATH, null, 0, 0, null, null, null);
- rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer1, parent);
- propertiesData1 = rGetChildPropertiesData.getResult();
- time = rGetChildPropertiesData.getTime();
- System.out.println("getChildPropertiesData with 6 properties, thread " + threads
- + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
-
- rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer2, parent);
- propertiesData2 = rGetChildPropertiesData.getResult();
- time = rGetChildPropertiesData.getTime();
- System.out.println("getChildPropertiesData with 6 properties, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
- + " length = " + propertiesData1.size());
-
- totalTimes = 100 / threads;
- Task<List<PropertyData>> getReferencesData = new Task<List<PropertyData>>()
- {
- public List<PropertyData> execute(Object... args) throws Exception
- {
- return getReferencesData((WorkspaceDataContainer)args[0], (String)args[1]);
- }
-
- };
- Result<List<PropertyData>> rGetReferencesData =
- executeTask(getReferencesData, totalTimes, threads, dataContainer1s, "dfcbf3cfc0a8010b00a3f5f3b962c76a");
- propertiesData1 = rGetReferencesData.getResult();
- time = rGetReferencesData.getTime();
- System.out.println("getReferencesData with 3 properties, thread " + threads
- + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
-
- rGetReferencesData =
- executeTask(getReferencesData, totalTimes, threads, dataContainer2s, "dfcbf3cfc0a8010b00a3f5f3b962c76a");
- propertiesData2 = rGetReferencesData.getResult();
- time = rGetReferencesData.getTime();
- System.out.println("getReferencesData with 3 properties, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- try
- {
- System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
- + " length = " + propertiesData1.size());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- totalTimes = 100 / threads;
- rGetReferencesData =
- executeTask(getReferencesData, totalTimes, threads, dataContainer1, "dfcbe9d6c0a8010b004ccac41a161c5d");
- propertiesData1 = rGetReferencesData.getResult();
- time = rGetReferencesData.getTime();
- System.out.println("getReferencesData with 1 property, thread " + threads
- + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
- + (time / (threads * totalTimes)));
-
- rGetReferencesData =
- executeTask(getReferencesData, totalTimes, threads, dataContainer2, "dfcbe9d6c0a8010b004ccac41a161c5d");
- propertiesData2 = rGetReferencesData.getResult();
- time = rGetReferencesData.getTime();
- System.out.println("getReferencesData with 1 property, thread " + threads
- + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
- System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
- + " length = " + propertiesData1.size());
- }
-
- private static boolean equals(PersistedNodeData nodeData1, PersistedNodeData nodeData2)
- {
- return nodeData1.getACL().equals(nodeData2.getACL())
- && nodeData1.getIdentifier().equals(nodeData2.getIdentifier())
- && Arrays.equals(nodeData1.getMixinTypeNames(), nodeData2.getMixinTypeNames())
- && nodeData1.getOrderNumber() == nodeData2.getOrderNumber()
- && nodeData1.getParentIdentifier().equals(nodeData2.getParentIdentifier())
- && nodeData1.getPersistedVersion() == nodeData2.getPersistedVersion()
- && nodeData1.getPrimaryTypeName().equals(nodeData2.getPrimaryTypeName())
- && nodeData1.getQPath().equals(nodeData2.getQPath()) && nodeData1.isNode() == nodeData2.isNode();
- }
-
- private static boolean equals(PersistedPropertyData propertyData1, PersistedPropertyData propertyData2)
- {
- boolean result =
- propertyData1.isMultiValued() == propertyData2.isMultiValued()
- && propertyData1.isNode() == propertyData2.isNode()
- && propertyData1.getIdentifier().equals(propertyData2.getIdentifier())
- && propertyData1.getParentIdentifier().equals(propertyData2.getParentIdentifier())
- && propertyData1.getPersistedVersion() == propertyData2.getPersistedVersion()
- && propertyData1.getQPath().equals(propertyData2.getQPath())
- && propertyData1.getType() == propertyData2.getType();
- if (!result)
- {
- return false;
- }
- List<ValueData> values1 = propertyData1.getValues();
- List<ValueData> values2 = propertyData2.getValues();
- if (values1 == null)
- {
- return values2 == null;
- }
- else if (values2 == null || values1.size() != values2.size())
- {
- return false;
- }
- else
- {
- for (int i = 0; i < values1.size(); i++)
- {
- ValueData value1 = values1.get(i);
- ValueData value2 = values2.get(i);
- result =
- value1.isByteArray() == value2.isByteArray() && value1.getLength() == value2.getLength()
- && value1.getOrderNumber() == value2.getOrderNumber();
- if (!result)
- {
- return false;
- }
- }
- }
- return true;
- }
-
- private static boolean equals(QPath path1, QPath path2)
- {
- return path1.equals(path2);
- }
-
- private static boolean equalsP(List<PropertyData> propertiesData1, List<PropertyData> propertiesData2)
- {
- if (propertiesData1 == null)
- {
- return propertiesData2 == null;
- }
- else if (propertiesData2 == null || propertiesData1.size() != propertiesData2.size())
- {
- return false;
- }
- else
- {
- for (int i = 0; i < propertiesData1.size(); i++)
- {
- PersistedPropertyData propertyData1 = (PersistedPropertyData)propertiesData1.get(i);
- PersistedPropertyData propertyData2 = (PersistedPropertyData)propertiesData2.get(i);
- if (!equals(propertyData1, propertyData2))
- {
- return false;
- }
- }
- }
- return true;
- }
-
- private static boolean equals(List<NodeData> nodesData1, List<NodeData> nodesData2)
- {
- if (nodesData1 == null)
- {
- return nodesData2 == null;
- }
- else if (nodesData2 == null || nodesData1.size() != nodesData2.size())
- {
- return false;
- }
- else
- {
- for (int i = 0; i < nodesData1.size(); i++)
- {
- PersistedNodeData nodeData1 = (PersistedNodeData)nodesData1.get(i);
- PersistedNodeData nodeData2 = (PersistedNodeData)nodesData2.get(i);
- if (!equals(nodeData1, nodeData2))
- {
- return false;
- }
- }
- }
- return true;
- }
-
- public static ItemData getItemData(WorkspaceDataContainer dataContainer, NodeData parentData, QPathEntry name)
- throws RepositoryException, IllegalStateException
- {
- final WorkspaceStorageConnection con = dataContainer.openConnection();
- try
- {
- return con.getItemData(parentData, name);
- }
- finally
- {
- con.close();
- }
- }
-
- private static ItemData getItemData(WorkspaceDataContainer dataContainer, final String identifier)
- throws RepositoryException
- {
- final WorkspaceStorageConnection con = dataContainer.openConnection();
- try
- {
- return con.getItemData(identifier);
- }
- finally
- {
- con.close();
- }
- }
-
- private static List<NodeData> getChildNodesData(WorkspaceDataContainer dataContainer, final NodeData parent)
- throws RepositoryException
- {
- final WorkspaceStorageConnection con = dataContainer.openConnection();
- try
- {
- return con.getChildNodesData(parent);
- }
- finally
- {
- con.close();
- }
- }
-
- private static List<PropertyData> getChildPropertiesData(WorkspaceDataContainer dataContainer, final NodeData parent)
- throws RepositoryException
- {
- final WorkspaceStorageConnection con = dataContainer.openConnection();
- try
- {
- return con.getChildPropertiesData(parent);
- }
- finally
- {
- con.close();
- }
- }
-
- private static List<PropertyData> getReferencesData(WorkspaceDataContainer dataContainer, final String identifier)
- throws RepositoryException
- {
- final WorkspaceStorageConnection con = dataContainer.openConnection();
- try
- {
- return con.getReferencesData(identifier);
- }
- finally
- {
- con.close();
- }
- }
-
- private static QPath traverseQPath(WorkspaceDataContainer dataContainer, final String identifier)
- throws RepositoryException, SQLException, InvalidItemStateException, IllegalNameException
- {
- final JDBCStorageConnection con = (JDBCStorageConnection)dataContainer.openConnection();
- try
- {
- return con.traverseQPath(con.getInternalId(identifier));
- }
- finally
- {
- con.close();
- }
- }
-
- private static interface Task<R>
- {
- R execute(Object... args) throws Exception;
- }
-
- private static class Result<R>
- {
- private final R result;
-
- private final long time;
-
- public Result(R result, long time)
- {
- this.result = result;
- this.time = time;
- }
-
- public R getResult()
- {
- return result;
- }
-
- public long getTime()
- {
- return time;
- }
- }
-
- private static <R> Result<R> executeTask(final Task<R> task, final int totalTimes, int threads, final Object... args)
- throws InterruptedException
- {
- final CountDownLatch startSignal = new CountDownLatch(1);
- final CountDownLatch doneSignal = new CountDownLatch(threads);
- final AtomicReference<R> result = new AtomicReference<R>();
- for (int i = 0; i < threads; i++)
- {
- Thread t = new Thread()
- {
- public void run()
- {
- try
- {
- startSignal.await();
- for (int i = 0; i < totalTimes; i++)
- {
- result.set(task.execute(args));
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- doneSignal.countDown();
- }
- }
- };
- t.start();
- }
- long time = System.currentTimeMillis();
- startSignal.countDown();
- doneSignal.await();
- return new Result<R>(result.get(), System.currentTimeMillis() - time);
- }
-}
Copied: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/jdbc/SQLBenchmarkTest.java (from rev 1302, jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLBenchmarkTest.java)
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/jdbc/SQLBenchmarkTest.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/jdbc/SQLBenchmarkTest.java 2010-01-05 21:52:56 UTC (rev 1303)
@@ -0,0 +1,706 @@
+package org.exoplatform.services.jcr.load.storage.jdbc;
+
+import org.exoplatform.container.StandaloneContainer;
+import org.exoplatform.services.jcr.BaseStandaloneTest;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
+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.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+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.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * This benchmark only works with mysql with the dump that you can find in src/test/resources/SQLBenchmark/exodb_data.sql.zip
+ *
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 18 nov. 2009
+ */
+public class SQLBenchmarkTest
+{
+/*
+ static
+ {
+ try
+ {
+ Class.forName("com.jdbmonitor.MonitorDriver");
+ System.out.println("Driver Loaded");
+ }
+ catch (ClassNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+*/
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception
+ {
+ String containerConf =
+ BaseStandaloneTest.class.getResource("/conf/standalone/sql-benchmark-configuration.xml").toString();
+ String loginConf = BaseStandaloneTest.class.getResource("/login.conf").toString();
+
+ StandaloneContainer.addConfigurationURL(containerConf);
+
+ StandaloneContainer container = StandaloneContainer.getInstance();
+
+ if (System.getProperty("java.security.auth.login.config") == null)
+ System.setProperty("java.security.auth.login.config", loginConf);
+
+ benchmark(1, container);
+ benchmark(10, container);
+ benchmark(20, container);
+ benchmark(50, container);
+ benchmark(100, container);
+ }
+
+ private static void benchmark(int threads, StandaloneContainer container) throws Exception
+ {
+ RepositoryService repositoryService =
+ (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
+ RepositoryImpl repository1 = (RepositoryImpl)repositoryService.getRepository("repository1");
+ WorkspaceContainerFacade wsc1 = repository1.getWorkspaceContainer("collaboration");
+ final WorkspaceDataContainer dataContainer1 =
+ (WorkspaceDataContainer)wsc1.getComponent(WorkspaceDataContainer.class);
+ WorkspaceContainerFacade wsc1s = repository1.getWorkspaceContainer("system");
+ final WorkspaceDataContainer dataContainer1s =
+ (WorkspaceDataContainer)wsc1s.getComponent(WorkspaceDataContainer.class);
+ RepositoryImpl repository2 = (RepositoryImpl)repositoryService.getRepository("repository2");
+ WorkspaceContainerFacade wsc2 = repository2.getWorkspaceContainer("collaboration");
+ final WorkspaceDataContainer dataContainer2 =
+ (WorkspaceDataContainer)wsc2.getComponent(WorkspaceDataContainer.class);
+ WorkspaceContainerFacade wsc2s = repository2.getWorkspaceContainer("system");
+ final WorkspaceDataContainer dataContainer2s =
+ (WorkspaceDataContainer)wsc2s.getComponent(WorkspaceDataContainer.class);
+
+ System.out.println("########################################");
+
+ int totalTimes;
+ long time;
+ NodeData parent;
+
+ totalTimes = 5000 / threads;
+ QPath path1 = null;
+ Task<QPath> traverseQPath = new Task<QPath>()
+ {
+ public QPath execute(Object... args) throws Exception
+ {
+ return traverseQPath((WorkspaceDataContainer)args[0], (String)args[1]);
+ }
+
+ };
+ Result<QPath> rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer1, Constants.ROOT_UUID);
+ path1 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 0, thread " + threads
+ + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ QPath path2 = null;
+ rTraverseQPath = executeTask(traverseQPath, totalTimes, threads, dataContainer2, Constants.ROOT_UUID);
+ path2 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 0, thread " + threads + ": Total time with the new strategy 0 = "
+ + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("path1 == path2 = " + equals(path1, path2));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbd34bc0a8010b006357806c7f108d");
+ path1 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 1, thread " + threads
+ + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbd34bc0a8010b006357806c7f108d");
+ path2 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 1, thread " + threads
+ + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("path1 == path2 = " + equals(path1, path2));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbe240c0a8010b00ff024d54e46b9f");
+ path1 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 2, thread " + threads
+ + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbe240c0a8010b00ff024d54e46b9f");
+ path2 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 2, thread " + threads
+ + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("path1 == path2 = " + equals(path1, path2));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer1, "dfcbffaec0a8010b00ed7dad7cb43540");
+ path1 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 5, thread " + threads
+ + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer2, "dfcbffaec0a8010b00ed7dad7cb43540");
+ path2 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 5, thread " + threads
+ + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("path1 == path2 = " + equals(path1, path2));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer1, "83cb7ebeac1b00a400bf3596e43c8f18");
+ path1 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 9, thread " + threads
+ + ": Total time with the old strategy (n queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rTraverseQPath =
+ executeTask(traverseQPath, totalTimes, threads, dataContainer2, "83cb7ebeac1b00a400bf3596e43c8f18");
+ path2 = rTraverseQPath.getResult();
+ time = rTraverseQPath.getTime();
+ System.out.println("traverseQPath with deep 9, thread " + threads
+ + ": Total time with the new strategy (n/2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("path1 == path2 = " + equals(path1, path2));
+
+ totalTimes = 1;
+ parent =
+ new PersistedNodeData("83cb2a36ac1b00a400bdbe4f3f4f6e0e", Constants.ROOT_PATH, null, 0, 0, null, null, null);
+
+ Task<List<NodeData>> getChildNodesData = new Task<List<NodeData>>()
+ {
+ public List<NodeData> execute(Object... args) throws Exception
+ {
+ return getChildNodesData((WorkspaceDataContainer)args[0], (NodeData)args[1]);
+ }
+
+ };
+ List<NodeData> nodesData1 = null;
+
+ Result<List<NodeData>> rGetChildNodesData =
+ executeTask(getChildNodesData, totalTimes, threads, dataContainer1, parent);
+ nodesData1 = rGetChildNodesData.getResult();
+ time = rGetChildNodesData.getTime();
+ System.out.println("getChildNodesData with 1034 subnodes, thread " + threads
+ + ": Total time with the old strategy (4*n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+ List<NodeData> nodesData2 = null;
+ rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer2, parent);
+ nodesData2 = rGetChildNodesData.getResult();
+ time = rGetChildNodesData.getTime();
+ System.out.println("getChildNodesData with 1034 subnodes, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ try
+ {
+ System.out.println("length = " + nodesData1.size());
+ System.out.println("nodesData1 == nodesData2 = " + equals(nodesData1, nodesData2) + " length = "
+ + nodesData1.size());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ totalTimes = 100 / threads;
+ parent =
+ new PersistedNodeData("83c6e36cac1b00a400688aeb844539b2", Constants.ROOT_PATH, null, 0, 0, null, null, null);
+ rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer1, parent);
+ nodesData1 = rGetChildNodesData.getResult();
+ time = rGetChildNodesData.getTime();
+ System.out.println("getChildNodesData with 4 subnodes, thread " + threads
+ + ": Total time with the old strategy (4*n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+
+ rGetChildNodesData = executeTask(getChildNodesData, totalTimes, threads, dataContainer2, parent);
+ nodesData2 = rGetChildNodesData.getResult();
+ time = rGetChildNodesData.getTime();
+ System.out.println("getChildNodesData with 4 subnodes, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("nodesData1 == nodesData2 = " + equals(nodesData1, nodesData2) + " length = "
+ + nodesData1.size());
+
+ totalTimes = 1000 / threads;
+
+ Task<ItemData> getItemData = new Task<ItemData>()
+ {
+ public ItemData execute(Object... args) throws Exception
+ {
+ return getItemData((WorkspaceDataContainer)args[0], (String)args[1]);
+ }
+
+ };
+ PersistedNodeData nodeData1 = null;
+ Result<ItemData> rGetItemData =
+ executeTask(getItemData, totalTimes, threads, dataContainer1, "83c6e36cac1b00a400688aeb844539b2");
+ nodeData1 = (PersistedNodeData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by Id for a node, thread " + threads
+ + ": Total time with the old strategy (5 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ PersistedNodeData nodeData2 = null;
+ rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer2, "83c6e36cac1b00a400688aeb844539b2");
+ nodeData2 = (PersistedNodeData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by Id for a node, thread " + threads
+ + ": Total time with the new strategy (2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("nodeData1 == nodeData2 = " + equals(nodeData1, nodeData2));
+
+ PersistedPropertyData propertyData1 = null;
+ rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer1, "83c6e36cac1b00a40038e9e950ecff39");
+ propertyData1 = (PersistedPropertyData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by Id for a property, thread " + threads
+ + ": Total time with the old strategy (2 queries) = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ PersistedPropertyData propertyData2 = null;
+ rGetItemData = executeTask(getItemData, totalTimes, threads, dataContainer2, "83c6e36cac1b00a40038e9e950ecff39");
+ propertyData2 = (PersistedPropertyData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by Id for a property, thread " + threads
+ + ": Total time with the new strategy (2 queries) (=old strategy) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+ System.out.println("propertyData1 == propertyData2 = " + equals(propertyData1, propertyData2));
+
+ NodeData parent2 =
+ new PersistedNodeData("00exo0jcr0root0uuid0000000000000", Constants.ROOT_PATH, null, 0, 0, null, null, null);
+ QPathEntry name2 = new QPathEntry(null, "Documents", 1);
+
+ Task<ItemData> getItemData2 = new Task<ItemData>()
+ {
+ public ItemData execute(Object... args) throws Exception
+ {
+ return getItemData((WorkspaceDataContainer)args[0], (NodeData)args[1], (QPathEntry)args[2]);
+ }
+
+ };
+ rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer1, parent2, name2);
+ nodeData1 = (PersistedNodeData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by QPathEntry for a node, thread " + threads
+ + ": Total time with the old strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer2, parent2, name2);
+ nodeData2 = (PersistedNodeData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by QPathEntry for a node, thread " + threads
+ + ": Total time with the new strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("nodeData1 == nodeData2 = " + equals(nodeData1, nodeData2));
+
+ NodeData parent3 = nodeData1;
+ QPathEntry name3 = new QPathEntry("http://www.exoplatform.com/jcr/exo/1.0", "permissions", 1);
+
+ rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer1, parent3, name3);
+ propertyData1 = (PersistedPropertyData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by QPathEntry for a property, thread " + threads
+ + ": Total time with the old strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
+
+ rGetItemData = executeTask(getItemData2, totalTimes, threads, dataContainer2, parent3, name3);
+ propertyData2 = (PersistedPropertyData)rGetItemData.getResult();
+ time = rGetItemData.getTime();
+ System.out.println("getItemData by QPathEntry for a property, thread " + threads
+ + ": Total time with the new strategy = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("propertyData1 == propertyData2 = " + equals(propertyData1, propertyData2));
+
+ parent =
+ new PersistedNodeData("83c7507eac1b00a400cf6d951b948e23", Constants.ROOT_PATH, null, 0, 0, null, null, null);
+
+ totalTimes = 100 / threads;
+ Task<List<PropertyData>> getChildPropertiesData = new Task<List<PropertyData>>()
+ {
+ public List<PropertyData> execute(Object... args) throws Exception
+ {
+ return getChildPropertiesData((WorkspaceDataContainer)args[0], (NodeData)args[1]);
+ }
+
+ };
+ List<PropertyData> propertiesData1 = null;
+ Result<List<PropertyData>> rGetChildPropertiesData =
+ executeTask(getChildPropertiesData, totalTimes, threads, dataContainer1, parent);
+ propertiesData1 = rGetChildPropertiesData.getResult();
+ time = rGetChildPropertiesData.getTime();
+ System.out.println("getChildPropertiesData with 20 properties, thread " + threads
+ + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+ List<PropertyData> propertiesData2 = null;
+ rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer2, parent);
+ propertiesData2 = rGetChildPropertiesData.getResult();
+ time = rGetChildPropertiesData.getTime();
+ System.out.println("getChildPropertiesData with 20 properties, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ try
+ {
+ System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
+ + " length = " + propertiesData1.size());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ totalTimes = 100 / threads;
+ parent =
+ new PersistedNodeData("83c6e36cac1b00a400688aeb844539b2", Constants.ROOT_PATH, null, 0, 0, null, null, null);
+ rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer1, parent);
+ propertiesData1 = rGetChildPropertiesData.getResult();
+ time = rGetChildPropertiesData.getTime();
+ System.out.println("getChildPropertiesData with 6 properties, thread " + threads
+ + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+
+ rGetChildPropertiesData = executeTask(getChildPropertiesData, totalTimes, threads, dataContainer2, parent);
+ propertiesData2 = rGetChildPropertiesData.getResult();
+ time = rGetChildPropertiesData.getTime();
+ System.out.println("getChildPropertiesData with 6 properties, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
+ + " length = " + propertiesData1.size());
+
+ totalTimes = 100 / threads;
+ Task<List<PropertyData>> getReferencesData = new Task<List<PropertyData>>()
+ {
+ public List<PropertyData> execute(Object... args) throws Exception
+ {
+ return getReferencesData((WorkspaceDataContainer)args[0], (String)args[1]);
+ }
+
+ };
+ Result<List<PropertyData>> rGetReferencesData =
+ executeTask(getReferencesData, totalTimes, threads, dataContainer1s, "dfcbf3cfc0a8010b00a3f5f3b962c76a");
+ propertiesData1 = rGetReferencesData.getResult();
+ time = rGetReferencesData.getTime();
+ System.out.println("getReferencesData with 3 properties, thread " + threads
+ + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+
+ rGetReferencesData =
+ executeTask(getReferencesData, totalTimes, threads, dataContainer2s, "dfcbf3cfc0a8010b00a3f5f3b962c76a");
+ propertiesData2 = rGetReferencesData.getResult();
+ time = rGetReferencesData.getTime();
+ System.out.println("getReferencesData with 3 properties, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ try
+ {
+ System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
+ + " length = " + propertiesData1.size());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ totalTimes = 100 / threads;
+ rGetReferencesData =
+ executeTask(getReferencesData, totalTimes, threads, dataContainer1, "dfcbe9d6c0a8010b004ccac41a161c5d");
+ propertiesData1 = rGetReferencesData.getResult();
+ time = rGetReferencesData.getTime();
+ System.out.println("getReferencesData with 1 property, thread " + threads
+ + ": Total time with the old strategy (n + 1 queries) = " + time + ", avg = "
+ + (time / (threads * totalTimes)));
+
+ rGetReferencesData =
+ executeTask(getReferencesData, totalTimes, threads, dataContainer2, "dfcbe9d6c0a8010b004ccac41a161c5d");
+ propertiesData2 = rGetReferencesData.getResult();
+ time = rGetReferencesData.getTime();
+ System.out.println("getReferencesData with 1 property, thread " + threads
+ + ": Total time with the new strategy (1 query) = " + time + ", avg = " + (time / (threads * totalTimes)));
+ System.out.println("propertiesData1 == propertiesData2 = " + equalsP(propertiesData1, propertiesData2)
+ + " length = " + propertiesData1.size());
+ }
+
+ private static boolean equals(PersistedNodeData nodeData1, PersistedNodeData nodeData2)
+ {
+ return nodeData1.getACL().equals(nodeData2.getACL())
+ && nodeData1.getIdentifier().equals(nodeData2.getIdentifier())
+ && Arrays.equals(nodeData1.getMixinTypeNames(), nodeData2.getMixinTypeNames())
+ && nodeData1.getOrderNumber() == nodeData2.getOrderNumber()
+ && nodeData1.getParentIdentifier().equals(nodeData2.getParentIdentifier())
+ && nodeData1.getPersistedVersion() == nodeData2.getPersistedVersion()
+ && nodeData1.getPrimaryTypeName().equals(nodeData2.getPrimaryTypeName())
+ && nodeData1.getQPath().equals(nodeData2.getQPath()) && nodeData1.isNode() == nodeData2.isNode();
+ }
+
+ private static boolean equals(PersistedPropertyData propertyData1, PersistedPropertyData propertyData2)
+ {
+ boolean result =
+ propertyData1.isMultiValued() == propertyData2.isMultiValued()
+ && propertyData1.isNode() == propertyData2.isNode()
+ && propertyData1.getIdentifier().equals(propertyData2.getIdentifier())
+ && propertyData1.getParentIdentifier().equals(propertyData2.getParentIdentifier())
+ && propertyData1.getPersistedVersion() == propertyData2.getPersistedVersion()
+ && propertyData1.getQPath().equals(propertyData2.getQPath())
+ && propertyData1.getType() == propertyData2.getType();
+ if (!result)
+ {
+ return false;
+ }
+ List<ValueData> values1 = propertyData1.getValues();
+ List<ValueData> values2 = propertyData2.getValues();
+ if (values1 == null)
+ {
+ return values2 == null;
+ }
+ else if (values2 == null || values1.size() != values2.size())
+ {
+ return false;
+ }
+ else
+ {
+ for (int i = 0; i < values1.size(); i++)
+ {
+ ValueData value1 = values1.get(i);
+ ValueData value2 = values2.get(i);
+ result =
+ value1.isByteArray() == value2.isByteArray() && value1.getLength() == value2.getLength()
+ && value1.getOrderNumber() == value2.getOrderNumber();
+ if (!result)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static boolean equals(QPath path1, QPath path2)
+ {
+ return path1.equals(path2);
+ }
+
+ private static boolean equalsP(List<PropertyData> propertiesData1, List<PropertyData> propertiesData2)
+ {
+ if (propertiesData1 == null)
+ {
+ return propertiesData2 == null;
+ }
+ else if (propertiesData2 == null || propertiesData1.size() != propertiesData2.size())
+ {
+ return false;
+ }
+ else
+ {
+ for (int i = 0; i < propertiesData1.size(); i++)
+ {
+ PersistedPropertyData propertyData1 = (PersistedPropertyData)propertiesData1.get(i);
+ PersistedPropertyData propertyData2 = (PersistedPropertyData)propertiesData2.get(i);
+ if (!equals(propertyData1, propertyData2))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static boolean equals(List<NodeData> nodesData1, List<NodeData> nodesData2)
+ {
+ if (nodesData1 == null)
+ {
+ return nodesData2 == null;
+ }
+ else if (nodesData2 == null || nodesData1.size() != nodesData2.size())
+ {
+ return false;
+ }
+ else
+ {
+ for (int i = 0; i < nodesData1.size(); i++)
+ {
+ PersistedNodeData nodeData1 = (PersistedNodeData)nodesData1.get(i);
+ PersistedNodeData nodeData2 = (PersistedNodeData)nodesData2.get(i);
+ if (!equals(nodeData1, nodeData2))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static ItemData getItemData(WorkspaceDataContainer dataContainer, NodeData parentData, QPathEntry name)
+ throws RepositoryException, IllegalStateException
+ {
+ final WorkspaceStorageConnection con = dataContainer.openConnection();
+ try
+ {
+ return con.getItemData(parentData, name);
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static ItemData getItemData(WorkspaceDataContainer dataContainer, final String identifier)
+ throws RepositoryException
+ {
+ final WorkspaceStorageConnection con = dataContainer.openConnection();
+ try
+ {
+ return con.getItemData(identifier);
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static List<NodeData> getChildNodesData(WorkspaceDataContainer dataContainer, final NodeData parent)
+ throws RepositoryException
+ {
+ final WorkspaceStorageConnection con = dataContainer.openConnection();
+ try
+ {
+ return con.getChildNodesData(parent);
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static List<PropertyData> getChildPropertiesData(WorkspaceDataContainer dataContainer, final NodeData parent)
+ throws RepositoryException
+ {
+ final WorkspaceStorageConnection con = dataContainer.openConnection();
+ try
+ {
+ return con.getChildPropertiesData(parent);
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static List<PropertyData> getReferencesData(WorkspaceDataContainer dataContainer, final String identifier)
+ throws RepositoryException
+ {
+ final WorkspaceStorageConnection con = dataContainer.openConnection();
+ try
+ {
+ return con.getReferencesData(identifier);
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static QPath traverseQPath(WorkspaceDataContainer dataContainer, final String identifier)
+ throws RepositoryException, SQLException, InvalidItemStateException, IllegalNameException
+ {
+ final JDBCStorageConnection con = (JDBCStorageConnection)dataContainer.openConnection();
+ try
+ {
+ return con.traverseQPath(con.getInternalId(identifier));
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+
+ private static interface Task<R>
+ {
+ R execute(Object... args) throws Exception;
+ }
+
+ private static class Result<R>
+ {
+ private final R result;
+
+ private final long time;
+
+ public Result(R result, long time)
+ {
+ this.result = result;
+ this.time = time;
+ }
+
+ public R getResult()
+ {
+ return result;
+ }
+
+ public long getTime()
+ {
+ return time;
+ }
+ }
+
+ private static <R> Result<R> executeTask(final Task<R> task, final int totalTimes, int threads, final Object... args)
+ throws InterruptedException
+ {
+ final CountDownLatch startSignal = new CountDownLatch(1);
+ final CountDownLatch doneSignal = new CountDownLatch(threads);
+ final AtomicReference<R> result = new AtomicReference<R>();
+ for (int i = 0; i < threads; i++)
+ {
+ Thread t = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ startSignal.await();
+ for (int i = 0; i < totalTimes; i++)
+ {
+ result.set(task.execute(args));
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ doneSignal.countDown();
+ }
+ }
+ };
+ t.start();
+ }
+ long time = System.currentTimeMillis();
+ startSignal.countDown();
+ doneSignal.await();
+ return new Result<R>(result.get(), System.currentTimeMillis() - time);
+ }
+}
16 years, 4 months
exo-jcr SVN: r1302 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/itemfilters and 6 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-01-05 12:49:40 -0500 (Tue, 05 Jan 2010)
New Revision: 1302
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataFilter.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataNamePatternFilter.java
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/DefaultItemDataCopyVisitor.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataCloneVisitor.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/EntityCollection.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/NodeIteratorOnDemand.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/exporting/BaseXmlExporter.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/TestJira282.java
Log:
EXOJCR-359 Reduce amount of NodeImpl created on read operations + lazy child items refactoring (EXOJCR-338)
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -706,8 +706,11 @@
{
NodeImpl parent = (NodeImpl)item(getParentIdentifier());
if (parent == null)
+ {
throw new ItemNotFoundException("FATAL: Parent is null for " + getPath() + " parent UUID: "
+ getParentIdentifier());
+ }
+
return parent;
}
@@ -722,8 +725,11 @@
{
NodeData parent = (NodeData)dataManager.getItemData(getData().getParentIdentifier());
if (parent == null)
+ {
throw new ItemNotFoundException("FATAL: Parent is null for " + getPath() + " parent UUID: "
+ getData().getParentIdentifier());
+ }
+
return parent;
}
@@ -778,7 +784,7 @@
}
/**
- * Loads data
+ * Loads data.
*
* @param data
* source item data
@@ -788,6 +794,18 @@
abstract void loadData(ItemData data) throws RepositoryException;
/**
+ * Loads data using existing parent data (used primary and mixin types for Item Definition discovery).
+ *
+ * @param data
+ * source item data
+ * @param parent NodeData
+ * Items's parent
+ * @throws RepositoryException
+ * if errors occurs
+ */
+ abstract void loadData(ItemData data, NodeData parent) throws RepositoryException;
+
+ /**
* Loads data.
*
* @param data
@@ -811,11 +829,13 @@
{
NodeData ndata;
if (isNode())
+ {
ndata = (NodeData)getData();
+ }
else
- ndata = parentData(); // (NodeData)
- // dataManager.getItemData(data.getParentIdentifier
- // ())
+ {
+ ndata = parentData();
+ }
return session.getAccessManager().hasPermission(ndata.getACL(), action, session.getUserState().getIdentity());
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -42,7 +42,8 @@
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.itemfilters.ItemFilter;
+import org.exoplatform.services.jcr.impl.core.itemfilters.ItemDataFilter;
+import org.exoplatform.services.jcr.impl.core.itemfilters.ItemDataNamePatternFilter;
import org.exoplatform.services.jcr.impl.core.itemfilters.NamePatternFilter;
import org.exoplatform.services.jcr.impl.core.lock.LockImpl;
import org.exoplatform.services.jcr.impl.core.nodetype.ItemAutocreator;
@@ -58,7 +59,6 @@
import org.exoplatform.services.jcr.impl.dataflow.session.SessionChangesLog;
import org.exoplatform.services.jcr.impl.dataflow.session.TransactionableDataManager;
import org.exoplatform.services.jcr.impl.util.EntityCollection;
-import org.exoplatform.services.jcr.impl.util.NodeIteratorOnDemand;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
@@ -75,6 +75,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import javax.jcr.AccessDeniedException;
import javax.jcr.InvalidItemStateException;
@@ -90,6 +91,7 @@
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.PropertyType;
+import javax.jcr.RangeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
@@ -156,7 +158,7 @@
*
* @param data
* Node data
- * @param parent parent NodeData
+ * @param parent NodeData Nodes's parent
* @param session
* Session
* @throws RepositoryException
@@ -166,7 +168,7 @@
{
super(data, session);
this.sysLocFactory = session.getSystemLocationFactory();
- loadNodeData(data, parent);
+ loadData(data, parent);
}
/**
@@ -482,7 +484,9 @@
checkValid();
if (!session.getAccessManager().hasPermission(getACL(), actions, session.getUserState().getIdentity()))
+ {
throw new AccessControlException("Permission denied " + getPath() + " : " + actions);
+ }
}
/**
@@ -494,7 +498,8 @@
* @throws AccessDeniedException
* if Nodes cannot be listed due to permissions on this Node
*/
- public List<NodeImpl> childNodes() throws RepositoryException, AccessDeniedException
+ @Deprecated
+ private List<NodeImpl> childNodes() throws RepositoryException, AccessDeniedException
{
List<NodeImpl> storedNodes = dataManager.getChildNodes(nodeData(), true);
@@ -511,7 +516,8 @@
* @throws AccessDeniedException
* if Properties cannot be listed due to permissions on this Node
*/
- public List<PropertyImpl> childProperties() throws RepositoryException, AccessDeniedException
+ @Deprecated
+ private List<PropertyImpl> childProperties() throws RepositoryException, AccessDeniedException
{
List<PropertyImpl> storedProperties = dataManager.getChildProperties(nodeData(), true);
@@ -801,7 +807,9 @@
{
NodeData corrNode = (NodeData)corrDataManager.getItemData(getUUID());
if (corrNode != null)
+ {
return corrNode;
+ }
}
else
{
@@ -826,7 +834,9 @@
}
NodeData corrNode = (NodeData)corrDataManager.getItemData(myPath);
if (corrNode != null)
+ {
return corrNode;
+ }
throw new ItemNotFoundException("No corresponding path for " + getPath() + " in "
+ corrSession.getWorkspace().getName());
@@ -886,7 +896,10 @@
.getMixinTypeNames());
if (definition == null)
+ {
throw new ConstraintViolationException("Node definition not found for " + getPath());
+ }
+
// TODO same functionality in NodeTypeImpl
InternalQName[] rnames = definition.getRequiredPrimaryTypes();
NodeType[] rnts = new NodeType[rnames.length];
@@ -898,7 +911,6 @@
nodeDefinition =
new NodeDefinitionImpl(definition, nodeTypesHolder, nodeTypeManager, sysLocFactory, session
.getValueFactory());
-
}
}
@@ -927,7 +939,10 @@
LockImpl lock = session.getLockManager().getLock(this);
if (lock == null)
+ {
throw new LockException("Lock not found " + getPath());
+ }
+
return lock;
}
@@ -942,7 +957,9 @@
// should not be null
if (nodeData().getMixinTypeNames() == null)
+ {
throw new RepositoryException("Data Container implementation error getMixinTypeNames == null");
+ }
ExtendedNodeTypeManager nodeTypeManager = (ExtendedNodeTypeManager)session.getWorkspace().getNodeTypeManager();
NodeType[] mixinNodeTypes = new NodeType[nodeData().getMixinTypeNames().length];
@@ -966,7 +983,10 @@
NodeType[] mixinTypes = getMixinNodeTypes();
String[] mtNames = new String[mixinTypes.length];
for (int i = 0; i < mtNames.length; i++)
+ {
mtNames[i] = mixinTypes[i].getName();
+ }
+
return mtNames;
}
@@ -982,8 +1002,11 @@
ItemImpl node = dataManager.getItem(nodeData(), itemPath.getInternalPath().getEntries(), true);
if (node == null || !node.isNode())
+ {
throw new PathNotFoundException("Node not found " + (isRoot() ? "" : getLocation().getAsString(false)) + "/"
+ itemPath.getAsString(false));
+ }
+
return (NodeImpl)node;
}
@@ -993,6 +1016,7 @@
public String getIdentifier() throws RepositoryException
{
checkValid();
+
return this.getInternalIdentifier();
}
@@ -1004,17 +1028,25 @@
long start = System.currentTimeMillis();
if (LOG.isDebugEnabled())
+ {
LOG.debug("getNodes() >>>>>");
+ }
checkValid();
try
{
- return new NodeIteratorOnDemand(childNodesData(), dataManager, nodeData());
+ // TODO full iterator code
+ // return new EntityCollection(childNodes());
+
+ // lazy childs
+ return new LazyNodeIterator(childNodesData());
}
finally
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("getNodes() <<<<< " + ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -1026,25 +1058,35 @@
long start = System.currentTimeMillis();
if (LOG.isDebugEnabled())
+ {
LOG.debug("getNodes(String) >>>>>");
+ }
checkValid();
try
{
- ItemFilter filter = new NamePatternFilter(namePattern);
- ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
- for (NodeImpl item : childNodes())
- {
- if (filter.accept(item))
- list.add(item);
- }
- return new EntityCollection(list);
+ // TODO full iterator code
+ // ItemFilter filter = new NamePatternFilter(namePattern);
+ // ArrayList<NodeImpl> list = new ArrayList<NodeImpl>();
+ // for (NodeImpl item : childNodes())
+ // {
+ // if (filter.accept(item))
+ // {
+ // list.add(item);
+ // }
+ // }
+ // return new EntityCollection(list);
+
+ // lazy childs
+ return new LazyNodeIterator(childNodesData(), new ItemDataNamePatternFilter(namePattern, session));
}
finally
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("getNodes(String) <<<<< " + ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -1107,12 +1149,18 @@
try
{
- return new EntityCollection(childProperties());
+ // TODO full iterator code
+ // return new EntityCollection(childProperties());
+
+ // lazy childs
+ return new LazyPropertyIterator(childPropertiesData());
}
finally
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("getProperties() <<<<< " + ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -1130,20 +1178,26 @@
try
{
- ItemFilter filter = new NamePatternFilter(namePattern);
- ArrayList<PropertyImpl> list = new ArrayList<PropertyImpl>();
- for (PropertyImpl item : childProperties())
- {
- if (filter.accept(item))
- list.add(item);
- }
+ // TODO full iterator code
+ // ItemFilter filter = new NamePatternFilter(namePattern);
+ // ArrayList<PropertyImpl> list = new ArrayList<PropertyImpl>();
+ // for (PropertyImpl item : childProperties())
+ // {
+ // if (filter.accept(item))
+ // list.add(item);
+ // }
+ //
+ // return new EntityCollection(list);
- return new EntityCollection(list);
+ // lazy childs
+ return new LazyPropertyIterator(childPropertiesData(), new ItemDataNamePatternFilter(namePattern, session));
}
finally
{
if (LOG.isDebugEnabled())
+ {
LOG.debug("getProperties(String) <<<<< " + ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -1364,18 +1418,23 @@
public void loadData(ItemData data) throws RepositoryException, InvalidItemStateException,
ConstraintViolationException
{
- loadNodeData(data, null);
+ loadData(data, (NodeData)null);
}
- private void loadNodeData(ItemData data, NodeData parent) throws RepositoryException, InvalidItemStateException,
+ /**
+ * {@inheritDoc}
+ */
+ public void loadData(ItemData data, NodeData parent) throws RepositoryException, InvalidItemStateException,
ConstraintViolationException
{
- if (data == null)
- {
- throw new InvalidItemStateException("Data is null for " + this.getPath()
- + " Probably was deleted by another session and can not be loaded from container ");
- }
+ // TODO
+ // if (data == null)
+ // {
+ // throw new InvalidItemStateException("Data is null for " + this.getPath()
+ // + " Probably was deleted by another session and can not be loaded from container ");
+ // }
+
if (data.isNode())
{
NodeData nodeData = (NodeData)data;
@@ -2316,10 +2375,14 @@
protected void doOrderBefore(QPath srcPath, QPath destPath) throws RepositoryException
{
if (!getPrimaryNodeType().hasOrderableChildNodes())
+ {
throw new UnsupportedRepositoryOperationException("child node ordering not supported on node " + getPath());
+ }
if (srcPath.equals(destPath))
+ {
return;
+ }
// check existence
if (dataManager.getItemData(srcPath) == null)
@@ -2334,17 +2397,24 @@
}
if (!checkedOut())
+ {
throw new VersionException(" cannot change child node ordering of a checked-in node ");
+ }
if (destPath != null && srcPath.getDepth() != destPath.getDepth())
+ {
throw new ItemNotFoundException("Source and destenation is not relative paths of depth one, "
+ "i.e. is not a childs of same parent node");
+ }
- List<NodeData> siblings = dataManager.getChildNodesData(nodeData());
- Collections.sort(siblings, new NodeDataOrderComparator());
+ List<NodeData> siblings = new ArrayList<NodeData>(dataManager.getChildNodesData(nodeData()));
if (siblings.size() < 2)
+ {
throw new UnsupportedRepositoryOperationException("Nothing to order Count of child nodes " + siblings.size());
+ }
+ Collections.sort(siblings, new NodeDataOrderComparator());
+
// calculating source and destination position
int srcInd = -1, destInd = -1;
for (int i = 0; i < siblings.size(); i++)
@@ -2572,6 +2642,26 @@
}
/**
+ * Return child Properties list.
+ *
+ * @return List of child Properties
+ * @throws RepositoryException
+ * if error occurs
+ * @throws AccessDeniedException
+ * if Nodes cannot be listed due to permissions on this Node
+ */
+ private List<PropertyData> childPropertiesData() throws RepositoryException, AccessDeniedException
+ {
+
+ List<PropertyData> storedProps = new ArrayList<PropertyData>(dataManager.getChildPropertiesData(nodeData()));
+
+ // TODO we should not sort here!
+ Collections.sort(storedProps, new PropertiesDataOrderComparator<PropertyData>());
+
+ return storedProps;
+ }
+
+ /**
* Return child Nodes list.
*
* @return List of child Nodes
@@ -2580,34 +2670,41 @@
* @throws AccessDeniedException
* if Nodes cannot be listed due to permissions on this Node
*/
- private List<Object> childNodesData() throws RepositoryException, AccessDeniedException
+ private List<NodeData> childNodesData() throws RepositoryException, AccessDeniedException
{
- List<NodeData> storedNodes = dataManager.getChildNodesData(nodeData());
- Collections.sort(storedNodes, new NodeDataOrderComparator());
- List<Object> results = new ArrayList<Object>(storedNodes.size());
+ //List<NodeData> storedNodes = dataManager.getChildNodesData(nodeData());
+ List<NodeData> storedNodes = new ArrayList<NodeData>(dataManager.getChildNodesData(nodeData()));
- Iterator<NodeData> it = storedNodes.iterator();
- while (it.hasNext())
- {
- NodeData node = it.next();
+ // TODO we should not sort here!
+ Collections.sort(storedNodes, new NodeDataOrderComparator());
- if (session.getAccessManager().hasPermission(node.getACL(), new String[]{PermissionType.READ},
- session.getUserState().getIdentity()))
- {
- ItemImpl pooled = dataManager.reloadItem(node);
- if (pooled != null)
- {
- results.add(pooled);
- }
- else
- {
- results.add(node);
- }
- }
- }
+ return storedNodes;
- return results;
+ // TODO cleanup
+ // List<Object> results = new ArrayList<Object>(storedNodes.size());
+ //
+ // Iterator<NodeData> it = storedNodes.iterator();
+ // while (it.hasNext())
+ // {
+ // NodeData node = it.next();
+ //
+ // if (session.getAccessManager().hasPermission(node.getACL(), new String[]{PermissionType.READ},
+ // session.getUserState().getIdentity()))
+ // {
+ // ItemImpl pooled = dataManager.reloadItem(node);
+ // if (pooled != null)
+ // {
+ // results.add(pooled);
+ // }
+ // else
+ // {
+ // results.add(node);
+ // }
+ // }
+ // }
+ //
+ // return results;
}
private EntityCollection createMergeFailed(Map<String, String> failed, SessionChangesLog changes)
@@ -2675,17 +2772,6 @@
private int getNextChildOrderNum() throws RepositoryException
{
- // int max = -1;
- // for (NodeData sibling : siblings)
- // {
- // int cur = sibling.getOrderNumber();
- // if (cur > max)
- // max = cur;
- // }
- // return ++max;
-
- //return siblings.size();
-
return dataManager.getChildNodesCount(nodeData());
}
@@ -2771,7 +2857,6 @@
InternalQName[] mixinTypeNames = new InternalQName[0];
String identifier = IdGenerator.generate();
- //List<NodeData> siblings = dataManager.getChildNodesData(parentNode.nodeData());
int orderNum = parentNode.getNextChildOrderNum();
int index = parentNode.getNextChildIndex(name, parentNode.nodeData());
@@ -2795,7 +2880,7 @@
itemAutocreator.makeAutoCreatedItems(node.nodeData(), primaryTypeName, dataManager, session.getUserID());
for (ItemState autoCreatedState : changes.getAllStates())
{
- dataManager.update(autoCreatedState, false);
+ dataManager.update(autoCreatedState, false); // TODO creates ItemImpl (EXOJCR-362)
}
// addAutoCreatedItems(node.nodeData(), primaryTypeName);
@@ -2997,4 +3082,256 @@
return r;
}
}
+
+ private static class PropertiesDataOrderComparator<P extends PropertyData> implements Comparator<P>
+ {
+ public int compare(P p1, P p2)
+ {
+ int r = 0;
+ try
+ {
+ InternalQName qname1 = p1.getQPath().getName();
+ InternalQName qname2 = p2.getQPath().getName();
+ if (qname1.equals(Constants.JCR_PRIMARYTYPE))
+ {
+ r = Integer.MIN_VALUE;
+ }
+ else if (qname2.equals(Constants.JCR_PRIMARYTYPE))
+ {
+ r = Integer.MAX_VALUE;
+ }
+ else if (qname1.equals(Constants.JCR_MIXINTYPES))
+ {
+ r = Integer.MIN_VALUE + 1;
+ }
+ else if (qname2.equals(Constants.JCR_MIXINTYPES))
+ {
+ r = Integer.MAX_VALUE - 1;
+ }
+ else if (qname1.equals(Constants.JCR_UUID))
+ {
+ r = Integer.MIN_VALUE + 2;
+ }
+ else if (qname2.equals(Constants.JCR_UUID))
+ {
+ r = Integer.MAX_VALUE - 2;
+ }
+ else
+ {
+ r = qname1.getAsString().compareTo(qname2.getAsString());
+ }
+ }
+ catch (Exception e)
+ {
+ LOG.error("PropertiesDataOrderComparator error: " + e, e);
+ }
+ return r;
+ }
+ }
+
+ protected abstract class LazyItemsIterator implements RangeIterator
+ {
+
+ protected final ItemDataFilter filter;
+
+ protected Iterator<? extends ItemData> iter;
+
+ protected int size = -1;
+
+ protected ItemImpl next;
+
+ protected int pos = 0;
+
+ LazyItemsIterator(List<? extends ItemData> items, ItemDataFilter filter) throws RepositoryException
+ {
+ this.iter = items.iterator();
+ this.filter = filter;
+ fetchNext();
+ }
+
+ protected void fetchNext() throws RepositoryException
+ {
+ if (iter.hasNext())
+ {
+ ItemData item = iter.next();
+
+ // check read conditions
+ if (canRead(item))
+ {
+ next = (ItemImpl)session.getTransientNodesManager().readItem(item, nodeData(), true, false);
+ }
+ else
+ {
+ // try next
+ next = null;
+ fetchNext();
+ }
+ }
+ else
+ {
+ next = null;
+ }
+ }
+
+ protected boolean canRead(ItemData item)
+ {
+ // TODO check if deleted // if (session.getTransientNodesManager().isDeleted(item.getQPath()))
+ return (filter != null ? filter.accept(item) : true)
+ && session.getAccessManager().hasPermission(
+ item.isNode() ? ((NodeData)item).getACL() : nodeData().getACL(), new String[]{PermissionType.READ},
+ session.getUserState().getIdentity());
+ }
+
+ public ItemImpl nextItem()
+ {
+ if (next != null)
+ {
+ try
+ {
+ ItemImpl i = next;
+ fetchNext();
+ pos++;
+
+ // fire action post-READ
+ session.getActionHandler().postRead(i);
+ return i;
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e);
+ throw new NoSuchElementException(e.toString());
+ }
+ }
+
+ throw new NoSuchElementException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object next()
+ {
+ return nextItem();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void skip(long skipNum)
+ {
+ pos += skipNum;
+ while (skipNum-- > 1)
+ {
+ iter.next();
+ }
+
+ try
+ {
+ fetchNext();
+ }
+ catch (RepositoryException e)
+ {
+ LOG.error(e);
+ throw new NoSuchElementException(e.toString());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getSize()
+ {
+ if (size == -1)
+ {
+ // calc size
+
+ int sz = pos + (next != null ? 1 : 0);
+ if (iter.hasNext())
+ {
+ List<ItemData> itemsLeft = new ArrayList<ItemData>();
+ do
+ {
+ ItemData item = iter.next();
+ if (canRead(item))
+ {
+ itemsLeft.add(item);
+ sz++;
+ }
+ }
+ while (iter.hasNext());
+
+ iter = itemsLeft.iterator();
+ }
+ size = sz;
+ }
+
+ return size;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getPosition()
+ {
+ return pos;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove()
+ {
+ LOG.warn("Remove not supported");
+ }
+ }
+
+ protected class LazyNodeIterator extends LazyItemsIterator implements NodeIterator
+ {
+ LazyNodeIterator(List<? extends ItemData> nodes) throws RepositoryException
+ {
+ super(nodes, null);
+ }
+
+ LazyNodeIterator(List<? extends ItemData> nodes, ItemDataFilter filter) throws RepositoryException
+ {
+ super(nodes, filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Node nextNode()
+ {
+ return (Node)nextItem();
+ }
+ }
+
+ protected class LazyPropertyIterator extends LazyItemsIterator implements PropertyIterator
+ {
+ LazyPropertyIterator(List<? extends ItemData> props) throws RepositoryException
+ {
+ super(props, null);
+ }
+
+ LazyPropertyIterator(List<? extends ItemData> props, ItemDataFilter filter) throws RepositoryException
+ {
+ super(props, filter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Property nextProperty()
+ {
+ return (Property)nextItem();
+ }
+ }
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -83,14 +83,40 @@
}
/**
+ * PropertyImpl constructor.
+ *
+ * @param data
+ * ItemData object
+ * @param parent NodeData Property's parent
+ * @param session
+ * Session object
+ * @throws RepositoryException
+ * @throws ConstraintViolationException
+ */
+ PropertyImpl(ItemData data, NodeData parent, SessionImpl session) throws RepositoryException,
+ ConstraintViolationException
+ {
+ super(data, session);
+ loadData(data, parent);
+ }
+
+ /**
* {@inheritDoc}
*/
void loadData(ItemData data) throws RepositoryException, ConstraintViolationException
{
+ loadData(data, (NodeData)null);
+ }
- // TODO
- //if (!(data instanceof TransientPropertyData))
- // throw new RepositoryException("Load data: TransientPropertyData is expected, but have " + data);
+ /**
+ * {@inheritDoc}
+ */
+ void loadData(ItemData data, NodeData parent) throws RepositoryException, ConstraintViolationException
+ {
+ if (data.isNode())
+ {
+ throw new RepositoryException("Load data failed: Property expected");
+ }
this.data = data;
this.propertyData = (PropertyData)data;
@@ -99,19 +125,16 @@
this.qpath = data.getQPath();
this.location = null;
- initDefinitions(this.propertyData.isMultiValued());
+ initDefinitions(this.propertyData.isMultiValued(), parent);
}
/**
* {@inheritDoc}
*/
+ @Deprecated
void loadData(ItemData data, ItemDefinitionData itemDefinitionData) throws RepositoryException,
ConstraintViolationException
{
-
- //if (!(data instanceof TransientPropertyData))
- // throw new RepositoryException("Load data: TransientPropertyData is expected, but have " + data);
-
this.data = data;
this.propertyData = (PropertyData)data;
this.type = propertyData.getType();
@@ -343,17 +366,26 @@
}
/**
+ * @param multiple
+ * @param parent
* @throws RepositoryException
* @throws ConstraintViolationException
*/
- private void initDefinitions(boolean multiple) throws RepositoryException, ConstraintViolationException
+ private void initDefinitions(boolean multiple, NodeData parent) throws RepositoryException,
+ ConstraintViolationException
{
- NodeData parent = parentData();
InternalQName pname = getData().getQPath().getName();
+
+ if (parent == null)
+ {
+ parent = parentData();
+ }
+
PropertyDefinitionDatas definitions =
session.getWorkspace().getNodeTypesHolder().getPropertyDefinitions(pname, parent.getPrimaryTypeName(),
parent.getMixinTypeNames());
+
if (definitions == null)
{
throw new ConstraintViolationException("Definition for property " + getPath() + " not found.");
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -177,12 +177,18 @@
item = getItemData(parent, relPathEntries[i]);
if (item == null)
+ {
break;
+ }
if (item.isNode())
+ {
parent = (NodeData)item;
+ }
else if (i < relPathEntries.length - 1)
+ {
throw new IllegalPathException("Path can not contains a property as the intermediate element");
+ }
}
return item;
}
@@ -195,9 +201,13 @@
if (name.getName().equals(JCRPath.PARENT_RELPATH) && name.getNamespace().equals(Constants.NS_DEFAULT_URI))
{
if (parent.getIdentifier().equals(Constants.ROOT_UUID))
+ {
return null;
+ }
else
+ {
return getItemData(parent.getParentIdentifier());
+ }
}
ItemData data = null;
@@ -368,25 +378,27 @@
*/
protected ItemImpl readItem(ItemData itemData, boolean pool) throws RepositoryException
{
- return readItem(itemData, pool, true);
+ return readItem(itemData, null, pool, true);
}
/**
- * Read ItemImpl of given ItemData.
+ * Create or reload pooled ItemImpl with the given ItemData.
*
- * @param itemData ItemData
+ * @param itemData ItemData, data to create ItemImpl
+ * @param parent NodeData, this item parent data, can be null. Not null used for getChildXXX()
* @param pool boolean, if true will reload pooled ItemImpl
- * @param jcrAPI, boolean if true will call postRead Action and check permissions
+ * @param apiRead boolean, if true will call postRead Action and check permissions
* @return ItemImpl
* @throws RepositoryException if errro occurs
*/
- protected ItemImpl readItem(ItemData itemData, boolean pool, boolean jcrAPI) throws RepositoryException
+ protected ItemImpl readItem(ItemData itemData, NodeData parent, boolean pool, boolean apiRead)
+ throws RepositoryException
{
if (itemData != null)
{
ItemImpl item;
ItemImpl pooledItem;
- if (pool && (pooledItem = itemsPool.get(itemData)) != null)
+ if (pool && (pooledItem = itemsPool.get(itemData, parent)) != null)
{
// use pooled & reloaded
item = pooledItem;
@@ -394,10 +406,10 @@
else
{
// create new
- item = itemFactory.createItem(itemData);
+ item = itemFactory.createItem(itemData, parent);
}
- if (jcrAPI)
+ if (apiRead)
{
// TODO post read will be logically to call after the permissions check
session.getActionHandler().postRead(item);
@@ -477,12 +489,57 @@
ItemState lastState = changesLog.getItemState(identifier);
if (lastState == null || lastState.isDeleted())
+ {
return false;
+ }
return changesLog.getItemState(identifier, ItemState.ADDED) != null;
}
/**
+ * Returns true if the item with <code>identifier</code> was deleted in this session. Within a transaction,
+ * isDelete on an Item may return false (because the item has been saved) even if that Item is not in
+ * persistent storage (because the transaction has not yet been committed).
+ *
+ * @param identifier
+ * of the item
+ * @return boolean, true if the item was deleted
+ */
+ public boolean isDeleted(String identifier)
+ {
+
+ ItemState lastState = changesLog.getItemState(identifier);
+
+ if (lastState != null && lastState.isDeleted())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true if the item with <code>itemPath</code> was deleted in this session. Within a transaction,
+ * isDelete on an Item may return false (because the item has been saved) even if that Item is not in
+ * persistent storage (because the transaction has not yet been committed).
+ *
+ * @param itemPath QPath, path of the item
+ * @return boolean, true if the item was deleted
+ */
+ public boolean isDeleted(QPath itemPath)
+ {
+
+ ItemState lastState = changesLog.getItemState(itemPath);
+
+ if (lastState != null && lastState.isDeleted())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Returns true if this Item has been saved but has subsequently been modified through the current
* session and therefore the state of this item as recorded in the session differs from the state
* of this item as saved. Within a transaction, isModified on an Item may return false (because
@@ -551,12 +608,12 @@
continue;
}
- item = (PropertyImpl)readItem(state.getData(), true, false);
+ item = (PropertyImpl)readItem(state.getData(), null, true, false);
// TODO item = (PropertyImpl)itemFactory.createItem(state.getData());
}
else
{
- item = (PropertyImpl)readItem(data, true, false);
+ item = (PropertyImpl)readItem(data, null, true, false);
// TODO item = (PropertyImpl)itemFactory.createItem(data);
}
@@ -580,6 +637,7 @@
* @throws AccessDeniedException
* if it's no permissions for childs listing
*/
+ @Deprecated
public List<NodeImpl> getChildNodes(NodeData parent, boolean pool) throws RepositoryException, AccessDeniedException
{
@@ -600,9 +658,9 @@
.getIdentity()))
{
//NodeImpl item = itemFactory.createNode(data, parent.getPrimaryTypeName(), parent.getMixinTypeNames());
- NodeImpl item = (NodeImpl) readItem(data, pool, false);
+ NodeImpl item = (NodeImpl)readItem(data, parent, pool, false);
session.getActionHandler().postRead(item);
-
+
//TODO if (pool)
// item = (NodeImpl)itemsPool.get(item);
@@ -632,13 +690,16 @@
* @throws AccessDeniedException
* if it's no permissions for childs listing
*/
+ @Deprecated
public List<PropertyImpl> getChildProperties(NodeData parent, boolean pool) throws RepositoryException,
AccessDeniedException
{
long start = System.currentTimeMillis();
if (log.isDebugEnabled())
+ {
log.debug("getChildProperties(" + parent.getQPath().getAsString() + ") >>>>>");
+ }
try
{
@@ -653,9 +714,9 @@
{
// TODO if (pool)
// item = itemsPool.get(item);
- ItemImpl item = readItem(data, pool, false);
+ ItemImpl item = readItem(data, parent, pool, false);
session.getActionHandler().postRead(item);
-
+
props.add((PropertyImpl)item);
}
}
@@ -676,7 +737,9 @@
{
long start = System.currentTimeMillis();
if (log.isDebugEnabled())
+ {
log.debug("getChildNodesData(" + parent.getQPath().getAsString() + ") >>>>>");
+ }
try
{
@@ -685,8 +748,10 @@
finally
{
if (log.isDebugEnabled())
+ {
log.debug("getChildNodesData(" + parent.getQPath().getAsString() + ") <<<<< "
+ ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -725,8 +790,10 @@
finally
{
if (log.isDebugEnabled())
+ {
log.debug("getChildPropertiesData(" + parent.getQPath().getAsString() + ") <<<<< "
+ ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -749,8 +816,10 @@
finally
{
if (log.isDebugEnabled())
+ {
log.debug("listChildPropertiesData(" + parent.getQPath().getAsString() + ") <<<<< "
+ ((System.currentTimeMillis() - start) / 1000d) + "sec");
+ }
}
}
@@ -791,17 +860,23 @@
}
if (item != null && item.isNode())
+ {
// node ACL
return ((NodeData)item).getACL();
+ }
else
+ {
// item not found or it's a property - return parent ACL
return parent.getACL();
+ }
}
finally
{
if (log.isDebugEnabled())
+ {
log.debug("getACL(" + path.getAsString() + ") <<<<< " + ((System.currentTimeMillis() - start) / 1000d)
+ "sec");
+ }
}
}
@@ -1137,7 +1212,7 @@
changesLog.add(itemState);
- return readItem(itemState.getData(), pool, false);
+ return readItem(itemState.getData(), null, pool, false);
}
/**
@@ -1422,10 +1497,9 @@
* @throws RepositoryException
* if errors is occurs
*/
- public NodeImpl wrapNodeData(NodeData data, NodeData parent)
- throws RepositoryException
+ public NodeImpl wrapNodeData(NodeData data, NodeData parent) throws RepositoryException
{
-
+
NodeImpl node = itemFactory.createNode(data, parent);
//NodeImpl node = (NodeImpl)itemsPool.get(data);
session.getActionHandler().postRead(node);
@@ -1500,20 +1574,26 @@
.getQPath().getEntries().length - 1]);
if (persisted != null)
+ {
// reload item data
removed.loadData(persisted);
+ }
} // else it's transient item
removedIter.remove();
}
if (exceptions.length() > 0 && log.isDebugEnabled())
+ {
log.warn(exceptions);
+ }
}
- /*
- * (non-Javadoc)
+ /**
* @see javax.jcr.Item#refresh(boolean)
+ * @param item ItemData
+ * @throws InvalidItemStateException
+ * @throws RepositoryException
*/
void refresh(ItemData item) throws InvalidItemStateException, RepositoryException
{
@@ -1618,7 +1698,7 @@
}
else
{
- return new ArrayList<ItemData>(dataManager.getChildNodesData((NodeData)rootData));
+ return dataManager.getChildNodesData((NodeData)rootData);
}
}
@@ -1660,7 +1740,7 @@
}
else
{
- return new ArrayList<ItemData>(dataManager.getChildPropertiesData((NodeData)rootData));
+ return dataManager.getChildPropertiesData((NodeData)rootData);
}
}
@@ -1726,7 +1806,7 @@
}
else
{
- return new ArrayList<ItemData>(getStoredDescendants(rootData, dataManager, action));
+ return getStoredDescendants(rootData, dataManager, action);
}
}
@@ -1859,17 +1939,17 @@
private WeakHashMap<String, ItemImpl> items;
- private WeakHashMap<String, ItemData> datas;
+ //private WeakHashMap<String, ItemData> datas;
ItemReferencePool()
{
items = new WeakHashMap<String, ItemImpl>();
- datas = new WeakHashMap<String, ItemData>();
+ //datas = new WeakHashMap<String, ItemData>();
}
ItemImpl remove(String identifier)
{
- datas.remove(identifier);
+ //datas.remove(identifier);
return items.remove(identifier);
}
@@ -1906,7 +1986,7 @@
ItemImpl item = items.get(identifier);
if (item == null)
{
- datas.remove(identifier);
+ //datas.remove(identifier);
items.put(identifier, newItem);
return newItem;
}
@@ -1926,20 +2006,36 @@
*/
ItemImpl get(final ItemData newData) throws RepositoryException
{
+ return get(newData, null);
+ }
+
+ /**
+ * Get ItemImpl from the pool using given data.
+ *
+ * @param newData ItemData
+ * @param parent nodeData
+ * @return ItemImpl item
+ * @throws RepositoryException
+ */
+ ItemImpl get(final ItemData newData, final NodeData parent) throws RepositoryException
+ {
final String identifier = newData.getIdentifier();
ItemImpl item = items.get(identifier);
if (item != null)
{
- item.loadData(newData);
+ item.loadData(newData, parent);
}
else
{
-// ItemData preloaded = datas.remove(identifier);
-// item =
-// itemFactory.createItem(preloaded != null
-// && preloaded.getPersistedVersion() > newData.getPersistedVersion() ? preloaded : newData);
- datas.remove(identifier);
- item = itemFactory.createItem(newData);
+ // ItemData preloaded = datas.remove(identifier);
+ // item =
+ // itemFactory.createItem(preloaded != null
+ // && preloaded.getPersistedVersion() > newData.getPersistedVersion() ? preloaded : newData);
+ //datas.remove(identifier);
+
+ // TODO if (changesLog.get) check if DELETED!!
+
+ item = itemFactory.createItem(newData, parent);
items.put(item.getInternalIdentifier(), item);
}
return item;
@@ -1952,6 +2048,7 @@
* item identifier
* @return ItemImpl object from pool
*/
+ @Deprecated
ItemImpl getItem(String identifier)
{
return items.get(identifier);
@@ -1964,9 +2061,10 @@
* item identifier
* @return ItemData object from pool
*/
+ @Deprecated
ItemData getData(String identifier)
{
- return datas.get(identifier);
+ return null; //datas.get(identifier);
}
/**
@@ -1990,10 +2088,10 @@
item.loadData(newItemData);
return item;
}
- else
- {
- datas.put(identifier, newItemData);
- }
+ // else
+ // {
+ // datas.put(identifier, newItemData);
+ // }
return null;
}
@@ -2106,11 +2204,28 @@
{
if (data.isNode())
+ {
return createNode((NodeData)data);
+ }
else
+ {
return createProperty(data);
+ }
}
+ private ItemImpl createItem(ItemData data, NodeData parent) throws RepositoryException
+ {
+
+ if (data.isNode())
+ {
+ return createNode((NodeData)data, parent);
+ }
+ else
+ {
+ return createProperty(data, parent);
+ }
+ }
+
private NodeImpl createNode(NodeData data) throws RepositoryException
{
NodeImpl node = new NodeImpl(data, session);
@@ -2146,6 +2261,10 @@
return new PropertyImpl(data, session);
}
+ private PropertyImpl createProperty(ItemData data, NodeData parent) throws RepositoryException
+ {
+ return new PropertyImpl(data, parent, session);
+ }
}
/**
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionImpl.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -609,9 +609,7 @@
if (uri != null)
return uri;
}
- // uri = ;
- // if (namespaces.values().contains(uri))
- // return null;
+
return workspace.getNamespaceRegistry().getURI(prefix);
}
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataFilter.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataFilter.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataFilter.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.itemfilters;
+
+import org.exoplatform.services.jcr.datamodel.ItemData;
+
+public interface ItemDataFilter
+{
+
+ /**
+ * Returns <code>true</code> if the specified element is to be included in the set of child
+ * elements returbned by
+ *
+ * @param item ItemData,
+ * The item to be tested for inclusion in the returned set.
+ * @return a <code>boolean</code>.
+ */
+ public boolean accept(ItemData item);
+}
Property changes on: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataNamePatternFilter.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataNamePatternFilter.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataNamePatternFilter.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.itemfilters;
+
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.impl.core.JCRName;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
+ * @version $Id$
+ */
+
+public class ItemDataNamePatternFilter implements ItemDataFilter
+{
+
+ /**
+ * Logger.
+ */
+ protected static final Log LOG = ExoLogger.getLogger("jcr.ItemDataNamePatternFilter");
+
+ private final SessionImpl session;
+
+ private final List<String> expressions = new ArrayList<String>();
+
+ public ItemDataNamePatternFilter(String namePattern, SessionImpl session) throws NamespaceException,
+ RepositoryException
+ {
+ this.session = session;
+
+ StringTokenizer parser = new StringTokenizer(namePattern, "|");
+ while (parser.hasMoreTokens())
+ {
+ String token = parser.nextToken();
+
+ // String expr;
+ // int prefixIndex = token.indexOf(":");
+ // if (prefixIndex > 0)
+ // {
+ // expr =
+ // "[" + session.getNamespaceURI(token.substring(0, prefixIndex)) + "]"
+ // + (prefixIndex < token.length() - 1 ? token.substring(prefixIndex + 1) : "");
+ // }
+ // else
+ // {
+ // expr = token;
+ // }
+
+ expressions.add(token.trim());
+ }
+ }
+
+ public boolean accept(ItemData item)
+ {
+ try
+ {
+ JCRName name = session.getLocationFactory().createJCRName(item.getQPath().getName());
+ for (String expr : expressions)
+ {
+ if (estimate(name.getAsString(), expr))
+ {
+ return true;
+ }
+ }
+ }
+ catch (RepositoryException e)
+ {
+ // if error - just log and don't accept it
+ LOG.error("Cannot parse JCR name for " + item.getQPath().getAsString(), e);
+ }
+
+ return false;
+ }
+
+ private boolean estimate(String name, String expr)
+ {
+ if (expr.indexOf("*") == -1)
+ {
+ return name.equals(expr);
+ }
+
+ String regexp = expr.replaceAll("\\*", ".*");
+ return Pattern.compile(regexp).matcher(name).matches();
+ }
+
+}
Property changes on: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/itemfilters/ItemDataNamePatternFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -124,7 +124,7 @@
}
}
}
- if (events.size() > 0)
+ if (events.getSize() > 0)
{
// TCK says, no events - no onEvent() action
listener.onEvent(events);
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -84,11 +84,11 @@
* {@inheritDoc}
*/
@Override
- public void loadData(ItemData vhData) throws RepositoryException, InvalidItemStateException,
+ public void loadData(ItemData vhData, NodeData parent) throws RepositoryException, InvalidItemStateException,
ConstraintViolationException
{
super.loadData(new VersionHistoryDataHelper((NodeData)vhData, session.getTransientNodesManager()
- .getTransactManager(), session.getWorkspace().getNodeTypesHolder()));
+ .getTransactManager(), session.getWorkspace().getNodeTypesHolder()), parent);
}
/**
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/DefaultItemDataCopyVisitor.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/DefaultItemDataCopyVisitor.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/DefaultItemDataCopyVisitor.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -149,7 +149,7 @@
{
ancestorToSave = curParent().getQPath();
}
-
+
NodeData parent = curParent();
QPath qpath = calculateNewNodePath(node, level);
// Calc order number if parent supports orderable nodes...
@@ -246,6 +246,11 @@
return null;
}
+ protected int calculateNewNodeOrderNumber() throws RepositoryException
+ {
+ return dataManager.getChildNodesCount(curParent());
+ }
+
protected QPath calculateNewNodePath(NodeData node, int level) throws RepositoryException
{
NodeData parent = curParent();
@@ -273,16 +278,4 @@
}
return QPath.makeChildPath(parent.getQPath(), qname, newIndex);
}
-
- protected int calculateNewNodeOrderNumber() throws RepositoryException
- {
- NodeData parent = curParent();
- List<NodeData> existedChilds = dataManager.getChildNodesData(parent);
- int orderNum = 0;
- if (existedChilds.size() > 0) {
- orderNum = existedChilds.get(existedChilds.size() - 1).getOrderNumber() + 1;
- }
-
- return orderNum;
- }
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataCloneVisitor.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataCloneVisitor.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/ItemDataCloneVisitor.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -104,20 +104,20 @@
{
Collections.reverse(itemDeletedExistingStates);
}
-
+
return itemDeletedExistingStates;
}
- @Override
protected int calculateNewNodeOrderNumber() throws RepositoryException
{
NodeData parent = curParent();
List<NodeData> existedChilds = getMargedChildNodesData(parent);
int orderNum = 0;
- if (existedChilds.size() > 0) {
+ if (existedChilds.size() > 0)
+ {
orderNum = existedChilds.get(existedChilds.size() - 1).getOrderNumber() + 1;
}
-
+
return orderNum;
}
@@ -147,7 +147,7 @@
qname = node.getQPath().getName();
newIndex = node.getQPath().getIndex();
}
-
+
return QPath.makeChildPath(parent.getQPath(), qname, newIndex);
}
@@ -158,7 +158,7 @@
boolean isMixReferenceable =
ntManager.isNodeType(Constants.MIX_REFERENCEABLE, node.getPrimaryTypeName(), node.getMixinTypeNames());
deletedExistingPropery = false;
-
+
if (isMixReferenceable)
{
String identifier = node.getIdentifier();
@@ -226,7 +226,7 @@
}
}
}
-
+
super.entering(property, level);
};
@@ -250,7 +250,7 @@
break;
}
}
-
+
return retval;
}
@@ -259,14 +259,14 @@
if (itemInItemStateList(itemDeletedExistingStates, item.getIdentifier(), ItemState.DELETED))
return true;
ItemState changesItemState = null;
-
+
if (changes != null)
{
changesItemState = changes.getItemState(item.getIdentifier());
if (changesItemState != null && changesItemState.isDeleted())
return true;
}
-
+
return false;
}
@@ -277,9 +277,11 @@
for (NodeData nodeData : existedChilds)
{
if (!isItemDeleted(nodeData))
+ {
result.add(nodeData);
+ }
}
-
+
return result;
}
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/EntityCollection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/EntityCollection.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/EntityCollection.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -80,6 +80,7 @@
this.pos = 0;
}
+ @Deprecated
public void reverse()
{
Collections.reverse(list);
@@ -236,6 +237,7 @@
iter = list.iterator();
}
+ @Deprecated
public void remove(Object obj)
{
pos = 0;
@@ -243,11 +245,17 @@
iter = list.iterator();
}
+ @Deprecated
public long size()
{
return getSize();
}
+ /**
+ * For TESTs only.
+ *
+ * @return List backed the iterator
+ */
public List getList()
{
return list;
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/NodeIteratorOnDemand.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/NodeIteratorOnDemand.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/NodeIteratorOnDemand.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -16,14 +16,12 @@
*/
package org.exoplatform.services.jcr.impl.util;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -39,18 +37,21 @@
* @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy Bazko</a>
* @version $Id$
*/
+@Deprecated
public class NodeIteratorOnDemand extends EntityCollection
{
protected static Log log = ExoLogger.getLogger("jcr.NodeIteratorOnDemand");
- private final Iterator iter;
+ private final Iterator<Object> iter;
- private final List list;
+ private final List<Object> list;
private final SessionDataManager dataManager;
private final NodeData parent;
+ private NodeImpl next;
+
private int pos;
/**
@@ -66,12 +67,10 @@
* @param dataManager
* session data manager
*/
- public NodeIteratorOnDemand(List list, SessionDataManager dataManager, NodeData parent)
+ @Deprecated
+ public NodeIteratorOnDemand(List<Object> list, SessionDataManager dataManager, NodeData parent)
{
- if (list == null)
- this.list = new ArrayList();
- else
- this.list = list;
+ this.list = list;
this.dataManager = dataManager;
this.parent = parent;
@@ -170,4 +169,5 @@
}
}
+
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/exporting/BaseXmlExporter.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/exporting/BaseXmlExporter.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/exporting/BaseXmlExporter.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -31,12 +31,12 @@
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.NodeDataOrderComparator;
import org.exoplatform.services.jcr.impl.dataflow.PropertyDataOrderComparator;
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
import org.exoplatform.services.jcr.impl.util.ISO9075;
import org.xml.sax.SAXException;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -162,9 +162,10 @@
{
currentLevel++;
- List<PropertyData> properies = dataManager.getChildPropertiesData(node);
+ List<PropertyData> properies = new ArrayList<PropertyData>(dataManager.getChildPropertiesData(node));
// Sorting properties
Collections.sort(properies, new PropertyDataOrderComparator());
+
for (PropertyData data : properies)
{
InternalQName propName = data.getQPath().getName();
@@ -180,7 +181,7 @@
}
if (!isNoRecurse() && (currentLevel > 0))
{
- List<NodeData> nodes = dataManager.getChildNodesData(node);
+ List<NodeData> nodes = new ArrayList<NodeData>(dataManager.getChildNodesData(node));
// Sorting nodes
Collections.sort(nodes, new NodeDataOrderComparator());
for (NodeData data : nodes)
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/TestJira282.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/TestJira282.java 2010-01-05 17:43:15 UTC (rev 1301)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/TestJira282.java 2010-01-05 17:49:40 UTC (rev 1302)
@@ -33,6 +33,7 @@
import java.util.Set;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -234,11 +235,9 @@
try
{
NodeImpl node = (NodeImpl)agentSession.getItem(validName);
- List<NodeImpl> list = node.childNodes();
- // log.info("Node:" + node.getPath() + " child count" + list.size());
- for (NodeImpl nodeImpl : list)
+ for (NodeIterator iter = node.getNodes(); iter.hasNext();)
{
- String name = nodeImpl.getPath();
+ String name = iter.nextNode().getPath();
}
}
catch (PathNotFoundException e)
16 years, 4 months
exo-jcr SVN: r1301 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation: db and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2010-01-05 12:43:15 -0500 (Tue, 05 Jan 2010)
New Revision: 1301
Removed:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnectionIJ.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainerIJ.java
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-302: code cleanup
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -82,7 +82,10 @@
*/
protected String FIND_NODE_MAIN_PROPERTIES_BY_PARENTID_CQ;
- protected String FIND_REFERENCE_PROPERTIES;
+ /**
+ * FIND_REFERENCE_PROPERTIES_CQ.
+ */
+ protected String FIND_REFERENCE_PROPERTIES_CQ;
/**
* FIND_ITEM_QPATH_BY_ID_CQ.
@@ -125,13 +128,13 @@
* @param dbConnection
* JDBC connection
* @param containerName
- * Workspace conatiner name
+ * Workspace container name
* @param valueStorageProvider
* External Value Storage provider
* @param maxBufferSize
- * maximum buffer size (config)
+ * maximum buffer size (configuration)
* @param swapDirectory
- * swap directory (config)
+ * swap directory (configuration)
* @param swapCleaner
* swap cleaner (FileCleaner)
* @throws SQLException
@@ -203,7 +206,6 @@
checkIfOpened();
try
{
-
ResultSet resultSet = findChildPropertiesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
List<PropertyData> children = new ArrayList<PropertyData>();
if (resultSet.next())
@@ -211,9 +213,7 @@
while (!resultSet.isAfterLast())
children.add(loadPropertyRecord(resultSet, parent.getQPath()));
}
-
return children;
-
}
catch (SQLException e)
{
@@ -234,15 +234,6 @@
try
{
ResultSet refProps = findReferencePropertiesCQ(getInternalId(nodeIdentifier));
- // List<PropertyData> references = new ArrayList<PropertyData>();
- //
- //
- // while (refProps.next())
- // {
- // while (!refProps.isAfterLast())
- // references.add(loadPropertyRecord(refProps, null));
- // }
- // return references;
return loadReferences(refProps);
}
catch (SQLException e)
@@ -255,14 +246,21 @@
}
}
+ /**
+ * Load Property references
+ *
+ * @param resultSet
+ * @return
+ * @throws RepositoryException
+ * @throws SQLException
+ * @throws IOException
+ */
private List<PropertyData> loadReferences(ResultSet resultSet) throws RepositoryException, SQLException, IOException
{
-
List<PropertyData> resultProps = new ArrayList<PropertyData>();
- // id and how many copies in result
+ // Property Id and amount of copies in result
Map<String, Integer> dublicatedProps = new HashMap<String, Integer>();
-
Map<String, PersistedPropertyData> propertyBuffer = new HashMap<String, PersistedPropertyData>();
Map<String, List<ValueData>> valuesBuffer = new HashMap<String, List<ValueData>>();
@@ -313,7 +311,6 @@
.getBinaryStream(COLUMN_VDATA)) : readValueData(identifier, valueOrderNum, storageId);
values.add(vdata);
- //TODO do we need reset values list into buffer?
valuesBuffer.put(identifier, values);
}
}
@@ -337,10 +334,8 @@
resultProps.add(new PersistedPropertyData(prop.getIdentifier(), prop.getQPath(), prop
.getParentIdentifier(), prop.getPersistedVersion(), prop.getType(), prop.isMultiValued(), newValues));
}
-
values.clear();
}
-
}
catch (IllegalNameException e)
{
@@ -348,7 +343,6 @@
}
finally
{
-
// clean buffers
propertyBuffer.clear();
valuesBuffer.clear();
@@ -356,9 +350,17 @@
}
return resultProps;
-
}
+ /**
+ * Read ACL Permissions from properties set.
+ *
+ * @param cid node id (used only for error messages)
+ * @param properties - Property name and property values
+ * @return list ACL
+ * @throws SQLException
+ * @throws IllegalACLException
+ */
protected List<AccessControlEntry> readACLPermisions(String cid, Map<String, List<byte[]>> properties)
throws SQLException, IllegalACLException
{
@@ -379,6 +381,14 @@
throw new IllegalACLException("Property exo:permissions is not found for node with id: " + getIdentifier(cid));
}
+ /**
+ * Read ACL owner.
+ *
+ * @param cid - node id (used only in exception message)
+ * @param properties - Proeprty name and property values
+ * @return ACL owner
+ * @throws IllegalACLException
+ */
protected String readACLOwner(String cid, Map<String, List<byte[]>> properties) throws IllegalACLException
{
List<byte[]> ownerValues = properties.get(Constants.EXO_OWNER.getAsString());
@@ -386,7 +396,6 @@
return new String(ownerValues.get(0));
else
throw new IllegalACLException("Property exo:owner is not found for node with id: " + getIdentifier(cid));
-
}
/**
@@ -431,7 +440,7 @@
}
/**
- * Create a new node from the given parameter
+ * Create a new node from the given parameter.
*/
private PersistedNodeData loadNodeRecord(QPath parentPath, String cname, String cid, String cpid, int cindex,
int cversion, int cnordernumb, Map<String, List<byte[]>> properties, AccessControlList parentACL)
@@ -441,7 +450,6 @@
{
InternalQName qname = InternalQName.parse(cname);
- // TODO can't avoid QPath traverse
QPath qpath;
String parentCid;
if (parentPath != null)
@@ -598,8 +606,6 @@
String cpid = resultSet.getString(COLUMN_PARENTID);
// if parent ID is empty string - it's a root node
- // cpid = cpid.equals(Constants.ROOT_PARENT_UUID) ? null : cpid;
-
try
{
int cptype = resultSet.getInt(COLUMN_PTYPE);
Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnectionIJ.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnectionIJ.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnectionIJ.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2003-2009 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation;
-
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date:
- *
- * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: CQJDBCStorageConnectionIJ.java 111 2008-11-11 11:11:11Z serg $
- */
-abstract class CQJDBCStorageConnectionIJ extends CQJDBCStorageConnection
-{
-
- /**
- * JDBCStorageConnection constructor.
- *
- * @param dbConnection
- * JDBC connection
- * @param containerName
- * Workspace conatiner name
- * @param valueStorageProvider
- * External Value Storage provider
- * @param maxBufferSize
- * maximum buffer size (config)
- * @param swapDirectory
- * swap directory (config)
- * @param swapCleaner
- * swap cleaner (FileCleaner)
- * @throws SQLException
- * database error
- */
- protected CQJDBCStorageConnectionIJ(Connection dbConnection, boolean readOnly, String containerName,
- ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
- throws SQLException
- {
- super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
-
- }
-
-}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainer.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -236,7 +236,7 @@
}
/**
- * Prepare sefault connection factory.
+ * Prepare default connection factory.
*
* @return GenericConnectionFactory
* @throws NamingException
Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainerIJ.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainerIJ.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCWorkspaceDataContainerIJ.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2003-2009 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation;
-
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
-import org.exoplatform.services.naming.InitialContextInitializer;
-
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-import javax.naming.NamingException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date:
- *
- * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: CQJDBWorkspaceDataContainerIJ.java 111 2008-11-11 11:11:11Z serg $
- */
-public class CQJDBCWorkspaceDataContainerIJ extends CQJDBCWorkspaceDataContainer
-{
- /**
- * Constructor with value storage plugins.
- *
- * @param wsConfig
- * Workspace configuration
- * @param valueStrorageProvider
- * External Value Stprages provider
- * @throws RepositoryConfigurationException
- * if Repository configuration is wrong
- * @throws NamingException
- * if JNDI exception (on DataSource lookup)
- */
- public CQJDBCWorkspaceDataContainerIJ(WorkspaceEntry wsConfig, RepositoryEntry repConfig,
- InitialContextInitializer contextInit, ValueStoragePluginProvider valueStorageProvider)
- throws RepositoryConfigurationException, NamingException, RepositoryException, IOException
- {
- super(wsConfig, repConfig, contextInit, valueStorageProvider);
- }
-}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -189,7 +189,7 @@
"select P.ID, P.PARENT_ID, P.VERSION, P.P_TYPE, P.P_MULTIVALUED, P.NAME" + " from JCR_MREF R, JCR_MITEM P"
+ " where R.NODE_ID=? and P.ID=R.PROPERTY_ID and P.I_CLASS=2";
- FIND_REFERENCE_PROPERTIES =
+ FIND_REFERENCE_PROPERTIES_CQ =
"select P.ID, P.PARENT_ID, P.VERSION, P.P_TYPE, P.P_MULTIVALUED, P.NAME, V.ORDER_NUM, V.DATA, V.STORAGE_DESC"
+ " from JCR_MREF R, JCR_MITEM P, JCR_MVALUE V"
+ " where R.NODE_ID=? and P.ID=R.PROPERTY_ID and P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by P.ID, V.ORDER_NUM";
@@ -621,6 +621,9 @@
return findValuesStorageDescriptorsByPropertyId.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findChildPropertiesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
@@ -633,6 +636,9 @@
return findPropertiesByParentIdCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findNodeMainPropertiesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
@@ -646,6 +652,9 @@
return findNodeMainPropertiesByParentIdentifierCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findItemQPathByIdentifierCQ(String identifier) throws SQLException
{
@@ -665,7 +674,7 @@
protected ResultSet findReferencePropertiesCQ(String nodeIdentifier) throws SQLException
{
if (findReferencePropertiesCQ == null)
- findReferencePropertiesCQ = dbConnection.prepareStatement(FIND_REFERENCE_PROPERTIES);
+ findReferencePropertiesCQ = dbConnection.prepareStatement(FIND_REFERENCE_PROPERTIES_CQ);
else
findReferencePropertiesCQ.clearParameters();
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2010-01-05 17:23:13 UTC (rev 1300)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2010-01-05 17:43:15 UTC (rev 1301)
@@ -195,7 +195,7 @@
"select P.ID, P.PARENT_ID, P.VERSION, P.P_TYPE, P.P_MULTIVALUED, P.NAME" + " from JCR_SREF R, JCR_SITEM P"
+ " where R.NODE_ID=? and P.CONTAINER_NAME=? and P.ID=R.PROPERTY_ID and P.I_CLASS=2";
- FIND_REFERENCE_PROPERTIES =
+ FIND_REFERENCE_PROPERTIES_CQ =
"select P.ID, P.PARENT_ID, P.VERSION, P.P_TYPE, P.P_MULTIVALUED, P.NAME, V.ORDER_NUM, V.DATA, V.STORAGE_DESC"
+ " from JCR_SREF R, JCR_SITEM P, JCR_SVALUE V"
+ " where R.NODE_ID=? and P.CONTAINER_NAME=? and P.ID=R.PROPERTY_ID and P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by P.ID, V.ORDER_NUM";
@@ -621,6 +621,9 @@
return renameNode.executeUpdate();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findChildNodesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
@@ -635,6 +638,9 @@
return findNodesByParentIdCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findChildPropertiesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
@@ -649,6 +655,9 @@
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findNodeMainPropertiesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
@@ -663,6 +672,9 @@
return findNodeMainPropertiesByParentIdentifierCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findItemQPathByIdentifierCQ(String identifier) throws SQLException
{
@@ -675,11 +687,14 @@
return findItemQPathByIdentifierCQ.executeQuery();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected ResultSet findReferencePropertiesCQ(String nodeIdentifier) throws SQLException
{
if (findReferencePropertiesCQ == null)
- findReferencePropertiesCQ = dbConnection.prepareStatement(FIND_REFERENCE_PROPERTIES);
+ findReferencePropertiesCQ = dbConnection.prepareStatement(FIND_REFERENCE_PROPERTIES_CQ);
else
findReferencePropertiesCQ.clearParameters();
16 years, 4 months
exo-jcr SVN: r1300 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test: java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-05 12:23:13 -0500 (Tue, 05 Jan 2010)
New Revision: 1300
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
Log:
EXOJCR-333 : The test TestExoEvictionActionPolicy was added.
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java 2010-01-05 17:23:13 UTC (rev 1300)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+
+import org.exoplatform.services.cache.CacheListenerContext;
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeEvicted;
+import org.jboss.cache.notifications.event.NodeEvent;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+@CacheListener
+public class TestExoEvictionActionPolicy
+ extends JcrImplBaseTest
+{
+ protected Cache<Serializable, Object> cache;
+
+ protected Fqn<String> itemsRoot;
+
+ protected Fqn<String> childNodesList;
+
+ protected Fqn<String> childPropsList;
+
+ protected String jbcConfig;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ initJBCConfig();
+
+ cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig, false);
+
+ cache.create();
+ cache.start();
+
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ this.itemsRoot = Fqn.fromElements(JBossCacheWorkspaceStorageCache.ITEMS);
+ cacheRoot.addChild(this.itemsRoot).setResident(true);
+
+ this.childNodesList = Fqn.fromElements(JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST);
+ cacheRoot.addChild(this.childNodesList).setResident(true);
+
+ this.childPropsList = Fqn.fromElements(JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST);
+ cacheRoot.addChild(this.childPropsList).setResident(true);
+ }
+
+ protected void initJBCConfig()
+ {
+ jbcConfig = "src/test/resources/conf/standalone/test-jbosscache-exo-config.xml";
+ }
+
+ public void testEviction() throws Exception
+ {
+
+ String evictionNodeId = IdGenerator.generate();
+
+ TransientNodeData evictionNodeData = new TransientNodeData(QPath.parse("[]:1[]node:1"), evictionNodeId, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ IdGenerator.generate(), new AccessControlList());
+
+ String evictionPropId = IdGenerator.generate();
+
+ TransientPropertyData evictionPropData = new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, InternalQName.parse("[]prop1")), evictionPropId, 1, 1, evictionNodeId, false);
+ String propValue1 = "Property value #1";
+ evictionPropData.setValue(new TransientValueData(propValue1));
+
+ // add nodes who will be eviction
+ // put NodeData
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evictionNodeData);
+
+ // put PropertyData
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evictionPropData);
+
+ // put to CHILD_NODES_LIST
+ cache.put(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), evictionNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ // put to CHILD_PROPS_LIST
+ cache.put(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), evictionPropData.getIdentifier()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+
+ // check for exists
+ assertEquals( 2, cache.getChildrenNames(itemsRoot).size());
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier())));
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier())));
+
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), evictionNodeData.getIdentifier())));
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), evictionPropData.getIdentifier())));
+
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier())).size());
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier())).size());
+
+
+ Thread.sleep(10 * 1000);
+
+ cache.addCacheListener(this);
+
+ for (int i = 0 ; i< 50; i++)
+ {
+ TransientNodeData evicNodeData = new TransientNodeData(QPath.parse("[]:1[]node" + i + ":1"), IdGenerator.generate(), 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList());
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evicNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evicNodeData);
+ }
+
+ Thread.sleep(15 * 1000);
+
+ // check
+ assertNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier())));
+ assertNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier())));
+
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier())));
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier())));
+ }
+
+ @NodeEvicted
+ public void createdNodeEvent(NodeEvent ne)
+ {
+ System.out.println("Node evicred: " + ne.getFqn());
+ }
+
+
+ public void testEvictionRecurcive() throws Exception
+ {
+ String parentId = IdGenerator.generate();
+
+ // put to CHILD_PROPS_LIST
+ cache.put(Fqn.fromRelativeElements(childPropsList, parentId, IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childPropsList, parentId, IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childPropsList, parentId)).size());
+
+ cache.evict(Fqn.fromRelativeElements(childPropsList, parentId), true);
+
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, parentId)));
+ }
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml 2010-01-05 17:23:13 UTC (rev 1300)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1">
+
+ <locking useLockStriping="false" concurrencyLevel="50000" lockParentForChildInsertRemove="false" lockAcquisitionTimeout="3600000"/>
+
+ <!-- Configure the TransactionManager -->
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup" />
+
+ <!-- Enable batching -->
+ <invocationBatching enabled="true" />
+
+ <!-- Eviction configuration -->
+ <eviction wakeUpInterval="3000">
+ <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm">
+ <property name="maxNodes" value="50" />
+ <property name="timeToLiveSeconds" value="20" />
+ </default>
+ <region name="/" algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ExoEvictionActionPolicy" eventQueueSize="1000000">
+ <property name="maxNodes" value="50" />
+ <property name="timeToLiveSeconds" value="20" />
+ </region>
+ </eviction>
+
+</jbosscache>
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
___________________________________________________________________
Name: svn:eol-style
+ native
16 years, 4 months
exo-jcr SVN: r1299 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-05 12:21:28 -0500 (Tue, 05 Jan 2010)
New Revision: 1299
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
Log:
EXOJCR-333 : The ExoEvictionActionPolicy was changed.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 16:50:17 UTC (rev 1298)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 17:21:28 UTC (rev 1299)
@@ -45,22 +45,22 @@
if (fqn.size() == 3 && (JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST.equals(fqn.get(0)) || JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST.equals(fqn.get(0))))
{
- return eviction(fqn.getParent());
+ return eviction(fqn.getParent(), true);
}
else
{
- return eviction(fqn);
+ return eviction(fqn, false);
}
}
- private boolean eviction(Fqn fqn)
+ private boolean eviction(Fqn fqn, boolean recurcive)
{
try
{
if (LOG.isDebugEnabled())
LOG.debug("Evicting Fqn " + fqn);
- cache.evict(fqn);
+ cache.evict(fqn, recurcive);
return true;
}
catch (Exception e)
16 years, 4 months
exo-jcr SVN: r1298 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-01-05 11:50:17 -0500 (Tue, 05 Jan 2010)
New Revision: 1298
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
Log:
EXOJCR-340: Added fulltext search test.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java 2010-01-05 15:54:13 UTC (rev 1297)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java 2010-01-05 16:50:17 UTC (rev 1298)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.cluster.functional;
import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.common.http.client.ModuleException;
import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
@@ -26,9 +27,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.xml.namespace.QName;
import javax.xml.stream.FactoryConfigurationError;
@@ -38,7 +42,7 @@
import javax.xml.stream.events.StartElement;
/**
- * Class contains set of query tests for clustered environment
+ * Class contains set of query tests for cluster environment
*
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: WebdavQueryTest.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
@@ -47,38 +51,164 @@
public class WebdavQueryTest extends BaseClusteringFunctionalTest
{
- public void testSimpleGetAllSql() throws Exception
+ /**
+ * Fulltext queries
+ */
+ public void testFullTextSearch() throws Exception
{
- String testLocalRootName = "node";
JCRWebdavConnection conn = getConnection();
+ // Nodes with some text, with unique words in each one.
+ Map<String, String> expected = new HashMap<String, String>();
+ expected
+ .put(
+ "JCR_Overview",
+ "A JCR is a type of Object Database tailored to the storage, searching, and retrieval of hierarchical data. The JCR API grew o"
+ + "ut of the needs of content management systems, which require storage of documents and other binary objects with associated me"
+ + "tadata; however, the API is applicable to many additional types of application. In addition to object storage, the JCR provid"
+ + "es: APIs for versioning of data; transactions; observation of changes in data; and import or export of data to XML in a standard way.");
+ expected
+ .put(
+ "JCR_Structure",
+ "The data in a JCR consists of a tree of Nodes with associated Properties. Data is stored in the Properties, which may hold simple "
+ + "values such as numbers and strings or binary data of arbitrary length. Nodes may optionally have one or more types associated with"
+ + " them which dictate the kinds of properties, number and type of child nodes, and certain behavioral characteristics of the nodes. API");
+
+ expected
+ .put(
+ "JCR_Queries",
+ "A JCR can be queried with XPathQuery, can export portions of its tree to XML in two standard formats and can import hierarchies directly"
+ + " from XML. A JCR may optionally support a standardized form of SQL for queries. The Apache Jackrabbit reference implementation of "
+ + "JCR also supports the integration of the Apache Lucene search engine to give full text searches of data in the repository.");
+
+ expected.put("JCR_Impl",
+ "eXo Platform JCR implementation on the company wiki. eXo Platform 2 article on theserverside");
+
+ // add nodes
+ for (Entry<String, String> entry : expected.entrySet())
+ {
+ conn.addNode(entry.getKey(), entry.getValue().getBytes(), "text/plain");
+ }
+
+ // map containing test-case: <SQL query> : <expected nodes>
+ Map<String, String[]> sqlCases = new HashMap<String, String[]>();
+ sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'tailored')", new String[]{"JCR_Overview"});
+ sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'XPathQuery')", new String[]{"JCR_Queries"});
+ sqlCases.put("SELECT * FROM nt:resource WHERE CONTAINS(*,'API')", new String[]{"JCR_Structure", "JCR_Overview"});
+
+ // SQL
+ for (Entry<String, String[]> entry : sqlCases.entrySet())
+ {
+ HTTPResponse response = conn.sqlQuery(entry.getKey());
+ assertEquals(207, response.getStatusCode());
+ assertResponse(entry.getValue(), response);
+ }
+
+ // map containing test-case: <XPATH query> : <expected nodes>
+ Map<String, String[]> xpathCases = new HashMap<String, String[]>();
+ xpathCases.put("//element(*, nt:base)[jcr:contains(.,'tailored')]", new String[]{"JCR_Overview"});
+ xpathCases.put("//element(*, nt:base)[jcr:contains(.,'XPathQuery')]", new String[]{"JCR_Queries"});
+ xpathCases.put("//element(*, nt:resource)[jcr:contains(.,'API')]", new String[]{"JCR_Structure", "JCR_Overview"});
+
+ // XPATH
+ for (Entry<String, String[]> entry : xpathCases.entrySet())
+ {
+ HTTPResponse response = conn.xpathQuery(entry.getKey());
+ assertEquals(207, response.getStatusCode());
+ assertResponse(entry.getValue(), response);
+ }
+ // remove created nodes
+ for (Entry<String, String> entry : expected.entrySet())
+ {
+ conn.removeNode(entry.getKey());
+ }
+ }
+
+ /**
+ * Simple test, searching nodes by given path
+ */
+ public void testPathSearch() throws Exception
+ {
+ String testLocalRootName = "testSimpleGetAll";
+ JCRWebdavConnection conn = getConnection();
conn.addDir(testLocalRootName);
List<String> expected = new ArrayList<String>();
- expected.add("exo_String");
- expected.add("exo_Boolean");
- expected.add("exo_Integer");
- expected.add("exo_Long");
- expected.add("exo_Float");
- expected.add("exo_Double");
+ expected.add("exoString");
+ expected.add("exoBoolean");
+ expected.add("exoInteger");
+ expected.add("exoLong");
+ expected.add("exoFloat");
+ expected.add("exoDouble");
for (String name : expected)
{
conn.addNode(testLocalRootName + "/" + name, "_data_".getBytes());
- System.out.println("added: " + name);
}
-
+ // SQL
HTTPResponse response =
- conn.sqlQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName + "[%]/%'");
+ conn.sqlQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName
+ + "[%]/%' AND NOT jcr:path LIKE '/" + testLocalRootName + "[%]/%/%' ");
assertEquals(207, response.getStatusCode());
- List<String> found = parseNodeNames(response.getData());
- assertTrue("Some nodes not found", assertLists(expected, found));
+ assertResponse(expected, response);
+ // XPath
+ response = conn.xpathQuery("/jcr:root/" + testLocalRootName + "/ element(*, nt:base)");
+ assertEquals(207, response.getStatusCode());
+ assertResponse(expected, response);
conn.removeNode(testLocalRootName);
}
/**
+ * @param expected
+ * @param response
+ * @throws IOException
+ * @throws ModuleException
+ * @throws XMLStreamException
+ * @throws FactoryConfigurationError
+ */
+ private void assertResponse(Collection<String> expected, HTTPResponse response) throws IOException, ModuleException,
+ XMLStreamException, FactoryConfigurationError
+ {
+ List<String> found;
+ assertEquals(207, response.getStatusCode());
+ found = parseNodeNames(response.getData());
+ assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + expected,
+ compareLists(expected, found));
+ }
+
+ /**
+ * @param expected
+ * @param response
+ * @throws IOException
+ * @throws ModuleException
+ * @throws XMLStreamException
+ * @throws FactoryConfigurationError
+ */
+ private void assertResponse(String[] expected, HTTPResponse response) throws IOException, ModuleException,
+ XMLStreamException, FactoryConfigurationError
+ {
+ assertResponse(Arrays.asList(expected), response);
+ }
+
+ /**
+ * returns true if lists are equals (order doesn't matter)
+ *
+ * @param expected
+ * @param found
+ * @return
+ */
+ private boolean compareLists(Collection<String> expected, Collection<String> found)
+ {
+ if (expected == null || found == null)
+ {
+ return false;
+ }
+ return expected.containsAll(found) && found.containsAll(expected);
+ }
+
+ /**
* Extracts names of nodes from response XML
*
* TODO: fix
- * /!\ During parsing method accumulates nodes in SET, because of https://jira.jboss.org/jira/browse/EXOJCR-364 /!\
+ * /!\ Method accumulates nodes in SET, because of https://jira.jboss.org/jira/browse/EXOJCR-364 /!\
*
* @param data
* @return
@@ -86,11 +216,12 @@
* @throws FactoryConfigurationError
* @throws IOException
*/
- public List<String> parseNodeNames(byte[] data) throws XMLStreamException, FactoryConfigurationError, IOException
+ private List<String> parseNodeNames(byte[] data) throws XMLStreamException, FactoryConfigurationError, IOException
{
// flag, that notifies when parser is inside <D:displayname></D:displayname>
boolean displayName = false;
- Set<String> nodes = new HashSet<String>();
+ //Set<String> nodes = new HashSet<String>();
+ List<String> nodes = new ArrayList<String>();
InputStream input = new ByteArrayInputStream(data);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input);
QName name = QName.valueOf("{DAV:}displayname");
@@ -136,20 +267,4 @@
}
return new ArrayList<String>(nodes);
}
-
- /**
- * returns true if lists are equals (order doesn't matter)
- *
- * @param expected
- * @param found
- * @return
- */
- public boolean assertLists(List<String> expected, List<String> found)
- {
- if (expected == null || found == null)
- {
- return false;
- }
- return expected.containsAll(found) && found.containsAll(expected);
- }
}
16 years, 4 months
exo-jcr SVN: r1297 - jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-01-05 10:54:13 -0500 (Tue, 05 Jan 2010)
New Revision: 1297
Modified:
jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
Log:
EXOJCR-340: Added method addNode, with mimetype parameter.
Modified: jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java 2010-01-05 14:53:40 UTC (rev 1296)
+++ jcr/branches/1.12.0-JBCCACHE/applications/cluster.test.client/src/main/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java 2010-01-05 15:54:13 UTC (rev 1297)
@@ -74,6 +74,52 @@
Put(workspacePath + name, data, headers).getStatusCode();
}
+ /**
+ * Adds node with given mixin types.
+ *
+ * @param name
+ * @param nodeType
+ * @param mixinTypes
+ * @param data
+ * @return
+ * @throws IOException
+ * @throws ModuleException
+ */
+ public HTTPResponse addNode(String name, String[] mixinTypes, byte[] data) throws IOException, ModuleException
+ {
+ // construct string containing mixins in comma separated format
+ String mixins = mixinTypes.length > 0 ? mixinTypes[0] : "";
+ for (int i = 1; i < mixinTypes.length; i++)
+ {
+ mixins = mixins + ", " + mixinTypes[i];
+ }
+ NVPair[] headers = new NVPair[2];
+ headers[0] = new NVPair(ExtHttpHeaders.CONTENT_MIXINTYPES, mixins);
+ headers[1] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/plain");
+ HTTPResponse response = Put(workspacePath + name, data, headers);
+ response.getStatusCode();
+ return response;
+ }
+
+ /**
+ * Adds node (nt:file) with given mimetype.
+ *
+ * @param name
+ * @param data
+ * @param mimeType
+ * @return
+ * @throws IOException
+ * @throws ModuleException
+ */
+ public HTTPResponse addNode(String name, byte[] data, String mimeType) throws IOException, ModuleException
+ {
+ NVPair[] headers = new NVPair[1];
+ headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, mimeType);
+ HTTPResponse response = Put(workspacePath + name, data, headers);
+ response.getStatusCode();
+ return response;
+ }
+
public HTTPResponse addNode(String name, HttpOutputStream stream) throws IOException, ModuleException
{
return Put(workspacePath + name, stream);
@@ -286,6 +332,7 @@
/**
* Performs SQL query on workspace and returns plain HTTPResponse. It should be returned with status 207
* and must contain the XML with node collection.
+ *
* @param query
* @return
* @throws IOException
16 years, 4 months
exo-jcr SVN: r1296 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-05 09:53:40 -0500 (Tue, 05 Jan 2010)
New Revision: 1296
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
Log:
EXOJCR-333 : The ExoEvictionActionPolicy was changed.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 14:42:11 UTC (rev 1295)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 14:53:40 UTC (rev 1296)
@@ -30,7 +30,8 @@
* @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
* @version $Id$
*/
-public class ExoEvictionActionPolicy implements EvictionActionPolicy
+public class ExoEvictionActionPolicy
+ implements EvictionActionPolicy
{
private static final Log LOG = ExoLogger.getLogger("jcr.ExoEvictionActionPolicy");
@@ -42,18 +43,10 @@
public boolean evict(Fqn fqn)
{
- if (fqn.size() != 3)
+ if (fqn.size() == 3 && (JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST.equals(fqn.get(0)) || JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST.equals(fqn.get(0))))
{
- return eviction(fqn);
- }
- else if (fqn.size() == 3 && JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST.equals(fqn.get(0)))
- {
return eviction(fqn.getParent());
}
- else if (fqn.size() == 3 && JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST.equals(fqn.get(0)))
- {
- return eviction(fqn.getParent());
- }
else
{
return eviction(fqn);
16 years, 4 months
exo-jcr SVN: r1295 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-01-05 09:42:11 -0500 (Tue, 05 Jan 2010)
New Revision: 1295
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
Log:
EXOJCR-333 : The ExoEvictionActionPolicy was changed.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 14:01:39 UTC (rev 1294)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/ExoEvictionActionPolicy.java 2010-01-05 14:42:11 UTC (rev 1295)
@@ -42,14 +42,18 @@
public boolean evict(Fqn fqn)
{
- if (fqn.size() == 3 && JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST.equals(fqn.get(0)))
+ if (fqn.size() != 3)
{
- return eviction(fqn.getParent());
+ return eviction(fqn);
}
else if (fqn.size() == 3 && JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST.equals(fqn.get(0)))
{
return eviction(fqn.getParent());
}
+ else if (fqn.size() == 3 && JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST.equals(fqn.get(0)))
+ {
+ return eviction(fqn.getParent());
+ }
else
{
return eviction(fqn);
16 years, 4 months