Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.Property


    public void addMixin( SessionCache cache,
                          Name mixinName ) {
        assert mixinName != null;
        if (isNew) {
            // We have the actual properties, so just update the jcr:mixinTypes property ...
            Property mixinTypes = cache.getContext().getPropertyFactory().create(JcrLexicon.MIXIN_TYPES, new Name[] {mixinName});
            Property existing = changedProperties().putIfAbsent(mixinTypes.getName(), mixinTypes);
            while (existing != null) {
                // There was an existing property ...
                List<Object> values = new ArrayList<Object>(existing.size());
                for (Object value : existing) {
                    if (mixinName.equals(value)) {
                        // Already a mixin
                        return;
                    }
                    values.add(value);
                }
                values.add(mixinName);
                mixinTypes = cache.getContext().getPropertyFactory().create(JcrLexicon.MIXIN_TYPES, values);
                Property existing2 = changedProperties().put(mixinTypes.getName(), mixinTypes);
                if (existing2 == existing) {
                    // We replaced the property object that we used to create the new one, so we're good
                    existing = null;
                } else {
                    // Someone snuck in there, so try the operation again ...
View Full Code Here


    @Override
    public void removeMixin( SessionCache cache,
                             Name mixinName ) {
        if (isNew) {
            // We have the actual properties, so just update the jcr:mixinTypes property ...
            Property existing = changedProperties().get(JcrLexicon.MIXIN_TYPES);
            while (existing != null) {
                // There was an existing property ...
                List<Object> values = new ArrayList<Object>(existing.size());
                boolean found = false;
                for (Object value : existing) {
                    if (mixinName.equals(value)) {
                        found = true;
                    } else {
                        values.add(value);
                    }
                }
                if (!found) {
                    // The mixin was not in the list ...
                    return;
                }
                Property mixinTypes = cache.getContext().getPropertyFactory().create(JcrLexicon.MIXIN_TYPES, values);
                Property existing2 = changedProperties().put(mixinTypes.getName(), mixinTypes);
                if (existing2 == existing) {
                    // We replaced the property object that we used to create the new one, so we're good
                    existing = null;
                } else {
                    // Someone snuck in there, so try the operation again ...
View Full Code Here

            MixinChanges mixinChanges = mixinChanges(false);
            if (mixinChanges != null) return mixinChanges.getAdded();
            return Collections.emptySet();
        }
        // Otherwise this is a new node, so we should get the 'jcr:mixinTypes' property ...
        Property prop = changedProperties.get(JcrLexicon.MIXIN_TYPES);
        if (prop == null || prop.size() == 0) {
            return Collections.emptySet();
        }
        final NameFactory nameFactory = session(cache).nameFactory();
        Set<Name> names = new HashSet<Name>();
        for (Object value : prop) {
View Full Code Here

    }

    @Override
    public Property getProperty( Name name,
                                 NodeCache cache ) {
        Property prop = null;
        if ((prop = changedProperties.get(name)) != null) return prop;
        if (isPropertyRemoved(name)) return null;
        // Otherwise, delegate to the workspace node (if it exists) ...
        AbstractSessionCache session = session(cache);
        CachedNode raw = nodeInWorkspace(session);
View Full Code Here

            @Override
            public Property getProperty( Name name ) {
                // First check the removed properties ...
                if (removedProperties.containsKey(name)) return null;
                // Then check the changed properties ...
                Property property = changedProperties.get(name);
                if (property == null && raw != null) {
                    // Check the raw property ...
                    property = raw.getProperty(name, cache);
                }
                return property;
View Full Code Here

        Iterable<Property> rawProps = raw == null ? null : new Iterable<Property>() {
            @Override
            public Iterator<Property> iterator() {
                List<Property> values = new LinkedList<Property>();
                for (Iterator<Property> iter = raw.getProperties(workspace(cache)); iter.hasNext();) {
                    Property prop = iter.next();
                    // we need to reflect transient state, so ignore removed and changed properties from the raw values
                    if (isPropertyRemoved(prop.getName()) || changedProperties.containsKey(prop.getName())) {
                        continue;
                    }
                    values.add(prop);
                }
                return values.iterator();
View Full Code Here

    }

    private void updateReferences( SessionCache cache,
                                   Name propertyName,
                                   SessionCache systemCache ) {
        Property propertyWhichWasRemoved = null;
        Property propertyWhichWasAdded = null;

        // first try to determine if there's old reference property with the same name so that old references can be removed
        boolean oldPropertyWasReference = false;
        List<Reference> referencesToRemove = new ArrayList<>();
        if (isPropertyModified(cache, propertyName) || isPropertyRemoved(propertyName)) {
            // remove potential existing references
            CachedNode persistedNode = nodeInWorkspace(session(cache));
            Property oldProperty = persistedNode.getProperty(propertyName, cache);
            if (oldProperty != null && oldProperty.isReference()) {
                oldPropertyWasReference = true;
                propertyWhichWasRemoved = oldProperty;
                for (Object referenceObject : oldProperty.getValuesAsArray()) {
                    assert referenceObject instanceof Reference;
                    referencesToRemove.add((Reference)referenceObject);
                }
            }
        }

        // if the updated property is a reference, determine which are the references that need updating
        boolean updatedPropertyIsReference = false;
        List<Reference> referencesToAdd = new ArrayList<>();
        Property property = changedProperties.get(propertyName);
        if (property != null && property.isReference()) {
            updatedPropertyIsReference = true;
            propertyWhichWasAdded = property;
            for (Object referenceObject : property.getValuesAsArray()) {
                assert referenceObject instanceof Reference;
                Reference updatedReference = (Reference)referenceObject;
                if (referencesToRemove.contains(updatedReference)) {
                    // the reference is already present on a property with the same name, so this is a no-op for that reference
                    // therefore we remove it from the list of references that will be removed
View Full Code Here

        }
    }

    protected void removeAllReferences( SessionCache cache ) {
        for (Iterator<Property> it = this.getProperties(cache); it.hasNext();) {
            Property property = it.next();
            if (!property.isReference()) {
                continue;
            }

            this.addOrRemoveReferrers(cache, null, property, property.getValues(), false);
        }
    }
View Full Code Here

    @Override
    public void setProperties( SessionCache cache,
                               Iterator<Property> properties ) {
        writableSession(cache).assertInSession(this);
        while (properties.hasNext()) {
            Property property = properties.next();
            Name name = property.getName();
            changedProperties.put(name, property);
            if (!isNew) removedProperties.remove(name);
            updateReferences(cache, name, null);
        }
    }
View Full Code Here

    @Override
    public String getEtag( SessionCache cache ) {
        StringBuilder sb = new StringBuilder();
        Iterator<Property> iter = getProperties(cache);
        while (iter.hasNext()) {
            Property prop = iter.next();
            if (prop.isEmpty()) continue;
            for (Object value : prop) {
                if (value instanceof BinaryValue) {
                    BinaryValue binary = (BinaryValue)value;
                    // we don't care about the string encoding, as long as its consistent and will change if a property changes
                    sb.append(binary.getHexHash());
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.Property

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.