Search in sources :

Example 1 with TokenNameLookup

use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.

the class SchemaStorageTest method shouldThrowExceptionOnRelationshipDuplicateRuleFound.

@Test
public void shouldThrowExceptionOnRelationshipDuplicateRuleFound() throws DuplicateSchemaRuleException, SchemaRuleNotFoundException {
    // GIVEN
    TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
    SchemaStorage schemaStorageSpy = Mockito.spy(storage);
    Mockito.when(schemaStorageSpy.loadAllSchemaRules(any(), any(), anyBoolean())).thenReturn(Iterators.iterator(getRelationshipPropertyExistenceConstraintRule(1L, TYPE1, PROP1), getRelationshipPropertyExistenceConstraintRule(2L, TYPE1, PROP1)));
    //EXPECT
    expectedException.expect(DuplicateSchemaRuleException.class);
    expectedException.expect(new KernelExceptionUserMessageMatcher(tokenNameLookup, "Multiple relationship property existence constraints found for -[:Type1(prop1)]-."));
    // WHEN
    schemaStorageSpy.constraintsGetSingle(ConstraintDescriptorFactory.existsForRelType(typeId(TYPE1), propId(PROP1)));
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) KernelExceptionUserMessageMatcher(org.neo4j.test.mockito.matcher.KernelExceptionUserMessageMatcher) Test(org.junit.Test)

Example 2 with TokenNameLookup

use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.

the class SchemaStorageTest method getDefaultTokenNameLookup.

private TokenNameLookup getDefaultTokenNameLookup() {
    TokenNameLookup tokenNameLookup = Mockito.mock(TokenNameLookup.class);
    Mockito.when(tokenNameLookup.labelGetName(labelId(LABEL1))).thenReturn(LABEL1);
    Mockito.when(tokenNameLookup.propertyKeyGetName(propId(PROP1))).thenReturn(PROP1);
    Mockito.when(tokenNameLookup.relationshipTypeGetName(typeId(TYPE1))).thenReturn(TYPE1);
    return tokenNameLookup;
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup)

Example 3 with TokenNameLookup

use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.

the class OperationsFacadeTest method testThrowExceptionWhenDuplicateUniqueIndexFound.

@Test
public void testThrowExceptionWhenDuplicateUniqueIndexFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    SchemaReadOperations readOperations = setupSchemaReadOperations();
    NewIndexDescriptor index = NewIndexDescriptorFactory.forSchema(SchemaBoundary.map(descriptor));
    Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), Mockito.eq(descriptor.getLabelId()))).thenReturn(Iterators.iterator(index, index));
    TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
    expectedException.expect(DuplicateSchemaRuleException.class);
    expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "Multiple constraint indexs found for :Label1(Prop1)."));
    operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Test(org.junit.Test)

Example 4 with TokenNameLookup

use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.

the class OperationsFacadeTest method getDefaultTokenNameLookup.

private TokenNameLookup getDefaultTokenNameLookup() {
    TokenNameLookup tokenNameLookup = Mockito.mock(TokenNameLookup.class);
    Mockito.when(tokenNameLookup.labelGetName(descriptor.getLabelId())).thenReturn(LABEL1);
    Mockito.when(tokenNameLookup.propertyKeyGetName(descriptor.getPropertyKeyId())).thenReturn(PROP1);
    return tokenNameLookup;
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup)

Example 5 with TokenNameLookup

use of org.neo4j.kernel.api.TokenNameLookup in project neo4j by neo4j.

the class BuiltInProcedures method listConstraints.

@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ)
public Stream<ConstraintResult> listConstraints() {
    Statement statement = tx.acquireStatement();
    ReadOperations operations = statement.readOperations();
    TokenNameLookup tokens = new StatementTokenNameLookup(operations);
    return asList(operations.constraintsGetAll()).stream().map((constraint) -> constraint.prettyPrint(tokens)).sorted().map(ConstraintResult::new).onClose(statement::close);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

TokenNameLookup (org.neo4j.kernel.api.TokenNameLookup)12 Test (org.junit.Test)7 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)3 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 KernelExceptionUserMessageMatcher (org.neo4j.test.mockito.matcher.KernelExceptionUserMessageMatcher)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Stream (java.util.stream.Stream)2 DependencyResolver (org.neo4j.graphdb.DependencyResolver)2 Label (org.neo4j.graphdb.Label)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 Iterators.asList (org.neo4j.helpers.collection.Iterators.asList)2 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2