Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.QName


                Lists.newArrayList("vtags='last'"),
                Lists.newArrayList("tables='myrecordtable'"));

        LilyIndexerConf idxConf = LilyIndexerConfBuilder.build(new ByteArrayInputStream(conf.getBytes()), repository);

        Record record = repository.getDefaultTable().recordBuilder().id("record").field(new QName("ns", "int"), new Integer(42)).build();

        assertNull(idxConf.getRecordFilter().getIndexCase("myrecordtable", record));
    }
View Full Code Here


                Lists.newArrayList("vtags='last'"),
                Lists.newArrayList("tables='myrecordtable'"));

        LilyIndexerConf idxConf = LilyIndexerConfBuilder.build(new ByteArrayInputStream(conf.getBytes()), repository);

        Record record = repository.getDefaultTable().recordBuilder().id("record").field(new QName("ns", "int"), new Integer(42)).build();

        assertNotNull(idxConf.getRecordFilter().getIndexCase("notmyrecordtable", record));
    }
View Full Code Here

        repository = repoSetup.getRepositoryManager().getDefaultRepository();
        table = repository.getDefaultTable();

        TypeManager typeManager = repository.getTypeManager();
        typeManager.createFieldType("STRING", new QName("ns", "stringField"), Scope.NON_VERSIONED);
        typeManager.createFieldType("LIST<STRING>", new QName("ns", "stringListField"), Scope.NON_VERSIONED);
        typeManager.createFieldType("LONG", new QName("ns", "longField"), Scope.NON_VERSIONED);
        typeManager.recordTypeBuilder()
                .defaultNamespace("ns")
                .name("rt")
                .fieldEntry()
                .name("stringField")
View Full Code Here

    @Test
    public void testNamespaceContexts() throws Exception {
        JsonImport.load(table, repository, getClass().getResourceAsStream("nscontexttest.json"));

        Record record1 = table.read(repository.getIdGenerator().fromString("USER.record1"));
        assertEquals("value1", record1.getField(new QName("import1", "f1")));
        assertEquals(new Integer(55), record1.getField(new QName("import2", "f2")));
    }
View Full Code Here

        assertEquals(500, parsedScan.getCaching());
    }

    @Test
    public void testScanRecordTypeFilter() throws Exception {
        QName recordType = new QName("ns", "rt");

        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(recordType));

        byte[] data = scanToBytes(scan);
View Full Code Here

                node.get("recordFilter").get("recordId").getTextValue());
    }

    @Test
    public void testScanFieldValueFilter() throws Exception {
        QName name = new QName("ns", "stringField");
        Object value = "foo";

        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(name, value));

        byte[] data = scanToBytes(scan);
        RecordScan parsedScan = scanFromBytes(data);

        assertNotNull(parsedScan.getRecordFilter());
        assertTrue(parsedScan.getRecordFilter() instanceof FieldValueFilter);
        FieldValueFilter filter = (FieldValueFilter) parsedScan.getRecordFilter();
        assertEquals(name, filter.getField());
        assertEquals(value, filter.getFieldValue());
        assertTrue(filter.getFilterIfMissing());

        // Check json structure
        JsonNode node = new ObjectMapper().readTree(data);
        assertEquals("org.lilyproject.repository.api.filter.FieldValueFilter",
                node.get("recordFilter").get("@class").getTextValue());
        assertEquals("foo", node.get("recordFilter").get("fieldValue").getTextValue());

        // Try different data types as field value
        value = 3L;
        scan.setRecordFilter(new FieldValueFilter(new QName("ns", "longField"), value));
        assertEquals(value, ((FieldValueFilter) scanFromBytes(scanToBytes(scan))
                .getRecordFilter()).getFieldValue());

        value = Lists.newArrayList("foo", "bar");
        scan.setRecordFilter(new FieldValueFilter(new QName("ns", "stringListField"), value));
        assertEquals(value, ((FieldValueFilter) scanFromBytes(scanToBytes(scan))
                .getRecordFilter()).getFieldValue());

        // The following test made more sense when we were using a generic type-detection
        // in the json serialization rather than using TypeManager.
        // Use a list as field value, but with a mixture of datatypes. This should fail,
        // as lists in Lily should contain values of the same type.
        value = Lists.newArrayList("foo", 123L);
        scan.setRecordFilter(new FieldValueFilter(new QName("ns", "stringListField"), value));
        try {
            data = scanToBytes(scan);
            fail("Expected exception with list containing different data types");
        } catch (Exception e) {
            // expected
View Full Code Here

        RecordId recordId = idGenerator.newRecordId("foo");

        RecordScan scan = new RecordScan();
        RecordFilterList filterList = new RecordFilterList(RecordFilterList.Operator.MUST_PASS_ONE);
        filterList.addFilter(new RecordIdPrefixFilter(recordId));
        filterList.addFilter(new RecordTypeFilter(new QName("ns", "stringField")));
        scan.setRecordFilter(filterList);

        byte[] data = scanToBytes(scan);
        RecordScan parsedScan = scanFromBytes(data);
View Full Code Here

        RecordScan parsedScan = scanFromBytes(data);

        assertEquals(ReturnFields.NONE.getType(), parsedScan.getReturnFields().getType());

        // Test with enumeration of fields to return
        scan.setReturnFields(new ReturnFields(new QName("ns", "f1"), new QName("ns", "f2")));
        data = scanToBytes(scan);
        parsedScan = scanFromBytes(data);

        assertEquals(ReturnFields.Type.ENUM, parsedScan.getReturnFields().getType());
        assertEquals(Lists.newArrayList(new QName("ns", "f1"), new QName("ns", "f2")),
                parsedScan.getReturnFields().getFields());
    }
