Package org.infinispan.schematic.document

Examples of org.infinispan.schematic.document.Document$ValueTransformer


                    value = values.createCode(readString());
                    break;
                case Bson.Type.JAVASCRIPT_WITH_SCOPE:
                    data.readInt(); // the length, but we don't use this
                    String code = readString();
                    Document scope = readDocument(false);
                    value = values.createCode(code, scope);
                    break;
                case Bson.Type.MAXKEY:
                    value = MaxKey.getInstance();
                    break;
View Full Code Here


    @Override
    public Map<Name, Property> getProperties( String id ) {
        File sidecarFile = sidecarFile(id);
        if (!sidecarFile.exists()) return NO_PROPERTIES;
        try {
            Document document = read(new FileInputStream(sidecarFile));
            Map<Name, Property> results = new HashMap<Name, Property>();
            translator.getProperties(document, results);
            return results;
        } catch (IOException e) {
            throw new DocumentStoreException(id, e);
View Full Code Here

            if (!sidecarFile.exists()) {
                if (properties.isEmpty()) return;
                sidecarFile.createNewFile();
                document = Schematic.newDocument();
            } else {
                Document existing = read(new FileInputStream(sidecarFile));
                document = Schematic.newDocument(existing);
            }
            for (Map.Entry<Name, Property> entry : properties.entrySet()) {
                Property property = entry.getValue();
                if (property == null) {
View Full Code Here

        }
    }

    protected SchemaLibrary.Results validate( String documentUri,
                                              String schemaUri ) {
        Document doc = docs.get(documentUri);
        ValidationResult problems = new ValidationResult();
        SchemaDocument schema = schemaDocs.get(schemaUri, problems);
        if (schema != null) {
            schema.getValidator().validate(null, null, doc, Paths.rootPath(), problems, schemaDocs);
        }
View Full Code Here

        assert entry == null : "Should not have found a prior entry";
    }

    @Test
    public void shouldStoreDocumentWithUnusedKeyAndWithNullMetadata() {
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assert prior == null : "Should not have found a prior entry";
        SchematicEntry entry = db.get(key);
        assert entry != null : "Should have found the entry";

        // Verify the content ...
        Document read = entry.getContent();
        assert read != null;
        assert "value1".equals(read.getString("k1"));
        assert 2 == read.getInteger("k2");
        assert read.containsAll(doc);
        assert read.equals(doc);

        // Verify the metadata ...
        Document readMetadata = entry.getMetadata();
        assert readMetadata != null;
        assert readMetadata.getString("id").equals(key);
    }
View Full Code Here

        assert readMetadata.getString("id").equals(key);
    }

    @Test
    public void shouldStoreDocumentWithUnusedKeyAndWithNonNullMetadata() {
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assert prior == null : "Should not have found a prior entry";

        // Read back from the database ...
        SchematicEntry entry = db.get(key);
        assert entry != null : "Should have found the entry";

        // Verify the content ...
        Document read = entry.getContent();
        assert read != null;
        assert "value1".equals(read.getString("k1"));
        assert 2 == read.getInteger("k2");
        assert read.containsAll(doc);
        assert read.equals(doc);

        // Verify the metadata ...
        Document readMetadata = entry.getMetadata();
        assert readMetadata != null;
        assert readMetadata.getString("id").equals(key);
    }
View Full Code Here

    }

    @Test
    public void shouldStoreDocumentAndFetchAndModifyAndRefetch() throws Exception {
        // Store the document ...
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assert prior == null : "Should not have found a prior entry";

        // Read back from the database ...
        SchematicEntry entry = db.get(key);
        assert entry != null : "Should have found the entry";

        // Verify the content ...
        Document read = entry.getContent();
        assert read != null;
        assert "value1".equals(read.getString("k1"));
        assert 2 == read.getInteger("k2");
        assert read.containsAll(doc);
        assert read.equals(doc);

        // Modify using an editor ...
        try {
            tm.begin();
            db.lock(key);
            EditableDocument editable = db.editContent(key, true);
            editable.setBoolean("k3", true);
            editable.setNumber("k4", 3.5d);
        } finally {
            tm.commit();
        }

        // Now re-read ...
        SchematicEntry entry2 = db.get(key);
        Document read2 = entry2.getContent();
        assert read2 != null;
        assert "value1".equals(read2.getString("k1"));
        assert 2 == read2.getInteger("k2");
        assert true == read2.getBoolean("k3");
        assert 3.4d < read2.getDouble("k4");
    }
