use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexProcedures method createNodeKey.
public Stream<BuiltInProcedures.SchemaIndexInfo> createNodeKey(String constraintName, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap) throws ProcedureException {
return createIndex(constraintName, labels, properties, indexProviderDescriptor, configMap, "node key constraint online", (schemaWrite, name, schema, provider, indexConfig) -> {
final IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, provider).withName(name).withIndexConfig(indexConfig);
schemaWrite.nodeKeyConstraintCreate(prototype);
});
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertParseIndexRule.
private static void assertParseIndexRule(String serialized, String name) throws Exception {
// GIVEN
long ruleId = 24;
IndexPrototype prototype = forLabel(512, 4).withIndexProvider(PROVIDER_25);
byte[] bytes = decodeBase64(serialized);
// WHEN
IndexDescriptor deserialized = assertIndexRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
// THEN
assertThat(deserialized.getId()).isEqualTo(ruleId);
assertThat(deserialized).isEqualTo(prototype.withName(name).materialise(ruleId));
assertThat(deserialized.schema()).isEqualTo(prototype.schema());
assertThat(deserialized.getIndexProvider().getKey()).isEqualTo(PROVIDER_KEY);
assertThat(deserialized.getIndexProvider().getVersion()).isEqualTo(PROVIDER_VERSION_25);
assertThat(deserialized.getName()).isEqualTo(name);
assertTrue(deserialized.getOwningConstraintId().isEmpty());
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaStore method buildIndexRule.
private static SchemaRule buildIndexRule(long schemaRuleId, Map<String, Value> props) throws MalformedSchemaRuleException {
SchemaDescriptor schema = buildSchemaDescriptor(props);
String indexRuleType = getString(PROP_INDEX_RULE_TYPE, props);
boolean unique = parseIndexType(indexRuleType);
IndexPrototype prototype = unique ? IndexPrototype.uniqueForSchema(schema) : IndexPrototype.forSchema(schema);
prototype = prototype.withName(getString(PROP_SCHEMA_RULE_NAME, props));
prototype = prototype.withIndexType(getIndexType(getString(PROP_INDEX_TYPE, props)));
String providerKey = getString(PROP_INDEX_PROVIDER_NAME, props);
String providerVersion = getString(PROP_INDEX_PROVIDER_VERSION, props);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
prototype = prototype.withIndexProvider(providerDescriptor);
IndexDescriptor index = prototype.materialise(schemaRuleId);
IndexConfig indexConfig = extractIndexConfig(props);
index = index.withIndexConfig(indexConfig);
if (props.containsKey(PROP_OWNING_CONSTRAINT)) {
index = index.withOwningConstraintId(getLong(PROP_OWNING_CONSTRAINT, props));
}
return index;
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexIT method shouldBeAbleToRemoveAConstraintIndexWithoutOwner.
@Test
void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception {
// given
AssertableLogProvider logProvider = new AssertableLogProvider();
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
IndexProviderDescriptor provider = GenericNativeIndexProvider.DESCRIPTOR;
IndexPrototype prototype = uniqueForSchema(schema).withName("constraint name").withIndexProvider(provider);
IndexDescriptor constraintIndex = creator.createConstraintIndex(prototype);
// then
KernelTransaction transaction = newTransaction();
assertEquals(emptySet(), asSet(transaction.schemaRead().constraintsGetForLabel(labelId)));
commit();
// when
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
schemaWrite.indexDrop(constraintIndex);
commit();
// then
transaction = newTransaction();
assertEquals(emptySet(), asSet(transaction.schemaRead().indexesGetForLabel(labelId)));
commit();
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexIT method shouldListMultiTokenIndexesInTheCoreAPI.
@Test
void shouldListMultiTokenIndexesInTheCoreAPI() throws Exception {
KernelTransaction transaction = newTransaction(AUTH_DISABLED);
long initialIndexCount = Iterators.count(transaction.schemaRead().indexesGetAll());
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.NODE, new int[] { labelId, labelId2 }, new int[] { propertyKeyId });
IndexPrototype prototype = IndexPrototype.forSchema(schema, FulltextIndexProviderFactory.DESCRIPTOR).withIndexType(IndexType.FULLTEXT).withName("multi token index");
transaction.schemaWrite().indexCreate(prototype);
commit();
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
// then
Set<IndexDefinition> indexes = Iterables.asSet(tx.schema().getIndexes());
assertThat(indexes.size()).isEqualTo(initialIndexCount + 1);
IndexDefinition index = tx.schema().getIndexByName("multi token index");
assertThrows(IllegalStateException.class, index::getRelationshipTypes);
assertThat(index.getLabels()).containsOnly(label(LABEL), label(LABEL2));
assertThat(index.getPropertyKeys()).containsOnly(PROPERTY_KEY);
assertFalse(index.isConstraintIndex(), "should not be a constraint index");
assertTrue(index.isMultiTokenIndex(), "should be a multi-token index");
assertFalse(index.isCompositeIndex(), "should not be a composite index");
assertTrue(index.isNodeIndex(), "should be a node index");
assertFalse(index.isRelationshipIndex(), "should not be a relationship index");
}
}
Aggregations