Package org.jboss.dna.graph

Examples of org.jboss.dna.graph.Location


     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.CreateNodeRequest)
     */
    @Override
    public void process( CreateNodeRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            // Create nodes have to be defined via a path ...
            Location parentLocation = request.under();
            ActualLocation actual = getActualLocation(workspace.getId(), parentLocation);
            String parentUuidString = actual.uuid;
            assert parentUuidString != null;

            // We need to look for an existing UUID property in the request,
View Full Code Here


                nextIndexInParent = childrenOfParent.size();
                if (nextIndexInParent > 1) {
                    // Since we want the last indexes, process the list backwards ...
                    ListIterator<Location> iter = childrenOfParent.listIterator(childrenOfParent.size());
                    while (iter.hasPrevious()) {
                        Location existing = iter.previous();
                        Path.Segment segment = existing.getPath().getLastSegment();
                        if (!segment.getName().equals(childName)) continue;
                        // Otherwise the name matched, so get the indexes ...
                        nextSnsIndex = segment.getIndex() + 1;
                    }
                }
            } else {
                // The cache did not have the complete list of children for the parent node,
                // so we need to look the values up by querying the database ...

                // Find the largest SNS index in the existing ChildEntity objects with the same name ...
                String childLocalName = childName.getLocalName();
                Query query = entities.createNamedQuery("ChildEntity.findMaximumSnsIndex");
                query.setParameter("workspaceId", workspaceId);
                query.setParameter("parentUuid", parentUuid);
                query.setParameter("ns", ns.getId());
                query.setParameter("childName", childLocalName);
                try {
                    Integer result = (Integer)query.getSingleResult();
                    nextSnsIndex = result != null ? result + 1 : 1; // SNS index is 1-based
                } catch (NoResultException e) {
                }

                // Find the largest child index in the existing ChildEntity objects ...
                query = entities.createNamedQuery("ChildEntity.findMaximumChildIndex");
                query.setParameter("workspaceId", workspaceId);
                query.setParameter("parentUuid", parentUuid);
                try {
                    Integer result = (Integer)query.getSingleResult();
                    nextIndexInParent = result != null ? result + 1 : 0; // index-in-parent is 0-based
                } catch (NoResultException e) {
                }
            }

            // Create the new ChildEntity ...
            entity = new ChildEntity(id, nextIndexInParent, ns, childName.getLocalName(), nextSnsIndex);
        } else {
            // The parent does not allow same-name-siblings, so we only need to find the next index ...
            // Find the largest child index in the existing ChildEntity objects ...
            if (childrenOfParent != null) {
                // The cache had the complete list of children for the parent node, which means
                // we know about all of the children and can walk the children to figure out the next indexes.
                nextIndexInParent = childrenOfParent.size();
            } else {
                // We don't have the children cached, so we need to do a query ...
                Query query = entities.createNamedQuery("ChildEntity.findMaximumChildIndex");
                query.setParameter("workspaceId", workspaceId);
                query.setParameter("parentUuid", parentUuid);
                try {
                    Integer result = (Integer)query.getSingleResult();
                    nextIndexInParent = result != null ? result + 1 : 0; // index-in-parent is 0-based
                } catch (NoResultException e) {
                }
            }

            // Create the new child entity ...
            entity = new ChildEntity(id, nextIndexInParent, ns, childName.getLocalName(), 1);
        }

        // Persist the new child entity ...
        entity.setAllowsSameNameChildren(allowSameNameChildrenInNewNode);
        entities.persist(entity);

        // Set the actual path, regardless of the supplied path...
        Path path = pathFactory.create(parentPath, childName, nextSnsIndex);
        Location actualLocation = Location.create(path, UUID.fromString(childUuid));

        // Finally, update the cache with the information we know ...
        if (childrenOfParent != null) {
            // Add to the cached list of children ...
            childrenOfParent.add(actualLocation);
View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadNodeRequest)
     */
    @Override
    public void process( ReadNodeRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            Location location = request.at();
            ActualLocation actual = getActualLocation(workspaceId, location);
            String parentUuidString = actual.uuid;
            actualLocation = actual.location;

            // Record the UUID as a property, since it's not stored in the serialized properties...
View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllChildrenRequest)
     */
    @Override
    public void process( ReadAllChildrenRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            Location location = request.of();
            ActualLocation actual = getActualLocation(workspaceId, location);
            actualLocation = actual.location;

            // Get the children for this node ...
            for (Location childLocation : getAllChildren(workspaceId, actual)) {
View Full Code Here

            String localName = child.getChildName();
            Name childName = nameFactory.create(namespaceUri, localName);
            int sns = child.getSameNameSiblingIndex();
            Path childPath = pathFactory.create(parentPath, childName, sns);
            String childUuidString = child.getId().getChildUuidString();
            Location childLocation = Location.create(childPath, UUID.fromString(childUuidString));
            childLocations.add(childLocation);
        }
        // Update the cache ...
        cache.setAllChildren(workspaceId, parentPath, childLocations);
        return childLocations;
View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadBlockOfChildrenRequest)
     */
    @Override
    public void process( ReadBlockOfChildrenRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        final int startingIndex = request.startingAtIndex();
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            Location parentLocation = request.of();
            ActualLocation actualParent = getActualLocation(workspaceId, parentLocation);
            actualLocation = actualParent.location;

            Path parentPath = actualParent.location.getPath();
            assert parentPath != null;
            LinkedList<Location> cachedChildren = cache.getAllChildren(workspaceId, parentPath);
            if (cachedChildren != null) {
                // The cache has all of the children for the node ...
                if (startingIndex < cachedChildren.size()) {
                    ListIterator<Location> iter = cachedChildren.listIterator(startingIndex);
                    for (int i = 0; i != request.count() && iter.hasNext(); ++i) {
                        Location child = iter.next();
                        request.addChild(child);
                    }
                }
            } else {
                // Nothing was cached, so we need to search the database for the children ...
                Query query = entities.createNamedQuery("ChildEntity.findRangeUnderParent");
                query.setParameter("workspaceId", workspaceId);
                query.setParameter("parentUuidString", actualParent.uuid);
                query.setParameter("firstIndex", startingIndex);
                query.setParameter("afterIndex", startingIndex + request.count());
                @SuppressWarnings( "unchecked" )
                List<ChildEntity> children = query.getResultList();
                for (ChildEntity child : children) {
                    String namespaceUri = child.getChildNamespace().getUri();
                    String localName = child.getChildName();
                    Name childName = nameFactory.create(namespaceUri, localName);
                    int sns = child.getSameNameSiblingIndex();
                    Path childPath = pathFactory.create(parentPath, childName, sns);
                    String childUuidString = child.getId().getChildUuidString();
                    Location childLocation = Location.create(childPath, UUID.fromString(childUuidString));
                    request.addChild(childLocation);
                }
                // Do not update the cache, since we don't know all of the children.
            }

View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadNextBlockOfChildrenRequest)
     */
    @Override
    public void process( ReadNextBlockOfChildrenRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        final Location previousSibling = request.startingAfter();
        final int count = request.count();
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            ActualLocation actualSibling = getActualLocation(workspaceId, previousSibling);
            actualLocation = actualSibling.location;
            if (!actualLocation.getPath().isRoot()) {
                // First look in the cache for the children of the parent ...
                Path parentPath = actualSibling.location.getPath().getParent();
                assert parentPath != null;
                LinkedList<Location> cachedChildren = cache.getAllChildren(workspaceId, parentPath);
                if (cachedChildren != null) {
                    // The cache has all of the children for the node.
                    // First find the location of the previous sibling ...
                    boolean accumulate = false;
                    int counter = 0;
                    for (Location child : cachedChildren) {
                        if (accumulate) {
                            // We're accumulating children ...
                            request.addChild(child);
                            ++counter;
                            if (counter <= count) continue;
                            break;
                        }
                        // Haven't found the previous sibling yet ...
                        if (child.isSame(previousSibling)) {
                            accumulate = true;
                        }
                    }
                } else {
                    // The children were not found in the cache, so we have to search the database.
                    // We don't know the UUID of the parent, so find the previous sibling and
                    // then get the starting index and the parent UUID ...
                    ChildEntity previousChild = actualSibling.childEntity;
                    if (previousChild == null) {
                        Query query = entities.createNamedQuery("ChildEntity.findByChildUuid");
                        query.setParameter("workspaceId", workspaceId);
                        query.setParameter("childUuidString", actualSibling.uuid);
                        previousChild = (ChildEntity)query.getSingleResult();
                    }
                    int startingIndex = previousChild.getIndexInParent() + 1;
                    String parentUuid = previousChild.getId().getParentUuidString();

                    // Now search the database for the children ...
                    Query query = entities.createNamedQuery("ChildEntity.findRangeUnderParent");
                    query.setParameter("workspaceId", workspaceId);
                    query.setParameter("parentUuidString", parentUuid);
                    query.setParameter("firstIndex", startingIndex);
                    query.setParameter("afterIndex", startingIndex + request.count());
                    @SuppressWarnings( "unchecked" )
                    List<ChildEntity> children = query.getResultList();
                    LinkedList<Location> allChildren = null;
                    if (startingIndex == 1 && children.size() < request.count()) {
                        // The previous child was the first sibling, and we got fewer children than
                        // the max count. This means we know all of the children, so accumulate the locations
                        // so they can be cached ...
                        allChildren = new LinkedList<Location>();
                        allChildren.add(actualSibling.location);
                    }
                    for (ChildEntity child : children) {
                        String namespaceUri = child.getChildNamespace().getUri();
                        String localName = child.getChildName();
                        Name childName = nameFactory.create(namespaceUri, localName);
                        int sns = child.getSameNameSiblingIndex();
                        Path childPath = pathFactory.create(parentPath, childName, sns);
                        String childUuidString = child.getId().getChildUuidString();
                        Location childLocation = Location.create(childPath, UUID.fromString(childUuidString));
                        request.addChild(childLocation);
                        if (allChildren != null) {
                            // We're going to cache the results, so add this child ...
                            allChildren.add(childLocation);
                        }
View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.ReadAllPropertiesRequest)
     */
    @Override
    public void process( ReadAllPropertiesRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            Location location = request.at();
            ActualLocation actual = getActualLocation(workspaceId, location);
            String uuidString = actual.uuid;
            actualLocation = actual.location;

            // Record the UUID as a property, since it's not stored in the serialized properties...
View Full Code Here

     */
    @Override
    public void process( ReadPropertyRequest request ) {
        logger.trace(request.toString());
        // Process the one property that's requested ...
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            // Small optimization ...
            final Name propertyName = request.named();
            if (DnaLexicon.UUID.equals(propertyName)) {
                try {
                    // Just get the UUID ...
                    Location location = request.on();
                    ActualLocation actual = getActualLocation(workspaceId, location); // verifies the UUID
                    UUID uuid = actual.location.getUuid();
                    Property uuidProperty = getExecutionContext().getPropertyFactory().create(propertyName, uuid);
                    request.setProperty(uuidProperty);
                    request.setActualLocationOfNode(actual.location);
                    setCacheableInfo(request);
                } catch (Throwable e) { // Includes PathNotFoundException
                    request.setError(e);
                }
                return;
            }

            Location location = request.on();
            ActualLocation actual = getActualLocation(workspaceId, location);
            String uuidString = actual.uuid;
            actualLocation = actual.location;

            // Find the properties entity for this node ...
View Full Code Here

     * @see org.jboss.dna.graph.request.processor.RequestProcessor#process(org.jboss.dna.graph.request.UpdatePropertiesRequest)
     */
    @Override
    public void process( UpdatePropertiesRequest request ) {
        logger.trace(request.toString());
        Location actualLocation = null;
        try {
            // Find the workspace ...
            WorkspaceEntity workspace = getExistingWorkspace(request.inWorkspace(), request);
            if (workspace == null) return;
            Long workspaceId = workspace.getId();
            assert workspaceId != null;

            Location location = request.on();
            ActualLocation actual = getActualLocation(workspaceId, location);
            actualLocation = actual.location;

            // Find the properties entity for this node ...
            Query query = entities.createNamedQuery("PropertiesEntity.findByUuid");
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.Location

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.