Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.TypeManager



        String scopeName = getString(node, "scope", "non_versioned");
        Scope scope = parseScope(scopeName);

        TypeManager typeManager = repository.getTypeManager();

        // Be gentle to users of Lily 1.0
        if (node.has("valueType") && node.get("valueType").isObject() && node.get("valueType").has("primitive")) {
            throw new JsonFormatException("Lily 1.1 format change: the valueType should now be specified as a string" +
                    " rather than a nested object with the 'primitive' property.");
        }

        String valueTypeString = getString(node, "valueType");
        ValueType valueType = typeManager.getValueType(ValueTypeNSConverter.fromJson(valueTypeString, namespaces));
        FieldType fieldType = typeManager.newFieldType(valueType, name, scope);

        String idString = getString(node, "id", null);
        SchemaId id = null;
        if (idString != null) {
            id = new SchemaIdImpl(idString);
View Full Code Here


    }

    @Test
    public void testCreateRecord() throws Exception {
        // Create schema
        TypeManager typeManager = repository.getTypeManager();

        FieldType fieldType1 = null;
        try {
            fieldType1 = typeManager.getFieldTypeByName(FIELD1);
        } catch (FieldTypeNotFoundException e) {
            System.out.println("[KeepDataTest] Field Type does not exist yet: " + FIELD1);
        }

        try {
            fieldType1 = typeManager.createFieldType(typeManager.newFieldType(typeManager.getValueType("STRING"),
                    FIELD1, Scope.NON_VERSIONED));
        } catch (FieldTypeExistsException e) {
            System.out.println("[KeepDataTest] Field Type already exists: " + FIELD1);
        }

        RecordType recordType1 = null;
        try {
            recordType1 = typeManager.getRecordTypeByName(RECORDTYPE1, 1L);
            System.out.println("[KeepDataTest] RecordType already exists: " + recordType1);
        } catch (RecordTypeNotFoundException e) {
            System.out.println("[KeepDataTest] RecordType does not exist yet. Create it: " + recordType1);
            recordType1 = typeManager.newRecordType(RECORDTYPE1);
            recordType1.addFieldTypeEntry(typeManager.newFieldTypeEntry(fieldType1.getId(), false));
            typeManager.createRecordType(recordType1);
        }

        // Add index
        String indexName = "testIndex";
        lilyProxy.getLilyServerProxy().addIndexFromResource(repository.getRepositoryName(), indexName,
View Full Code Here

    protected static class RecordFormatter implements ValueFormatter {
        @Override
        public String format(Object record, ValueType valueType, FormatContext formatCtx) throws InterruptedException {
            StringBuilder builder = new StringBuilder();
            TypeManager typeManager = formatCtx.repository.getTypeManager();

            for (Map.Entry<QName, Object> field : ((Record)record).getFields().entrySet()) {
                ValueType fieldValueType;
                try {
                    fieldValueType = typeManager.getFieldTypeByName(field.getKey()).getValueType();
                } catch (RepositoryException e) {
                    // error loading field type: skip this field
                    continue;
                }
View Full Code Here

        ObjectNode node = (ObjectNode)nodeNode;

        namespaces = NamespacesConverter.fromContextJson(node, namespaces);

        TypeManager typeManager = repository.getTypeManager();
        QName name = QNameConverter.fromJson(getString(node, "name"), namespaces);

        RecordType recordType = typeManager.newRecordType(name);

        String id = getString(node, "id", null);
        if (id != null) {
            recordType.setId(new SchemaIdImpl(id));
        }

        if (node.get("fields") != null) {
            ArrayNode fields = getArray(node, "fields");
            for (int i = 0; i < fields.size(); i++) {
                JsonNode field = fields.get(i);

                boolean mandatory = getBoolean(field, "mandatory", false);

                String fieldIdString = getString(field, "id", null);
                String fieldName = getString(field, "name", null);

                if (fieldIdString != null) {
                    recordType.addFieldTypeEntry(new SchemaIdImpl(fieldIdString), mandatory);
                } else if (fieldName != null) {
                    QName fieldQName = QNameConverter.fromJson(fieldName, namespaces);

                    try {
                        SchemaId fieldId = typeManager.getFieldTypeByName(fieldQName).getId();
                        recordType.addFieldTypeEntry(fieldId, mandatory);
                    } catch (RepositoryException e) {
                        throw new JsonFormatException("Record type " + name + ": error looking up field type with name: " +
                                fieldQName, e);
                    }
                } else {
                    throw new JsonFormatException("Record type " + name + ": field entry should specify an id or name");
                }
            }
        }

        if (node.get("supertypes") != null && node.get("mixins") != null) {
            throw new JsonFormatException("Only one of 'supertypes' or 'mixins' can be specified " +
                    "(they are synonyms, and mixins is deprecated).");
        }

        if (node.get("supertypes") != null) {
            ArrayNode supertypes = getArray(node, "supertypes", null);
            for (int i = 0; i < supertypes.size(); i++) {
                JsonNode supertype = supertypes.get(i);

                String rtIdString = getString(supertype, "id", null);
                String rtName = getString(supertype, "name", null);
                Long rtVersion = getLong(supertype, "version", null);

                if (rtIdString != null) {
                    recordType.addSupertype(new SchemaIdImpl(rtIdString), rtVersion);
                } else if (rtName != null) {
                    QName rtQName = QNameConverter.fromJson(rtName, namespaces);

                    try {
                        SchemaId rtId = typeManager.getRecordTypeByName(rtQName, null).getId();
                        recordType.addSupertype(rtId, rtVersion);
                    } catch (RepositoryException e) {
                        throw new JsonFormatException("Record type " + name +
                                ": error looking up supertype record type with name: " + rtQName, e);
                    }
                } else {
                    throw new JsonFormatException("Record type " + name + ": supertype should specify an id or name");
                }
            }
        } else if (node.get("mixins") != null) {
            // This was deprecated in 2.2, and can be removed in 2.4
            LogFactory.getLog("lily.deprecation").warn("The use of 'mixins' is deprecated, please use supertypes instead");
            ArrayNode mixins = getArray(node, "mixins", null);
            for (int i = 0; i < mixins.size(); i++) {
                JsonNode mixin = mixins.get(i);

                String rtIdString = getString(mixin, "id", null);
                String rtName = getString(mixin, "name", null);
                Long rtVersion = getLong(mixin, "version", null);

                if (rtIdString != null) {
                    recordType.addMixin(new SchemaIdImpl(rtIdString), rtVersion);
                } else if (rtName != null) {
                    QName rtQName = QNameConverter.fromJson(rtName, namespaces);

                    try {
                        SchemaId rtId = typeManager.getRecordTypeByName(rtQName, null).getId();
                        recordType.addMixin(rtId, rtVersion);
                    } catch (RepositoryException e) {
                        throw new JsonFormatException("Record type " + name + ": error looking up mixin record type with name: " +
                                rtQName, e);
                    }
View Full Code Here

    private TracingRepository() {
    }

    public static Repository wrap(Repository repository) {
        TypeManager typeManager = (TypeManager) Proxy.newProxyInstance(TypeManager.class.getClassLoader(),
                new Class[]{TypeManager.class}, new TracingTypeManagerIH(repository.getTypeManager()));

        IdGenerator idGenerator = (IdGenerator) Proxy.newProxyInstance(IdGenerator.class.getClassLoader(),
                new Class[]{IdGenerator.class}, new TracingIdGeneratorIH(repository.getIdGenerator()));
View Full Code Here

    @Test
    public void testCreateRecord() throws Exception {
        repository = lilyClient.getRepository();
        // Create schema
        TypeManager typeManager = repository.getTypeManager();
        FieldType fieldType1 = typeManager.createFieldType(typeManager.newFieldType(typeManager.getValueType("STRING"),
                FIELD1, Scope.NON_VERSIONED));
        RecordType recordType1 = typeManager.newRecordType(RECORDTYPE1);
        recordType1.addFieldTypeEntry(typeManager.newFieldTypeEntry(fieldType1.getId(), false));
        typeManager.createRecordType(recordType1);

        // Add index
        String indexName = "testIndex";
        lilyProxy.getLilyServerProxy().addIndexFromResource(repository.getRepositoryName(), indexName,
                SolrDefinition.DEFAULT_CORE_NAME, "org/lilyproject/lilyservertestfw/test/lilytestutility_indexerconf.xml",
View Full Code Here

        RecordEvent.IndexRecordFilterData idxSel = recordEvent.getIndexRecordFilterData();
        if (idxSel != null) {
            Record newRecord = idxSel.getNewRecordExists() ? repository.getRecordFactory().newRecord(recordId) : null;
            Record oldRecord = idxSel.getOldRecordExists() ? repository.getRecordFactory().newRecord(recordId) : null;

            TypeManager typeManager = repository.getTypeManager();

            if (idxSel.getFieldChanges() != null) {
                for (RecordEvent.FieldChange fieldChange : idxSel.getFieldChanges()) {
                    FieldType fieldType = typeManager.getFieldTypeById(fieldChange.getId());
                    QName name = fieldType.getName();

                    if (fieldChange.getNewValue() != null) {
                        Object value = fieldType.getValueType().read(fieldChange.getNewValue());
                        newRecord.setField(name, value);
                    }

                    if (fieldChange.getOldValue() != null) {
                        Object value = fieldType.getValueType().read(fieldChange.getOldValue());
                        oldRecord.setField(name, value);
                    }
                }
            }

            if (idxSel.getNewRecordType() != null) {
                newRecord.setRecordType(typeManager.getRecordTypeById(idxSel.getNewRecordType(), null).getName());
            }

            if (idxSel.getOldRecordType() != null) {
                oldRecord.setRecordType(typeManager.getRecordTypeById(idxSel.getOldRecordType(), null).getName());
            }

            return Pair.create(oldRecord, newRecord);
        }
View Full Code Here

        table = mock(LTable.class);
        Repository repository = mock(Repository.class);
        this.repository = repository;
        when(repository.getTable(Table.RECORD.name)).thenReturn(table);
        when(repositoryManager.getRepository(repositoryName)).thenReturn(repository);
        TypeManager typeManager = mock(TypeManager.class);
        avroConverter = mock(AvroConverter.class);
        avroLilyImpl = new AvroLilyImpl(repositoryManager, typeManager);
        avroLilyImpl.setAvroConverter(avroConverter);
    }
View Full Code Here

        LilyClient client = lilyProxy.getLilyServerProxy().getClient();

        // Obtain a repository
        Repository repository = client.getRepository();

        TypeManager typeMgr = repository.getTypeManager();

        QName fieldName = new QName("ns", "f1");
        FieldType fieldType = typeMgr.newFieldType(typeMgr.getValueType("STRING"), fieldName, Scope.NON_VERSIONED);
        fieldType = typeMgr.createFieldType(fieldType);

        QName typeName = new QName("ns", "rt1");
        RecordType recordType = typeMgr.newRecordType(typeName);
        recordType.addFieldTypeEntry(fieldType.getId(), false);
        recordType = typeMgr.createRecordType(recordType);

        Record record = repository.newRecord();
        record.setRecordType(typeName);
        record.setField(fieldName, "foo");
        record = repository.create(record);
View Full Code Here

        //
        // Create some records
        //
        Repository repository = client.getRepository();
        TypeManager typeManager = repository.getTypeManager();
        IdGenerator idGenerator = repository.getIdGenerator();

        FieldType ft1 = typeManager.createFieldType("STRING", new QName("test", "field1"), Scope.NON_VERSIONED);
        FieldType ft2 = typeManager.createFieldType("LINK", new QName("test", "field2"), Scope.NON_VERSIONED);

        RecordType rt1 = typeManager.recordTypeBuilder()
                .defaultNamespace("test")
                .name("rt1")
                .fieldEntry().use(ft1).add()
                .fieldEntry().use(ft2).add()
                .create();
View Full Code Here

TOP

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

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.