/** * Get the {@link SchemaCompositeIndex} with the given name in the given {@link SchemaObjectType}. * * @param type object type * @param name index name * @throws IllegalArgumentException if either paramter is null * @return the unique {@link SchemaCompositeIndex} with name {@code name} in {@code type}, or null if not found * @throws IllegalArgumentException if {@code type} is not indexed by this instance */ public SchemaCompositeIndex getSchemaCompositeIndex(SchemaObjectType type, String name) { Preconditions.checkArgument(type != null, "null type"); Preconditions.checkArgument(name != null, "null name"); final TreeMap<String, SchemaCompositeIndex> indexMap = this.typeCompositeIndexMap.get(type.getStorageId()); if (indexMap == null) throw new IllegalArgumentException("unknown type `" + type.getName() + "' with storage ID " + type.getStorageId()); return indexMap.get(name); }
/** * Get the {@link SchemaField} with the given name in the given {@link SchemaObjectType}. * * @param type object type * @param name field name * @throws IllegalArgumentException if either paramter is null * @return the unique {@link SchemaField} with name {@code name} in {@code type}, or null if not found * @throws IllegalArgumentException if {@code type} is not indexed by this instance */ public SchemaField getSchemaField(SchemaObjectType type, String name) { Preconditions.checkArgument(type != null, "null type"); Preconditions.checkArgument(name != null, "null name"); final TreeMap<String, SchemaField> fieldMap = this.typeFieldMap.get(type.getStorageId()); if (fieldMap == null) throw new IllegalArgumentException("unknown type `" + type.getName() + "' with storage ID " + type.getStorageId()); return fieldMap.get(name); }
/** * Get all of the names of {@link SchemaCompositeIndex}s in the given {@link SchemaObjectType}. * * @param type schema object * @return unmodifiable set of {@link SchemaCompositeIndex} names in {@code type} * @throws IllegalArgumentException if {@code type} is not indexed by this instance */ public NavigableSet<String> getSchemaCompositeIndexNames(SchemaObjectType type) { Preconditions.checkArgument(type != null, "null type"); final TreeMap<String, SchemaCompositeIndex> indexMap = this.typeCompositeIndexMap.get(type.getStorageId()); if (indexMap == null) throw new IllegalArgumentException("unknown type `" + type.getName() + "' with storage ID " + type.getStorageId()); return Collections.unmodifiableNavigableSet(indexMap.navigableKeySet()); } }
/** * Get all of the names of {@link SchemaField}s in the given {@link SchemaObjectType}. * * @param type schema object * @return unmodifiable set of {@link SchemaField} names in {@code type} * @throws IllegalArgumentException if {@code type} is not indexed by this instance */ public NavigableSet<String> getSchemaFieldNames(SchemaObjectType type) { Preconditions.checkArgument(type != null, "null type"); final TreeMap<String, SchemaField> fieldMap = this.typeFieldMap.get(type.getStorageId()); if (fieldMap == null) throw new IllegalArgumentException("unknown type `" + type.getName() + "' with storage ID " + type.getStorageId()); return Collections.unmodifiableNavigableSet(fieldMap.navigableKeySet()); }
if (this.typeMap.put(type.getName(), type) != null) throw new IllegalArgumentException("schema model is invalid");
super(schemaObjectType.getName(), schemaObjectType.getStorageId(), schema);
private void doValidate() { // Validate object types and verify object type names are unique final TreeMap<String, SchemaObjectType> schemaObjectTypesByName = new TreeMap<>(); for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { schemaObjectType.validate(); final String schemaObjectTypeName = schemaObjectType.getName(); final SchemaObjectType otherSchemaObjectType = schemaObjectTypesByName.put(schemaObjectTypeName, schemaObjectType); if (otherSchemaObjectType != null) throw new InvalidSchemaException("duplicate object name `" + schemaObjectTypeName + "'"); } // Collect all field storage ID's final TreeMap<Integer, AbstractSchemaItem> globalItemsByStorageId = new TreeMap<>(); for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { for (SchemaField field : schemaObjectType.getSchemaFields().values()) { globalItemsByStorageId.put(field.getStorageId(), field); if (field instanceof ComplexSchemaField) { final ComplexSchemaField complexField = (ComplexSchemaField)field; for (SimpleSchemaField subField : complexField.getSubFields().values()) globalItemsByStorageId.put(subField.getStorageId(), subField); } } } // Verify object type, field, and index storage ID's are non-overlapping for (SchemaObjectType schemaObjectType : this.schemaObjectTypes.values()) { SchemaModel.verifyUniqueStorageId(globalItemsByStorageId, schemaObjectType); for (SchemaCompositeIndex index : schemaObjectType.getSchemaCompositeIndexes().values()) SchemaModel.verifyUniqueStorageId(globalItemsByStorageId, index); } }