Package org.jboss.dna.graph

Examples of org.jboss.dna.graph.Location


        // but use a batch so that we can read the latest list of children ...
        Results results = store.batch().copy(source).fromWorkspace(sourceWorkspace).to(destination).execute();

        // Find the copy request to get the actual location of the copy ...
        CopyBranchRequest request = (CopyBranchRequest)results.getRequests().get(0);
        Location locationOfCopy = request.getActualLocationAfter();

        // Find the parent node in the session ...
        Node<Payload, PropertyPayload> parent = this.findNodeWith(locationOfCopy.getPath().getParent(), false);
        if (parent != null && parent.isLoaded()) {
            // Update the children to make them match the latest snapshot from the store ...
            parent.synchronizeWithNewlyPersistedNode(locationOfCopy);
        }
    }
View Full Code Here


        // Now execute these two operations ...
        Results results = batch.execute();

        // Find the copy request to get the actual location of the copy ...
        CloneBranchRequest request = (CloneBranchRequest)results.getRequests().get(0);
        Location locationOfCopy = request.getActualLocationAfter();

        // Remove from the session all of the nodes that were removed as part of this clone ...
        Set<Path> removedAlready = new HashSet<Path>();
        for (Location removed : request.getRemovedNodes()) {
            Path path = removed.getPath();
            if (isBelow(path, removedAlready)) {
                // This node is below a node we've already removed, so skip it ...
                continue;
            }
            Node<Payload, PropertyPayload> removedNode = findNodeWith(path, false);
            removedNode.remove(false);
            removedAlready.add(path);
        }

        // Find the parent node in the session ...
        Node<Payload, PropertyPayload> parent = this.findNodeWith(locationOfCopy.getPath().getParent(), false);
        if (parent != null && parent.isLoaded()) {
            // Update the children to make them match the latest snapshot from the store ...
            parent.synchronizeWithNewlyPersistedNode(locationOfCopy);
        }
    }
