Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.QName


    private boolean calculateRecordChanges(Record record, Record originalRecord, Long version, Put put,
                                           RecordEvent recordEvent, Set<BlobReference> referencedBlobs,
                                           Set<BlobReference> unReferencedBlobs,
                                           boolean useLatestRecordType, FieldTypes fieldTypes)
            throws InterruptedException, RepositoryException {
        final QName newRecordTypeName;
        final Long newRecordTypeVersion;
        if (record.getRecordTypeName() == null) {
            newRecordTypeName = originalRecord.getRecordTypeName();
            newRecordTypeVersion = null;
        } else {
            newRecordTypeName = record.getRecordTypeName();
            newRecordTypeVersion = useLatestRecordType ? null : record.getRecordTypeVersion();
        }

        RecordType recordType = typeManager.getRecordTypeByName(newRecordTypeName, newRecordTypeVersion);

        // Check which fields have changed
        EnumSet<Scope> changedScopes = calculateChangedFields(record, originalRecord, recordType, version, put, recordEvent,
                referencedBlobs, unReferencedBlobs, fieldTypes);

        // If no versioned fields have changed, keep the original version
        boolean versionedFieldsHaveChanged = changedScopes.contains(Scope.VERSIONED)
                || changedScopes.contains(Scope.VERSIONED_MUTABLE);
        if (!versionedFieldsHaveChanged) {
            version = originalRecord.getVersion();
        }

        // The provided recordTypeVersion could have been null, so the latest version of the recordType was taken
        // and we need to know which version that is
        Long actualRecordTypeVersion = newRecordTypeVersion == null ? recordType.getVersion() : newRecordTypeVersion;
        boolean recordTypeHasChanged = !newRecordTypeName.equals(originalRecord.getRecordTypeName())
                || !actualRecordTypeVersion.equals(originalRecord.getRecordTypeVersion());

        boolean fieldsHaveChanged = !changedScopes.isEmpty();

        boolean changed = needToApplyChanges(newRecordTypeVersion, useLatestRecordType, fieldsHaveChanged);
View Full Code Here


        Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries();
        List<QName> fieldsToDelete = record.getFieldsToDelete();
        for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) {
            if (fieldTypeEntry.isMandatory()) {
                FieldType fieldType = fieldTypes.getFieldType(fieldTypeEntry.getFieldTypeId());
                QName fieldName = fieldType.getName();
                if (fieldsToDelete.contains(fieldName)) {
                    throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId());
                }
                if (!record.hasField(fieldName) && !originalRecord.hasField(fieldName)) {
                    throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId());
View Full Code Here

            long versionOfRTField = version;
            if (Scope.NON_VERSIONED.equals(scope)) {
                versionOfRTField = 1L; // For non-versioned fields the record type is always stored at version 1.
            }
            // Only update the recordTypeNames and versions if they have indeed changed
            QName originalScopeRecordTypeName = originalRecord.getRecordTypeName(scope);
            if (originalScopeRecordTypeName == null) {
                put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(scope), versionOfRTField,
                        recordType.getId().getBytes());
                put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(scope), versionOfRTField,
                        Bytes.toBytes(recordType.getVersion()));
View Full Code Here

        }

        FieldValueWriter fieldValueWriter = newFieldValueWriter(put, parentRecord);

        for (Entry<QName, Object> field : fields.entrySet()) {
            QName fieldName = field.getKey();
            Object newValue = field.getValue();
            boolean fieldIsNewOrDeleted = !originalFields.containsKey(fieldName);
            Object originalValue = originalFields.get(fieldName);
            if (!(
                    ((newValue == null) && (originalValue == null))         // Don't update if both are null
View Full Code Here

                }

                // Update the record types

                // If no record type is specified explicitly, use the current one of the non-versioned scope
                QName recordTypeName = record.getRecordTypeName() != null ? record.getRecordTypeName() :
                        originalRecord.getRecordTypeName();
                Long recordTypeVersion;
                if (latestRecordType) {
                    recordTypeVersion = null;
                } 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()));
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) {
View Full Code Here

        String uri = namespaces.getNamespace(prefix);
        if (uri == null) {
            throw new JsonFormatException("Undefined prefix in qualified name: " + name);
        }

        return new QName(uri, localName);
    }
View Full Code Here

    protected static TypeManager typeManager;
    protected static boolean avro = false;

    @Test
    public void testCreate() throws Exception {
        QName name = new QName(namespace, "testCreate");
        ValueType valueType = typeManager.getValueType("STRING");
        FieldType fieldType = typeManager.newFieldType(valueType , name, Scope.NON_VERSIONED);
        fieldType = typeManager.createFieldType(fieldType);
        assertEquals(fieldType, typeManager.getFieldTypeById(fieldType.getId()));
        assertEquals(fieldType, typeManager.getFieldTypeByName(fieldType.getName()));
View Full Code Here

    @Test
    public void testCreateIgnoresGivenId() throws Exception {
        SchemaId id = new SchemaIdImpl(UUID.randomUUID());
        ValueType valueType = typeManager.getValueType("STRING");
        FieldType fieldType = typeManager.newFieldType(id, valueType , new QName(namespace, "aName"), Scope.VERSIONED_MUTABLE);
        fieldType = typeManager.createFieldType(fieldType);
        assertFalse(fieldType.getId().equals(id));
    }
View Full Code Here

        assertFalse(fieldType.getId().equals(id));
    }

    @Test
    public void testCreateSameNameFails() throws Exception {
        QName name = new QName(namespace, "testCreateSameNameFails");
        ValueType valueType = typeManager.getValueType("STRING");
        FieldType fieldType = typeManager.newFieldType(valueType , name, Scope.NON_VERSIONED);
        fieldType = typeManager.createFieldType(fieldType);

        ValueType valueType2 = typeManager.getValueType("INTEGER");
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.