Search in sources :

Example 21 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method createUniquenessConstraint.

private NewIndexDescriptor createUniquenessConstraint(int labelId, int... propertyIds) throws Exception {
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyIds);
    statement.schemaWriteOperations().uniquePropertyConstraintCreate(descriptor);
    NewIndexDescriptor result = statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(SchemaBoundary.map(descriptor));
    commit();
    return result;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 22 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldNeverDelegateWrites.

@Test
public void shouldNeverDelegateWrites() throws Exception {
    KernelStatement state = mockedState();
    when(state.txState()).thenReturn(new TxState());
    StoreStatement storeStatement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(storeStatement);
    when(inner.indexesGetForLabel(0)).thenReturn(iterator(NewIndexDescriptorFactory.forLabel(0, 0)));
    when(storeStatement.acquireSingleNodeCursor(anyLong())).thenReturn(asNodeCursor(0));
    when(inner.nodeGetProperties(eq(storeStatement), any(NodeItem.class))).thenReturn(asPropertyCursor());
    StateHandlingStatementOperations ctx = newTxStateOps(inner);
    // When
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
    ctx.indexCreate(state, descriptor);
    ctx.nodeAddLabel(state, 0, 0);
    ctx.indexDrop(state, NewIndexDescriptorFactory.forSchema(descriptor));
    ctx.nodeRemoveLabel(state, 0, 0);
    // one for add and one for remove
    verify(storeStatement, times(2)).acquireSingleNodeCursor(0);
    verifyNoMoreInteractions(storeStatement);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 23 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class SchemaCacheTest method shouldResolveIndexDescriptor.

@Test
public void shouldResolveIndexDescriptor() throws Exception {
    // Given
    SchemaCache cache = newSchemaCache();
    cache.addSchemaRule(newIndexRule(1L, 1, 2));
    cache.addSchemaRule(newIndexRule(2L, 1, 3));
    cache.addSchemaRule(newIndexRule(3L, 2, 2));
    // When
    LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(1, 3);
    NewIndexDescriptor descriptor = cache.indexDescriptor(schema);
    // Then
    assertThat(descriptor.schema(), equalTo(schema));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Aggregations

LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)23 Test (org.junit.Test)12 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)5 Transaction (org.neo4j.graphdb.Transaction)4 Statement (org.neo4j.kernel.api.Statement)4 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)4 Node (org.neo4j.graphdb.Node)3 Pair (org.neo4j.helpers.collection.Pair)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1