Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordType


    @Override
    public RecordType getRecordTypeByName(QName name, Long version)
            throws RecordTypeNotFoundException, TypeException, RepositoryException, InterruptedException {
        ArgumentValidator.notNull(name, "name");
        RecordType recordType = getRecordTypeFromCache(name, version);
        if (recordType == null) {
            throw new RecordTypeNotFoundException(name, version);
        }
        return recordType.clone();
    }
View Full Code Here


        //     rtB  |
        //      |   |
        //     rtC<-|
        //

        RecordType rtA = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesLoops", "rtA")
                .fieldEntry().use(fieldType1).add()
                .create();

        RecordType rtB = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesLoops", "rtB")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtA).add()
                .create();

        RecordType rtC = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesLoops", "rtC")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtB).add()
                .create();

        rtA = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesLoops", "rtA")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtC).add()
                .update();

        // Update record type A, this should update B & C but don't go in an endless loop
        rtA.addFieldTypeEntry(fieldType2.getId(), false);
        rtA = typeManager.updateRecordType(rtA, true);

        // Check the subtypes were updated
        rtB = typeManager.getRecordTypeById(rtB.getId(), null);
        rtC = typeManager.getRecordTypeById(rtC.getId(), null);

        assertEquals(Long.valueOf(3L), rtB.getSupertypes().get(rtA.getId()));
        assertEquals(Long.valueOf(2L), rtC.getSupertypes().get(rtB.getId()));
    }