View Full Code Here

                String path = snapshot.getLocation().getPath().getString(registry);
                maxLength = Math.max(maxLength, path.length());
            }
            StringBuilder sb = new StringBuilder();
            for (Snapshot<PropertyPayload> snapshot : this) {
                Location location = snapshot.getLocation();
                sb.append(StringUtil.justifyLeft(location.getPath().getString(registry), maxLength, ' '));
                // Append the node identifier ...
                sb.append(StringUtil.justifyRight(snapshot.getId().toString(), 10, ' '));
                // Append the various state flags
                if (snapshot.isChanged()) sb.append(" (*)");
                else if (!snapshot.isLoaded()) sb.append(" (-)");
                else sb.append("    ");
                // Append the location's identifier properties ...
                if (location.hasIdProperties()) {
                    sb.append("  ");
                    if (location.getIdProperties().size() == 1 && location.getUuid() != null) {
                        sb.append(location.getUuid());
                    } else {
                        boolean first = true;
                        sb.append('[');
                        for (Property property : location) {
                            sb.append(property.getString(registry));
View Full Code Here

    @Override
    public void notify( Changes changes ) {
        Map<String, Map<Location, NetChangeDetails>> detailsByLocationByWorkspace = new HashMap<String, Map<Location, NetChangeDetails>>();
        // Process each of the events, extracting the node path and property details for each ...
        for (ChangeRequest change : changes.getChangeRequests()) {
            Location location = change.changedLocation();
            assert (location.getPath() != null);

            // Find or create the NetChangeDetails for this node ...
            String workspace = change.changedWorkspace();
            NetChangeDetails details = findDetailsByLocation(workspace, location, detailsByLocationByWorkspace);

            // Process the specific kind of change ...
            if (change instanceof CreateNodeRequest) {
                CreateNodeRequest create = (CreateNodeRequest)change;
                details.addEventType(ChangeType.NODE_ADDED);
                for (Property property : create) {
                    details.addProperty(property);
                }
            } else if (change instanceof UpdatePropertiesRequest) {
                UpdatePropertiesRequest update = (UpdatePropertiesRequest)change;
                for (Map.Entry<Name, Property> entry : update.properties().entrySet()) {
                    Name propName = entry.getKey();
                    Property property = entry.getValue();

                    if (property != null) {
                        if (update.isNewProperty(propName)) {
                            details.addProperty(property);
                        } else {
                            details.changeProperty(property);
                        }
                    } else {
                        details.removeProperty(propName);
                    }
                }
            } else if (change instanceof SetPropertyRequest) {
                SetPropertyRequest set = (SetPropertyRequest)change;

                if (set.isNewProperty()) {
                    details.addProperty(set.property());
                } else {
                    details.changeProperty(set.property());
                }
            } else if (change instanceof RemovePropertyRequest) {
                RemovePropertyRequest remove = (RemovePropertyRequest)change;
                details.removeProperty(remove.propertyName());
            } else if (change instanceof DeleteBranchRequest) {
                // if the node was previously added than a remove results in a net no change
                if (details.getEventTypes().contains(ChangeType.NODE_ADDED)) {
                    deleteLocationDetails(workspace, location, detailsByLocationByWorkspace);
                } else {
                    details.addEventType(ChangeType.NODE_REMOVED);
                }
            } else if (change instanceof DeleteChildrenRequest) {
                DeleteChildrenRequest delete = (DeleteChildrenRequest)change;
                for (Location deletedChild : delete.getActualChildrenDeleted()) {
                    NetChangeDetails childDetails = findDetailsByLocation(workspace, deletedChild, detailsByLocationByWorkspace);
                    // if a child node was previously added than a remove results in a net no change
                    if (childDetails.getEventTypes().contains(ChangeType.NODE_ADDED)) {
                        deleteLocationDetails(workspace, deletedChild, detailsByLocationByWorkspace);
                    } else {
                        childDetails.addEventType(ChangeType.NODE_REMOVED);
                    }
                }
            } else if (change instanceof LockBranchRequest) {
                details.setLockAction(LockAction.LOCKED);
            } else if (change instanceof UnlockBranchRequest) {
                details.setLockAction(LockAction.UNLOCKED);
            } else if (change instanceof CopyBranchRequest) {
                details.addEventType(ChangeType.NODE_ADDED);
            } else if (change instanceof MoveBranchRequest) {
                // the old location is a removed node event and if it is the same location as the original location it is a
                // reorder
                Location original = ((MoveBranchRequest)change).getActualLocationBefore();
                NetChangeDetails originalDetails = findDetailsByLocation(workspace, original, detailsByLocationByWorkspace);
                originalDetails.addEventType(ChangeType.NODE_REMOVED);

                // the new location is a new node event
                details.addEventType(ChangeType.NODE_ADDED);
            } else if (change instanceof CloneBranchRequest) {
                CloneBranchRequest cloneRequest = (CloneBranchRequest)change;

                // create event details for any nodes that were removed
                for (Location removed : cloneRequest.getRemovedNodes()) {
                    NetChangeDetails removedDetails = findDetailsByLocation(workspace, removed, detailsByLocationByWorkspace);
                    removedDetails.addEventType(ChangeType.NODE_REMOVED);
                }

                // create event details for new node
                details.addEventType(ChangeType.NODE_ADDED);
            } else if (change instanceof RenameNodeRequest) {
                // the old location is a removed node event
                Location original = ((RenameNodeRequest)change).getActualLocationBefore();
                NetChangeDetails originalDetails = findDetailsByLocation(workspace, original, detailsByLocationByWorkspace);
                originalDetails.addEventType(ChangeType.NODE_REMOVED);

                // the new location is a new node event
                details.addEventType(ChangeType.NODE_ADDED);
            } else if (change instanceof UpdateValuesRequest) {
                UpdateValuesRequest updateValuesRequest = (UpdateValuesRequest)change;

                if (!updateValuesRequest.addedValues().isEmpty() || !updateValuesRequest.removedValues().isEmpty()) {
                    assert (updateValuesRequest.getActualProperty() != null);

                    if (updateValuesRequest.isNewProperty()) {
                        details.addEventType(ChangeType.PROPERTY_ADDED);
                        details.addProperty(updateValuesRequest.getActualProperty());
                    } else {
                        details.addEventType(ChangeType.PROPERTY_CHANGED);
                        details.changeProperty(updateValuesRequest.getActualProperty());
                    }
                } else if (details.getEventTypes().isEmpty()) {
                    // details was just created for this request and now it is not needed
                    deleteLocationDetails(workspace, location, detailsByLocationByWorkspace);
                }
            } else if (change instanceof CreateWorkspaceRequest) {
                details.addEventType(ChangeType.NODE_ADDED);
            } else if (change instanceof DestroyWorkspaceRequest) {
                details.addEventType(ChangeType.NODE_REMOVED);
            } else if (change instanceof CloneWorkspaceRequest) {
                details.addEventType(ChangeType.NODE_ADDED);
            }
        }

        // Walk through the net changes ...
        List<NetChange> netChanges = new LinkedList<NetChange>();
        for (Map.Entry<String, Map<Location, NetChangeDetails>> byWorkspaceEntry : detailsByLocationByWorkspace.entrySet()) {
            String workspaceName = byWorkspaceEntry.getKey();
            // Iterate over the entries. Since we've used a TreeSet, we'll get these with the lower paths first ...
            for (Map.Entry<Location, NetChangeDetails> entry : byWorkspaceEntry.getValue().entrySet()) {
                Location location = entry.getKey();
                NetChangeDetails details = entry.getValue();
                netChanges.add(new NetChange(workspaceName, location, details.getEventTypes(), details.getAddedProperties(),
                                             details.getModifiedProperties(), details.getRemovedProperties()));
            }
        }
View Full Code Here

            int depth = cache.getDepthForLoadingNodes();
            if (depth == 1) {
                // Then read the node from the store ...
                org.jboss.dna.graph.Node persistentNode = cache.store.getNodeAt(getLocation());
                // Check the actual location ...
                Location actualLocation = persistentNode.getLocation();
                if (!this.location.isSame(actualLocation)) {
                    // The actual location is changed, so update it ...
                    this.location = actualLocation;
                }
                // Update the persistent information ...
                cache.nodeOperations.materialize(persistentNode, this);
            } else {
                // Then read the node from the store ...
                Subgraph subgraph = cache.store.getSubgraphOfDepth(depth).at(getLocation());
                Location actualLocation = subgraph.getLocation();
                if (!this.location.isSame(actualLocation)) {
                    // The actual location is changed, so update it ...
                    this.location = actualLocation;
                }
                // Update the persistent information ...
View Full Code Here

                if (this.isRoot()) return;
                // This must be the root ...
                newPath = cache.pathFactory.createRootPath();
                assert this.isRoot();
            }
            Location newLocation = this.location.with(newPath);
            if (newLocation != this.location) {
                Location oldLocation = this.location;
                this.location = newLocation;
                cache.nodeOperations.postUpdateLocation(this, oldLocation);
            }

            if (isLoaded() && childrenByName != cache.NO_CHILDREN) {
View Full Code Here

            cache.nodeOperations.preCopy(this, parent);

            Name childName = child.getName();
            // Figure out the name and SNS of the new copy ...
            List<Node<Payload, PropertyPayload>> currentChildren = parent.childrenByName.get(childName);
            Location copyLocation = Location.create(cache.pathFactory.create(parent.getPath(),
                                                                             childName,
                                                                             currentChildren.size() + 1));

            // Perform the copy ...
            cache.operations.copy(child.getLocation()).to(copyLocation);
View Full Code Here

            load();

            // Figure out the name and SNS of the new copy ...
            List<Node<Payload, PropertyPayload>> currentChildren = childrenByName.get(name);
            Path newPath = cache.pathFactory.create(path, name, currentChildren.size() + 1);
            Location newChild = idProperties != null && !idProperties.isEmpty() ? Location.create(newPath, idProperties) : Location.create(newPath);

            // Create the properties ...
            Map<Name, PropertyInfo<PropertyPayload>> newProperties = new HashMap<Name, PropertyInfo<PropertyPayload>>();
            if (idProperties != null) {
                for (Property idProp : idProperties) {
                    PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(idProp, idProp.isMultiple(),
                                                                                           Status.NEW, null);
                    newProperties.put(info.getName(), info);
                }
            }
            if (remainingProperties != null) {
                for (Property property : remainingProperties) {
                    PropertyInfo<PropertyPayload> info2 = new PropertyInfo<PropertyPayload>(property, property.isMultiple(),
                                                                                            Status.NEW, null);
                    newProperties.put(info2.getName(), info2);
                }
            }

            // Notify before the addition ...
            cache.nodeOperations.preCreateChild(this, newPath.getLastSegment(), newProperties);

            // Record the current state before any changes ...
            Status statusBefore = this.status;
            boolean changedBelowBefore = this.changedBelow;

            // Add the child to the parent ...
            Node<Payload, PropertyPayload> child = cache.createNode(this, cache.idFactory.create(), newChild);
            child.markAsNew(); // marks parent as changed
            if (childrenByName == cache.NO_CHILDREN) {
                childrenByName = LinkedListMultimap.create();
            }
            childrenByName.put(name, child);

            // Set the properties on the new node, but in a private backdoor way ...
            assert child.properties == null;
            child.properties = newProperties;
            child.childrenByName = cache.NO_CHILDREN;

            try {
                // The node has been changed, so try notifying before we record the creation (which can't be undone) ...
                cache.nodeOperations.postCreateChild(this, child, child.properties);

                // Notification was fine, so now do the create ...
                Graph.Create<Graph.Batch> create = cache.operations.create(newChild.getPath());
                if (!child.properties.isEmpty()) {
                    // Process the property infos (in case some were added during the pre- or post- operations ...
                    for (PropertyInfo<PropertyPayload> property : child.properties.values()) {
                        create.with(property.getProperty());
                    }
View Full Code Here

                public String getExpectedType() {
                    return typeSystem.getLongFactory().getTypeName(); // depth is always LONG
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return new Long(path.size());
                }
            };
        }
        if (operand instanceof NodePath) {
            NodePath nodePath = (NodePath)operand;
            final int locationIndex = columns.getLocationIndex(nodePath.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    assert location.getPath() != null;
                    return stringFactory.create(location.getPath());
                }
            };
        }
        if (operand instanceof NodeName) {
            NodeName nodeName = (NodeName)operand;
            final int locationIndex = columns.getLocationIndex(nodeName.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return path.isRoot() ? "" : stringFactory.create(location.getPath().getLastSegment().getName());
                }
            };
        }
        if (operand instanceof NodeLocalName) {
            NodeLocalName nodeName = (NodeLocalName)operand;
            final int locationIndex = columns.getLocationIndex(nodeName.getSelectorName().getName());
            return new DynamicOperation() {
                public String getExpectedType() {
                    return stringFactory.getTypeName();
                }

                public Object evaluate( Object[] tuple ) {
                    Location location = (Location)tuple[locationIndex];
                    if (location == null) return null;
                    Path path = location.getPath();
                    assert path != null;
                    return path.isRoot() ? "" : location.getPath().getLastSegment().getName().getLocalName();
                }
            };
        }
        if (operand instanceof FullTextSearchScore) {
            FullTextSearchScore score = (FullTextSearchScore)operand;
View Full Code Here

            // We can do this a tad faster if we know there is only one Location object ...
            final int locationIndex = columns.getColumnCount();
            return new Comparator<Object[]>() {
                public int compare( Object[] tuple1,
                                    Object[] tuple2 ) {
                    Location value1 = (Location)tuple1[locationIndex];
                    Location value2 = (Location)tuple2[locationIndex];
                    return typeComparator.compare(value1, value2);
                }
            };
        }
        final int firstLocationIndex = columns.getColumnCount();
        return new Comparator<Object[]>() {
            public int compare( Object[] tuple1,
                                Object[] tuple2 ) {
                int result = 0;
                for (int locationIndex = firstLocationIndex; locationIndex != numLocations; ++locationIndex) {
                    Location value1 = (Location)tuple1[locationIndex];
                    Location value2 = (Location)tuple2[locationIndex];
                    result = typeComparator.compare(value1, value2);
                    if (result != 0) return result;
                }
                return result;
            }
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.