use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class CountsComputerTest method getRelTypeIdsFrom.
private int[] getRelTypeIdsFrom(Transaction tx, RelationshipType... types) throws KernelException {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenWrite tokenWrite = ktx.tokenWrite();
int[] ids = new int[types.length];
tokenWrite.relationshipTypeGetOrCreateForNames(Arrays.stream(types).map(RelationshipType::name).toArray(String[]::new), ids);
return ids;
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class CountsComputerTest method getLabelIdsFrom.
private int[] getLabelIdsFrom(Transaction tx, Label... labels) throws KernelException {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenWrite tokenWrite = ktx.tokenWrite();
int[] ids = new int[labels.length];
tokenWrite.relationshipTypeGetOrCreateForNames(Arrays.stream(labels).map(Label::name).toArray(String[]::new), ids);
return ids;
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class WriteTestSupport method setup.
@Override
public void setup(Path storeDir, Consumer<GraphDatabaseService> sysCreate) {
TestDatabaseManagementServiceBuilder databaseManagementServiceBuilder = newManagementServiceBuilder(storeDir);
managementService = configure(databaseManagementServiceBuilder).build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try (KernelTransaction tx = beginTransaction()) {
// We are creating these dummy tokens so that that the ones that we actually use don't get
// the value 0. Using 0 may hide bugs that are caused by default the initialization of ints
TokenWrite tokenWrite = tx.tokenWrite();
tokenWrite.propertyKeyCreateForName("DO_NOT_USE", false);
tokenWrite.labelCreateForName("DO_NOT_USE", false);
tokenWrite.relationshipTypeCreateForName("DO_NOT_USE", false);
} catch (KernelException e) {
throw new AssertionError("Failed to setup database", e);
}
GraphDatabaseService sysDb = managementService.database(SYSTEM_DATABASE_NAME);
sysCreate.accept(sysDb);
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class CachingExpandIntoTest method shouldComputeDegreeWithType.
@Test
void shouldComputeDegreeWithType() throws Exception {
// GIVEN
long node;
int in, out, loop;
try (KernelTransaction tx = transaction()) {
Write write = tx.dataWrite();
node = denseNode(tx);
TokenWrite tokenWrite = tx.tokenWrite();
out = tokenWrite.relationshipTypeGetOrCreateForName("OUT");
in = tokenWrite.relationshipTypeGetOrCreateForName("IN");
loop = tokenWrite.relationshipTypeGetOrCreateForName("LOOP");
write.relationshipCreate(node, out, write.nodeCreate());
write.relationshipCreate(node, out, write.nodeCreate());
write.relationshipCreate(write.nodeCreate(), in, node);
write.relationshipCreate(node, loop, node);
tx.commit();
}
try (KernelTransaction tx = transaction()) {
Read read = tx.dataRead();
CursorFactory cursors = tx.cursors();
try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
read.singleNode(node, nodes);
assertThat(nodes.next()).isEqualTo(true);
assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
assertThat(degrees.outgoingDegree(out)).isEqualTo(2);
assertThat(degrees.outgoingDegree(in)).isEqualTo(0);
assertThat(degrees.outgoingDegree(loop)).isEqualTo(1);
assertThat(degrees.incomingDegree(out)).isEqualTo(0);
assertThat(degrees.incomingDegree(in)).isEqualTo(1);
assertThat(degrees.incomingDegree(loop)).isEqualTo(1);
assertThat(degrees.totalDegree(out)).isEqualTo(2);
assertThat(degrees.totalDegree(in)).isEqualTo(1);
assertThat(degrees.totalDegree(loop)).isEqualTo(1);
}
}
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class IndexCreateIT method shouldFailCreateIndexWithDuplicateProperties.
@Test
void shouldFailCreateIndexWithDuplicateProperties() throws KernelException {
// given
TokenWrite tokenWrite = tokenWriteInNewTransaction();
int labelId = tokenWrite.labelGetOrCreateForName("Label");
int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
commit();
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
// when
final FulltextSchemaDescriptor descriptor = SchemaDescriptor.fulltext(EntityType.NODE, new int[] { labelId }, new int[] { propId, propId });
// then
assertThrows(RepeatedPropertyInSchemaException.class, () -> schemaWrite.indexCreate(descriptor, null));
}
Aggregations