Package org.infinispan.schematic.document

Examples of org.infinispan.schematic.document.EditableDocument


    }

    @Test
    @FixFor( "MODE-1361" )
    public void shouldSequenceWithCriteriaAndRegexInputPath() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "default://(*.foo)[bar/@baz] => /output");
        startRepositoryWithConfiguration(doc);

        Node foo = session.getRootNode().addNode("foo.foo");
        Node bar = foo.addNode("bar");
View Full Code Here


    }

    @Test
    @FixFor( "MODE-1361" )
    public void shouldGenerateCorrectOutputNodePathForCapturingGroup() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc,
                     "seq1",
                     TestSequencersHolder.DefaultSequencer.class.getName(),
                     "default://(*.xml)/jcr:content[@jcr:data] => /output/$1");
        startRepositoryWithConfiguration(doc);
View Full Code Here

     */
    protected void predefineWorkspace( String workspaceName ) {
        assertThat(workspaceName, is(notNullValue()));
        // Edit the configuration ...
        Editor editor = config.edit();
        EditableDocument workspaces = editor.getOrCreateDocument("workspaces");
        EditableArray predefined = workspaces.getOrCreateArray("predefined");
        predefined.addStringIfAbsent(workspaceName);

        // And apply the changes ...
        Changes changes = editor.getChanges();
        if (changes.isEmpty()) return;
View Full Code Here

    @Test
    public void shouldNotSplitDocumentWithChildReferenceBlocksThatAreAlreadyTooSmall() throws Exception {
        NodeKey key = new NodeKey("source1works1-childB");
        txnManager().begin();
        EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true);
        EditableArray children = doc.getArray(DocumentTranslator.CHILDREN);
        String nextBlock = doc.getDocument(DocumentTranslator.CHILDREN_INFO).getString(DocumentTranslator.NEXT_BLOCK);
        boolean changed = optimizer.splitChildren(key, doc, children, 100, 50, true, nextBlock);
        txnManager().commit();
        assertThat(changed, is(false));
    }
View Full Code Here

    @Test
    public void shouldMergeDocumentWithTooSmallChildReferencesSegmentInFirstBlock() throws Exception {
        NodeKey key = new NodeKey("source1works1-childB");
        txnManager().begin();
        EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true);
        EditableArray children = doc.getArray(DocumentTranslator.CHILDREN);
        String nextBlock = doc.getDocument(DocumentTranslator.CHILDREN_INFO).getString(DocumentTranslator.NEXT_BLOCK);
        optimizer.mergeChildren(key, doc, children, true, nextBlock);
        txnManager().commit();

        // Refetch the document, which should no longer be segmented ...
        txnManager().begin();
        doc = workspaceCache.documentStore().edit(key.toString(), true);
        assertInfo(key.toString(), 2, null, null, true, 0);
        children = doc.getArray(DocumentTranslator.CHILDREN);
        txnManager().commit();
        assertThat(children.size(), is(2));
        assertChildren(doc, name("childC"), name("childD"));

        print(false);
View Full Code Here

        session1.save();

        // Optimize the storage ...
        txnManager().begin();
        NodeKey key = nodeB.getKey();
        EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true);
        optimizer.optimizeChildrenBlocks(key, doc, 9, 5);
        txnManager().commit();

        print(false);
        print(doc, true);
View Full Code Here

        session1.save();

        // Optimize the storage ...
        txnManager().begin();
        NodeKey key = nodeB.getKey();
        EditableDocument doc = workspaceCache.documentStore().edit(key.toString(), true);
        optimizer.optimizeChildrenBlocks(key, doc, 5, 3); // will merge into a single block ...
        optimizer.optimizeChildrenBlocks(key, doc, 5, 3); // will split into two blocks ...
        txnManager().commit();

        print(false);
