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());
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations