Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordType


                // At least the non-versioned record type should be read since that is also the record type of the whole record
                scopesForVersion.add(Scope.NON_VERSIONED);
                for (Scope scope : scopesForVersion) {
                    Pair<SchemaId, Long> recordTypePair = extractVersionRecordType(scope, result, recordEntry.getKey());
                    if (recordTypePair != null) {
                        RecordType recordType =
                                typeManager.getRecordTypeById(recordTypePair.getV1(), recordTypePair.getV2());
                        recordEntry.getValue().setRecordType(scope, recordType.getName(), recordType.getVersion());
                    }
                }
            }
        }
View Full Code Here


                    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";
View Full Code Here

        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,
View Full Code Here

                        }
                    };
                    for (Map<SchemaId, Map<Long, RecordType>> bucket : buckets.values()) {
                        for (Map<Long, RecordType> recordTypeByVersion : bucket.values()) {
                            // TODO: we only look at the last record type here, not sure why
                            RecordType lastRecordType = getRecordTypeWithVersion(recordTypeByVersion, null);
                            for (SchemaId parent : lastRecordType.getSupertypes().keySet()) {
                                newChildRecordTypes.get(parent).add(lastRecordType.getId());
                            }
                        }
                    }
                    childRecordTypes = newChildRecordTypes;
                    childRecordTypesOutOfDate = false;
View Full Code Here

    /**
     * Update the cache to contain the new recordType
     */
    public void update(RecordType recordType) {
        // Clone the RecordType to avoid changes to it while it is in the cache
        RecordType rtToCache = recordType.clone();
        SchemaId id = rtToCache.getId();
        String bucketId = AbstractSchemaCache.encodeHex(id.getBytes());
        // First increment the number of buckets that are being updated
        incCount();
        // Get a lock on the bucket to be updated
        synchronized (getBucketMonitor(bucketId)) {
View Full Code Here

        Map<Long, RecordType> recordTypesByVersion = localUpdateBucket.get(recordType.getId());
        if (recordTypesByVersion == null) {
            return false;
        }

        RecordType localRt = recordTypesByVersion.remove(recordType.getVersion());
        return localRt != null;
    }
View Full Code Here

        //      |  /
        //     rt3
        //

        // First create the types without supertype links
        RecordType rt1 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt1")
                .field(stringField.getId(), false)
                .create();

        RecordType rt2 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt2")
                .field(stringField.getId(), false)
                .create();

        RecordType rt3 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt3")
                .field(stringField.getId(), false)
                .create();

        RecordType rt4 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt4")
                .field(stringField.getId(), false)
                .create();

        RecordType rt5 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt5")
                .field(stringField.getId(), false)
                .create();

        RecordType rt6 = typeManager.recordTypeBuilder()
                .defaultNamespace("ns1")
                .name("rt6")
                .field(stringField.getId(), false)
                .create();
View Full Code Here

        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);
                    }
                } else {
View Full Code Here

        } 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);

        if (changed) {
            if ((recordTypeHasChanged && fieldsHaveChanged) || (recordTypeHasChanged && !useLatestRecordType)) {
                recordEvent.setRecordTypeChanged(true);
                // If NON_VERSIONED is in the changed scopes, the record type will already have been set as part
                // of calculateChangedFields, and the result would be double key-values in the Put object
                if (!changedScopes.contains(Scope.NON_VERSIONED)) {
                    put.add(RecordCf.DATA.bytes, RecordColumn.NON_VERSIONED_RT_ID.bytes, 1L, recordType.getId().getBytes());
                    put.add(RecordCf.DATA.bytes, RecordColumn.NON_VERSIONED_RT_VERSION.bytes, 1L,
                            Bytes.toBytes(actualRecordTypeVersion));
                    changedScopes.add(Scope.NON_VERSIONED); // because the record type version changed
                }
            }
View Full Code Here

                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()));
            } else {
                RecordType originalScopeRecordType = typeManager.getRecordTypeByName(originalScopeRecordTypeName,
                        originalRecord.getRecordTypeVersion(scope));
                if (!recordType.getId().equals(originalScopeRecordType.getId())) {
                    put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(scope), versionOfRTField,
                            recordType.getId().getBytes());
                }
                if (!recordType.getVersion().equals(originalScopeRecordType.getVersion())) {
                    put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(scope), versionOfRTField,
                            Bytes.toBytes(recordType.getVersion()));
                }
            }
            record.setRecordType(scope, recordType.getName(), recordType.getVersion());
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.