Search in sources :

Example 21 with SchemaRead

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

the class GraphCountsSection method constraints.

private static List<Map<String, Object>> constraints(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) {
    List<Map<String, Object>> constraints = new ArrayList<>();
    Iterator<ConstraintDescriptor> iterator = schemaRead.constraintsGetAll();
    while (iterator.hasNext()) {
        ConstraintDescriptor constraint = iterator.next();
        EntityType entityType = constraint.schema().entityType();
        Map<String, Object> data = new HashMap<>();
        data.put("properties", map(constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
        data.put("type", constraintType(constraint));
        int entityTokenId = constraint.schema().getEntityTokenIds()[0];
        switch(entityType) {
            case NODE:
                data.put("label", anonymizer.label(tokens.labelGetName(entityTokenId), entityTokenId));
                constraints.add(data);
                break;
            case RELATIONSHIP:
                data.put("relationshipType", anonymizer.relationshipType(tokens.relationshipTypeGetName(entityTokenId), entityTokenId));
                constraints.add(data);
                break;
            default:
        }
    }
    return constraints;
}
Also used : EntityType(org.neo4j.common.EntityType) Arrays(java.util.Arrays) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexType(org.neo4j.internal.schema.IndexType) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) Kernel(org.neo4j.kernel.api.Kernel) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stream(java.util.stream.Stream) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) EntityType(org.neo4j.common.EntityType) Map(java.util.Map) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) IntFunction(java.util.function.IntFunction) HashMap(java.util.HashMap) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with SchemaRead

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

the class TransactionImpl method findUsableMatchingIndex.

/**
 * Find an ONLINE index that matches the schema.
 */
private static IndexDescriptor findUsableMatchingIndex(KernelTransaction transaction, SchemaDescriptor schemaDescriptor) {
    SchemaRead schemaRead = transaction.schemaRead();
    Iterator<IndexDescriptor> iterator = schemaRead.index(schemaDescriptor);
    while (iterator.hasNext()) {
        IndexDescriptor index = iterator.next();
        if (index.getIndexType() != IndexType.FULLTEXT && indexIsOnline(schemaRead, index)) {
            return index;
        }
    }
    return IndexDescriptor.NO_INDEX;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 23 with SchemaRead

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

the class SchemaImpl method getConstraints.

@Override
public Iterable<ConstraintDefinition> getConstraints(final Label label) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    int labelId = tokenRead.nodeLabel(label.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    return asConstraintDefinitions(schemaRead.constraintsGetForLabel(labelId), tokenRead);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 24 with SchemaRead

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

the class SchemaImpl method awaitIndexOnline.

@Override
public void awaitIndexOnline(String indexName, long duration, TimeUnit unit) {
    requireNonNull(indexName);
    transaction.assertOpen();
    SchemaRead schemaRead = transaction.schemaRead();
    Iterable<IndexDescriptor> iterable = () -> Iterators.iterator(schemaRead.indexGetForName(indexName));
    if (awaitIndexesOnline(iterable, index -> "`" + indexName + "`", duration, unit, false)) {
        throw new IllegalStateException("Expected index to come online within a reasonable time.");
    }
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 25 with SchemaRead

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

the class SchemaImpl method getIndexes.

@Override
public Iterable<IndexDefinition> getIndexes() {
    transaction.assertOpen();
    SchemaRead schemaRead = transaction.schemaRead();
    List<IndexDefinition> definitions = new ArrayList<>();
    Iterator<IndexDescriptor> indexes = schemaRead.indexesGetAll();
    addDefinitions(definitions, transaction.tokenRead(), IndexDescriptor.sortByType(indexes));
    return definitions;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Aggregations

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3