Package org.infinispan.schematic.document

Examples of org.infinispan.schematic.document.EditableDocument


                try {
                    latch.await(); // synchronize ...
                    tm().begin();
                    print("Began txn1");
                    db.lock(key);
                    EditableDocument editor = db.editContent(key, true);
                    editor.setNumber("k2", 3); // update an existing field
                    print(editor);
                    print("Committing txn1");
                    tm().commit();
                } catch (Exception e) {
                    log.error("Unexpected error performing transaction", e);
                }
            }
        }, false);
        Thread t2 = fork(new Runnable() {
            @SuppressWarnings( "synthetic-access" )
            @Override
            public void run() {
                try {
                    latch.await(); // synchronize ...
                    tm().begin();
                    print("Began txn2");
                    db.lock(key);
                    EditableDocument editor = db.editContent(key, true);
                    editor.setNumber("k3", 3); // add a new field
                    print(editor);
                    print("Committing txn2");
                    tm().commit();
                } catch (Exception e) {
                    log.error("Unexpected error performing transaction", e);
View Full Code Here


    @Override
    public DocumentWriter addPage( String parentId,
                                   String nextPageOffset,
                                   long blockSize,
                                   long totalChildCount ) {
        EditableDocument childrenInfo = document().getOrCreateDocument(DocumentTranslator.CHILDREN_INFO);
        childrenInfo.setNumber(DocumentTranslator.COUNT, totalChildCount);
        childrenInfo.setNumber(DocumentTranslator.BLOCK_SIZE, blockSize);
        PageKey pageKey = new PageKey(parentId, nextPageOffset, blockSize);
        childrenInfo.setString(DocumentTranslator.NEXT_BLOCK, pageKey.toString());
        return this;
    }
View Full Code Here

     * @param id the identifier of the additional document; may not be null
     * @return the writer for the additional document; never null
     */
    @Override
    public DocumentWriter writeAdditionalDocument( String id ) {
        EditableDocument embeddedDocs = document().getOrCreateDocument(DocumentTranslator.EMBEDDED_DOCUMENTS);
        // Create a new nested document with the supplied ID as the field name ...
        EditableDocument embedded = embeddedDocs.getOrCreateDocument(id);
        return new FederatedDocumentWriter(translator, embedded);
    }
View Full Code Here

        protected void writeToChangedArea( Iterable<BinaryKey> unusedBinaries ) {
            LOGGER.debug("Writing unused binaries to change area of backup for {0} repository at {1}", repositoryName(),
                         backupLocation());
            File file = new File(changeDirectory, SUMMARY_FILE_NAME);
            try {
                EditableDocument doc = Schematic.newDocument();
                EditableArray keys = doc.setArray(FieldName.UNUSED_BINARY_KEYS);
                for (BinaryKey key : unusedBinaries) {
                    if (key != null) keys.add(key.toString());
                }
                OutputStream outputStream = new FileOutputStream(file);
                try {
View Full Code Here

    protected void addSequencer( EditableDocument doc,
                                 String desc,
                                 String type,
                                 String... pathExpressions ) {
        EditableDocument sequencing = doc.getOrCreateDocument(FieldName.SEQUENCING);
        EditableDocument sequencers = sequencing.getOrCreateDocument(FieldName.SEQUENCERS);
        // Create the sequencer doc ...
        String name = desc;
        EditableDocument sequencer = Schematic.newDocument();
        sequencer.set(FieldName.NAME, name);
        sequencer.set(FieldName.CLASSNAME, type);
        sequencer.setArray(FieldName.PATH_EXPRESSIONS, (Object[])pathExpressions);
        // Set it on the 'sequencers' doc ...
        sequencers.set(name, sequencer);
    }
View Full Code Here

        startRepositoryWithConfiguration("{}");
    }

    @Test
    public void shouldStartRepositoryWithOneSequencer() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "/foo[@bar] => /output");
        startRepositoryWithConfiguration(doc);

        // Now use a session to add a '/foo' node with a 'bar' property ...
        Node foo = session.getRootNode().addNode("foo");
View Full Code Here

        assertThat(derivedNode, is(notNullValue()));
    }

    @Test
    public void shouldAllowSequencerToBeConfiguredWithOnlyInputPath() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "/foo[@bar]");
        startRepositoryWithConfiguration(doc);

        // Now use a session to add a '/foo' node with a 'bar' property ...
        Node foo = session.getRootNode().addNode("foo");
View Full Code Here

        assertThat(derivedNode.getParent(), is(sameInstance(foo)));
    }

    @Test
    public void shouldNotWreakHavocIfSequencerFails() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringExecute.class.getName(), "/foo[@bar] => /output");
        startRepositoryWithConfiguration(doc);

        // Now use a session to add a '/foo' node with a 'bar' property ...
        Node foo = session.getRootNode().addNode("foo");
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void shouldCreateStartRepositoryWithValidButUnusableSequencerPathExpression() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.DefaultSequencer.class.getName(), "## valid but unusable");
        startRepositoryWithConfiguration(doc);
    }
View Full Code Here

        startRepositoryWithConfiguration(doc);
    }

    @Test
    public void shouldRemoveSequencerIfItCrashesDuringInitialize() throws Exception {
        EditableDocument doc = Schematic.newDocument();
        addSequencer(doc, "seq1", TestSequencersHolder.FaultyDuringInitialize.class.getName(), "/foo[@bar] => /output");
        startRepositoryWithConfiguration(doc);

        Node foo = session.getRootNode().addNode("foo");
        foo.setProperty("bar", "value of bar");
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.