Search in sources :

Example 6 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class SchemaStatementProcedureTest method schemaStatementsShouldHandleIndexWithBackticks.

@Test
void schemaStatementsShouldHandleIndexWithBackticks() throws IndexNotFoundKernelException, ProcedureException, LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
    IndexDescriptor index = forSchema(forLabel(1, 1)).withName(NAME_WITH_BACKTICKS).materialise(1);
    InternalIndexState internalIndexState = InternalIndexState.ONLINE;
    SchemaReadCore schemaReadCore = getSchemaReadCore(index, internalIndexState);
    TokenRead tokenRead = mock(TokenRead.class);
    when(tokenRead.nodeLabelName(1)).thenReturn(LABEL_WITH_BACKTICKS);
    when(tokenRead.propertyKeyName(1)).thenReturn(PROPERTY_KEY_WITH_BACKTICKS);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
    assertTrue(iter.hasNext());
    BuiltInProcedures.SchemaStatementResult next = iter.next();
    assertEquals(NAME_WITH_BACKTICKS, next.name);
    assertEquals(format("CALL db.createIndex('%s', ['%s'], ['%s'], 'Undecided-0', {})", NAME_WITH_BACKTICKS, LABEL_WITH_BACKTICKS, PROPERTY_KEY_WITH_BACKTICKS), next.createStatement);
    assertEquals(format("DROP INDEX %s", ESCAPED_NAME_WITH_BACKTICKS), next.dropStatement);
    assertFalse(iter.hasNext());
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 7 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeFailedIndexes.

@Test
void schemaStatementsMustNotIncludeFailedIndexes() throws IndexNotFoundKernelException, ProcedureException {
    IndexDescriptor index = someIndex();
    InternalIndexState indexState = InternalIndexState.FAILED;
    SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
    TokenRead tokenRead = mock(TokenRead.class);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    assertEquals(0, result.size());
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 8 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class NodeEntity method getAllProperties.

public Map<String, Object> getAllProperties(NodeCursor nodes, PropertyCursor propertyCursor) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    Map<String, Object> properties = new HashMap<>();
    try {
        TokenRead token = transaction.tokenRead();
        if (nodes.isClosed() || nodes.nodeReference() != getId()) {
            singleNode(transaction, nodes);
        }
        nodes.properties(propertyCursor);
        while (propertyCursor.next()) {
            properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
    return properties;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) HashMap(java.util.HashMap) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 9 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class NodeEntity method getRelationshipTypes.

@Override
public Iterable<RelationshipType> getRelationshipTypes() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    try {
        NodeCursor nodes = transaction.ambientNodeCursor();
        TokenRead tokenRead = transaction.tokenRead();
        singleNode(transaction, nodes);
        Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
        List<RelationshipType> types = new ArrayList<>();
        for (int type : degrees.types()) {
            // only include this type if there are any relationships with this type
            if (degrees.totalDegree(type) > 0) {
                types.add(RelationshipType.withName(tokenRead.relationshipTypeName(type)));
            }
        }
        return types;
    } catch (KernelException e) {
        throw new NotFoundException("Relationship name not found.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Degrees(org.neo4j.storageengine.api.Degrees) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 10 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method getLabelIdsByName.

private Map<String, Integer> getLabelIdsByName(Transaction tx, String... names) {
    Map<String, Integer> labelNameIdMap = new HashMap<>();
    KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
    TokenRead tokenRead = ktx.tokenRead();
    for (String name : names) {
        labelNameIdMap.put(name, tokenRead.nodeLabel(name));
    }
    return labelNameIdMap;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) HashMap(java.util.HashMap) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Aggregations

TokenRead (org.neo4j.internal.kernel.api.TokenRead)59 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)42 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 Test (org.junit.jupiter.api.Test)19 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Transaction (org.neo4j.graphdb.Transaction)13 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)13 Label (org.neo4j.graphdb.Label)12 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)11 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)11 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 RelationshipType (org.neo4j.graphdb.RelationshipType)7 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 Arrays (java.util.Arrays)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5