Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordType


                } else if (record.getRecordTypeName() == null) {
                    recordTypeVersion = originalRecord.getRecordTypeVersion();
                } else {
                    recordTypeVersion = record.getRecordTypeVersion();
                }
                RecordType recordType = typeManager.getRecordTypeByName(recordTypeName, recordTypeVersion);

                // Update the mutable record type in the record object
                Scope mutableScope = Scope.VERSIONED_MUTABLE;
                newRecord.setRecordType(mutableScope, recordType.getName(), recordType.getVersion());

                // If the record type changed, update it on the record table
                QName originalMutableScopeRecordTypeName = originalRecord.getRecordTypeName(mutableScope);
                if (originalMutableScopeRecordTypeName == null) { // There was no initial mutable record type yet
                    put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version,
                            recordType.getId().getBytes());
                    put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(mutableScope), version,
                            Bytes.toBytes(recordType.getVersion()));
                } else {
                    RecordType originalMutableScopeRecordType = typeManager
                            .getRecordTypeByName(originalMutableScopeRecordTypeName,
                                    originalRecord.getRecordTypeVersion(mutableScope));
                    if (!recordType.getId().equals(originalMutableScopeRecordType.getId())) {
                        // If the next record version had the same record type name, copy the original value to that one
                        if (originalNextRecord != null && originalMutableScopeRecordType.getName()
                                .equals(originalNextRecord.getRecordTypeName(mutableScope))) {
                            put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version + 1,
                                    originalMutableScopeRecordType.getId().getBytes());
                        }
                        put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version,
                                recordType.getId().getBytes());
                    }
                    if (!recordType.getVersion().equals(originalMutableScopeRecordType.getVersion())) {
                        // If the next record version had the same record type version, copy the original value to that one
                        if (originalNextRecord != null && originalMutableScopeRecordType.getVersion()
                                .equals(originalNextRecord.getRecordTypeVersion(mutableScope))) {
                            put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version + 1,
                                    Bytes.toBytes(originalMutableScopeRecordType.getVersion()));
                        }
                        put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(mutableScope), version,
                                Bytes.toBytes(recordType.getVersion()));
                    }
                }
View Full Code Here


    public void testRecordVTReadWrite() throws Exception {
        String ns = "testRecordVTWrite";
     // Create a fieldType to be used as a field in a record type to be used as the type for a RecordValueType
        FieldType fieldType1 = typeManager.createFieldType(typeManager.newFieldType(typeManager.getValueType("STRING"), new QName(ns, "field1"), Scope.NON_VERSIONED));
        // Create a record type to be used as the type for a RecordValueType
        RecordType rt1 = typeManager.recordTypeBuilder().name(new QName(ns, "rt1")).field(fieldType1.getId(), false).create();

        // Make a RecordValueType without the record type specified
        ValueType recordVT = typeManager.getValueType("RECORD");


        RecordType rt2 = typeManager.recordTypeBuilder()
            .name(new QName(ns, "rt2"))
            .supertype().id(rt1.getId()).add()
            .create();

View Full Code Here

    }

    private static void forEachSupertype(Record record, TypeManager typeManager, boolean includeRecordType,
            SupertypeCallback callback) throws RepositoryException, InterruptedException {

        RecordType recordType = typeManager.getRecordTypeByName(record.getRecordTypeName(),
                record.getRecordTypeVersion());

        if (includeRecordType) {
            callback.handle(recordType);
        }

        for (Map.Entry<SchemaId, Long> supertype : recordType.getSupertypes().entrySet()) {
            RecordType supertypeRt = typeManager.getRecordTypeById(supertype.getKey(), supertype.getValue());
            callback.handle(supertypeRt);
        }
    }
View Full Code Here

        // (3)
        title = typeManager.createFieldType(title);

        // (4)
        RecordType book = typeManager.newRecordType(new QName(BNS, "Book"));
        book.addFieldTypeEntry(title.getId(), true);

        // (5)
        book = typeManager.createRecordType(book);

        // (6)
View Full Code Here

        FieldType pages = typeManager.createFieldType("LONG", new QName(BNS, "pages"), Scope.VERSIONED);
        FieldType sequelTo = typeManager.createFieldType("LINK", new QName(BNS, "sequel_to"), Scope.VERSIONED);
        FieldType manager = typeManager.createFieldType("STRING", new QName(BNS, "manager"), Scope.NON_VERSIONED);
        FieldType reviewStatus = typeManager.createFieldType("STRING", new QName(BNS, "review_status"), Scope.VERSIONED_MUTABLE);

        RecordType book = typeManager.getRecordTypeByName(new QName(BNS, "Book"), null);

        // The order in which fields are added does not matter
        book.addFieldTypeEntry(description.getId(), false);
        book.addFieldTypeEntry(authors.getId(), false);
        book.addFieldTypeEntry(released.getId(), false);
        book.addFieldTypeEntry(pages.getId(), false);
        book.addFieldTypeEntry(sequelTo.getId(), false);
        book.addFieldTypeEntry(manager.getId(), false);
        book.addFieldTypeEntry(reviewStatus.getId(), false);

        // Now we call updateRecordType instead of createRecordType
        book = typeManager.updateRecordType(book);

        PrintUtil.print(book, repository);
