Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 24810 invoked from network); 7 Mar 2005 15:12:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Mar 2005 15:12:34 -0000 Received: (qmail 79454 invoked by uid 500); 7 Mar 2005 15:12:34 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 79434 invoked by uid 500); 7 Mar 2005 15:12:34 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 79429 invoked by uid 99); 7 Mar 2005 15:12:34 -0000 X-ASF-Spam-Status: No, hits=-9.7 required=10.0 tests=ALL_TRUSTED,EXCUSE_3,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 07 Mar 2005 07:12:32 -0800 Received: (qmail 24769 invoked by uid 65534); 7 Mar 2005 15:12:31 -0000 Message-ID: <20050307151231.24761.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 07 Mar 2005 15:12:30 -0000 Subject: svn commit: r156426 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: RepositoryImpl.java SearchManager.java To: jackrabbit-cvs@incubator.apache.org From: mreutegg@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: mreutegg Date: Mon Mar 7 07:12:27 2005 New Revision: 156426 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D156426 Log: Simplify SearchManager and use SharedItemStateManager instead of SessionIte= mStateManager of system session. Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Reposito= ryImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchMa= nager.java Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Re= positoryImpl.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/RepositoryImpl.java?view=3Ddiff&r1=3D156425&r2=3D156= 426 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Reposito= ryImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Reposito= ryImpl.java Mon Mar 7 07:12:27 2005 @@ -927,7 +927,10 @@ // no search index configured return null; } - searchMgr =3D new SearchManager(getSystemSession(), config= .getSearchConfig(), ntReg); + searchMgr =3D new SearchManager(getSystemSession(), + config.getSearchConfig(), + ntReg, + getItemStateProvider()); } return searchMgr; } Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Se= archManager.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/SearchManager.java?view=3Ddiff&r1=3D156425&r2=3D1564= 26 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchMa= nager.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchMa= nager.java Mon Mar 7 07:12:27 2005 @@ -27,6 +27,7 @@ import org.apache.jackrabbit.core.search.PropertyTypeRegistry; import org.apache.jackrabbit.core.state.ItemStateException; import org.apache.jackrabbit.core.state.NodeState; +import org.apache.jackrabbit.core.state.ItemStateManager; import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry; import org.apache.log4j.Logger; =20 @@ -42,16 +43,11 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.List; +import java.util.ArrayList; =20 /** * Acts as a global entry point to execute queries and index nodes. - * - * todo The SearchManager currently uses the system session to obtain an - * ItemStateManager from where it reads persistent ItemStates. This is kind - * of nasty, because the system session it is possible to change content t= hrough - * the system session as well. - * After switch to version 0.16 there is a shared ItemStateManager which - * represents the persistent view of item states. */ public class SearchManager implements SynchronousEventListener { =20 @@ -79,14 +75,9 @@ public static final String NS_JCRFN_URI =3D "http://www.jcp.org/jcr/xp= ath-functions/1.0"; =20 /** - * HierarchyManager for path resolution + * The shared item state manager instance for the workspace. */ - private final HierarchyManager hmgr; - - /** - * Session for accessing Nodes - */ - private final SessionImpl session; + private final ItemStateManager itemMgr; =20 /** * Storage for search index @@ -98,12 +89,20 @@ */ private final QueryHandler handler; =20 - public SearchManager(SessionImpl session, SearchConfig config, NodeTyp= eRegistry ntReg) - throws RepositoryException { - this.session =3D session; - this.hmgr =3D session.getHierarchyManager(); + /** + * Creates a new SearchManager. + * @param session the system session. + * @param config the search configuration. + * @param ntReg the node type registry. + * @param itemMgr the shared item state manager. + * @throws RepositoryException + */ + public SearchManager(SessionImpl session, + SearchConfig config, + NodeTypeRegistry ntReg, + ItemStateManager itemMgr) throws RepositoryExcept= ion { this.fs =3D config.getFileSystem(); - + this.itemMgr =3D itemMgr; // register namespaces NamespaceRegistry nsReg =3D session.getWorkspace().getNamespaceReg= istry(); try { @@ -150,29 +149,21 @@ * Adds a Node to the search index. * * @param node the NodeState to add. - * @param path the path of the node. * @throws RepositoryException if an error occurs while indexing the n= ode. * @throws IOException if an error occurs while adding the nod= e to the index. */ - public void addNode(NodeState node, Path path) + public void addNode(NodeState node) throws RepositoryException, IOException { - if (log.isDebugEnabled()) { - log.debug("add node to index: " + path); - } handler.addNode(node); } =20 /** * Deletes the Node with UUID from the search index. * - * @param path the path of the node to delete. * @param uuid the UUID of the node to delete. * @throws IOException if an error occurs while deleting the node. */ - public void deleteNode(Path path, String uuid) throws IOException { - if (log.isDebugEnabled()) { - log.debug("remove node from index: " + path.toString()); - } + public void deleteNode(String uuid) throws IOException { handler.deleteNode(uuid); } =20 @@ -234,80 +225,67 @@ //---------------< EventListener interface >--------------------------= ------ =20 public void onEvent(EventIterator events) { - Set modified =3D new HashSet(); - Set added =3D new HashSet(); log.debug("onEvent: indexing started"); long time =3D System.currentTimeMillis(); =20 - // remember nodes we have to index at the end. - Set pendingNodes =3D new HashSet(); + // nodes that need to be removed from the index. + Set removedNodes =3D new HashSet(); + // nodes that need to be added to the index. + Set addedNodes =3D new HashSet(); + // property events + List propEvents =3D new ArrayList(); =20 - // delete removed and modified nodes from index while (events.hasNext()) { - try { - EventImpl e =3D (EventImpl) events.nextEvent(); - long type =3D e.getType(); - if (type =3D=3D Event.NODE_ADDED) { - - // @todo use UUIDs for pending nodes? - Path path =3D Path.create(e.getPath(), - session.getNamespaceResolver(), - true); - pendingNodes.add(path); - added.add(e.getChildUUID()); - } else if (type =3D=3D Event.NODE_REMOVED) { - - Path path =3D Path.create(e.getPath(), - session.getNamespaceResolver(), - true); - deleteNode(path, e.getChildUUID()); - - } else if (type =3D=3D Event.PROPERTY_ADDED - || type =3D=3D Event.PROPERTY_CHANGED - || type =3D=3D Event.PROPERTY_REMOVED) { - - Path path =3D Path.create(e.getPath(), - session.getNamespaceResolver(), - true).getAncestor(1); - - if (type =3D=3D Event.PROPERTY_ADDED) { - // do not delete and re-add if associated node got= added too - if (!added.contains(e.getParentUUID())) { - deleteNode(path, e.getParentUUID()); - modified.add(e.getParentUUID()); - pendingNodes.add(path); - } - } else { - if (!modified.contains(e.getParentUUID())) { - deleteNode(path, e.getParentUUID()); - modified.add(e.getParentUUID()); - pendingNodes.add(path); - } else { - // already deleted - } - } + EventImpl e =3D (EventImpl) events.nextEvent(); + long type =3D e.getType(); + if (type =3D=3D Event.NODE_ADDED) { + addedNodes.add(e.getChildUUID()); + } else if (type =3D=3D Event.NODE_REMOVED) { + removedNodes.add(e.getChildUUID()); + } else { + propEvents.add(e); + } + } =20 + // sort out property events + for (int i =3D 0; i < propEvents.size(); i++) { + EventImpl event =3D (EventImpl) propEvents.get(i); + String nodeUUID =3D event.getParentUUID(); + if (event.getType() =3D=3D Event.PROPERTY_ADDED) { + if (addedNodes.add(nodeUUID)) { + // only property added + // need to re-index + removedNodes.add(nodeUUID); + } else { + // the node where this prop belongs to is also new } - } catch (MalformedPathException e) { - log.error("error indexing node.", e); - } catch (RepositoryException e) { - log.error("error indexing node.", e); - } catch (IOException e) { - log.error("error indexing node.", e); + } else if (event.getType() =3D=3D Event.PROPERTY_CHANGED) { + // need to re-index + addedNodes.add(nodeUUID); + removedNodes.add(nodeUUID); + } else { + // property removed event is only generated when node stil= l exists + addedNodes.add(nodeUUID); + removedNodes.add(nodeUUID); } } =20 - for (Iterator it =3D pendingNodes.iterator(); it.hasNext();) { + for (Iterator it =3D removedNodes.iterator(); it.hasNext();) { + try { + deleteNode((String) it.next()); + } catch (IOException e) { + log.error("Error deleting node from index.", e); + } + } + for (Iterator it =3D addedNodes.iterator(); it.hasNext();) { try { - Path path =3D (Path) it.next(); - ItemId id =3D hmgr.resolvePath(path); - addNode((NodeState) session.getItemStateManager().getItemS= tate(id), path); + addNode((NodeState) itemMgr.getItemState(new NodeId((Strin= g) it.next()))); } catch (ItemStateException e) { - log.error("error indexing node.", e); + log.error("Error indexing node.", e); } catch (RepositoryException e) { - log.error("error indexing node.", e); + log.error("Error indexing node.", e); } catch (IOException e) { - log.error("error indexing node.", e); + log.error("Error indexing node.", e); } } if (log.isDebugEnabled()) {