View Full Code Here

    private Set<QName> findSubTypes(QName recordTypeName, boolean recursive)
            throws InterruptedException, RepositoryException {
        ArgumentValidator.notNull(recordTypeName, "recordTypeName");

        RecordType recordType = getRecordTypeByName(recordTypeName, null);
        Set<SchemaId> result = new HashSet<SchemaId>();
        collectSubTypes(recordType.getId(), result, recursive);

        // Translate schema id's to QName's
        Set<QName> names = new HashSet<QName>();
        for (SchemaId id : result) {
            try {
View Full Code Here

            // We use a map of SchemaId to FieldTypeEntry so that we can let mandatory field type entries
            // for the same field type override non-mandatory versions
            Map<SchemaId, FieldTypeEntry> fieldTypeMap = Maps.newHashMap();

            for (Pair<SchemaId, Long> recordSuperTypePair : recordSupertypeMap.keySet()) {
                RecordType superRecordType = recordSupertypeMap.get(recordSuperTypePair);
                for (FieldTypeEntry fieldTypeEntry : superRecordType.getFieldTypeEntries()) {
                    SchemaId fieldTypeId = fieldTypeEntry.getFieldTypeId();
                    if (fieldTypeMap.containsKey(fieldTypeId)) {
                        // Only overwrite an existing entry if we have one that is mandatory
                        if (fieldTypeEntry.isMandatory()) {
                            fieldTypeMap.put(fieldTypeId, fieldTypeEntry);
View Full Code Here

        //
        //     rtA
        //      |
        //     rtB

        RecordType rtA = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesCreateOrUpdate", "rtA")
                .fieldEntry().use(fieldType1).add()
                .create();

        RecordType rtB = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesCreateOrUpdate", "rtB")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtA).add()
                .create();

        assertEquals(Long.valueOf(1L), rtB.getSupertypes().get(rtA.getId()));

        // Update record type A, pointer in record type B should be updated
        rtA.addFieldTypeEntry(fieldType2.getId(), false);
        rtA = typeManager.updateRecordType(rtA, true);

        // Now B should point to new version of A
        rtB = typeManager.getRecordTypeById(rtB.getId(), null);
        assertEquals(Long.valueOf(2L), rtB.getSupertypes().get(rtA.getId()));
    }
View Full Code Here

            Map<Pair<SchemaId, Long>, RecordType> recordSuperTypes)
            throws RecordTypeNotFoundException, TypeException, RepositoryException, InterruptedException {
        if (recordSuperTypes.containsKey(recordTypeAndVersion)) {
            return;
        }
        RecordType recordType = getRecordTypeById(recordTypeAndVersion.getV1(), recordTypeAndVersion.getV2());
        recordSuperTypes.put(recordTypeAndVersion, recordType);
        for (Entry<SchemaId, Long> entry : recordType.getSupertypes().entrySet()) {
            collectRecordSupertypes(Pair.create(entry.getKey(), entry.getValue()), recordSuperTypes);
        }

    }
View Full Code Here

        //
        //     rtA
        //      |
        //     rtB

        RecordType rtA = typeManager.recordTypeBuilder()
                .name("RefreshNoSubtypes", "rtA")
                .fieldEntry().use(fieldType1).add()
                .create();

        RecordType rtB = typeManager.recordTypeBuilder()
                .name("RefreshNoSubtypes", "rtB")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtA).add()
                .create();

        assertEquals(Long.valueOf(1L), rtB.getSupertypes().get(rtA.getId()));

        // Update record type A, pointer in record type B should NOT be updated
        rtA.addFieldTypeEntry(fieldType2.getId(), false);
        rtA = typeManager.updateRecordType(rtA, false);

        // Verify B still points to old version of A
        rtB = typeManager.getRecordTypeById(rtB.getId(), null);
        assertEquals(Long.valueOf(1L), rtB.getSupertypes().get(rtA.getId()));

        // Do the same without explicit refreshSubtypes argument
        rtA.addFieldTypeEntry(fieldType3.getId(), false);
        rtA = typeManager.updateRecordType(rtA);

        // Verify B still points to old version of A
        rtB = typeManager.getRecordTypeById(rtB.getId(), null);
        assertEquals(Long.valueOf(1L), rtB.getSupertypes().get(rtA.getId()));
    }
View Full Code Here

        //
        //     rtA
        //      |
        //     rtB

        RecordType rtA = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesBuilder", "rtA")
                .fieldEntry().use(fieldType1).add()
                .create();

        RecordType rtB = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesBuilder", "rtB")
                .fieldEntry().use(fieldType1).add()
                .supertype().use(rtA).add()
                .create();

        assertEquals(Long.valueOf(1L), rtB.getSupertypes().get(rtA.getId()));

        // Update record type A, pointer in record type B should be updated
        rtA = typeManager.recordTypeBuilder()
                .name("RefreshSubtypesBuilder", "rtA")
                .fieldEntry().use(fieldType1).add()
                .fieldEntry().use(fieldType2).add()
                .update(true);

        // Now B should point to new version of A
        rtB = typeManager.getRecordTypeById(rtB.getId(), null);
        assertEquals(Long.valueOf(2L), rtB.getSupertypes().get(rtA.getId()));
    }
View Full Code Here

        Record record = new RecordImpl();
        dataInput.readByte(); // Ignore, there is currently only one encoding : 1
        int length = dataInput.readVInt();
        byte[] recordTypeId = dataInput.readBytes(length);
        Long recordTypeVersion = dataInput.readLong();
        RecordType recordType = typeManager.getRecordTypeById(new SchemaIdImpl(recordTypeId), recordTypeVersion);
        record.setRecordType(recordType.getName(), recordTypeVersion);

        Map<SchemaId, QName> idToQNameMapping = new HashMap<SchemaId, QName>();
        List<FieldType> fieldTypes = getSortedFieldTypes(recordType);
        for (FieldType fieldType : fieldTypes) {
            byte readByte = dataInput.readByte();
            if (DEFINED == readByte) {
                Object value = fieldType.getValueType().read(dataInput);
                record.setField(fieldType.getName(), value);
                idToQNameMapping.put(fieldType.getId(), fieldType.getName());
            }
        }

        Map<Scope, SchemaId> recordTypeIds = new EnumMap<Scope, SchemaId>(Scope.class);
        recordTypeIds.put(Scope.NON_VERSIONED, recordType.getId());

        return new IdRecordImpl(record, idToQNameMapping, recordTypeIds);
    }
View Full Code Here

        if (parentRecords.contains(record)) {
            throw new RecordException("A record may not be nested in itself: " + record.getId());
        }


        RecordType recordType;
        QName recordRecordTypeName = record.getRecordTypeName();
        if (recordRecordTypeName != null) {
            if (valueTypeRecordTypeName != null) {
                // Validate the same record type is being used
                // 20130314: temporarily disabled this, see LILY-1279
//                if (!valueTypeRecordTypeName.equals(recordRecordTypeName)) {
//                    throw new RecordException("The record's Record Type '" + recordRecordTypeName +
//                            "' does not match the record value type's record type '" + valueTypeRecordTypeName + "'");
//                }
            }
            recordType = typeManager.getRecordTypeByName(recordRecordTypeName, null);
        } else if (valueTypeRecordTypeName != null) {
                recordType = typeManager.getRecordTypeByName(valueTypeRecordTypeName, null);
        } else {
            throw new RecordException("The record '" + record + "' should specify a record type");
        }

        // Get and sort the field type entries that should be in the record
        List<FieldType> fieldTypes = getSortedFieldTypes(recordType);

        Map<QName, Object> recordFields = record.getFields();
        List<QName> expectedFields = new ArrayList<QName>();

        // Write the record type information
        // Encoding:
        // - encoding version : byte (1)
        // - nr of bytes in recordtype id : vInt
        // - recordtype id : bytes
        // - recordtype version : long
        dataOutput.writeByte(ENCODING_VERSION);
        byte[] recordIdBytes = recordType.getId().getBytes();
        dataOutput.writeVInt(recordIdBytes.length);
        dataOutput.writeBytes(recordIdBytes);
        dataOutput.writeLong(recordType.getVersion());

        // Write the content of the fields
        // Encoding: for each field :
        // - if not present in the record : undefined marker : byte (0)
        // - if present in the record : defined marker : byte (1)
        //      - fieldValue : bytes
        for (FieldType fieldType : fieldTypes) {
            QName name = fieldType.getName();
            expectedFields.add(name);
            Object fieldValue = recordFields.get(name);
            if (fieldValue == null) {
                dataOutput.writeByte(UNDEFINED);
            } else {
                dataOutput.writeByte(DEFINED);
                parentRecords.push(record);
                fieldType.getValueType().write(fieldValue, dataOutput, parentRecords);
                parentRecords.pop();
            }
        }

        // Check if the record does contain fields that are not defined in the record type
        if (!expectedFields.containsAll(recordFields.keySet())) {
            throw new InvalidRecordException("Record contains fields not part of the record type '" +
                    recordType.getName() + "'", record.getId());
        }
    }
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.