View Full Code Here

                    removedNodes.add(key);

                    // if there were any referrer changes for the removed nodes, we need to process them
                    ReferrerChanges referrerChanges = referrerChangesForRemovedNodes.get(key);
                    if (referrerChanges != null) {
                        EditableDocument doc = documentStore.edit(keyStr, false, acquireLock);
                        if (doc != null) translator.changeReferrers(doc, referrerChanges);
                    }

                    // if the node had any binary properties, make sure we decrement the ref count of each
                    for (Iterator<Property> propertyIterator = persisted.getProperties(persistedCache); propertyIterator.hasNext();) {
                        Property property = propertyIterator.next();
                        if (property.isBinary()) {
                            Object value = property.isMultiple() ? Arrays.asList(property.getValuesAsArray()) : property.getFirstValue();
                            translator.decrementBinaryReferenceCount(value, unusedBinaryKeys, null);
                        }
                    }

                    // Note 1: Do not actually remove the document from the documentStore yet; see below (note 2)
                }
                // Otherwise, the removed node was created in the session (but not ever persisted),
                // so we don't have to do anything ...
            } else {
                // Get the primary and mixin type names; even though we're passing in the session, the two properties
                // should be there and shouldn't require a looking in the cache...
                Name primaryType = node.getPrimaryType(this);
                Set<Name> mixinTypes = node.getMixinTypes(this);
                boolean queryable = node.isQueryable(this);

                CachedNode persisted = null;
                Path newPath = sessionPaths.getPath(node);
                NodeKey newParent = node.newParent();
                EditableDocument doc = null;
                ChangedAdditionalParents additionalParents = node.additionalParents();

                if (node.isNew()) {
                    doc = Schematic.newDocument();
                    translator.setKey(doc, key);
View Full Code Here

    public void setProperty( EditableDocument document,
                             Property property,
                             Set<BinaryKey> unusedBinaryKeys,
                             Set<BinaryKey> usedBinaryKeys) {
        // Get or create the properties container ...
        EditableDocument properties = document.getDocument(PROPERTIES);
        if (properties == null) {
            properties = document.setDocument(PROPERTIES);
        }

        // Get or create the namespace container for the property name's namespace ...
        Name propertyName = property.getName();
        String namespaceUri = propertyName.getNamespaceUri();
        EditableDocument urlProps = properties.getDocument(namespaceUri);
        if (urlProps == null) {
            urlProps = properties.setDocument(namespaceUri);
        }

        // Get the old value ...
        String localName = propertyName.getLocalName();
        Object oldValue = urlProps.get(localName);
        decrementBinaryReferenceCount(oldValue, unusedBinaryKeys, usedBinaryKeys);

        // Now set the property ...
        if (property.isEmpty()) {
            urlProps.setArray(localName);
        } else if (property.isMultiple()) {
            EditableArray values = Schematic.newArray(property.size());
            for (Object v : property) {
                values.add(valueToDocument(v, unusedBinaryKeys, usedBinaryKeys));
            }
            urlProps.setArray(localName, values);
        } else {
            assert property.isSingle();
            Object value = valueToDocument(property.getFirstValue(), unusedBinaryKeys, usedBinaryKeys);
            if (value == null) {
                urlProps.remove(localName);
            } else {
                urlProps.set(localName, value);
            }
        }
    }
View Full Code Here

    public Property removeProperty( EditableDocument document,
                                    Name propertyName,
                                    Set<BinaryKey> unusedBinaryKeys,
                                    Set<BinaryKey> usedBinaryKeys) {
        // Get the properties container if it exists ...
        EditableDocument properties = document.getDocument(PROPERTIES);
        if (properties == null) {
            // Doesn't contain the property ...
            return null;
        }

        // Get the namespace container for the property name's namespace ...
        String namespaceUri = propertyName.getNamespaceUri();
        EditableDocument urlProps = properties.getDocument(namespaceUri);
        if (urlProps == null) {
            // Doesn't contain the property ...
            return null;
        }

        // Now remove the property ...
        String localName = propertyName.getLocalName();
        Object fieldValue = urlProps.remove(localName);

        // We're removing a reference to a binary value, and we need to decrement the reference count ...
        decrementBinaryReferenceCount(fieldValue, unusedBinaryKeys, usedBinaryKeys);

        // Now remove the namespace if empty ...
        if (urlProps.isEmpty()) {
            properties.remove(namespaceUri);
        }
        return fieldValue == null ? null : propertyFor(propertyName, fieldValue);
    }
View Full Code Here

TOP

Related Classes of org.infinispan.schematic.document.EditableDocument

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.