View Full Code Here

                parsedScan.getReturnFields().getFields());
    }

    @Test
    public void testScanNamespaces() throws Exception {
        QName name = new QName("ns", "stringField");
        Object value = "foo";

        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(name, value));
View Full Code Here

    }

    @Test
    public void testMetadata() throws Exception {
        Record record = repository.getRecordFactory().newRecord();
        record.setMetadata(new QName("ns", "field1"),
                new MetadataBuilder()
                        .value("stringfield", "string")
                        .value("intfield", 55)
                        .value("longfield", 999999999999L)
                        .value("booleanfield", Boolean.TRUE)
                        .value("floatfield", 33.33f)
                        .value("doublefield", 66.66d)
                        .value("binaryfield", new ByteArray("foo".getBytes()))
                        .build());

        record.setMetadata(new QName("ns", "field2"),
                new MetadataBuilder()
                        .value("stringfield", "another_string")
                        .build());

        ObjectNode recordNode = RecordWriter.INSTANCE.toJson(record, null, repository);

        // go through ser/deser
        String recordJson = JsonFormat.serializeAsString(recordNode);
        recordNode = (ObjectNode)JsonFormat.deserializeNonStd(recordJson);

        // Do some structural validations of the json
        ObjectNode metadataNode = (ObjectNode)recordNode.get("metadata");
        assertNotNull(metadataNode);
        assertNull(recordNode.get("metadataToDelete"));

        String prefix = recordNode.get("namespaces").get("ns").getTextValue();

        assertEquals(2, metadataNode.size());

        assertTrue(metadataNode.get(prefix + "$field1").get("stringfield").isTextual());
        assertEquals("string", metadataNode.get(prefix + "$field1").get("stringfield").getTextValue());

        assertTrue(metadataNode.get(prefix + "$field1").get("intfield").isInt());
        assertEquals(55, metadataNode.get(prefix + "$field1").get("intfield").getIntValue());

        assertTrue(metadataNode.get(prefix + "$field1").get("longfield").isLong());
        assertEquals(999999999999L, metadataNode.get(prefix + "$field1").get("longfield").getLongValue());

        assertTrue(metadataNode.get(prefix + "$field1").get("booleanfield").isBoolean());
        assertEquals(Boolean.TRUE, metadataNode.get(prefix + "$field1").get("booleanfield").getBooleanValue());

        // in JSON, no distinction between floats & doubles
        assertTrue(metadataNode.get(prefix + "$field1").get("floatfield").isFloatingPointNumber());
        assertEquals(33.33d, metadataNode.get(prefix + "$field1").get("floatfield").getDoubleValue(), 0.001);

        assertTrue(metadataNode.get(prefix + "$field1").get("doublefield").isFloatingPointNumber());
        assertEquals(33.33d, metadataNode.get(prefix + "$field1").get("floatfield").getDoubleValue(), 0.001);

        assertTrue(metadataNode.get(prefix + "$field1").get("binaryfield").isObject());
        ObjectNode binaryNode = (ObjectNode)metadataNode.get(prefix + "$field1").get("binaryfield");
        assertEquals("binary", binaryNode.get("type").getTextValue());
        assertArrayEquals("foo".getBytes(), binaryNode.get("value").getBinaryValue());

        assertTrue(metadataNode.get(prefix + "$field2").get("stringfield").isTextual());
        assertEquals("another_string", metadataNode.get(prefix + "$field2").get("stringfield").getTextValue());

        // Now parse json again to API objects
        record = RecordReader.INSTANCE.fromJson(recordNode, repository);
        assertEquals(2, record.getMetadataMap().size());

        Metadata metadata = record.getMetadata(new QName("ns", "field1"));
        assertEquals("string", metadata.get("stringfield"));
        assertEquals(55, metadata.getInt("intfield", null).intValue());
        assertEquals(999999999999L, metadata.getLong("longfield", null).longValue());
        assertEquals(Boolean.TRUE, metadata.getBoolean("booleanfield", null));
        assertEquals(33.33f, metadata.getFloat("floatfield", null), 0.001);
        assertEquals(66.66d, metadata.getDouble("doublefield", null), 0.001);
        assertEquals(new ByteArray("foo".getBytes()), metadata.getBytes("binaryfield"));

        metadata = record.getMetadata(new QName("ns", "field2"));
        assertEquals(1, metadata.getMap().size());
        assertEquals(0, metadata.getFieldsToDelete().size());
    }
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.QName

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.