use of apoc.result.AssertSchemaResult in project neo4j-apoc-procedures by neo4j-contrib.
the class Schemas method createCompoundIndex.
private AssertSchemaResult createCompoundIndex(String label, List<String> keys) {
List<String> backTickedKeys = new ArrayList<>();
keys.forEach(key -> backTickedKeys.add(String.format("`%s`", key)));
db.execute(String.format("CREATE INDEX ON :`%s` (%s)", label, String.join(",", backTickedKeys)));
return new AssertSchemaResult(label, keys).created();
}
use of apoc.result.AssertSchemaResult in project neo4j-apoc-procedures by neo4j-contrib.
the class Schemas method assertConstraints.
public List<AssertSchemaResult> assertConstraints(Map<String, List<String>> constraints0, boolean dropExisting) throws ExecutionException, InterruptedException {
Map<String, List<String>> constraints = copy(constraints0);
List<AssertSchemaResult> result = new ArrayList<>(constraints.size());
Schema schema = db.schema();
for (ConstraintDefinition definition : schema.getConstraints()) {
if (!definition.isConstraintType(ConstraintType.UNIQUENESS))
continue;
String label = definition.getLabel().name();
String key = Iterables.single(definition.getPropertyKeys());
AssertSchemaResult info = new AssertSchemaResult(label, key).unique();
if (!constraints.containsKey(label) || !constraints.get(label).remove(key)) {
if (dropExisting) {
definition.drop();
info.dropped();
}
}
result.add(info);
}
for (Map.Entry<String, List<String>> constraint : constraints.entrySet()) {
for (String key : constraint.getValue()) {
schema.constraintFor(label(constraint.getKey())).assertPropertyIsUnique(key).create();
result.add(new AssertSchemaResult(constraint.getKey(), key).unique().created());
}
}
return result;
}
use of apoc.result.AssertSchemaResult in project neo4j-apoc-procedures by neo4j-contrib.
the class Schemas method assertIndexes.
public List<AssertSchemaResult> assertIndexes(Map<String, List<Object>> indexes0, boolean dropExisting) throws ExecutionException, InterruptedException, IllegalArgumentException {
Schema schema = db.schema();
Map<String, List<Object>> indexes = copyMapOfObjects(indexes0);
List<AssertSchemaResult> result = new ArrayList<>(indexes.size());
for (IndexDefinition definition : schema.getIndexes()) {
if (definition.isConstraintIndex())
continue;
String label = definition.getLabel().name();
List<String> keys = new ArrayList<>();
definition.getPropertyKeys().forEach(keys::add);
AssertSchemaResult info = new AssertSchemaResult(label, keys);
if (indexes.containsKey(label)) {
if (keys.size() > 1) {
indexes.get(label).remove(keys);
} else if (keys.size() == 1) {
indexes.get(label).remove(keys.get(0));
} else
throw new IllegalArgumentException("Label given with no keys.");
}
if (dropExisting) {
definition.drop();
info.dropped();
}
result.add(info);
}
if (dropExisting)
indexes = copyMapOfObjects(indexes0);
for (Map.Entry<String, List<Object>> index : indexes.entrySet()) {
for (Object key : index.getValue()) {
if (key instanceof String) {
result.add(createSinglePropertyIndex(schema, index.getKey(), (String) key));
} else if (key instanceof List) {
result.add(createCompoundIndex(index.getKey(), (List<String>) key));
}
}
}
return result;
}
Aggregations