return indexes == null ? null : indexes.getDocument(name);
}
public IndexDefinition getIndex( final String name ) {
if (name == null) return null;
final Document doc = getRawIndex(name);
if (doc == null) return null;
return new IndexDefinition() {
private List<IndexColumnDefinition> columns;
private Map<String, Object> properties;
@Override
public String getName() {
return name;
}
@Override
public String getProviderName() {
return doc.getString(FieldName.PROVIDER_NAME);
}
@Override
public String getDescription() {
return doc.getString(FieldName.DESCRIPTION);
}
@Override
public IndexKind getKind() {
String kindStr = doc.getString(FieldName.KIND, Default.KIND);
if (FieldValue.KIND_VALUE.equalsIgnoreCase(kindStr)) {
return IndexKind.VALUE;
}
if (FieldValue.KIND_UNIQUE.equalsIgnoreCase(kindStr)) {
return IndexKind.UNIQUE_VALUE;
}
if (FieldValue.KIND_ENUMERATED.equalsIgnoreCase(kindStr)) {
return IndexKind.ENUMERATED_VALUE;
}
if (FieldValue.KIND_TEXT.equalsIgnoreCase(kindStr)) {
return IndexKind.TEXT;
}
if (FieldValue.KIND_NODE_TYPE.equalsIgnoreCase(kindStr)) {
return IndexKind.NODE_TYPE;
}
return IndexKind.VALUE;
}
@Override
public String getNodeTypeName() {
return doc.getString(FieldName.NODE_TYPE, Default.NODE_TYPE);
}
@Override
public WorkspaceMatchRule getWorkspaceMatchRule() {
String rule = doc.getString(FieldName.WORKSPACES, Default.WORKSPACES);
return RepositoryIndexDefinition.workspaceMatchRule(rule);
}
@Override
public boolean isSynchronous() {
return doc.getBoolean(FieldName.SYNCHRONOUS, Default.SYNCHRONOUS);
}
@Override
public boolean isEnabled() {
return true;
}
@Override
public int size() {
return columns().size();
}
@Override
public boolean appliesToProperty( String propertyName ) {
for (IndexColumnDefinition defn : columns()) {
if (defn.getPropertyName().equals(propertyName)) return true;
}
return false;
}
@Override
public IndexColumnDefinition getColumnDefinition( int position ) throws NoSuchElementException {
return columns().get(position);
}
@Override
public boolean hasSingleColumn() {
return size() == 1;
}
@Override
public Iterator<IndexColumnDefinition> iterator() {
return columns.iterator();
}
@Override
public Object getIndexProperty( String propertyName ) {
return doc.get(name);
}
@Override
public Map<String, Object> getIndexProperties() {
if (properties == null) {
// Read in the properties ...
properties = new HashMap<>();
for (Field field : doc.fields()) {
if (INDEX_PROVIDER_FIELDS.contains(field.getName())) continue;
properties.put(field.getName(), field.getValue());
}
}
return properties;
}
protected List<IndexColumnDefinition> columns() {
if (columns == null) {
columns = new ArrayList<>();
String columnDefnsStr = doc.getString(FieldName.COLUMNS);
if (columnDefnsStr != null) {
for (String columnDefn : columnDefnsStr.split(",")) {
if (columnDefn.trim().length() == 0) continue;
try {
Matcher matcher = COLUMN_DEFN_PATTERN.matcher(columnDefn);