View Full Code Here

    @Override
    public RecordType createRecordType(RecordType recordType) throws RepositoryException, InterruptedException {

        try {
            RecordType newRecordType = converter.convert(lilyProxy.createRecordType(converter.convert(recordType)), this);
            updateRecordTypeCache(newRecordType.clone());
            return newRecordType;
        } catch (AvroRepositoryException e) {
            throw converter.convert(e);
        } catch (AvroGenericException e) {
            throw converter.convert(e);
View Full Code Here

    @Override
    public RecordType createOrUpdateRecordType(RecordType recordType, boolean refreshSubtypes)
            throws RepositoryException, InterruptedException {
        try {
            RecordType newRecordType =
                    converter.convert(lilyProxy.createOrUpdateRecordType(converter.convert(recordType), refreshSubtypes), this);
            updateRecordTypeCache(newRecordType.clone());
            return newRecordType;
        } catch (AvroRepositoryException e) {
            throw converter.convert(e);
        } catch (AvroGenericException e) {
            throw converter.convert(e);
View Full Code Here

    @Override
    public RecordType updateRecordType(RecordType recordType, boolean refreshSubtypes)
            throws RepositoryException, InterruptedException {
        try {
            RecordType newRecordType = converter.convert(
                    lilyProxy.updateRecordType(converter.convert(recordType), refreshSubtypes), this);
            updateRecordTypeCache(newRecordType);
            return newRecordType;
        } catch (AvroRepositoryException e) {
            throw converter.convert(e);
View Full Code Here

    public void complexFields() throws Exception {
        // (1)
        FieldType name = typeManager.createFieldType("STRING", new QName(ANS, "name"), Scope.NON_VERSIONED);
        FieldType email = typeManager.createFieldType("STRING", new QName(ANS, "email"), Scope.NON_VERSIONED);

        RecordType authorType = typeManager.newRecordType(new QName(ANS, "author"));
        authorType.addFieldTypeEntry(name.getId(), true);
        authorType.addFieldTypeEntry(email.getId(), true);
        authorType = typeManager.createRecordType(authorType);

        // (2)
        FieldType title = typeManager.createFieldType("STRING", new QName(ANS, "title"), Scope.NON_VERSIONED);
        FieldType authors = typeManager.createFieldType("LIST<RECORD<{article}author>>",
                new QName(ANS, "authors"), Scope.NON_VERSIONED);
        FieldType body = typeManager.createFieldType("STRING", new QName(ANS, "body"), Scope.NON_VERSIONED);

        RecordType articleType = typeManager.newRecordType(new QName(ANS, "article"));
        articleType.addFieldTypeEntry(title.getId(), true);
        articleType.addFieldTypeEntry(authors.getId(), true);
        articleType.addFieldTypeEntry(body.getId(), true);
        articleType = typeManager.createRecordType(articleType);

        // (3)
        Record author1 = table.newRecord();
        author1.setRecordType(authorType.getName());
        author1.setField(name.getName(), "Author X");
        author1.setField(name.getName(), "author_x@authors.com");

        Record author2 = table.newRecord();
        author2.setRecordType(new QName(ANS, "author"));
        author2.setField(name.getName(), "Author Y");
        author2.setField(name.getName(), "author_y@authors.com");

        // (4)
        Record article = table.newRecord();
        article.setRecordType(articleType.getName());
        article.setField(new QName(ANS, "title"), "Title of the article");
        article.setField(new QName(ANS, "authors"), Lists.newArrayList(author1, author2));
        article.setField(new QName(ANS, "body"), "Body text of the article");
        article = table.create(article);
View Full Code Here

        if (!node.isObject()) {
            throw new ImportException("Record type should be specified as object node.");
        }

        RecordType recordType = RecordTypeReader.INSTANCE.fromJson(node, namespaces, repository);

        if (recordType.getName() == null) {
            throw new ImportException("Missing name property on record type.");
        }

        ImportMode mode = getImportMode(node, ImportMode.CREATE_OR_UPDATE);

        ImportResult<RecordType> result = RecordTypeImport.importRecordType(recordType, mode,
                IdentificationMode.NAME, recordType.getName(), true, repository.getTypeManager());
        RecordType newRecordType = result.getEntity();

        switch (result.getResultType()) {
            case CREATED:
                importListener.created(EntityType.RECORD_TYPE, newRecordType.getName().toString(), newRecordType.getId().toString());
                break;
            case UPDATED:
                importListener.updated(EntityType.RECORD_TYPE, newRecordType.getName().toString(),
                        newRecordType.getId().toString(), newRecordType.getVersion());
                break;
            case UP_TO_DATE:
                importListener.existsAndEqual(EntityType.RECORD_TYPE, recordType.getName().toString(), null);
                break;
            case CANNOT_CREATE_EXISTS:
View Full Code Here

TOP

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

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.