exo-jcr SVN: r495 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-06 11:55:26 -0500 (Fri, 06 Nov 2009)
New Revision: 495
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-200: new impl testing fixes
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 16:41:20 UTC (rev 494)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 16:55:26 UTC (rev 495)
@@ -88,7 +88,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
@@ -116,7 +116,7 @@
startBatch();
// check if parent is cached
- Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
@@ -141,7 +141,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
@@ -165,7 +165,7 @@
startBatch();
// check if parent is cached
- Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
@@ -387,9 +387,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
-
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-06 16:41:20 UTC (rev 494)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-06 16:55:26 UTC (rev 495)
@@ -141,7 +141,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -208,7 +208,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/jcr:primaryType)
String propId1 = "1";
@@ -280,7 +280,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -332,7 +332,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/jcr:primaryType)
String propId1 = "1";
@@ -369,7 +369,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -412,7 +412,7 @@
{
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/prop1)
String propId1 = "1";
@@ -458,7 +458,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -473,7 +473,7 @@
// check
ItemData nodeItem =
conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+ new InternalQName[0], 0, null, new AccessControlList()),
node1path.getEntries()[node1path.getEntries().length - 1]);
assertTrue("Node expected", nodeItem.isNode());
@@ -486,7 +486,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/jcr:primaryType)
String propId1 = "1";
@@ -501,7 +501,7 @@
// check
ItemData propItem =
conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+ new InternalQName[0], 0, null, new AccessControlList()),
propPath1.getEntries()[propPath1.getEntries().length - 1]);
assertFalse("Proeprty expected", propItem.isNode());
@@ -514,7 +514,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -539,7 +539,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/jcr:primaryType)
String propId1 = "1";
@@ -564,7 +564,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add node (/node)
String node1id = "1";
@@ -581,7 +581,7 @@
List<NodeData> childs =
conn.getChildNodesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
- Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, null, new AccessControlList()));
assertEquals("Childs amount wrong", 2, childs.size());
@@ -607,7 +607,7 @@
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
// add root (/)
conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ new InternalQName[0], 0, null, new AccessControlList()));
// add property (/jcr:primaryType)
String propId1 = "1";
@@ -636,7 +636,7 @@
List<PropertyData> childs =
conn.getChildPropertiesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
- Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, null, new AccessControlList()));
assertEquals("Childs amount wrong", 4, childs.size());
16 years, 8 months
exo-jcr SVN: r494 - in jcr/branches/1.12.0-JBC/component/core: src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-06 11:41:20 -0500 (Fri, 06 Nov 2009)
New Revision: 494
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Modified:
jcr/branches/1.12.0-JBC/component/core/pom.xml
Log:
EXOJCR-200: new impl tests
Modified: jcr/branches/1.12.0-JBC/component/core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/pom.xml 2009-11-06 16:18:11 UTC (rev 493)
+++ jcr/branches/1.12.0-JBC/component/core/pom.xml 2009-11-06 16:41:20 UTC (rev 494)
@@ -571,7 +571,7 @@
<include>**/**/JBossCacheServiceTest__.java</include>
<include>**/**/TestItem__.java</include>
- <include>**/**/JBossCacheTreeStorageConnectionTest.java</include>
+ <include>**/**/JBossCacheStorageConnectionTest.java</include>
</includes>
</configuration>
</plugin>
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-06 16:41:20 UTC (rev 494)
@@ -0,0 +1,668 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+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.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.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 25.10.2009
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id$
+ */
+public class JBossCacheStorageConnectionTest extends TestCase
+{
+
+ protected JBossCacheStorageConnection conn;
+
+ protected Cache<Serializable, Object> cache;
+
+ protected Node<Serializable, Object> nodes;
+
+ protected Node<Serializable, Object> props;
+
+ protected String jbcConfig;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // JBossCache
+ initJBCConfig();
+
+ cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig);
+
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ // prepare cache structures
+ nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
+ props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
+
+ // run cache
+ cache.create();
+ cache.start();
+
+ // JCR connection
+ conn = new JBossCacheStorageConnection(cache, nodes, props);
+ }
+
+ protected void initJBCConfig()
+ {
+ jbcConfig = "conf/standalone/test-jbosscache-config-jdbcloader.xml";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void tearDown() throws Exception
+ {
+
+ cache.stop();
+ cache.destroy();
+
+ super.tearDown();
+ }
+
+ private void treePrint(Node<Serializable, Object> node)
+ {
+ for (Node<Serializable, Object> child : node.getChildren())
+ {
+ System.out.println(child.toString());
+ for (Serializable key : child.getKeys())
+ {
+ System.out.println("\t" + key + "=" + child.get(key));
+ }
+ if (!child.isLeaf())
+ {
+ treePrint(child);
+ }
+ }
+ }
+
+ public void testAddNode() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // check in nodes
+ treePrint(nodes);
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+ assertNotNull("Node expected", rootNode);
+
+ // check root Node
+ Object dataObject = rootNode.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertTrue("Node item data is not a Node", dataObject instanceof NodeData);
+
+ NodeData data = (NodeData)dataObject;
+ assertEquals("Node id wrong", node1id, data.getIdentifier());
+ assertEquals("Node path wrong", node1path, data.getQPath());
+
+ // cehck childs
+ assertEquals("Childs expected", 2, rootNode.getChildren().size());
+
+ for (Node<Serializable, Object> child : rootNode.getChildren())
+ {
+ // check id and name
+ String nodeName = child.getFqn().getLastElementAsString();
+ String nodeId = (String)child.get(JBossCacheStorageConnection.ITEM_ID);
+ if (nodeName.equals(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)))
+ {
+ assertEquals("Node id wrong", node1id, nodeId);
+ }
+ else if (nodeName
+ .equals(Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1]
+ .getAsString(true)))
+ {
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, nodeId);
+ }
+ else
+ {
+ fail("Wrong Node name " + nodeName);
+ }
+
+ // check data
+ Node<Serializable, Object> childNode = nodes.getChild(Fqn.fromElements(nodeId));
+ assertNotNull("Node expected", childNode);
+
+ Object childData = childNode.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertTrue("Child Node item data is not a Node", childData instanceof NodeData);
+
+ assertEquals("Node id wrong", nodeId, ((NodeData)childData).getIdentifier());
+ assertEquals("Node path wrong", nodeName,
+ data.getQPath().getEntries()[data.getQPath().getEntries().length - 1].getAsString(true));
+ }
+ }
+
+ public void testAddProperty() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+ String propValue1 = "Property value #1";
+ propData1.setValue(new TransientValueData(propValue1));
+ conn.add(propData1);
+
+ // add property (/jcr:mixinTypes)
+ String propId2 = "2";
+ QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+ TransientPropertyData propData2 = new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false);
+ String propValue2 = "Property value #2";
+ propData2.setValue(new TransientValueData(propValue2));
+ conn.add(propData2);
+
+ // check in nodes
+ treePrint(nodes);
+ treePrint(props);
+
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+ assertEquals("Attributes ammount wrong", 3, rootNode.getKeys().size());
+
+ String pid1 = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+ assertNotNull("Property ID should exists", pid1);
+ assertEquals("Property ID wrong", propId1, pid1);
+
+ String pid2 = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
+ assertNotNull("Property ID should exists", pid2);
+ assertEquals("Property ID wrong", propId2, pid2);
+
+ // TODO check order
+ int index = 0;
+ for (Serializable key : rootNode.getKeys())
+ {
+ //System.out.println(key);
+ //index++;
+ }
+
+ // check in props
+ treePrint(nodes);
+
+ Node<Serializable, Object> itemsProp1 = props.getChild(Fqn.fromElements(propId1));
+ Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertNotNull("Property item data should exists", data1Object);
+ assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+ PropertyData data1 = (PropertyData)data1Object;
+ assertEquals("Property id wrong", propId1, data1.getIdentifier());
+ assertEquals("Property path wrong", propPath1, data1.getQPath());
+ assertEquals("Property Value wrong", propValue1, new String(data1.getValues().get(0).getAsByteArray(),
+ Constants.DEFAULT_ENCODING));
+
+ Node<Serializable, Object> itemsProp2 = props.getChild(Fqn.fromElements(propId2));
+ Object data2Object = itemsProp2.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertNotNull("Property item data should exists", data2Object);
+ assertTrue("Property item data is not a Property", data2Object instanceof PropertyData);
+
+ PropertyData data2 = (PropertyData)data2Object;
+ assertEquals("Property id wrong", propId2, data2.getIdentifier());
+ assertEquals("Property path wrong", propPath2, data2.getQPath());
+ assertEquals("Property Value wrong", propValue2, new String(data2.getValues().get(0).getAsByteArray(),
+ Constants.DEFAULT_ENCODING));
+ }
+
+ public void testDeleteNode() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+ assertEquals("Number of childs wrong", 2, rootNode.getChildren().size());
+
+ // delete /node
+ conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // check in nodes
+ treePrint(nodes);
+
+ // check childs
+ assertEquals("Childs expected", 1, rootNode.getChildren().size());
+
+ assertNull("Child Node should be deleted", rootNode.getChild(Fqn.fromElements(node1path.getEntries()[node1path
+ .getEntries().length - 1].getAsString(true))));
+
+ assertNotNull("Child Node should be not deleted", rootNode.getChild(Fqn.fromElements(Constants.JCR_SYSTEM_PATH
+ .getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1].getAsString(true))));
+
+ // to be sure ;)
+ Node<Serializable, Object> child = rootNode.getChildren().iterator().next();
+ assertEquals("Node name wrong",
+ Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1].getAsString(true),
+ child.getFqn().getLastElementAsString());
+
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, (String)child.get(JBossCacheStorageConnection.ITEM_ID));
+
+ // check nodes
+ assertNull("Node item data should not exists", nodes.getChild(Fqn.fromElements(node1id)));
+
+ Node<Serializable, Object> system = nodes.getChild(Fqn.fromElements(Constants.SYSTEM_UUID));
+ assertNotNull("Node item data should exists", system);
+ }
+
+ public void testDeleteProperty() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // add property (/jcr:mixinTypes)
+ String propId2 = "2";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES), propId2,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+ // delete /jcr:primaryType
+ conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
+ propId1, 1, 1, Constants.ROOT_UUID, false));
+
+ // check in nodes
+ treePrint(nodes);
+
+ assertEquals("Number of childs wrong", 2, rootNode.getKeys().size());
+ assertNull("Property should be deleted", rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString()));
+ assertNotNull("Property should exists", rootNode.get(Constants.JCR_MIXINTYPES.getAsString()));
+
+ // check in props
+ treePrint(props);
+
+ assertNull("Property item data should not exists", props.getChild(Fqn.fromElements(propId1)));
+ assertNotNull("Property item data should exists", props.getChild(Fqn.fromElements(propId2)));
+ }
+
+ public void testUpdateNode() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+ // update /node (order number)
+ int nodeOrderNumb = 1;
+ conn.update(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+ nodeOrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+ // check in tree
+ treePrint(nodes);
+
+ Node<Serializable, Object> node =
+ rootNode.getChild(Fqn
+ .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+
+ assertNotNull("Node should exists", node);
+ assertEquals("Child expected", 1, rootNode.getChildren().size());
+
+ // check in items
+ treePrint(nodes);
+
+ Node<Serializable, Object> itemNode = nodes.getChild(Fqn.fromElements(node1id));
+ assertNotNull("Node item data should exists", itemNode);
+
+ Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertTrue("Node item data should be a NodeData", dataObject instanceof NodeData);
+ assertEquals("Node id wrong", node1id, ((NodeData)dataObject).getIdentifier());
+ assertEquals("Node path wrong", node1path, ((NodeData)dataObject).getQPath());
+ assertEquals("Node order number wrong", nodeOrderNumb, ((NodeData)dataObject).getOrderNumber());
+ }
+
+ public void testUpdateProperty() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/prop1)
+ String propId1 = "1";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+ String propValue1 = "Property value #1";
+ propData1.setValue(new TransientValueData(propValue1));
+ conn.add(propData1);
+
+ // update property (/prop1) with new value
+ TransientPropertyData propDataU = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+ String propValueU = "Updated Property value #1";
+ propDataU.setValue(new TransientValueData(propValueU));
+ conn.update(propDataU);
+
+ // check in tree
+ treePrint(nodes);
+
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+ assertEquals("Attributes ammount wrong", 2, rootNode.getKeys().size());
+
+ String pid = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+ assertEquals("Property ID wrong", propId1, pid);
+
+ // check in items
+ treePrint(nodes);
+
+ Node<Serializable, Object> itemsProp1 = props.getChild(Fqn.fromElements(propId1));
+ Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+ assertNotNull("Property item data should exists", data1Object);
+ assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+ PropertyData data1 = (PropertyData)data1Object;
+ assertEquals("Property id wrong", propId1, data1.getIdentifier());
+ assertEquals("Property path wrong", propPath1, data1.getQPath());
+ assertEquals("Property Value wrong", propValueU, new String(data1.getValues().get(0).getAsByteArray(),
+ Constants.DEFAULT_ENCODING));
+ }
+
+ public void testGetNodeByName() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // check
+ ItemData nodeItem =
+ conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+ node1path.getEntries()[node1path.getEntries().length - 1]);
+
+ assertTrue("Node expected", nodeItem.isNode());
+ assertEquals("Node id wrong", node1id, nodeItem.getIdentifier());
+ assertEquals("Node path wrong", node1path, nodeItem.getQPath());
+ }
+
+ public void testGetPropertyByName() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ conn.add(new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false));
+
+ // add property (/jcr:mixinTypes)
+ String propId2 = "2";
+ QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+ conn.add(new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false));
+
+ // check
+ ItemData propItem =
+ conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()),
+ propPath1.getEntries()[propPath1.getEntries().length - 1]);
+
+ assertFalse("Proeprty expected", propItem.isNode());
+ assertEquals("Proeprty id wrong", propId1, propItem.getIdentifier());
+ assertEquals("Proeprty path wrong", propPath1, propItem.getQPath());
+ }
+
+ public void testGetNodeById() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // check
+ ItemData nodeItem = conn.getItemData(node1id);
+
+ assertTrue("Node expected", nodeItem.isNode());
+ assertEquals("Node id wrong", node1id, nodeItem.getIdentifier());
+ assertEquals("Node path wrong", node1path, nodeItem.getQPath());
+ }
+
+ public void testGetPropertyById() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ conn.add(new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false));
+
+ // add property (/jcr:mixinTypes)
+ String propId2 = "2";
+ QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+ conn.add(new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false));
+
+ // check
+ ItemData propItem = conn.getItemData(propId1);
+
+ assertFalse("Proeprty expected", propItem.isNode());
+ assertEquals("Proeprty id wrong", propId1, propItem.getIdentifier());
+ assertEquals("Proeprty path wrong", propPath1, propItem.getQPath());
+ }
+
+ public void _testGetChildNodes() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // check in tree
+ treePrint(nodes);
+
+ List<NodeData> childs =
+ conn.getChildNodesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ assertEquals("Childs amount wrong", 2, childs.size());
+
+ for (NodeData child : childs)
+ {
+ if (child.getQPath().equals(node1path))
+ {
+ assertEquals("Node id wrong", node1id, child.getIdentifier());
+ }
+ else if (child.getQPath().equals(Constants.JCR_SYSTEM_PATH))
+ {
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, child.getIdentifier());
+ }
+ else
+ {
+ fail("Wrong Node found");
+ }
+ }
+ }
+
+ public void _testGetChildProperties() throws Exception
+ {
+ // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // add property (/jcr:mixinTypes)
+ String propId2 = "2";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES), propId2,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // add property (/a)
+ String propId3 = "3";
+ InternalQName propName3 = InternalQName.parse("[]a");
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName3), propId3, 1, 1,
+ Constants.ROOT_UUID, false));
+
+ // add property (/b)
+ String propId4 = "4";
+ InternalQName propName4 = InternalQName.parse("[]b");
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName4), propId4, 1, 1,
+ Constants.ROOT_UUID, false));
+
+ // check
+ treePrint(nodes);
+
+ List<PropertyData> childs =
+ conn.getChildPropertiesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ assertEquals("Childs amount wrong", 4, childs.size());
+
+ for (PropertyData child : childs)
+ {
+ if (child.getQPath().getName().equals(Constants.JCR_PRIMARYTYPE))
+ {
+ assertEquals("Property id wrong", propId1, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(Constants.JCR_MIXINTYPES))
+ {
+ assertEquals("Property id wrong", propId2, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(propName3))
+ {
+ assertEquals("Property id wrong", propId3, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(propName4))
+ {
+ assertEquals("Property id wrong", propId4, child.getIdentifier());
+ }
+ else
+ {
+ fail("Wrong Property found");
+ }
+ }
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
16 years, 8 months
exo-jcr SVN: r493 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query: cacheloader and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-11-06 11:18:11 -0500 (Fri, 06 Nov 2009)
New Revision: 493
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java
Log:
EXOJCR-202: IndexerCacheLoader updated
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-11-06 16:16:58 UTC (rev 492)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2009-11-06 16:18:11 UTC (rev 493)
@@ -16,163 +16,23 @@
*/
package org.exoplatform.services.jcr.impl.core.query;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.exoplatform.container.configuration.ConfigurationManager;
-import org.exoplatform.services.document.DocumentReaderService;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerParams;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
-import org.exoplatform.services.jcr.dataflow.persistent.MandatoryItemsPersistenceListener;
import org.exoplatform.services.jcr.datamodel.InternalQName;
-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.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
-import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
-import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
-import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
-import org.exoplatform.services.jcr.impl.core.query.lucene.ScoreNode;
-import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
-import org.exoplatform.services.jcr.impl.core.value.NameValue;
-import org.exoplatform.services.jcr.impl.core.value.PathValue;
-import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
-import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.picocontainer.Startable;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.StringTokenizer;
import javax.jcr.Node;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
-import javax.jcr.Value;
import javax.jcr.query.InvalidQueryException;
import javax.jcr.query.Query;
/**
* Acts as a global entry point to execute queries and index nodes.
*/
-public class SearchManager implements Startable, MandatoryItemsPersistenceListener
+public interface SearchManager
{
-
/**
- * Logger instance for this class
- */
- private static final Log log = ExoLogger.getLogger(SearchManager.class);
-
- protected final QueryHandlerEntry config;
-
- /**
- * Text extractor for extracting text content of binary properties.
- */
- protected final DocumentReaderService extractor;
-
- /**
- * QueryHandler where query execution is delegated to
- */
- protected QueryHandler handler;
-
- /**
- * The shared item state manager instance for the workspace.
- */
- protected final ItemDataConsumer itemMgr;
-
- /**
- * The namespace registry of the repository.
- */
- protected final NamespaceRegistryImpl nsReg;
-
- /**
- * The node type registry.
- */
- protected final NodeTypeDataManager nodeTypeDataManager;
-
- /**
- * QueryHandler of the parent search manager or <code>null</code> if there
- * is none.
- */
- protected final SearchManager parentSearchManager;
-
- // protected QPath indexingRoot;
- //
- // protected List<QPath> excludedPaths = new ArrayList<QPath>();
-
- protected IndexingTree indexingTree;
-
- private final ConfigurationManager cfm;
-
- protected LuceneVirtualTableResolver virtualTableResolver;
-
- /**
- * Creates a new <code>SearchManager</code>.
- *
- * @param config
- * the search configuration.
- * @param nsReg
- * the namespace registry.
- * @param ntReg
- * the node type registry.
- * @param itemMgr
- * the shared item state manager.
- * @param rootNodeId
- * the id of the root node.
- * @param parentMgr
- * the parent search manager or <code>null</code> if there is no
- * parent search manager.
- * @param excludedNodeId
- * id of the node that should be excluded from indexing. Any
- * descendant of that node will also be excluded from indexing.
- * @throws RepositoryException
- * if the search manager cannot be initialized
- * @throws RepositoryConfigurationException
- */
- public SearchManager(QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
- WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
- DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
- throws RepositoryException, RepositoryConfigurationException
- {
-
- this.extractor = extractor;
- indexSearcherHolder.addIndexSearcher(this);
- this.config = config;
- this.nodeTypeDataManager = ntReg;
- this.nsReg = nsReg;
- this.itemMgr = itemMgr;
- this.cfm = cfm;
- this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
- this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
- itemMgr.addItemPersistenceListener(this);
- }
-
- /**
* Creates a query object from a node that can be executed on the workspace.
*
* @param session
@@ -189,13 +49,8 @@
* @throws RepositoryException
* if any other error occurs.
*/
- public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, Node node)
- throws InvalidQueryException, RepositoryException
- {
- AbstractQueryImpl query = createQueryInstance();
- query.init(session, sessionDataManager, handler, node);
- return query;
- }
+ Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, Node node)
+ throws InvalidQueryException, RepositoryException;
/**
* Creates a query object that can be executed on the workspace.
@@ -216,645 +71,23 @@
* @throws RepositoryException
* if any other error occurs.
*/
- public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, String statement,
- String language) throws InvalidQueryException, RepositoryException
- {
- AbstractQueryImpl query = createQueryInstance();
- query.init(session, sessionDataManager, handler, statement, language);
- return query;
- }
+ Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, String statement, String language)
+ throws InvalidQueryException, RepositoryException;
- /**
- * just for test use only
- */
- public QueryHandler getHandler()
- {
+ Set<String> getFieldNames() throws IndexException;
- return handler;
- }
+ QueryHandler getHandler();
- public void onSaveItems(ItemStateChangesLog changesLog)
- {
- if (handler == null)
- return;
+ Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException;
- long time = System.currentTimeMillis();
-
- // nodes that need to be removed from the index.
- final Set<String> removedNodes = new HashSet<String>();
- // nodes that need to be added to the index.
- final Set<String> addedNodes = new HashSet<String>();
-
- final Map<String, List<ItemState>> updatedNodes = new HashMap<String, List<ItemState>>();
-
- for (Iterator<ItemState> iter = changesLog.getAllStates().iterator(); iter.hasNext();)
- {
- ItemState itemState = iter.next();
-
- if (!indexingTree.isExcluded(itemState))
- {
- String uuid =
- itemState.isNode() ? itemState.getData().getIdentifier() : itemState.getData().getParentIdentifier();
-
- if (itemState.isAdded())
- {
- if (itemState.isNode())
- {
- addedNodes.add(uuid);
- }
- else
- {
- if (!addedNodes.contains(uuid))
- {
- createNewOrAdd(uuid, itemState, updatedNodes);
- }
- }
- }
- else if (itemState.isRenamed())
- {
- if (itemState.isNode())
- {
- addedNodes.add(uuid);
- }
- else
- {
- createNewOrAdd(uuid, itemState, updatedNodes);
- }
- }
- else if (itemState.isUpdated())
- {
- createNewOrAdd(uuid, itemState, updatedNodes);
- }
- else if (itemState.isMixinChanged())
- {
- createNewOrAdd(uuid, itemState, updatedNodes);
- }
- else if (itemState.isDeleted())
- {
- if (itemState.isNode())
- {
- if (addedNodes.contains(uuid))
- {
- addedNodes.remove(uuid);
- removedNodes.remove(uuid);
- }
- else
- {
- removedNodes.add(uuid);
- }
- // remove all changes after node remove
- updatedNodes.remove(uuid);
- }
- else
- {
- if (!removedNodes.contains(uuid) && !addedNodes.contains(uuid))
- {
- createNewOrAdd(uuid, itemState, updatedNodes);
- }
- }
- }
- }
- }
- // TODO make quick changes
- for (String uuid : updatedNodes.keySet())
- {
- removedNodes.add(uuid);
- addedNodes.add(uuid);
- }
-
- Iterator<NodeData> addedStates = new Iterator<NodeData>()
- {
- private final Iterator<String> iter = addedNodes.iterator();
-
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- public NodeData next()
- {
-
- // cycle till find a next or meet the end of set
- do
- {
- String id = iter.next();
- try
- {
- ItemData item = itemMgr.getItemData(id);
- if (item != null)
- {
- if (item.isNode())
- return (NodeData)item; // return node
- else
- log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
- + " found. ");
- }
- else
- log.warn("Unable to index node with id " + id + ", node does not exist.");
-
- }
- catch (RepositoryException e)
- {
- log.error("Can't read next node data " + id, e);
- }
- }
- while (iter.hasNext()); // get next if error or node not found
-
- return null; // we met the end of iterator set
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
-
- Iterator<String> removedIds = new Iterator<String>()
- {
- private final Iterator<String> iter = removedNodes.iterator();
-
- public boolean hasNext()
- {
- return iter.hasNext();
- }
-
- public String next()
- {
- return nextNodeId();
- }
-
- public String nextNodeId() throws NoSuchElementException
- {
- return iter.next();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
-
- }
- };
-
- if (removedNodes.size() > 0 || addedNodes.size() > 0)
- {
- try
- {
- handler.updateNodes(removedIds, addedStates);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(removedNodes, addedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
-
- if (log.isDebugEnabled())
- {
- log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
- }
- }
-
- public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
- {
- List<ItemState> list = updatedNodes.get(key);
- if (list == null)
- {
- list = new ArrayList<ItemState>();
- updatedNodes.put(key, list);
- }
- list.add(state);
-
- }
-
- public void start()
- {
-
- if (log.isDebugEnabled())
- log.debug("start");
- try
- {
- if (indexingTree == null)
- {
- List<QPath> excludedPath = new ArrayList<QPath>();
- // Calculating excluded node identifiers
- excludedPath.add(Constants.JCR_SYSTEM_PATH);
-
- //if (config.getExcludedNodeIdentifers() != null)
- String excludedNodeIdentifer =
- config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
- if (excludedNodeIdentifer != null)
- {
- StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
- while (stringTokenizer.hasMoreTokens())
- {
-
- try
- {
- ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
- if (excludeData != null)
- excludedPath.add(excludeData.getQPath());
- }
- catch (RepositoryException e)
- {
- log.warn(e.getLocalizedMessage());
- }
- }
- }
-
- NodeData indexingRootData = null;
- String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
- if (rootNodeIdentifer != null)
- {
- try
- {
- ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
- if (indexingRootDataItem != null && indexingRootDataItem.isNode())
- indexingRootData = (NodeData)indexingRootDataItem;
- }
- catch (RepositoryException e)
- {
- log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
-
- }
-
- }
- else
- {
- try
- {
- indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
- }
- catch (RepositoryException e)
- {
- log.error("Fail to load root node data");
- }
- }
-
- indexingTree = new IndexingTree(indexingRootData, excludedPath);
- }
-
- initializeQueryHandler();
- }
- catch (RepositoryException e)
- {
- log.error(e.getLocalizedMessage());
- handler = null;
- throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
- }
- catch (RepositoryConfigurationException e)
- {
- log.error(e.getLocalizedMessage());
- handler = null;
- throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
- }
- }
-
- public void stop()
- {
- handler.close();
- log.info("Search manager stopped");
- }
-
- // /**
- // * Checks if the given event should be excluded based on the
- // * {@link #excludePath} setting.
- // *
- // * @param event
- // * observation event
- // * @return <code>true</code> if the event should be excluded,
- // * <code>false</code> otherwise
- // */
- // protected boolean isExcluded(ItemState event) {
- //
- // for (QPath excludedPath : excludedPaths) {
- // if (event.getData().getQPath().isDescendantOf(excludedPath)
- // || event.getData().getQPath().equals(excludedPath))
- // return true;
- // }
- //
- // return !event.getData().getQPath().isDescendantOf(indexingRoot)
- // && !event.getData().getQPath().equals(indexingRoot);
- // }
-
- protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
- throws RepositoryConfigurationException
- {
-
- QueryHandlerContext context =
- new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
- extractor, true, virtualTableResolver);
- return context;
- }
-
- protected String getIndexDir() throws RepositoryConfigurationException
- {
- String dir = config.getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR, null);
- if (dir == null)
- {
- log.warn(QueryHandlerParams.PARAM_INDEX_DIR + " parameter not found. Using outdated parameter name "
- + QueryHandlerParams.OLD_PARAM_INDEX_DIR);
- dir = config.getParameterValue(QueryHandlerParams.OLD_PARAM_INDEX_DIR);
- }
- return dir;
- }
-
/**
- * Initializes the query handler.
- *
- * @throws RepositoryException
- * if the query handler cannot be initialized.
- * @throws RepositoryConfigurationException
- * @throws ClassNotFoundException
- */
- protected void initializeQueryHandler() throws RepositoryException, RepositoryConfigurationException
- {
- // initialize query handler
- String className = config.getType();
- if (className == null)
- throw new RepositoryConfigurationException("Content hanler configuration fail");
-
- try
- {
- Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
- Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
- handler = (QueryHandler)constuctor.newInstance(config, cfm);
- QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
- QueryHandlerContext context = createQueryHandlerContext(parentHandler);
- handler.init(context);
-
- }
- catch (SecurityException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IllegalArgumentException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (ClassNotFoundException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (NoSuchMethodException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (InstantiationException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- catch (IOException e)
- {
- throw new RepositoryException(e.getMessage(), e);
- }
- }
-
- /**
- * Creates a new instance of an {@link AbstractQueryImpl} which is not
- * initialized.
- *
- * @return an new query instance.
- * @throws RepositoryException
- * if an error occurs while creating a new query instance.
- */
- protected AbstractQueryImpl createQueryInstance() throws RepositoryException
- {
- try
- {
- String queryImplClassName = handler.getQueryClass();
- Object obj = Class.forName(queryImplClassName).newInstance();
- if (obj instanceof AbstractQueryImpl)
- {
- return (AbstractQueryImpl)obj;
- }
- else
- {
- throw new IllegalArgumentException(queryImplClassName + " is not of type "
- + AbstractQueryImpl.class.getName());
- }
- }
- catch (Throwable t)
- {
- throw new RepositoryException("Unable to create query: " + t.toString(), t);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Set<String> getFieldNames() throws IndexException
- {
- final Set<String> fildsSet = new HashSet<String>();
- if (handler instanceof SearchIndex)
- {
- IndexReader reader = null;
- try
- {
- reader = ((SearchIndex)handler).getIndexReader();
- final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
- for (final Object field : fields)
- {
- fildsSet.add((String)field);
- }
- }
- catch (IOException e)
- {
- throw new IndexException(e.getLocalizedMessage(), e);
- }
- finally
- {
- try
- {
- if (reader != null)
- reader.close();
- }
- catch (IOException e)
- {
- throw new IndexException(e.getLocalizedMessage(), e);
- }
- }
-
- }
- return fildsSet;
- }
-
- public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
- {
-
- return getNodes(virtualTableResolver.resolve(nodeType, true));
- }
-
- /**
- * Return set of uuid of nodes. Contains in names prefixes maped to the
+ * Return set of uuid of nodes. Contains in names prefixes mapped to the
* given uri
*
* @param prefix
* @return
* @throws RepositoryException
*/
- public Set<String> getNodesByUri(final String uri) throws RepositoryException
- {
- Set<String> result;
- final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
- try
- {
+ Set<String> getNodesByUri(final String uri) throws RepositoryException;
- // final LocationFactory locationFactory = new
- // LocationFactory(this);
- final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
- BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
- BooleanQuery query = new BooleanQuery();
-
- final String prefix = nsReg.getNamespacePrefixByURI(uri);
- query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
- // name of the property
- query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
-
- result = getNodes(query);
-
- // value of the property
-
- try
- {
- final Set<String> props = getFieldNames();
-
- query = new BooleanQuery();
- for (final String fieldName : props)
- {
- if (!FieldNames.PROPERTIES_SET.equals(fieldName))
- {
- query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
- }
- }
- }
- catch (final IndexException e)
- {
- throw new RepositoryException(e.getLocalizedMessage(), e);
- }
-
- final Set<String> propSet = getNodes(query);
- // Manually check property values;
- for (final String uuid : propSet)
- {
- if (isPrefixMatch(valueFactory, uuid, prefix))
- {
- result.add(uuid);
- }
- }
- }
- finally
- {
- BooleanQuery.setMaxClauseCount(defaultClauseCount);
- }
-
- return result;
- }
-
- private boolean isPrefixMatch(final InternalQName value, final String prefix) throws RepositoryException
- {
- return value.getNamespace().equals(nsReg.getNamespaceURIByPrefix(prefix));
- }
-
- private boolean isPrefixMatch(final QPath value, final String prefix) throws RepositoryException
- {
- for (int i = 0; i < value.getEntries().length; i++)
- {
- if (isPrefixMatch(value.getEntries()[i], prefix))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @param valueFactory
- * @param dm
- * @param uuid
- * @param prefix
- * @throws RepositoryException
- */
- private boolean isPrefixMatch(final ValueFactoryImpl valueFactory, final String uuid, final String prefix)
- throws RepositoryException
- {
-
- final ItemData node = itemMgr.getItemData(uuid);
- if (node != null && node.isNode())
- {
- final List<PropertyData> props = itemMgr.getChildPropertiesData((NodeData)node);
- for (final PropertyData propertyData : props)
- {
- if (propertyData.getType() == PropertyType.PATH || propertyData.getType() == PropertyType.NAME)
- {
- for (final ValueData vdata : propertyData.getValues())
- {
- final Value val =
- valueFactory.loadValue(((AbstractValueData)vdata).createTransientCopy(), propertyData.getType());
- if (propertyData.getType() == PropertyType.PATH)
- {
- if (isPrefixMatch(((PathValue)val).getQPath(), prefix))
- {
- return true;
- }
- }
- else if (propertyData.getType() == PropertyType.NAME)
- {
- if (isPrefixMatch(((NameValue)val).getQName(), prefix))
- {
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- /**
- * @param query
- * @return
- * @throws RepositoryException
- */
- private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
- {
- Set<String> result = new HashSet<String>();
- try
- {
- QueryHits hits = handler.executeQuery(query);
-
- ScoreNode sn;
-
- while ((sn = hits.nextScoreNode()) != null)
- {
- // Node node = session.getNodeById(sn.getNodeId());
- result.add(sn.getNodeId());
- }
- }
- catch (IOException e)
- {
- throw new RepositoryException(e.getLocalizedMessage(), e);
- }
- return result;
- }
-
}
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManagerImpl.java 2009-11-06 16:18:11 UTC (rev 493)
@@ -0,0 +1,865 @@
+/*
+ * 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.core.query;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.document.DocumentReaderService;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
+import org.exoplatform.services.jcr.dataflow.persistent.MandatoryItemsPersistenceListener;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+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.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionDataManager;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
+import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
+import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ScoreNode;
+import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
+import org.exoplatform.services.jcr.impl.core.value.NameValue;
+import org.exoplatform.services.jcr.impl.core.value.PathValue;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.picocontainer.Startable;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: SearchManagerImpl.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class SearchManagerImpl implements SearchManager, Startable, MandatoryItemsPersistenceListener
+{
+
+ /**
+ * Logger instance for this class
+ */
+ private static final Log log = ExoLogger.getLogger(SearchManagerImpl.class);
+
+ protected final QueryHandlerEntry config;
+
+ /**
+ * Text extractor for extracting text content of binary properties.
+ */
+ protected final DocumentReaderService extractor;
+
+ /**
+ * QueryHandler where query execution is delegated to
+ */
+ protected QueryHandler handler;
+
+ /**
+ * The shared item state manager instance for the workspace.
+ */
+ protected final ItemDataConsumer itemMgr;
+
+ /**
+ * The namespace registry of the repository.
+ */
+ protected final NamespaceRegistryImpl nsReg;
+
+ /**
+ * The node type registry.
+ */
+ protected final NodeTypeDataManager nodeTypeDataManager;
+
+ /**
+ * QueryHandler of the parent search manager or <code>null</code> if there
+ * is none.
+ */
+ protected final SearchManager parentSearchManager;
+
+ // protected QPath indexingRoot;
+ //
+ // protected List<QPath> excludedPaths = new ArrayList<QPath>();
+
+ protected IndexingTree indexingTree;
+
+ private final ConfigurationManager cfm;
+
+ protected LuceneVirtualTableResolver virtualTableResolver;
+
+ /**
+ * Creates a new <code>SearchManager</code>.
+ *
+ * @param config
+ * the search configuration.
+ * @param nsReg
+ * the namespace registry.
+ * @param ntReg
+ * the node type registry.
+ * @param itemMgr
+ * the shared item state manager.
+ * @param rootNodeId
+ * the id of the root node.
+ * @param parentMgr
+ * the parent search manager or <code>null</code> if there is no
+ * parent search manager.
+ * @param excludedNodeId
+ * id of the node that should be excluded from indexing. Any
+ * descendant of that node will also be excluded from indexing.
+ * @throws RepositoryException
+ * if the search manager cannot be initialized
+ * @throws RepositoryConfigurationException
+ */
+ public SearchManagerImpl(QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
+ DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
+ throws RepositoryException, RepositoryConfigurationException
+ {
+
+ this.extractor = extractor;
+ indexSearcherHolder.addIndexSearcher(this);
+ this.config = config;
+ this.nodeTypeDataManager = ntReg;
+ this.nsReg = nsReg;
+ this.itemMgr = itemMgr;
+ this.cfm = cfm;
+ this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
+ this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
+ itemMgr.addItemPersistenceListener(this);
+ }
+
+ /**
+ * Creates a query object from a node that can be executed on the workspace.
+ *
+ * @param session
+ * the session of the user executing the query.
+ * @param itemMgr
+ * the item manager of the user executing the query. Needed to
+ * return <code>Node</code> instances in the result set.
+ * @param node
+ * a node of type nt:query.
+ * @return a <code>Query</code> instance to execute.
+ * @throws InvalidQueryException
+ * if <code>absPath</code> is not a valid persisted query (that
+ * is, a node of type nt:query)
+ * @throws RepositoryException
+ * if any other error occurs.
+ */
+ public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, Node node)
+ throws InvalidQueryException, RepositoryException
+ {
+ AbstractQueryImpl query = createQueryInstance();
+ query.init(session, sessionDataManager, handler, node);
+ return query;
+ }
+
+ /**
+ * Creates a query object that can be executed on the workspace.
+ *
+ * @param session
+ * the session of the user executing the query.
+ * @param itemMgr
+ * the item manager of the user executing the query. Needed to
+ * return <code>Node</code> instances in the result set.
+ * @param statement
+ * the actual query statement.
+ * @param language
+ * the syntax of the query statement.
+ * @return a <code>Query</code> instance to execute.
+ * @throws InvalidQueryException
+ * if the query is malformed or the <code>language</code> is
+ * unknown.
+ * @throws RepositoryException
+ * if any other error occurs.
+ */
+ public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, String statement,
+ String language) throws InvalidQueryException, RepositoryException
+ {
+ AbstractQueryImpl query = createQueryInstance();
+ query.init(session, sessionDataManager, handler, statement, language);
+ return query;
+ }
+
+ /**
+ * just for test use only
+ */
+ public QueryHandler getHandler()
+ {
+
+ return handler;
+ }
+
+ public void onSaveItems(ItemStateChangesLog changesLog)
+ {
+ if (handler == null)
+ return;
+
+ long time = System.currentTimeMillis();
+
+ // nodes that need to be removed from the index.
+ final Set<String> removedNodes = new HashSet<String>();
+ // nodes that need to be added to the index.
+ final Set<String> addedNodes = new HashSet<String>();
+
+ final Map<String, List<ItemState>> updatedNodes = new HashMap<String, List<ItemState>>();
+
+ for (Iterator<ItemState> iter = changesLog.getAllStates().iterator(); iter.hasNext();)
+ {
+ ItemState itemState = iter.next();
+
+ if (!indexingTree.isExcluded(itemState))
+ {
+ String uuid =
+ itemState.isNode() ? itemState.getData().getIdentifier() : itemState.getData().getParentIdentifier();
+
+ if (itemState.isAdded())
+ {
+ if (itemState.isNode())
+ {
+ addedNodes.add(uuid);
+ }
+ else
+ {
+ if (!addedNodes.contains(uuid))
+ {
+ createNewOrAdd(uuid, itemState, updatedNodes);
+ }
+ }
+ }
+ else if (itemState.isRenamed())
+ {
+ if (itemState.isNode())
+ {
+ addedNodes.add(uuid);
+ }
+ else
+ {
+ createNewOrAdd(uuid, itemState, updatedNodes);
+ }
+ }
+ else if (itemState.isUpdated())
+ {
+ createNewOrAdd(uuid, itemState, updatedNodes);
+ }
+ else if (itemState.isMixinChanged())
+ {
+ createNewOrAdd(uuid, itemState, updatedNodes);
+ }
+ else if (itemState.isDeleted())
+ {
+ if (itemState.isNode())
+ {
+ if (addedNodes.contains(uuid))
+ {
+ addedNodes.remove(uuid);
+ removedNodes.remove(uuid);
+ }
+ else
+ {
+ removedNodes.add(uuid);
+ }
+ // remove all changes after node remove
+ updatedNodes.remove(uuid);
+ }
+ else
+ {
+ if (!removedNodes.contains(uuid) && !addedNodes.contains(uuid))
+ {
+ createNewOrAdd(uuid, itemState, updatedNodes);
+ }
+ }
+ }
+ }
+ }
+ // TODO make quick changes
+ for (String uuid : updatedNodes.keySet())
+ {
+ removedNodes.add(uuid);
+ addedNodes.add(uuid);
+ }
+
+ Iterator<NodeData> addedStates = new Iterator<NodeData>()
+ {
+ private final Iterator<String> iter = addedNodes.iterator();
+
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ public NodeData next()
+ {
+
+ // cycle till find a next or meet the end of set
+ do
+ {
+ String id = iter.next();
+ try
+ {
+ ItemData item = itemMgr.getItemData(id);
+ if (item != null)
+ {
+ if (item.isNode())
+ return (NodeData)item; // return node
+ else
+ log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
+ + " found. ");
+ }
+ else
+ log.warn("Unable to index node with id " + id + ", node does not exist.");
+
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Can't read next node data " + id, e);
+ }
+ }
+ while (iter.hasNext()); // get next if error or node not found
+
+ return null; // we met the end of iterator set
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ Iterator<String> removedIds = new Iterator<String>()
+ {
+ private final Iterator<String> iter = removedNodes.iterator();
+
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ public String next()
+ {
+ return nextNodeId();
+ }
+
+ public String nextNodeId() throws NoSuchElementException
+ {
+ return iter.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+ };
+
+ if (removedNodes.size() > 0 || addedNodes.size() > 0)
+ {
+ try
+ {
+ handler.updateNodes(removedIds, addedStates);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
+ }
+ }
+
+ public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
+ {
+ List<ItemState> list = updatedNodes.get(key);
+ if (list == null)
+ {
+ list = new ArrayList<ItemState>();
+ updatedNodes.put(key, list);
+ }
+ list.add(state);
+
+ }
+
+ public void start()
+ {
+
+ if (log.isDebugEnabled())
+ log.debug("start");
+ try
+ {
+ if (indexingTree == null)
+ {
+ List<QPath> excludedPath = new ArrayList<QPath>();
+ // Calculating excluded node identifiers
+ excludedPath.add(Constants.JCR_SYSTEM_PATH);
+
+ //if (config.getExcludedNodeIdentifers() != null)
+ String excludedNodeIdentifer =
+ config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
+ if (excludedNodeIdentifer != null)
+ {
+ StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
+ while (stringTokenizer.hasMoreTokens())
+ {
+
+ try
+ {
+ ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
+ if (excludeData != null)
+ excludedPath.add(excludeData.getQPath());
+ }
+ catch (RepositoryException e)
+ {
+ log.warn(e.getLocalizedMessage());
+ }
+ }
+ }
+
+ NodeData indexingRootData = null;
+ String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
+ if (rootNodeIdentifer != null)
+ {
+ try
+ {
+ ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
+ if (indexingRootDataItem != null && indexingRootDataItem.isNode())
+ indexingRootData = (NodeData)indexingRootDataItem;
+ }
+ catch (RepositoryException e)
+ {
+ log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
+
+ }
+
+ }
+ else
+ {
+ try
+ {
+ indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Fail to load root node data");
+ }
+ }
+
+ indexingTree = new IndexingTree(indexingRootData, excludedPath);
+ }
+
+ initializeQueryHandler();
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage());
+ handler = null;
+ throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ log.error(e.getLocalizedMessage());
+ handler = null;
+ throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
+ public void stop()
+ {
+ handler.close();
+ log.info("Search manager stopped");
+ }
+
+ // /**
+ // * Checks if the given event should be excluded based on the
+ // * {@link #excludePath} setting.
+ // *
+ // * @param event
+ // * observation event
+ // * @return <code>true</code> if the event should be excluded,
+ // * <code>false</code> otherwise
+ // */
+ // protected boolean isExcluded(ItemState event) {
+ //
+ // for (QPath excludedPath : excludedPaths) {
+ // if (event.getData().getQPath().isDescendantOf(excludedPath)
+ // || event.getData().getQPath().equals(excludedPath))
+ // return true;
+ // }
+ //
+ // return !event.getData().getQPath().isDescendantOf(indexingRoot)
+ // && !event.getData().getQPath().equals(indexingRoot);
+ // }
+
+ protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
+ throws RepositoryConfigurationException
+ {
+
+ QueryHandlerContext context =
+ new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
+ extractor, true, virtualTableResolver);
+ return context;
+ }
+
+ protected String getIndexDir() throws RepositoryConfigurationException
+ {
+ String dir = config.getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR, null);
+ if (dir == null)
+ {
+ log.warn(QueryHandlerParams.PARAM_INDEX_DIR + " parameter not found. Using outdated parameter name "
+ + QueryHandlerParams.OLD_PARAM_INDEX_DIR);
+ dir = config.getParameterValue(QueryHandlerParams.OLD_PARAM_INDEX_DIR);
+ }
+ return dir;
+ }
+
+ /**
+ * Initializes the query handler.
+ *
+ * @throws RepositoryException
+ * if the query handler cannot be initialized.
+ * @throws RepositoryConfigurationException
+ * @throws ClassNotFoundException
+ */
+ protected void initializeQueryHandler() throws RepositoryException, RepositoryConfigurationException
+ {
+ // initialize query handler
+ String className = config.getType();
+ if (className == null)
+ throw new RepositoryConfigurationException("Content hanler configuration fail");
+
+ try
+ {
+ Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
+ Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
+ handler = (QueryHandler)constuctor.newInstance(config, cfm);
+ QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
+ QueryHandlerContext context = createQueryHandlerContext(parentHandler);
+ handler.init(context);
+
+ }
+ catch (SecurityException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Creates a new instance of an {@link AbstractQueryImpl} which is not
+ * initialized.
+ *
+ * @return an new query instance.
+ * @throws RepositoryException
+ * if an error occurs while creating a new query instance.
+ */
+ protected AbstractQueryImpl createQueryInstance() throws RepositoryException
+ {
+ try
+ {
+ String queryImplClassName = handler.getQueryClass();
+ Object obj = Class.forName(queryImplClassName).newInstance();
+ if (obj instanceof AbstractQueryImpl)
+ {
+ return (AbstractQueryImpl)obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException(queryImplClassName + " is not of type "
+ + AbstractQueryImpl.class.getName());
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new RepositoryException("Unable to create query: " + t.toString(), t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getFieldNames() throws IndexException
+ {
+ final Set<String> fildsSet = new HashSet<String>();
+ if (handler instanceof SearchIndex)
+ {
+ IndexReader reader = null;
+ try
+ {
+ reader = ((SearchIndex)handler).getIndexReader();
+ final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
+ for (final Object field : fields)
+ {
+ fildsSet.add((String)field);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new IndexException(e.getLocalizedMessage(), e);
+ }
+ finally
+ {
+ try
+ {
+ if (reader != null)
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ throw new IndexException(e.getLocalizedMessage(), e);
+ }
+ }
+
+ }
+ return fildsSet;
+ }
+
+ public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
+ {
+
+ return getNodes(virtualTableResolver.resolve(nodeType, true));
+ }
+
+ /**
+ * Return set of uuid of nodes. Contains in names prefixes maped to the
+ * given uri
+ *
+ * @param prefix
+ * @return
+ * @throws RepositoryException
+ */
+ public Set<String> getNodesByUri(final String uri) throws RepositoryException
+ {
+ Set<String> result;
+ final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
+ try
+ {
+
+ // final LocationFactory locationFactory = new
+ // LocationFactory(this);
+ final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
+ BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
+ BooleanQuery query = new BooleanQuery();
+
+ final String prefix = nsReg.getNamespacePrefixByURI(uri);
+ query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
+ // name of the property
+ query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
+
+ result = getNodes(query);
+
+ // value of the property
+
+ try
+ {
+ final Set<String> props = getFieldNames();
+
+ query = new BooleanQuery();
+ for (final String fieldName : props)
+ {
+ if (!FieldNames.PROPERTIES_SET.equals(fieldName))
+ {
+ query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
+ }
+ }
+ }
+ catch (final IndexException e)
+ {
+ throw new RepositoryException(e.getLocalizedMessage(), e);
+ }
+
+ final Set<String> propSet = getNodes(query);
+ // Manually check property values;
+ for (final String uuid : propSet)
+ {
+ if (isPrefixMatch(valueFactory, uuid, prefix))
+ {
+ result.add(uuid);
+ }
+ }
+ }
+ finally
+ {
+ BooleanQuery.setMaxClauseCount(defaultClauseCount);
+ }
+
+ return result;
+ }
+
+ private boolean isPrefixMatch(final InternalQName value, final String prefix) throws RepositoryException
+ {
+ return value.getNamespace().equals(nsReg.getNamespaceURIByPrefix(prefix));
+ }
+
+ private boolean isPrefixMatch(final QPath value, final String prefix) throws RepositoryException
+ {
+ for (int i = 0; i < value.getEntries().length; i++)
+ {
+ if (isPrefixMatch(value.getEntries()[i], prefix))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param valueFactory
+ * @param dm
+ * @param uuid
+ * @param prefix
+ * @throws RepositoryException
+ */
+ private boolean isPrefixMatch(final ValueFactoryImpl valueFactory, final String uuid, final String prefix)
+ throws RepositoryException
+ {
+
+ final ItemData node = itemMgr.getItemData(uuid);
+ if (node != null && node.isNode())
+ {
+ final List<PropertyData> props = itemMgr.getChildPropertiesData((NodeData)node);
+ for (final PropertyData propertyData : props)
+ {
+ if (propertyData.getType() == PropertyType.PATH || propertyData.getType() == PropertyType.NAME)
+ {
+ for (final ValueData vdata : propertyData.getValues())
+ {
+ final Value val =
+ valueFactory.loadValue(((AbstractValueData)vdata).createTransientCopy(), propertyData.getType());
+ if (propertyData.getType() == PropertyType.PATH)
+ {
+ if (isPrefixMatch(((PathValue)val).getQPath(), prefix))
+ {
+ return true;
+ }
+ }
+ else if (propertyData.getType() == PropertyType.NAME)
+ {
+ if (isPrefixMatch(((NameValue)val).getQName(), prefix))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param query
+ * @return
+ * @throws RepositoryException
+ */
+ private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
+ {
+ Set<String> result = new HashSet<String>();
+ try
+ {
+ QueryHits hits = handler.executeQuery(query);
+
+ ScoreNode sn;
+
+ while ((sn = hits.nextScoreNode()) != null)
+ {
+ // Node node = session.getNodeById(sn.getNodeId());
+ result.add(sn.getNodeId());
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e.getLocalizedMessage(), e);
+ }
+ return result;
+ }
+
+}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2009-11-06 16:16:58 UTC (rev 492)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2009-11-06 16:18:11 UTC (rev 493)
@@ -42,7 +42,7 @@
* @version $Id: SystemSearchManager.java 13891 2008-05-05 16:02:30Z pnedonosko
* $
*/
-public class SystemSearchManager extends SearchManager
+public class SystemSearchManager extends SearchManagerImpl
{
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java 2009-11-06 16:16:58 UTC (rev 492)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/cacheloader/IndexerCacheLoader.java 2009-11-06 16:18:11 UTC (rev 493)
@@ -16,12 +16,76 @@
*/
package org.exoplatform.services.jcr.impl.core.query.cacheloader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.document.DocumentReaderService;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+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.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionDataManager;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.AbstractQueryImpl;
+import org.exoplatform.services.jcr.impl.core.query.IndexException;
+import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
+import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
+import org.exoplatform.services.jcr.impl.core.query.QueryHandlerContext;
+import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
+import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManagerHolder;
+import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
+import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
+import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ScoreNode;
+import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
+import org.exoplatform.services.jcr.impl.core.value.NameValue;
+import org.exoplatform.services.jcr.impl.core.value.PathValue;
+import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
+import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.StringTokenizer;
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+
/**
* Created by The eXo Platform SAS.
*
@@ -30,43 +94,886 @@
* @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
* @version $Id: CacheIndexer.java 111 2008-11-11 11:11:11Z serg $
*/
-public class IndexerCacheLoader extends AbstractWriteOnlyCacheLoader
+public class IndexerCacheLoader extends AbstractWriteOnlyCacheLoader implements SearchManager
{
+ /**
+ * Logger instance for this class
+ */
+ private static final Log log = ExoLogger.getLogger(IndexerCacheLoader.class);
+ protected QueryHandlerEntry config;
+
+ /**
+ * Text extractor for extracting text content of binary properties.
+ */
+ protected DocumentReaderService extractor;
+
+ /**
+ * QueryHandler where query execution is delegated to
+ */
+ protected QueryHandler handler;
+
+ /**
+ * The shared item state manager instance for the workspace.
+ */
+ protected ItemDataConsumer itemMgr;
+
+ /**
+ * The namespace registry of the repository.
+ */
+ protected NamespaceRegistryImpl nsReg;
+
+ /**
+ * The node type registry.
+ */
+ protected NodeTypeDataManager nodeTypeDataManager;
+
+ /**
+ * QueryHandler of the parent search manager or <code>null</code> if there
+ * is none.
+ */
+ protected SearchManager parentSearchManager;
+
+ // protected QPath indexingRoot;
+ //
+ // protected List<QPath> excludedPaths = new ArrayList<QPath>();
+
+ protected IndexingTree indexingTree;
+
+ private ConfigurationManager cfm;
+
+ protected LuceneVirtualTableResolver virtualTableResolver;
+
+ public IndexerCacheLoader()
+ {
+ int i = 0;
+ i++;
+ }
+
+ /**
+ * Creates a new <code>SearchManager</code>.
+ *
+ * @param config
+ * the search configuration.
+ * @param nsReg
+ * the namespace registry.
+ * @param ntReg
+ * the node type registry.
+ * @param itemMgr
+ * the shared item state manager.
+ * @param rootNodeId
+ * the id of the root node.
+ * @param parentMgr
+ * the parent search manager or <code>null</code> if there is no
+ * parent search manager.
+ * @param excludedNodeId
+ * id of the node that should be excluded from indexing. Any
+ * descendant of that node will also be excluded from indexing.
+ * @throws RepositoryException
+ * if the search manager cannot be initialized
+ * @throws RepositoryConfigurationException
+ */
+ public IndexerCacheLoader(QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
+ DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
+ throws RepositoryException, RepositoryConfigurationException
+ {
+
+ this.extractor = extractor;
+ indexSearcherHolder.addIndexSearcher(this);
+ this.config = config;
+ this.nodeTypeDataManager = ntReg;
+ this.nsReg = nsReg;
+ this.itemMgr = itemMgr;
+ this.cfm = cfm;
+ this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
+ this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
+ }
+
+ private String parseUUID(Fqn fqn)
+ {
+ // TODO check is zero element not ROOT
+ // get just uuid
+ Fqn uuid = (Fqn)fqn.get(1);
+ //remove slash
+ return uuid.toString().substring(1);
+ }
+
+ private boolean isNode(Fqn fqn)
+ {
+ Fqn items = (Fqn)fqn.get(0);
+ String s = items.toString();
+ //TODO check Constants
+ return s.equals("/$NODES");
+ }
+
@Override
public void put(List<Modification> modifications) throws Exception
{
+ if (handler == null)
+ return;
+
+ long time = System.currentTimeMillis();
+
+ // nodes that need to be removed from the index.
+ final Set<String> removedNodes = new HashSet<String>();
+ // nodes that need to be added to the index.
+ final Set<String> addedNodes = new HashSet<String>();
+ final Map<String, List<ItemState>> updatedNodes = new HashMap<String, List<ItemState>>();
+
for (Modification m : modifications)
{
+
+ String uuid = parseUUID(m.getFqn());
+
switch (m.getType())
{
case PUT_DATA :
- put(m.getFqn(), m.getData());
+ // add node
+ // TODO do we need there update for property?
+ // if this is property ignore
+ if (isNode(m.getFqn()))
+ {
+ addedNodes.add(uuid);
+ }
+
break;
case PUT_DATA_ERASE :
- removeData(m.getFqn());
- put(m.getFqn(), m.getData());
+ // must be never called
+ // update node
+ if (isNode(m.getFqn()))
+ {
+ removedNodes.add(uuid);
+ addedNodes.add(uuid);
+ }
break;
case PUT_KEY_VALUE :
- put(m.getFqn(), m.getKey(), m.getValue());
+ // must be never called
+ // update node
+ if (isNode(m.getFqn()))
+ {
+ removedNodes.add(uuid);
+ addedNodes.add(uuid);
+ }
break;
case REMOVE_DATA :
- removeData(m.getFqn());
+ // must be never called
+ // update node
+ if (isNode(m.getFqn()))
+ {
+ addedNodes.add(uuid);
+ removedNodes.add(uuid);
+ }
break;
case REMOVE_KEY_VALUE :
- remove(m.getFqn(), m.getKey());
+ // must be never called
+ // removed property what to do
+ if (isNode(m.getFqn()))
+ {
+ addedNodes.add(uuid);
+ removedNodes.add(uuid);
+ }
break;
case REMOVE_NODE :
- remove(m.getFqn());
+ // if node - remove it, otherwise ignore it
+ if (isNode(m.getFqn()))
+ {
+ removedNodes.add(uuid);
+ }
+
break;
case MOVE :
// involve moving all children too
move(m.getFqn(), m.getFqn2());
+ if (isNode(m.getFqn()))
+ {
+ //remove first
+ removedNodes.add(parseUUID(m.getFqn()));
+ //add second
+ addedNodes.add(parseUUID(m.getFqn2()));
+ }
+ else
+ {
+ // must be never happen
+ // TODO update both nodes
+ }
+
break;
default :
throw new CacheException("Unknown modification " + m.getType());
}
}
+
+ // for (Iterator<ItemState> iter = changesLog.getAllStates().iterator(); iter.hasNext();)
+ // {
+ // ItemState itemState = iter.next();
+ //
+ // if (!indexingTree.isExcluded(itemState))
+ // {
+ // String uuid =
+ // itemState.isNode() ? itemState.getData().getIdentifier() : itemState.getData().getParentIdentifier();
+ //
+ // if (itemState.isAdded())
+ // {
+ // if (itemState.isNode())
+ // {
+ // addedNodes.add(uuid);
+ // }
+ // else
+ // {
+ // if (!addedNodes.contains(uuid))
+ // {
+ // createNewOrAdd(uuid, itemState, updatedNodes);
+ // }
+ // }
+ // }
+ // else if (itemState.isRenamed())
+ // {
+ // if (itemState.isNode())
+ // {
+ // addedNodes.add(uuid);
+ // }
+ // else
+ // {
+ // createNewOrAdd(uuid, itemState, updatedNodes);
+ // }
+ // }
+ // else if (itemState.isUpdated())
+ // {
+ // createNewOrAdd(uuid, itemState, updatedNodes);
+ // }
+ // else if (itemState.isMixinChanged())
+ // {
+ // createNewOrAdd(uuid, itemState, updatedNodes);
+ // }
+ // else if (itemState.isDeleted())
+ // {
+ // if (itemState.isNode())
+ // {
+ // if (addedNodes.contains(uuid))
+ // {
+ // addedNodes.remove(uuid);
+ // removedNodes.remove(uuid);
+ // }
+ // else
+ // {
+ // removedNodes.add(uuid);
+ // }
+ // // remove all changes after node remove
+ // updatedNodes.remove(uuid);
+ // }
+ // else
+ // {
+ // if (!removedNodes.contains(uuid) && !addedNodes.contains(uuid))
+ // {
+ // createNewOrAdd(uuid, itemState, updatedNodes);
+ // }
+ // }
+ // }
+ // }
+ // }
+
+ // TODO make quick changes
+ for (String uuid : updatedNodes.keySet())
+ {
+ removedNodes.add(uuid);
+ addedNodes.add(uuid);
+ }
+
+ Iterator<NodeData> addedStates = new Iterator<NodeData>()
+ {
+ private final Iterator<String> iter = addedNodes.iterator();
+
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ public NodeData next()
+ {
+
+ // cycle till find a next or meet the end of set
+ do
+ {
+ String id = iter.next();
+ try
+ {
+ ItemData item = itemMgr.getItemData(id);
+ if (item != null)
+ {
+ if (item.isNode())
+ return (NodeData)item; // return node
+ else
+ log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
+ + " found. ");
+ }
+ else
+ log.warn("Unable to index node with id " + id + ", node does not exist.");
+
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Can't read next node data " + id, e);
+ }
+ }
+ while (iter.hasNext()); // get next if error or node not found
+
+ return null; // we met the end of iterator set
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ Iterator<String> removedIds = new Iterator<String>()
+ {
+ private final Iterator<String> iter = removedNodes.iterator();
+
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ public String next()
+ {
+ return nextNodeId();
+ }
+
+ public String nextNodeId() throws NoSuchElementException
+ {
+ return iter.next();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+ };
+
+ if (removedNodes.size() > 0 || addedNodes.size() > 0)
+ {
+ try
+ {
+ handler.updateNodes(removedIds, addedStates);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
+ }
+
}
+ /**
+ * Creates a query object from a node that can be executed on the workspace.
+ *
+ * @param session
+ * the session of the user executing the query.
+ * @param itemMgr
+ * the item manager of the user executing the query. Needed to
+ * return <code>Node</code> instances in the result set.
+ * @param node
+ * a node of type nt:query.
+ * @return a <code>Query</code> instance to execute.
+ * @throws InvalidQueryException
+ * if <code>absPath</code> is not a valid persisted query (that
+ * is, a node of type nt:query)
+ * @throws RepositoryException
+ * if any other error occurs.
+ */
+ public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, Node node)
+ throws InvalidQueryException, RepositoryException
+ {
+ AbstractQueryImpl query = createQueryInstance();
+ query.init(session, sessionDataManager, handler, node);
+ return query;
+ }
+
+ /**
+ * Creates a query object that can be executed on the workspace.
+ *
+ * @param session
+ * the session of the user executing the query.
+ * @param itemMgr
+ * the item manager of the user executing the query. Needed to
+ * return <code>Node</code> instances in the result set.
+ * @param statement
+ * the actual query statement.
+ * @param language
+ * the syntax of the query statement.
+ * @return a <code>Query</code> instance to execute.
+ * @throws InvalidQueryException
+ * if the query is malformed or the <code>language</code> is
+ * unknown.
+ * @throws RepositoryException
+ * if any other error occurs.
+ */
+ public Query createQuery(SessionImpl session, SessionDataManager sessionDataManager, String statement,
+ String language) throws InvalidQueryException, RepositoryException
+ {
+ AbstractQueryImpl query = createQueryInstance();
+ query.init(session, sessionDataManager, handler, statement, language);
+ return query;
+ }
+
+ /**
+ * just for test use only
+ */
+ public QueryHandler getHandler()
+ {
+ return handler;
+ }
+
+ public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
+ {
+ List<ItemState> list = updatedNodes.get(key);
+ if (list == null)
+ {
+ list = new ArrayList<ItemState>();
+ updatedNodes.put(key, list);
+ }
+ list.add(state);
+
+ }
+
+ public void start()
+ {
+
+ if (log.isDebugEnabled())
+ log.debug("start");
+ try
+ {
+ if (indexingTree == null)
+ {
+ List<QPath> excludedPath = new ArrayList<QPath>();
+ // Calculating excluded node identifiers
+ excludedPath.add(Constants.JCR_SYSTEM_PATH);
+
+ //if (config.getExcludedNodeIdentifers() != null)
+ String excludedNodeIdentifer =
+ config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
+ if (excludedNodeIdentifer != null)
+ {
+ StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
+ while (stringTokenizer.hasMoreTokens())
+ {
+
+ try
+ {
+ ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
+ if (excludeData != null)
+ excludedPath.add(excludeData.getQPath());
+ }
+ catch (RepositoryException e)
+ {
+ log.warn(e.getLocalizedMessage());
+ }
+ }
+ }
+
+ NodeData indexingRootData = null;
+ String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
+ if (rootNodeIdentifer != null)
+ {
+ try
+ {
+ ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
+ if (indexingRootDataItem != null && indexingRootDataItem.isNode())
+ indexingRootData = (NodeData)indexingRootDataItem;
+ }
+ catch (RepositoryException e)
+ {
+ log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
+
+ }
+
+ }
+ else
+ {
+ try
+ {
+ indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Fail to load root node data");
+ }
+ }
+
+ indexingTree = new IndexingTree(indexingRootData, excludedPath);
+ }
+
+ initializeQueryHandler();
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e.getLocalizedMessage());
+ handler = null;
+ throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ log.error(e.getLocalizedMessage());
+ handler = null;
+ throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
+ public void stop()
+ {
+ handler.close();
+ log.info("Search manager stopped");
+ }
+
+ // /**
+ // * Checks if the given event should be excluded based on the
+ // * {@link #excludePath} setting.
+ // *
+ // * @param event
+ // * observation event
+ // * @return <code>true</code> if the event should be excluded,
+ // * <code>false</code> otherwise
+ // */
+ // protected boolean isExcluded(ItemState event) {
+ //
+ // for (QPath excludedPath : excludedPaths) {
+ // if (event.getData().getQPath().isDescendantOf(excludedPath)
+ // || event.getData().getQPath().equals(excludedPath))
+ // return true;
+ // }
+ //
+ // return !event.getData().getQPath().isDescendantOf(indexingRoot)
+ // && !event.getData().getQPath().equals(indexingRoot);
+ // }
+
+ protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
+ throws RepositoryConfigurationException
+ {
+
+ QueryHandlerContext context =
+ new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
+ extractor, true, virtualTableResolver);
+ return context;
+ }
+
+ protected String getIndexDir() throws RepositoryConfigurationException
+ {
+ String dir = config.getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR, null);
+ if (dir == null)
+ {
+ log.warn(QueryHandlerParams.PARAM_INDEX_DIR + " parameter not found. Using outdated parameter name "
+ + QueryHandlerParams.OLD_PARAM_INDEX_DIR);
+ dir = config.getParameterValue(QueryHandlerParams.OLD_PARAM_INDEX_DIR);
+ }
+ return dir;
+ }
+
+ /**
+ * Initializes the query handler.
+ *
+ * @throws RepositoryException
+ * if the query handler cannot be initialized.
+ * @throws RepositoryConfigurationException
+ * @throws ClassNotFoundException
+ */
+ protected void initializeQueryHandler() throws RepositoryException, RepositoryConfigurationException
+ {
+ // initialize query handler
+ String className = config.getType();
+ if (className == null)
+ throw new RepositoryConfigurationException("Content hanler configuration fail");
+
+ try
+ {
+ Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
+ Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
+ handler = (QueryHandler)constuctor.newInstance(config, cfm);
+ QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
+ QueryHandlerContext context = createQueryHandlerContext(parentHandler);
+ handler.init(context);
+
+ }
+ catch (SecurityException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Creates a new instance of an {@link AbstractQueryImpl} which is not
+ * initialized.
+ *
+ * @return an new query instance.
+ * @throws RepositoryException
+ * if an error occurs while creating a new query instance.
+ */
+ protected AbstractQueryImpl createQueryInstance() throws RepositoryException
+ {
+ try
+ {
+ String queryImplClassName = handler.getQueryClass();
+ Object obj = Class.forName(queryImplClassName).newInstance();
+ if (obj instanceof AbstractQueryImpl)
+ {
+ return (AbstractQueryImpl)obj;
+ }
+ else
+ {
+ throw new IllegalArgumentException(queryImplClassName + " is not of type "
+ + AbstractQueryImpl.class.getName());
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new RepositoryException("Unable to create query: " + t.toString(), t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getFieldNames() throws IndexException
+ {
+ final Set<String> fildsSet = new HashSet<String>();
+ if (handler instanceof SearchIndex)
+ {
+ IndexReader reader = null;
+ try
+ {
+ reader = ((SearchIndex)handler).getIndexReader();
+ final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
+ for (final Object field : fields)
+ {
+ fildsSet.add((String)field);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new IndexException(e.getLocalizedMessage(), e);
+ }
+ finally
+ {
+ try
+ {
+ if (reader != null)
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ throw new IndexException(e.getLocalizedMessage(), e);
+ }
+ }
+
+ }
+ return fildsSet;
+ }
+
+ public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
+ {
+
+ return getNodes(virtualTableResolver.resolve(nodeType, true));
+ }
+
+ /**
+ * Return set of uuid of nodes. Contains in names prefixes maped to the
+ * given uri
+ *
+ * @param prefix
+ * @return
+ * @throws RepositoryException
+ */
+ public Set<String> getNodesByUri(final String uri) throws RepositoryException
+ {
+ Set<String> result;
+ final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
+ try
+ {
+
+ // final LocationFactory locationFactory = new
+ // LocationFactory(this);
+ final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
+ BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
+ BooleanQuery query = new BooleanQuery();
+
+ final String prefix = nsReg.getNamespacePrefixByURI(uri);
+ query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
+ // name of the property
+ query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
+
+ result = getNodes(query);
+
+ // value of the property
+
+ try
+ {
+ final Set<String> props = getFieldNames();
+
+ query = new BooleanQuery();
+ for (final String fieldName : props)
+ {
+ if (!FieldNames.PROPERTIES_SET.equals(fieldName))
+ {
+ query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
+ }
+ }
+ }
+ catch (final IndexException e)
+ {
+ throw new RepositoryException(e.getLocalizedMessage(), e);
+ }
+
+ final Set<String> propSet = getNodes(query);
+ // Manually check property values;
+ for (final String uuid : propSet)
+ {
+ if (isPrefixMatch(valueFactory, uuid, prefix))
+ {
+ result.add(uuid);
+ }
+ }
+ }
+ finally
+ {
+ BooleanQuery.setMaxClauseCount(defaultClauseCount);
+ }
+
+ return result;
+ }
+
+ private boolean isPrefixMatch(final InternalQName value, final String prefix) throws RepositoryException
+ {
+ return value.getNamespace().equals(nsReg.getNamespaceURIByPrefix(prefix));
+ }
+
+ private boolean isPrefixMatch(final QPath value, final String prefix) throws RepositoryException
+ {
+ for (int i = 0; i < value.getEntries().length; i++)
+ {
+ if (isPrefixMatch(value.getEntries()[i], prefix))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param valueFactory
+ * @param dm
+ * @param uuid
+ * @param prefix
+ * @throws RepositoryException
+ */
+ private boolean isPrefixMatch(final ValueFactoryImpl valueFactory, final String uuid, final String prefix)
+ throws RepositoryException
+ {
+
+ final ItemData node = itemMgr.getItemData(uuid);
+ if (node != null && node.isNode())
+ {
+ final List<PropertyData> props = itemMgr.getChildPropertiesData((NodeData)node);
+ for (final PropertyData propertyData : props)
+ {
+ if (propertyData.getType() == PropertyType.PATH || propertyData.getType() == PropertyType.NAME)
+ {
+ for (final ValueData vdata : propertyData.getValues())
+ {
+ final Value val =
+ valueFactory.loadValue(((AbstractValueData)vdata).createTransientCopy(), propertyData.getType());
+ if (propertyData.getType() == PropertyType.PATH)
+ {
+ if (isPrefixMatch(((PathValue)val).getQPath(), prefix))
+ {
+ return true;
+ }
+ }
+ else if (propertyData.getType() == PropertyType.NAME)
+ {
+ if (isPrefixMatch(((NameValue)val).getQName(), prefix))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param query
+ * @return
+ * @throws RepositoryException
+ */
+ private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
+ {
+ Set<String> result = new HashSet<String>();
+ try
+ {
+ QueryHits hits = handler.executeQuery(query);
+
+ ScoreNode sn;
+
+ while ((sn = hits.nextScoreNode()) != null)
+ {
+ // Node node = session.getNodeById(sn.getNodeId());
+ result.add(sn.getNodeId());
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e.getLocalizedMessage(), e);
+ }
+ return result;
+ }
+
}
16 years, 8 months
exo-jcr SVN: r492 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/dataflow and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-06 11:16:58 -0500 (Fri, 06 Nov 2009)
New Revision: 492
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
Log:
EXOJCR-201 : In TransientValueData was changed serialization mechanism and added test TestTransientVAlueDataSerialization.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-11-06 16:14:01 UTC (rev 491)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-11-06 16:16:58 UTC (rev 492)
@@ -928,8 +928,26 @@
}
else
{
+ // write streams
out.writeInt(2);
+ //TODO Need optimization in backup service.
+ byte[] buf = new byte[4*1024];
+
+ if (!spooled)
+ spoolInputStream();
+ InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
+ long dataLength = (spoolFile == null ? data.length : spoolFile.length());
+ int len;
+
+ //write length of spoolFile
+ out.writeLong(dataLength);
+
+ while ((len = in.read(buf)) > 0)
+ out.write(buf, 0, len);
+
+ in.close();
}
+
out.writeInt(orderNumber);
out.writeInt(maxBufferSize);
}
@@ -946,6 +964,37 @@
data = new byte[in.readInt()];
in.readFully(data);
}
+ else
+ {
+ //read file form stream
+ long lengthSpoolFile = in.readLong();
+
+ //TODO May be optimization.
+ SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
+ sf.acquire(this);
+ OutputStream outStream = new FileOutputStream(sf);
+
+ byte[] buf = new byte[4*1024];
+
+ while (lengthSpoolFile > 0) {
+ if (lengthSpoolFile - buf.length > 0)
+ {
+ in.readFully(buf);
+ outStream.write(buf);
+ }
+ else
+ {
+ in.readFully(buf, 0, (int) lengthSpoolFile);
+ outStream.write(buf, 0, (int) lengthSpoolFile);
+ }
+ lengthSpoolFile-=buf.length;
+ }
+ outStream.flush();
+ outStream.close();
+ spoolFile = sf;
+ spooled = true;
+ }
+
orderNumber = in.readInt();
maxBufferSize = in.readInt();
}
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-11-06 16:16:58 UTC (rev 492)
@@ -0,0 +1,103 @@
+/*
+ * 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.dataflow;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestTransientValueDataSerialization
+ extends JcrImplBaseTest
+{
+
+ public void testTVDSerialization() throws Exception
+ {
+ File f = createBLOBTempFile(145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+
+ File out = File.createTempFile("test", ".data");
+ f.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+
+ public void testTVDSerialization2M() throws Exception
+ {
+ File f = createBLOBTempFile(2145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+ File out = File.createTempFile("test", ".data");
+ f.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
16 years, 8 months
exo-jcr SVN: r491 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl: storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2009-11-06 11:14:01 -0500 (Fri, 06 Nov 2009)
New Revision: 491
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
Log:
EXOJCR-205: first implementation LockCacheLoader
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-06 16:02:42 UTC (rev 490)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockManagerImpl.java 2009-11-06 16:14:01 UTC (rev 491)
@@ -375,6 +375,7 @@
* @seeorg.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener#onSaveItems(org.
* exoplatform.services.jcr.dataflow.ItemStateChangesLog)
*/
+ @Deprecated
public void onSaveItems(ItemStateChangesLog changesLog)
{
List<PlainChangesLog> chengesLogList = new ArrayList<PlainChangesLog>();
@@ -680,8 +681,10 @@
*
* @param nodeIdentifier
* @throws LockException
+ *
+ * TODO: Changed from private to public. Need for LockCacheLoader.
*/
- private synchronized void internalLock(String nodeIdentifier) throws LockException
+ public synchronized void internalLock(String nodeIdentifier) throws LockException
{
LockData ldata = pendingLocks.get(nodeIdentifier);
if (ldata != null)
@@ -741,8 +744,10 @@
* @param owner
* String
* @return LockData
+ *
+ * TODO: Changed from private to public. Need for LockCacheLoader.
*/
- private synchronized LockData createRemoteLock(String sessionId, String nodeIdentifier, String lockToken,
+ public synchronized LockData createRemoteLock(String sessionId, String nodeIdentifier, String lockToken,
boolean isDeep, boolean sessionScoped, String owner)
{
LockData lData = new LockData(nodeIdentifier, lockToken, isDeep, sessionScoped, owner, lockTimeOut);
@@ -799,4 +804,12 @@
{
removeExpired();
}
+
+ /**
+ * TODO: Added. Need for LockCacheLoader..
+ */
+ public boolean hasPendingLocks(String nodeIdentifier)
+ {
+ return pendingLocks.containsKey(nodeIdentifier);
+ }
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-06 16:02:42 UTC (rev 490)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/LockCacheLoader.java 2009-11-06 16:14:01 UTC (rev 491)
@@ -16,9 +16,15 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.lock.LockManager;
+import org.exoplatform.services.jcr.impl.core.lock.LockManagerImpl;
import org.jboss.cache.CacheException;
import org.jboss.cache.Modification;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -32,43 +38,78 @@
public class LockCacheLoader extends AbstractWriteOnlyCacheLoader
{
+ private LockManagerImpl lockManager;
+
/**
* {@inheritDoc}
*/
@Override
public void put(List<Modification> modifications) throws Exception
{
+ LockChanges lockChanges = new LockChanges();
+
for (Modification m : modifications)
{
- switch (m.getType())
+ // TODO $properties
+ if (m.getFqn().hasElement(JBossCacheStorage.PROPS))
{
- case PUT_DATA :
- // put(m.getFqn(), m.getData());
- break;
- case PUT_DATA_ERASE :
- // removeData(m.getFqn());
- // put(m.getFqn(), m.getData());
- break;
- case PUT_KEY_VALUE :
- // put(m.getFqn(), m.getKey(), m.getValue());
- break;
- case REMOVE_DATA :
- // removeData(m.getFqn());
- break;
- case REMOVE_KEY_VALUE :
- // remove(m.getFqn(), m.getKey());
- break;
- case REMOVE_NODE :
- // remove(m.getFqn());
- break;
- case MOVE :
- // involve moving all children too
- // move(m.getFqn(), m.getFqn2());
- break;
- default :
- throw new CacheException("Unknown modification " + m.getType());
+ switch (m.getType())
+ {
+ case PUT_DATA :
+ break;
+ case PUT_KEY_VALUE :
+ if (m.getKey().equals(JBossCacheStorage.ITEM_DATA))
+ {
+ PropertyData propertyData = (PropertyData)m.getValue();
+ InternalQName propertyName = propertyData.getQPath().getName();
+
+ if (propertyName.equals(Constants.JCR_LOCKISDEEP) || propertyName.equals(Constants.JCR_LOCKOWNER))
+ {
+ }
+ }
+ break;
+ case REMOVE_DATA :
+ break;
+ case REMOVE_KEY_VALUE :
+ break;
+ case REMOVE_NODE :
+ break;
+ case MOVE :
+ break;
+ default :
+ throw new CacheException("Unknown modification " + m.getType());
+ }
}
}
}
+ private void processLock()
+ {
+ // String nodeIdentifier = data.getParentIdentifier();
+ // if (lockManager.hasPendingLocks(nodeIdentifier))
+ // {
+ // lockManager.internalLock(nodeIdentifier);
+ // }
+ // else
+ // {
+ //
+ // }
+ }
+
+ private void processUnLock()
+ {
+
+ }
+
+ /**
+ *
+ */
+ private class LockChanges
+ {
+ PropertyData lockIsDeepData;
+
+ PropertyData lockOwnerData;
+
+ }
+
}
16 years, 8 months
exo-jcr SVN: r490 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl: storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-06 11:02:42 -0500 (Fri, 06 Nov 2009)
New Revision: 490
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
Log:
EXOJCR-204:Observation manager refactored
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-11-06 16:02:42 UTC (rev 490)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core.observation;
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
@@ -64,12 +65,16 @@
private final SessionRegistry sessionRegistry;
+ private final NodeTypeDataManager ntManager;
+
+
public ActionLauncher(ObservationManagerRegistry registry, WorkspacePersistentDataManager workspaceDataManager,
- SessionRegistry sessionRegistry)
+ NodeTypeDataManager ntManager, SessionRegistry sessionRegistry)
{
this.observationRegistry = registry;
this.workspaceDataManager = workspaceDataManager;
this.sessionRegistry = sessionRegistry;
+ this.ntManager = ntManager;
this.workspaceDataManager.addItemPersistenceListener(this);
}
@@ -104,9 +109,8 @@
try
{
int eventType = eventType(itemState);
- if (eventType != SKIP_EVENT && isTypeMatch(criteria, eventType)
- && isPathMatch(criteria, item, userSession) && isIdentifierMatch(criteria, item)
- && isNodeTypeMatch(criteria, item, userSession, subLog)
+ if (eventType != SKIP_EVENT && isTypeMatch(criteria, eventType) && isPathMatch(criteria, item)
+ && isIdentifierMatch(criteria, item) && isNodeTypeMatch(criteria, item, subLog)
&& isSessionMatch(criteria, sessionId))
{
@@ -146,25 +150,15 @@
return true;
}
- private boolean isPathMatch(ListenerCriteria criteria, ItemData item, SessionImpl userSession)
+ private boolean isPathMatch(ListenerCriteria criteria, ItemData item)
{
if (criteria.getAbsPath() == null)
return true;
- try
- {
- QPath cLoc = userSession.getLocationFactory().parseAbsPath(criteria.getAbsPath()).getInternalPath();
+ // 8.3.3 Only events whose associated parent node is at absPath (or
+ // within its subtree, if isDeep is true) will be received.
+ QPath itemPath = item.getQPath();
- // 8.3.3 Only events whose associated parent node is at absPath (or
- // within its subtree, if isDeep is true) will be received.
-
- QPath itemPath = item.getQPath();
-
- return itemPath.isDescendantOf(cLoc, !criteria.isDeep());
- }
- catch (RepositoryException e)
- {
- return false;
- }
+ return itemPath.isDescendantOf(criteria.getAbsPath(), !criteria.isDeep());
}
private boolean isIdentifierMatch(ListenerCriteria criteria, ItemData item)
@@ -185,8 +179,8 @@
}
- private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, SessionImpl userSession,
- PlainChangesLog changesLog) throws RepositoryException
+ private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, PlainChangesLog changesLog)
+ throws RepositoryException
{
if (criteria.getNodeTypeName() == null)
return true;
@@ -214,12 +208,9 @@
}
}
- NodeTypeDataManager ntManager = userSession.getWorkspace().getNodeTypesHolder();
- LocationFactory locationFactory = userSession.getLocationFactory();
for (int i = 0; i < criteria.getNodeTypeName().length; i++)
{
- InternalQName name = locationFactory.parseJCRName(criteria.getNodeTypeName()[i]).getInternalName();
- NodeTypeData criteriaNT = ntManager.getNodeType(name);
+ NodeTypeData criteriaNT = ntManager.getNodeType(criteria.getNodeTypeName()[i]);
InternalQName[] testQNames;
if (criteriaNT.isMixin())
{
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java 2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java 2009-11-06 16:02:42 UTC (rev 490)
@@ -18,7 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.core.observation;
-import javax.jcr.RepositoryException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
/**
* Created by The eXo Platform SAS.
@@ -32,20 +33,20 @@
private int eventTypes;
- private String absPath;
+ private QPath absPath;
private boolean deep;
private String[] identifier;
- private String[] nodeTypeName;
+ private InternalQName[] nodeTypeName;
private boolean noLocal;
private String sessionId;
- public ListenerCriteria(int eventTypes, String absPath, boolean isDeep, String[] identifier, String[] nodeTypeName,
- boolean noLocal, String sessionId) throws RepositoryException
+ public ListenerCriteria(int eventTypes, QPath absPath, boolean isDeep, String[] identifier, InternalQName[] nodeTypeName,
+ boolean noLocal, String sessionId)
{
this.eventTypes = eventTypes;
this.absPath = absPath;
@@ -61,7 +62,7 @@
return this.eventTypes;
}
- public String getAbsPath()
+ public QPath getAbsPath()
{
return this.absPath;
}
@@ -76,7 +77,7 @@
return this.identifier;
}
- public String[] getNodeTypeName()
+ public InternalQName[] getNodeTypeName()
{
return this.nodeTypeName;
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java 2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java 2009-11-06 16:02:42 UTC (rev 490)
@@ -20,6 +20,10 @@
import org.exoplatform.services.jcr.core.ExtendedSession;
import org.exoplatform.services.jcr.core.SessionLifecycleListener;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.util.EntityCollection;
import java.util.ArrayList;
@@ -46,15 +50,19 @@
private ObservationManagerRegistry registry;
+ private SessionRegistry sessionRegistry;
+
/**
* Protected constructor for subclasses
*
* @param session
*/
- ObservationManagerImpl(ObservationManagerRegistry registry, String sessionId)
+ ObservationManagerImpl(ObservationManagerRegistry registry, String sessionId, SessionRegistry sessionRegistry)
{
this.sessionId = sessionId;
this.registry = registry;
+
+ this.sessionRegistry = sessionRegistry;
}
/**
@@ -64,7 +72,23 @@
String[] nodeTypeName, boolean noLocal) throws RepositoryException
{
- registry.addEventListener(listener, new ListenerCriteria(eventTypes, absPath, isDeep, uuid, nodeTypeName,
+ // Convert all strings to internal view
+ QPath absQPath =
+ sessionRegistry.getSession(sessionId).getLocationFactory().parseAbsPath(absPath).getInternalPath();
+
+ InternalQName[] nodeTypeNames = null;
+
+ if (nodeTypeName != null && nodeTypeName.length > 0)
+ {
+ nodeTypeNames = new InternalQName[nodeTypeName.length];
+ LocationFactory locationFactory = sessionRegistry.getSession(sessionId).getLocationFactory();
+ for (int i = 0; i < nodeTypeNames.length; i++)
+ {
+ nodeTypeNames[i] = locationFactory.parseJCRName(nodeTypeName[i]).getInternalName();
+ }
+ }
+
+ registry.addEventListener(listener, new ListenerCriteria(eventTypes, absQPath, isDeep, uuid, nodeTypeNames,
noLocal, sessionId));
sessionListeners.add(listener);
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-06 16:02:42 UTC (rev 490)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.core.observation;
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -49,17 +51,26 @@
protected ActionLauncher launcher;
+
+ protected SessionRegistry sessionRegistry;
+
+ protected NamespaceAccessor namespaceAccessor;
+
+ protected NodeTypeDataManager nodeTypeDataManager;
+
public ObservationManagerRegistry(WorkspacePersistentDataManager workspaceDataManager,
- SessionRegistry sessionRegistry)
+ SessionRegistry sessionRegistry, NamespaceAccessor namespaceAccessor)
{
-
+ this.sessionRegistry = sessionRegistry;
this.listenersMap = new HashMap<EventListener, ListenerCriteria>();
- this.launcher = new ActionLauncher(this, workspaceDataManager, sessionRegistry);
+ this.namespaceAccessor = namespaceAccessor;
+ //this.nodeTypeDataManager = nodeTypeDataManager;
+ this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
}
public ObservationManagerImpl createObservationManager(SessionImpl session)
{
- return new ObservationManagerImpl(this, session.getId());
+ return new ObservationManagerImpl(this, session.getId(), sessionRegistry);
}
public void addEventListener(EventListener listener, ListenerCriteria filter)
@@ -100,5 +111,11 @@
listenersMap.remove(listener);
}
}
+
+ public ActionLauncher getLauncher()
+ {
+ return launcher;
+ }
+
}
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-06 16:02:42 UTC (rev 490)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.jboss.cache.Modification;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: ObservationCacheLoader.java 34360 2009-07-22 23:58:59Z aheritier $
+ *
+ */
+public class ObservationCacheLoader extends AbstractWriteOnlyCacheLoader
+{
+ private final ObservationManagerRegistry observationManagerRegistry;
+
+ /**
+ *
+ */
+ public ObservationCacheLoader(ObservationManagerRegistry observationManagerRegistry)
+ {
+ this.observationManagerRegistry = observationManagerRegistry;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
+ */
+ @Override
+ public void put(List<Modification> modifications) throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 8 months
exo-jcr SVN: r489 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-06 10:54:46 -0500 (Fri, 06 Nov 2009)
New Revision: 489
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
Log:
EXOJCR-200: new impl
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 15:51:12 UTC (rev 488)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 15:54:46 UTC (rev 489)
@@ -88,9 +88,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
-
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
@@ -118,9 +116,7 @@
startBatch();
// check if parent is cached
- Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
-
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
@@ -145,9 +141,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
-
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
@@ -171,9 +165,7 @@
startBatch();
// check if parent is cached
- Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
-
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ Node<Serializable, Object> parent = cache.getNode(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
16 years, 8 months
exo-jcr SVN: r488 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-06 10:51:12 -0500 (Fri, 06 Nov 2009)
New Revision: 488
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorage.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnectionTest.java
Log:
EXOJCR-200: new impl of ADD, REMOVE, UPDATE and GETs
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -39,7 +39,10 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import java.io.Serializable;
+
/**
* Created by The eXo Platform SAS.
*
@@ -51,85 +54,74 @@
public abstract class JBossCacheStorage
{
- @Deprecated
- public static final String TREE = "$TREE".intern();
+ public static final String NODES = "$NODES".intern();
+
+ public static final String PROPS = "$PROPS".intern();
- public static final String ITEMS = "$ITEMS".intern();
-
public static final String ITEM_DATA = "$data".intern();
public static final String ITEM_ID = "$id".intern();
- @Deprecated
- protected final Fqn<String> treeRoot;
+ protected final Node<Serializable, Object> nodesRoot;
+
+ protected final Node<Serializable, Object> propsRoot;
- protected final Fqn<String> itemsRoot;
-
- @Deprecated
- protected JBossCacheStorage(Fqn<String> treeRoot, Fqn<String> itemsRoot)
+ protected JBossCacheStorage(Node<Serializable, Object> nodesRoot, Node<Serializable, Object> propsRoot)
{
- this.itemsRoot = itemsRoot;
+ this.nodesRoot = nodesRoot;
- this.treeRoot = treeRoot;
+ this.propsRoot = propsRoot;
}
- protected JBossCacheStorage(Fqn<String> itemsRoot)
+ /**
+ * Make Child Node relative Fqn, i.e. ./NIDxxx/NAMExxx.
+ *
+ * @param parentId String
+ * @param nodeName QPathEntry
+ * @return Fqn
+ */
+ protected Fqn<String> makeChildNodeFqn(String parentId, QPathEntry nodeName)
{
- this.itemsRoot = itemsRoot;
-
- this.treeRoot = null;
+ //return Fqn.fromRelativeFqn(nodesRoot, Fqn.fromElements(parentId, itemName.getAsString(true)));
+ //return Fqn.fromRelativeFqn(nodesRoot.getFqn(), Fqn.fromElements(parentId, nodeName.getAsString(true)));
+ return Fqn.fromElements(parentId, nodeName.getAsString(true));
}
-
- @Deprecated
- protected Fqn<String> makeNodeFqn(QPath nodePath)
+
+ /**
+ * Make Child Node relative Fqn. i.e. ./NAMExxx.
+ *
+ * @param nodeName QPathEntry
+ * @return Fqn
+ */
+ protected Fqn<String> makeChildNodeFqn(QPathEntry nodeName)
{
- QPathEntry[] path = nodePath.getEntries();
- String[] fqns = new String[path.length];
-
- for (int i = 0; i < path.length; i++)
- {
- fqns[i] = path[i].getAsString(true);
- }
-
- return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(fqns));
+ return Fqn.fromElements(nodeName.getAsString(true));
}
- @Deprecated
- protected Fqn<String> makeParentFqn(QPath propertyPath)
- {
- QPathEntry[] path = propertyPath.getEntries();
- int pathLen = path.length - 1;
- String[] fqns = new String[pathLen];
- for (int i = 0; i < pathLen; i++)
- {
- fqns[i] = path[i].getAsString(true);
- }
- return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(fqns));
- }
-
/**
- * Make Child Node Fqn, i.e. /IDxxx/NAMExxx.
+ * Make Node relative Fqn, i.e. ./NIDxxx.
*
- * @param parentId String
- * @param itemName QPathEntry
+ * @param nodeId String
* @return Fqn
*/
- protected Fqn<String> makeChildNodeFqn(String parentId, QPathEntry itemName)
+ protected Fqn<String> makeNodeFqn(String nodeId)
{
- return Fqn.fromRelativeFqn(itemsRoot, Fqn.fromElements(parentId, itemName.getAsString(true)));
+ //return Fqn.fromRelativeFqn(nodesRoot, Fqn.fromElements(nodeId));
+ return Fqn.fromElements(nodeId);
}
/**
- * Make Item Fqn, i.e. /IDxxx.
+ * Make Property relative Fqn, i.e. ./PIDxxx.
*
- * @param itemId String
+ * @param propId String
* @return Fqn
*/
- protected Fqn<String> makeItemFqn(String itemId)
+ protected Fqn<String> makePropFqn(String propId)
{
- return Fqn.fromRelativeFqn(itemsRoot, Fqn.fromString(itemId));
+ //return Fqn.fromRelativeFqn(propsRoot, Fqn.fromElements(propId));
+ return Fqn.fromElements(propId);
}
-
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -18,17 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-
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.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
@@ -37,6 +30,13 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -69,9 +69,10 @@
*
* @param cache Cache<Serializable, Object>
*/
- public JBossCacheStorageConnection(Cache<Serializable, Object> cache, Node<Serializable, Object> itemsRoot)
+ public JBossCacheStorageConnection(Cache<Serializable, Object> cache, Node<Serializable, Object> nodesRoot,
+ Node<Serializable, Object> propsRoot)
{
- super(itemsRoot.getFqn());
+ super(nodesRoot, propsRoot);
this.cache = cache;
}
@@ -83,8 +84,29 @@
IllegalStateException
{
startBatch();
- //cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
- //cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data); // treePrint(treeRoot);
+
+ if (data.getParentIdentifier() != null)
+ {
+ // check if parent is cached
+ Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
+
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent == null)
+ {
+ throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // add child to Parent
+ Node<Serializable, Object> childNode =
+ parent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+
+ // set child id attr
+ childNode.put(ITEM_ID, data.getIdentifier());
+ }
+
+ // add in NODES
+ Node<Serializable, Object> node = nodesRoot.addChild(makeNodeFqn(data.getIdentifier()));
+ node.put(ITEM_DATA, data);
}
/**
@@ -94,11 +116,22 @@
InvalidItemStateException, IllegalStateException
{
startBatch();
- //Fqn<String> parentFqn = makeParentFqn(data.getQPath());
- // add an attr to the parent node as key=PropertyName value=PropertyId
- //cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
- //cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
+ // check if parent is cached
+ Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
+
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent == null)
+ {
+ throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // add to parent's properties attr
+ parent.put(data.getQPath().getName().getAsString(), data.getIdentifier());
+
+ // add in PROPERTIES
+ Node<Serializable, Object> prop = propsRoot.addChild(makePropFqn(data.getIdentifier()));
+ prop.put(ITEM_DATA, data);
}
/**
@@ -108,8 +141,25 @@
InvalidItemStateException, IllegalStateException
{
startBatch();
- //cache.removeNode(makeNodeFqn(data.getQPath()));
- //cache.removeNode(makeIdFqn(data.getIdentifier()));
+
+ if (data.getParentIdentifier() != null)
+ {
+ // check if parent is cached
+ Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
+
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent == null)
+ {
+ throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // remove child on Parent
+ boolean removed =
+ parent.removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+ }
+
+ // remove from NODES
+ boolean removed = nodesRoot.removeChild(makeNodeFqn(data.getIdentifier()));
}
/**
@@ -119,9 +169,21 @@
InvalidItemStateException, IllegalStateException
{
startBatch();
- // delete attr on parent by key=PropertyName
- //cache.remove(makeParentFqn(data.getQPath()), data.getQPath().getName().getAsString());
- //cache.removeNode(makeIdFqn(data.getIdentifier()));
+
+ // check if parent is cached
+ Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
+
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent == null)
+ {
+ throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // remove from parent's properties attr
+ Object prev = parent.remove(data.getQPath().getName().getAsString());
+
+ // remove from PROPERTIES
+ boolean removed = propsRoot.removeChild(makePropFqn(data.getIdentifier()));
}
/**
@@ -130,30 +192,30 @@
public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
{
//Set<Object> childNames = cache.getChildrenNames(makeNodeFqn(parent.getQPath()));
-// Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
-// if (parentNode == null)
-// {
-// throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
-// }
-//
-// Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
-//
-// List<NodeData> childs = new ArrayList<NodeData>();
-// for (Node<Serializable, Object> child : childNodes)
-// {
-// String childId = (String)child.get(ITEM_ID);
-//
-// // TODO NodeData or PropertyData? As ItemData check then and cast.
-// NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
-// if (node == null)
-// {
-// throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
-// }
-// childs.add(node);
-// }
-//
-// return childs;
-
+ // Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
+ // if (parentNode == null)
+ // {
+ // throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
+ // }
+ //
+ // Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
+ //
+ // List<NodeData> childs = new ArrayList<NodeData>();
+ // for (Node<Serializable, Object> child : childNodes)
+ // {
+ // String childId = (String)child.get(ITEM_ID);
+ //
+ // // TODO NodeData or PropertyData? As ItemData check then and cast.
+ // NodeData node = (NodeData)cache.get(makeIdFqn(childId), ITEM_DATA);
+ // if (node == null)
+ // {
+ // throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
+ // }
+ // childs.add(node);
+ // }
+ //
+ // return childs;
+
return null;
}
@@ -179,31 +241,31 @@
public List<PropertyData> getChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
{
// TODO treeRoot.getChild(f) possible if f not a direct child???
-// Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
-// if (parentNode == null)
-// {
-// throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
-// }
-//
-// List<PropertyData> childs = new ArrayList<PropertyData>();
-//
-// for (Serializable key : parentNode.getKeys())
-// {
-// if (!key.equals(ITEM_ID))
-// {
-// String propId = (String)parentNode.get(key);
-// // TODO NodeData or PropertyData? As ItemData check then and cast.
-// PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
-// if (property == null)
-// {
-// throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
-// }
-// childs.add(property);
-// }
-// }
-//
-// return childs;
-
+ // Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parent.getQPath()));
+ // if (parentNode == null)
+ // {
+ // throw new IllegalStateException("Get child Nodes error: parent not found " + parent.getQPath().getAsString());
+ // }
+ //
+ // List<PropertyData> childs = new ArrayList<PropertyData>();
+ //
+ // for (Serializable key : parentNode.getKeys())
+ // {
+ // if (!key.equals(ITEM_ID))
+ // {
+ // String propId = (String)parentNode.get(key);
+ // // TODO NodeData or PropertyData? As ItemData check then and cast.
+ // PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
+ // if (property == null)
+ // {
+ // throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
+ // }
+ // childs.add(property);
+ // }
+ // }
+ //
+ // return childs;
+
return null;
}
@@ -221,34 +283,28 @@
*/
public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException, IllegalStateException
{
-// Node<Serializable, Object> parentNode = cache.getNode(makeNodeFqn(parentData.getQPath()));
-// if (parentNode == null)
-// {
-// throw new IllegalStateException("Get Item data error: parent not found " + parentData.getQPath().getAsString());
-// }
-//
-// // TODO check performance of Node vs Property get
-//
-// String propertyId = (String)parentNode.get(name.getAsString());
-// if (propertyId != null)
-// {
-// // it's Property Item
-// return (PropertyData)cache.get(makeIdFqn(propertyId), ITEM_DATA);
-// }
-// else
-// {
-// // it's Node Item
-// Node<Serializable, Object> node = parentNode.getChild(name.getAsString(true)); // TODO String not Fqn?
-// if (node != null)
-// {
-// String nodeId = (String)node.get(ITEM_ID);
-// if (nodeId != null)
-// {
-// return (NodeData)cache.get(makeIdFqn(nodeId), ITEM_DATA);
-// }
-// }
-// }
+ // try as Node
+ Node<Serializable, Object> item = nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
+ if (item != null)
+ {
+ return (NodeData)item.get(ITEM_DATA);
+ }
+ else
+ {
+ // try as Property
+ Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(parentData.getIdentifier()));
+ if (parent != null)
+ {
+ // get property id
+ String propId = (String)parent.get(name.getAsString(false));
+ if (propId != null)
+ {
+ return (PropertyData)propsRoot.get(makePropFqn(propId));
+ }
+ }
+ }
+
return null;
}
@@ -257,7 +313,29 @@
*/
public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
{
- return (ItemData)cache.get(makeItemFqn(identifier), ITEM_DATA);
+
+ Node<Serializable, Object> item = nodesRoot.getChild(makeNodeFqn(identifier));
+ if (item == null)
+ {
+ item = propsRoot.getChild(makePropFqn(identifier));
+ }
+
+ if (item != null)
+ {
+ Object itemData = item.get(ITEM_DATA);
+ if (itemData != null)
+ {
+ return (ItemData)itemData;
+ }
+ else
+ {
+ throw new RepositoryException("FATAL ItemData empty " + item.getFqn());
+ }
+ }
+ else
+ {
+ return null;
+ }
}
/**
@@ -289,18 +367,57 @@
{
startBatch();
- // TODO it's put anyway.. but with check?
- Object prev = cache.put(makeNodeFqn(data.getQPath()), ITEM_ID, data.getIdentifier());
- if (prev == null)
+ // TODO recheck the logic
+
+ Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(data.getIdentifier()));
+ if (node == null)
{
- throw new IllegalStateException("Node was deleted (tree)");
+ throw new InvalidItemStateException("Node was updated previously or removed " + data.getQPath().getAsString());
}
- prev = cache.put(makeItemFqn(data.getIdentifier()), ITEM_DATA, data);
- if (prev == null)
+ QPath prevPath;
+
+ Object itemData = node.get(ITEM_DATA);
+ if (itemData == null)
{
- throw new IllegalStateException("Node was deleted (items)");
+ throw new RepositoryException("FATAL NodeData empty " + node.getFqn());
}
+
+ if (itemData instanceof NodeData)
+ {
+ prevPath = ((NodeData)itemData).getQPath();
+ }
+ else
+ {
+ throw new RepositoryException("FATAL Node data is not NodeData " + node.getFqn());
+ }
+
+ if (data.getParentIdentifier() != null)
+ {
+ // check if parent is cached
+ Fqn<String> parentFqn = makeNodeFqn(data.getParentIdentifier());
+
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent == null)
+ {
+ throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // update child on Parent (remove prev, add new)
+
+ // get previously cached NodeData and using its name remove child on the parent
+ boolean removed =
+ parent.removeChild(makeChildNodeFqn(prevPath.getEntries()[prevPath.getEntries().length - 1]));
+
+ Node<Serializable, Object> childNode =
+ parent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+
+ // set child id attr
+ childNode.put(ITEM_ID, data.getIdentifier());
+ }
+
+ // update in NODES
+ node.put(ITEM_DATA, data);
}
/**
@@ -311,19 +428,14 @@
{
startBatch();
- // TODO it's put anyway.. but with check?
-// Fqn<String> parentFqn = makeParentFqn(data.getQPath());
-// Object prev = cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
-// if (prev == null)
-// {
-// throw new IllegalStateException("Property was deleted (tree)");
-// }
-//
-// prev = cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
-// if (prev == null)
-// {
-// throw new IllegalStateException("Property was deleted (items)");
-// }
+ // update in PROPERTIES
+ Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(data.getIdentifier()));
+ if (prop == null)
+ {
+ throw new IllegalStateException("Property was deleted " + data.getQPath().getAsString());
+ }
+
+ prop.put(ITEM_DATA, data);
}
/**
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorage.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorage.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.jboss.cache.Fqn;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 31.10.2009
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id$
+ */
+@Deprecated
+public abstract class JBossCacheTreeStorage
+{
+
+ @Deprecated
+ public static final String TREE = "$TREE".intern();
+
+ @Deprecated
+ public static final String ITEMS = "$ITEMS".intern();
+
+ public static final String ITEM_DATA = "$data".intern();
+
+ public static final String ITEM_ID = "$id".intern();
+
+ @Deprecated
+ protected final Fqn<String> treeRoot;
+
+ protected final Fqn<String> itemsRoot;
+
+ @Deprecated
+ protected JBossCacheTreeStorage(Fqn<String> treeRoot, Fqn<String> itemsRoot)
+ {
+ this.itemsRoot = itemsRoot;
+
+ this.treeRoot = treeRoot;
+ }
+
+ @Deprecated
+ protected Fqn<String> makeNodeFqn(QPath nodePath)
+ {
+ QPathEntry[] path = nodePath.getEntries();
+ String[] fqns = new String[path.length];
+
+ for (int i = 0; i < path.length; i++)
+ {
+ fqns[i] = path[i].getAsString(true);
+ }
+
+ return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(fqns));
+ }
+
+ @Deprecated
+ protected Fqn<String> makeParentFqn(QPath propertyPath)
+ {
+ QPathEntry[] path = propertyPath.getEntries();
+ int pathLen = path.length - 1;
+ String[] fqns = new String[pathLen];
+
+ for (int i = 0; i < pathLen; i++)
+ {
+ fqns[i] = path[i].getAsString(true);
+ }
+
+ return Fqn.fromRelativeFqn(treeRoot, Fqn.fromElements(fqns));
+ }
+
+ protected Fqn<String> makeItemFqn(String nodeId)
+ {
+ return Fqn.fromRelativeFqn(itemsRoot, Fqn.fromString(nodeId));
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -53,7 +53,7 @@
* @version $Id$
*/
@Deprecated
-public class JBossCacheTreeStorageConnection extends JBossCacheStorage implements WorkspaceStorageConnection
+public class JBossCacheTreeStorageConnection extends JBossCacheTreeStorage implements WorkspaceStorageConnection
{
protected static final Log LOG = ExoLogger.getLogger("jcr.JBossCacheStorageConnection");
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -67,7 +67,8 @@
private final Cache<Serializable, Object> cache;
- private final Node<Serializable, Object> items;
+ private final Node<Serializable, Object> nodes;
+ private final Node<Serializable, Object> properties;
/**
* JBossWorkspaceDataContainer constructor.
@@ -111,7 +112,8 @@
//Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
// prepare cache structures
- this.items = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.ITEMS));
+ this.nodes = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.NODES));
+ this.properties = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.PROPS));
}
public void start()
@@ -143,7 +145,7 @@
*/
public WorkspaceStorageConnection openConnection() throws RepositoryException
{
- return new JBossCacheStorageConnection(cache, items);
+ return new JBossCacheStorageConnection(cache, nodes, properties);
}
/**
@@ -151,7 +153,7 @@
*/
public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
{
- return new JBossCacheStorageConnection(cache, items);
+ return new JBossCacheStorageConnection(cache, nodes, properties);
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -36,12 +36,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.ItemData;
@@ -57,6 +51,12 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.loader.AbstractCacheLoader;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Created by The eXo Platform SAS.
*
@@ -92,7 +92,7 @@
*/
public void put(List<Modification> modifications) throws Exception
{
-
+ // TODO
}
@@ -118,7 +118,7 @@
Map<Object, Object> attrs = new LinkedHashMap<Object, Object>();
if (name.size() > 1)
{
- if (name.get(1).equals(JBossCacheStorage.TREE))
+ if (name.get(1).equals(JBossCacheStorage.NODES))
{
// return Node
if (name.size() > 3)
@@ -157,7 +157,7 @@
attrs.put(JBossCacheStorage.ITEM_ID, Constants.ROOT_UUID);
}
}
- else if (name.get(1).equals(JBossCacheStorage.ITEMS))
+ else if (name.get(1).equals(JBossCacheStorage.NODES))
{
// we have all data on thrid level
if (name.size() == 3)
@@ -199,7 +199,7 @@
Set<String> childs = new LinkedHashSet<String>();
if (fqn.size() > 2)
{
- if (fqn.get(2).equals(JBossCacheStorage.TREE))
+ if (fqn.get(2).equals(JBossCacheStorage.NODES))
{
// return Node
if (fqn.size() > 3)
@@ -237,7 +237,7 @@
.getAsString(true));
}
}
- else if (fqn.get(2).equals(JBossCacheStorage.ITEMS))
+ else if (fqn.get(2).equals(JBossCacheStorage.NODES))
{
// we have all data on thrid level
if (fqn.size() == 3)
@@ -261,8 +261,8 @@
}
else if (fqn.equals(Fqn.ROOT))
{
- childs.add(JBossCacheStorage.TREE);
- childs.add(JBossCacheStorage.ITEMS);
+ childs.add(JBossCacheStorage.NODES);
+ childs.add(JBossCacheStorage.PROPS);
}
return childs;
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnectionTest.java 2009-11-06 15:01:45 UTC (rev 487)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnectionTest.java 2009-11-06 15:51:12 UTC (rev 488)
@@ -94,8 +94,8 @@
//Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements("repo", "ws"));
// prepare cache structures
- tree = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.TREE));
- items = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.ITEMS));
+ tree = cacheRoot.addChild(Fqn.fromString(JBossCacheTreeStorage.TREE));
+ items = cacheRoot.addChild(Fqn.fromString(JBossCacheTreeStorage.ITEMS));
// run cache
cache.create();
16 years, 8 months
exo-jcr SVN: r487 - in jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav: command/deltav and 1 other directory.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2009-11-06 10:01:45 -0500 (Fri, 06 Nov 2009)
New Revision: 487
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java
Log:
EXOJCR-220 Status messages added
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2009-11-06 14:57:07 UTC (rev 486)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2009-11-06 15:01:45 UTC (rev 487)
@@ -1141,7 +1141,7 @@
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
return new VersionControlCommand().versionControl(session, path(repoPath));
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java 2009-11-06 14:57:07 UTC (rev 486)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java 2009-11-06 15:01:45 UTC (rev 487)
@@ -77,7 +77,7 @@
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
16 years, 8 months
exo-jcr SVN: r486 - in jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav: command and 1 other directories.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2009-11-06 09:57:07 -0500 (Fri, 06 Nov 2009)
New Revision: 486
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/DeleteCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/HeadCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/OrderPatchCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropPatchCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/SearchCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/UnLockCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckInCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckOutCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/ReportCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/UnCheckOutCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java
Log:
EXOJCR-220 Status messages added
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -310,7 +310,7 @@
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -339,7 +339,7 @@
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -370,7 +370,7 @@
if (!destinationHeader.startsWith(serverURI))
{
- return Response.status(HTTPStatus.BAD_GATEWAY).build();
+ return Response.status(HTTPStatus.BAD_GATEWAY).entity("Bad Gateway").build();
}
String srcWorkspace = workspaceName(repoPath);
@@ -397,8 +397,7 @@
Response prpfind = new PropFindCommand().propfind(session, destNodePath, body, depth.getIntValue(), uri);
if (prpfind.getStatus() != HTTPStatus.NOT_FOUND)
{
-
- return Response.status(HTTPStatus.PRECON_FAILED).build();
+ return Response.status(HTTPStatus.PRECON_FAILED).entity("Not Found").build();
}
}
@@ -429,18 +428,18 @@
}
else
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity("Bad Request").build();
}
}
catch (PreconditionException exc)
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -472,12 +471,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -525,7 +524,7 @@
int dash = token.indexOf("-");
if (dash == -1)
{
- return Response.status(HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE).build();
+ return Response.status(HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE).entity("Requested Range Not Satisfiable").build();
}
else if (dash == 0)
{
@@ -553,12 +552,12 @@
catch (PathNotFoundException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -589,12 +588,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -624,19 +623,19 @@
catch (PreconditionException exc)
{
log.error("PreconditionException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.PRECON_FAILED).build();
+ return Response.status(HTTPStatus.PRECON_FAILED).entity(exc.getMessage()).build();
}
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -667,12 +666,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -709,12 +708,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -745,7 +744,7 @@
if (!destinationHeader.startsWith(serverURI))
{
- return Response.status(HTTPStatus.BAD_GATEWAY).build();
+ return Response.status(HTTPStatus.BAD_GATEWAY).entity("Bad Gateway").build();
}
String destPath = destinationHeader.substring(serverURI.length() + 1);
@@ -774,7 +773,7 @@
Response prpfind = new PropFindCommand().propfind(session, destNodePath, body, depth.getIntValue(), uri);
if (prpfind.getStatus() != HTTPStatus.NOT_FOUND)
{
- return Response.status(HTTPStatus.PRECON_FAILED).build();
+ return Response.status(HTTPStatus.PRECON_FAILED).entity("Preconditions Failed").build();
}
}
@@ -792,14 +791,14 @@
}
else
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity("Bad Request").build();
}
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -855,7 +854,7 @@
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -885,16 +884,16 @@
}
catch (NoSuchWorkspaceException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (PreconditionException exc)
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -926,12 +925,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspace. " + exc.getMessage());
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -994,18 +993,18 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (NoSuchNodeTypeException exc)
{
log.error("NoSuchNodeTypeException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -1037,12 +1036,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -1074,12 +1073,12 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -1108,13 +1107,13 @@
catch (NoSuchWorkspaceException exc)
{
log.error("NoSuchWorkspaceException " + exc.getMessage(), exc);
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -62,24 +62,24 @@
}
catch (ItemExistsException e)
{
- return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).build();
+ return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).entity(e.getMessage()).build();
}
catch (PathNotFoundException e)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(e.getMessage()).build();
}
catch (AccessDeniedException e)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(e.getMessage()).build();
}
catch (LockException e)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(e.getMessage()).build();
}
catch (RepositoryException e)
{
log.error(e.getMessage(), e);
- return Response.serverError().build();
+ return Response.serverError().entity(e.getMessage()).build();
}
}
@@ -101,23 +101,23 @@
}
catch (ItemExistsException e)
{
- return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).build();
+ return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).entity(e.getMessage()).build();
}
catch (PathNotFoundException e)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(e.getMessage()).build();
}
catch (AccessDeniedException e)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(e.getMessage()).build();
}
catch (LockException e)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(e.getMessage()).build();
}
catch (RepositoryException e)
{
- return Response.serverError().build();
+ return Response.serverError().entity(e.getMessage()).build();
}
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/DeleteCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/DeleteCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/DeleteCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -76,12 +76,12 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -129,7 +129,7 @@
HierarchicalProperty lastModifiedProperty = fileResource.getProperty(FileResource.GETLASTMODIFIED);
if((ifModifiedSince != null) && (ifModifiedSince.equals(lastModifiedProperty.getValue()))){
- return Response.notModified().build();
+ return Response.notModified().entity("Not Modified").build();
}
// content length is not present
@@ -202,16 +202,16 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/HeadCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/HeadCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/HeadCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -84,12 +84,12 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/LockCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -125,16 +125,16 @@
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (AccessDeniedException exc)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -92,27 +92,27 @@
}
catch (ItemExistsException exc)
{
- return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).build();
+ return Response.status(HTTPStatus.METHOD_NOT_ALLOWED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (AccessDeniedException exc)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
return Response.status(HTTPStatus.CREATED).build();
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -88,18 +88,18 @@
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
@@ -127,18 +127,18 @@
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/OrderPatchCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/OrderPatchCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/OrderPatchCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -92,16 +92,16 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -82,12 +82,12 @@
}
catch (PathNotFoundException e)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(e.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
WebDavNamespaceContext nsContext;
@@ -154,7 +154,7 @@
}
else
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity("Bad Request").build();
}
return Response.status(HTTPStatus.MULTISTATUS).entity(response).header(ExtHttpHeaders.CONTENT_TYPE,
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropPatchCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropPatchCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropPatchCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -111,16 +111,16 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -139,17 +139,17 @@
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
- catch (AccessDeniedException e)
+ catch (AccessDeniedException exc)
{
- return Response.status(HTTPStatus.FORBIDDEN).build();
+ return Response.status(HTTPStatus.FORBIDDEN).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
return Response.status(HTTPStatus.CREATED).build();
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/SearchCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/SearchCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/SearchCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -74,18 +74,18 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (UnsupportedQueryException exc)
{
- return Response.status(HTTPStatus.BAD_REQUEST).build();
+ return Response.status(HTTPStatus.BAD_REQUEST).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/UnLockCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/UnLockCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/UnLockCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -94,18 +94,18 @@
return Response.status(HTTPStatus.NO_CONTENT).build();
}
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckInCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckInCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckInCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -63,25 +63,25 @@
return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-cache").build();
}
- catch (UnsupportedRepositoryOperationException e)
+ catch (UnsupportedRepositoryOperationException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckOutCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckOutCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/CheckOutCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -62,25 +62,25 @@
node.checkout();
return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-cache").build();
}
- catch (UnsupportedRepositoryOperationException e)
+ catch (UnsupportedRepositoryOperationException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/ReportCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/ReportCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/ReportCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -100,17 +100,17 @@
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
catch (Exception exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/UnCheckOutCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/UnCheckOutCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/UnCheckOutCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -68,25 +68,25 @@
return Response.ok().header(HttpHeaders.CACHE_CONTROL, "no-cache").build();
}
- catch (UnsupportedRepositoryOperationException e)
+ catch (UnsupportedRepositoryOperationException exc)
{
- return Response.status(HTTPStatus.CONFLICT).build();
+ return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (RepositoryException exc)
{
log.error(exc.getMessage(), exc);
- return Response.serverError().build();
+ return Response.serverError().entity(exc.getMessage()).build();
}
}
Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java 2009-11-06 14:49:54 UTC (rev 485)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/deltav/VersionControlCommand.java 2009-11-06 14:57:07 UTC (rev 486)
@@ -66,12 +66,12 @@
}
catch (LockException exc)
{
- return Response.status(HTTPStatus.LOCKED).build();
+ return Response.status(HTTPStatus.LOCKED).entity(exc.getMessage()).build();
}
catch (PathNotFoundException exc)
{
- return Response.status(HTTPStatus.NOT_FOUND).build();
+ return Response.status(HTTPStatus.NOT_FOUND).entity(exc.getMessage()).build();
}
catch (Exception exc)
16 years, 8 months