View Full Code Here

        return result;
    }

    @Test
    public void shouldStoreDocumentWithUnusedKeyAndWithNullMetadata() {
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assertThat("Should not have found a prior entry", prior, is(nullValue()));
        SchematicEntry entry = db.get(key);
        assertThat("Should have found the entry", entry, is(notNullValue()));

        // Verify the content ...
        Document read = entry.getContent();
        assertThat(read, is(notNullValue()));
        assertThat(read.getString("k1"), is("value1"));
        assertThat(read.getInteger("k2"), is(2));
        assertThat(read.containsAll(doc), is(true));
        assertThat(read.equals(doc), is(true));

        // Verify the metadata ...
        Document readMetadata = entry.getMetadata();
        assertThat(readMetadata, is(notNullValue()));
        assertThat(readMetadata.getString("id"), is(key));
    }
View Full Code Here

        assertThat(readMetadata.getString("id"), is(key));
    }

    @Test
    public void shouldStoreDocumentWithUnusedKeyAndWithNonNullMetadata() {
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assertThat("Should not have found a prior entry", prior, is(nullValue()));

        // Read back from the database ...
        SchematicEntry entry = db.get(key);
        assertThat("Should have found the entry", entry, is(notNullValue()));

        // Verify the content ...
        Document read = entry.getContent();
        assertThat(read, is(notNullValue()));
        assertThat(read.getString("k1"), is("value1"));
        assertThat(read.getInteger("k2"), is(2));
        assertThat(read.containsAll(doc), is(true));
        assertThat(read.equals(doc), is(true));

        // Verify the metadata ...
        Document readMetadata = entry.getMetadata();
        assert readMetadata != null;
        assert readMetadata.getString("id").equals(key);
    }
View Full Code Here

    }

    @Test
    public void shouldStoreDocumentAndFetchAndModifyAndRefetch() throws Exception {
        // Store the document ...
        Document doc = Schematic.newDocument("k1", "value1", "k2", 2);
        String key = "can be anything";
        SchematicEntry prior = db.put(key, doc);
        assertThat("Should not have found a prior entry", prior, is(nullValue()));

        // Read back from the database ...
        SchematicEntry entry = db.get(key);
        assertThat("Should have found the entry", entry, is(notNullValue()));

        // Verify the content ...
        Document read = entry.getContent();
        assertThat(read, is(notNullValue()));
        assertThat(read.getString("k1"), is("value1"));
        assertThat(read.getInteger("k2"), is(2));
        assertThat(read.containsAll(doc), is(true));
        assertThat(read.equals(doc), is(true));

        // Modify using an editor ...
        try {
            tm.begin();
            db.lock(key);
            EditableDocument editable = db.editContent(key, true);
            editable.setBoolean("k3", true);
            editable.setNumber("k4", 3.5d);
        } finally {
            tm.commit();
        }

        // Now re-read ...
        SchematicEntry entry2 = db.get(key);
        Document read2 = entry2.getContent();
        assertThat(read2, is(notNullValue()));
        assertThat(read2.getString("k1"), is("value1"));
        assertThat(read2.getInteger("k2"), is(2));
        assertThat(read2.getBoolean("k3"), is(true));
        assertThat(read2.getDouble("k4") > 3.4d, is(true));
    }
View Full Code Here

TOP

Related Classes of org.infinispan.schematic.document.Document$ValueTransformer

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.