@Override @Deprecated public MixinBuilder use(RecordType recordType) { this.id = recordType.getId(); this.version = recordType.getVersion(); return this; }
@Override public SupertypeBuilder use(RecordType recordType) { this.id = recordType.getId(); this.version = recordType.getVersion(); return this; }
private boolean removeFromLocalUpdateBucket(RecordType recordType, String bucketId) { Map<SchemaId, Map<Long, RecordType>> localUpdateBucket = localUpdateBuckets.get(bucketId); if (localUpdateBucket == null) { return false; } Map<Long, RecordType> recordTypesByVersion = localUpdateBucket.get(recordType.getId()); if (recordTypesByVersion == null) { return false; } RecordType localRt = recordTypesByVersion.remove(recordType.getVersion()); return localRt != null; }
private Long putSupertypeOnRecordType(Long recordTypeVersion, Put put, SchemaId supertypeId, Long supertypeVersion) throws TypeException { // when specifying a version, this returns only a single result RecordType recordType = getRecordTypeByIdWithoutCache(supertypeId, supertypeVersion).get(0); Long newSupertypeVersion = recordType.getVersion(); put.add(TypeCf.SUPERTYPE.bytes, supertypeId.getBytes(), recordTypeVersion, Bytes.toBytes(newSupertypeVersion)); return newSupertypeVersion; }
private void putRecordTypeInBucket(Map<SchemaId, Map<Long, RecordType>> bucket, RecordType recordType) { if (!bucket.containsKey(recordType.getId())) { bucket.put(recordType.getId(), new HashMap<Long, RecordType>()); } bucket.get(recordType.getId()).put(recordType.getVersion(), recordType); }
private Map<QName, Map<Long, RecordType>> getNameCache() throws InterruptedException { // First check if the name cache is out of date if (nameCacheOutOfDate) { synchronized (monitor) { // Wait until no buckets are being updated while (count > 0) { monitor.wait(); } if (nameCacheOutOfDate) { // Re-initialize the nameCache Map<QName, Map<Long, RecordType>> newNameCache = new HashMap<QName, Map<Long, RecordType>>(); for (Map<SchemaId, Map<Long, RecordType>> bucket : buckets.values()) { for (Map<Long, RecordType> recordTypesByVersion : bucket.values()) { for (RecordType recordType : recordTypesByVersion.values()) { if (!newNameCache.containsKey(recordType.getName())) { newNameCache.put(recordType.getName(), new HashMap<Long, RecordType>()); } newNameCache.get(recordType.getName()).put(recordType.getVersion(), recordType); } } } nameCache = newNameCache; nameCacheOutOfDate = false; } } } return nameCache; }
@Override public RecordType createOrUpdateRecordType(RecordType recordType) throws RepositoryException, InterruptedException { if (recordType.getId() == null) { recordType.setId(new SchemaIdImpl(UUID.randomUUID())); } Long version = recordType.getVersion(); if (version == null) { version = new Long(0l); } recordType.setVersion(version + 1l); recordTypeByName.put(recordType.getName(), recordType); recordTypes.put(recordType.getId(), recordType); return recordType; }
@Override public Collection<FieldTypeEntry> getFieldTypesForRecordType(RecordType recordType, boolean includeSupertypes) throws RepositoryException, InterruptedException { if (!includeSupertypes) { return recordType.getFieldTypeEntries(); } else { // Pairs of record type id and version Map<Pair<SchemaId, Long>, RecordType> recordSupertypeMap = Maps.newHashMap(); collectRecordSupertypes(Pair.create(recordType.getId(), recordType.getVersion()), recordSupertypeMap); // 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); } } else { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } } return fieldTypeMap.values(); } }
@Override public Collection<FieldTypeEntry> getFieldTypesForRecordType(RecordType recordType, boolean includeSupertypes) throws RecordTypeNotFoundException, TypeException, RepositoryException, InterruptedException { if (!includeSupertypes) { return recordType.getFieldTypeEntries(); } else { // Pairs of record type id and version Map<Pair<SchemaId, Long>, RecordType> recordSupertypeMap = Maps.newHashMap(); collectRecordSupertypes(Pair.create(recordType.getId(), recordType.getVersion()), recordSupertypeMap); // 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); } } else { fieldTypeMap.put(fieldTypeId, fieldTypeEntry); } } } return fieldTypeMap.values(); } }
for (Map.Entry<SchemaId, Long> supertype : subRecordType.getSupertypes().entrySet()) { if (supertype.getKey().equals(updatedRecordType.getId())) { if (!supertype.getValue().equals(updatedRecordType.getVersion())) { subRecordType.addSupertype(updatedRecordType.getId(), updatedRecordType.getVersion());
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, 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());
for (Map.Entry<SchemaId, Long> supertype : subRecordType.getSupertypes().entrySet()) { if (supertype.getKey().equals(updatedRecordType.getId())) { if (!supertype.getValue().equals(updatedRecordType.getVersion())) { subRecordType.addSupertype(updatedRecordType.getId(), updatedRecordType.getVersion());
public AvroRecordType convert(RecordType recordType) { AvroRecordType avroRecordType = new AvroRecordType(); avroRecordType.setId(convert(recordType.getId())); avroRecordType.setName(convert(recordType.getName())); Long version = recordType.getVersion(); if (version != null) { avroRecordType.setVersion(version); } Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries(); avroRecordType.setFieldTypeEntries(new ArrayList<AvroFieldTypeEntry>(fieldTypeEntries.size())); for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) { avroRecordType.getFieldTypeEntries().add(convert(fieldTypeEntry)); } Set<Entry<SchemaId, Long>> supertypeEntries = recordType.getSupertypes().entrySet(); avroRecordType.setSupertypes(new ArrayList<AvroSupertype>(supertypeEntries.size())); for (Entry<SchemaId, Long> supertypeEntry : supertypeEntries) { avroRecordType.getSupertypes().add(convert(supertypeEntry)); } return avroRecordType; }
println(out, indent, "Version = " + recordType.getVersion()); println(out, indent, "Fields:");
Long actualRecordTypeVersion = newRecordTypeVersion == null ? recordType.getVersion() : newRecordTypeVersion; boolean recordTypeHasChanged = !newRecordTypeName.equals(originalRecord.getRecordTypeName()) || !actualRecordTypeVersion.equals(originalRecord.getRecordTypeVersion());
boolean exists = getRecordTypeFromCache(recordType.getName(), recordType.getVersion()) != null;
private Record writeRecord(Record record) throws RepositoryException, InterruptedException{ record = record.cloneRecord(); Record originalRecord = record; ResponseStatus status = ResponseStatus.UP_TO_DATE; if (records.containsKey(record.getId())) { originalRecord = records.get(record.getId()); record = merge(record, originalRecord); if (!originalRecord.equals(record)) { status = ResponseStatus.UPDATED; } } else { status = ResponseStatus.CREATED; } QName recordTypeName = record.getRecordTypeName(); Long recordTypeVersion = getTypeManager().getRecordTypeByName(recordTypeName, null).getVersion(); record.setRecordType(recordTypeName, recordTypeVersion); validateRecord(record, originalRecord, getTypeManager().getRecordTypeByName(recordTypeName, null)); Long version = record.getVersion() == null ? 0l : record.getVersion(); record.setVersion(version + 1); records.put(record.getId(), record.cloneRecord()); record.setResponseStatus(status); return record; }
if (getRecordTypeFromCache(recordType.getName(), recordType.getVersion()) != null) { clearConcurrency(nameBytes, now); throw new RecordTypeExistsException(recordType);
public static ObjectNode toJson(RecordType recordType, WriteOptions options, Namespaces namespaces, boolean includeName) { ObjectNode rtNode = JsonNodeFactory.instance.objectNode(); rtNode.put("id", recordType.getId().toString()); if (includeName) { rtNode.put("name", QNameConverter.toJson(recordType.getName(), namespaces)); } ArrayNode fieldsNode = rtNode.putArray("fields"); for (FieldTypeEntry entry : recordType.getFieldTypeEntries()) { ObjectNode entryNode = fieldsNode.addObject(); entryNode.put("id", entry.getFieldTypeId().toString()); entryNode.put("mandatory", entry.isMandatory()); } rtNode.put("version", recordType.getVersion()); ArrayNode supertypesNode = rtNode.putArray("supertypes"); for (Map.Entry<SchemaId, Long> supertype : recordType.getSupertypes().entrySet()) { ObjectNode entryNode = supertypesNode.addObject(); entryNode.put("id", supertype.getKey().toString()); entryNode.put("version", supertype.getValue()); } return rtNode; }
case UPDATED: importListener.updated(EntityType.RECORD_TYPE, newRecordType.getName().toString(), newRecordType.getId().toString(), newRecordType.getVersion()); break; case UP_TO_DATE: