public static <T1,T2> Pair<T1,T2>create(T1 v1, T2 v2) { return new Pair<T1,T2>(v1, v2); }
private void collectRecordSupertypes(Pair<SchemaId, Long> recordTypeAndVersion, 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); } }
protected Record read(RecordId recordId, Long requestedVersion, List<FieldType> fields, FieldTypes fieldTypes) throws RepositoryException, InterruptedException { return readWithOcc(recordId, requestedVersion, fields, fieldTypes).getV1(); }
public List<IndexCase> getAllIndexCases() { List<IndexCase> cases = new ArrayList<IndexCase>(includes.size()); for (Pair<RecordMatcher, IndexCase> include : includes) { cases.add(include.getV2()); } return cases; } }
@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(); } }
public BlobStoreAccess getBlobStoreAccess(Blob blob) throws BlobNotFoundException, BlobException { Pair<String, byte[]> decodedKey = decodeKey(blob); return registry.get(decodedKey.getV1()); }
@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(); } }
public void addInclude(RecordMatcher include, IndexCase indexCase) { includes.add(new Pair<RecordMatcher, IndexCase>(include, indexCase)); }
private void collectRecordSupertypes(Pair<SchemaId, Long> recordTypeAndVersion, 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 (Map.Entry<SchemaId, Long> entry : recordType.getSupertypes().entrySet()) { collectRecordSupertypes(Pair.create(entry.getKey(), entry.getValue()), recordSuperTypes); } }
public Set<QName> getFieldDependencies() { Set<QName> result = new HashSet<QName>(); for (Pair<RecordMatcher, IndexCase> include : includes) { result.addAll(include.getV1().getFieldDependencies()); } for (RecordMatcher exclude : excludes) { result.addAll(exclude.getFieldDependencies()); } return result; }
public Pair<Boolean, String> match(String input) { Pair<Boolean, String> result; switch (type) { case STARTS_WITH: if (input.startsWith(string)) { result = new Pair<Boolean, String>(Boolean.TRUE, input.substring(string.length())); } else { result = new Pair<Boolean, String>(Boolean.FALSE, null); } break; case ENDS_WITH: if (input.endsWith(string)) { result = new Pair<Boolean, String>(Boolean.TRUE, input.substring(0, input.length() - string.length())); } else { result = new Pair<Boolean, String>(Boolean.FALSE, null); } break; default: result = new Pair<Boolean, String>(input.equals(string), null); break; } return result; }
public boolean dependsOnRecordType() { for (Pair<RecordMatcher, IndexCase> include : includes) { if (include.getV1().dependsOnRecordType()) { return true; } } for (RecordMatcher exclude : excludes) { if (exclude.dependsOnRecordType()) { return true; } } return false; }
public IndexCase getIndexCase(String table, Record record) { // If an exclude matches, the record is not included in this index. // Excludes have higher precedence than includes. for (RecordMatcher exclude : excludes) { if (exclude.matches(table, record)) { return null; } } for (Pair<RecordMatcher, IndexCase> include : includes) { if (include.getV1().matches(table, record)) { return include.getV2(); } } return null; }
static private Pair<String, byte[]> decode(byte[] key) { int sizeofInt = Bytes.SIZEOF_INT; int idLength = Bytes.toInt(key, key.length - sizeofInt, sizeofInt); String id = Bytes.toString(key, key.length - sizeofInt - idLength, idLength); byte[] blobKey = Bytes.head(key, key.length - sizeofInt - idLength); return new Pair<String, byte[]>(id, blobKey); }
public AvroFieldAndRecordTypes convertFieldAndRecordTypes(Pair<List<FieldType>, List<RecordType>> types) { AvroFieldAndRecordTypes avroTypes = new AvroFieldAndRecordTypes(); List<FieldType> fieldTypes = types.getV1(); avroTypes.setFieldTypes(new ArrayList<AvroFieldType>(fieldTypes.size())); for (FieldType fieldType : fieldTypes) { avroTypes.getFieldTypes().add(convert(fieldType)); } List<RecordType> recordTypes = types.getV2(); avroTypes.setRecordTypes(new ArrayList<AvroRecordType>(recordTypes.size())); for (RecordType recordType : recordTypes) { avroTypes.getRecordTypes().add(convert(recordType)); } return avroTypes; }