use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class SchemaReadWriteTestBase method setUp.
@BeforeEach
void setUp() throws Exception {
try (KernelTransaction transaction = beginTransaction()) {
SchemaRead schemaRead = transaction.schemaRead();
SchemaWrite schemaWrite = transaction.schemaWrite();
Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetAll();
while (constraints.hasNext()) {
schemaWrite.constraintDrop(constraints.next());
}
Iterator<IndexDescriptor> indexes = schemaRead.indexesGetAll();
while (indexes.hasNext()) {
schemaWrite.indexDrop(indexes.next());
}
TokenWrite tokenWrite = transaction.tokenWrite();
label = tokenWrite.labelGetOrCreateForName("label");
label2 = tokenWrite.labelGetOrCreateForName("label2");
type = tokenWrite.relationshipTypeGetOrCreateForName("relationship");
prop1 = tokenWrite.propertyKeyGetOrCreateForName("prop1");
prop2 = tokenWrite.propertyKeyGetOrCreateForName("prop2");
prop3 = tokenWrite.propertyKeyGetOrCreateForName("prop3");
transaction.commit();
}
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class TransactionImpl method createNode.
@Override
public Node createNode(Label... labels) {
var ktx = kernelTransaction();
try {
TokenWrite tokenWrite = ktx.tokenWrite();
int[] labelIds = new int[labels.length];
String[] labelNames = new String[labels.length];
for (int i = 0; i < labelNames.length; i++) {
labelNames[i] = labels[i].name();
}
tokenWrite.labelGetOrCreateForNames(labelNames, labelIds);
Write write = ktx.dataWrite();
long nodeId = write.nodeCreateWithLabels(labelIds);
return newNodeEntity(nodeId);
} catch (ConstraintValidationException e) {
throw new ConstraintViolationException("Unable to add label.", e);
} catch (SchemaKernelException e) {
throw new IllegalArgumentException(e);
} catch (KernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class IndexCreateIT method shouldCreateWithSpecificExistingProviderName.
protected void shouldCreateWithSpecificExistingProviderName(IndexCreator creator) throws KernelException {
int counter = 0;
for (GraphDatabaseSettings.SchemaIndex indexSetting : GraphDatabaseSettings.SchemaIndex.values()) {
// given
TokenWrite tokenWrite = tokenWriteInNewTransaction();
int labelId = tokenWrite.labelGetOrCreateForName("Label" + counter);
int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
commit();
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
LabelSchemaDescriptor descriptor = forLabel(labelId, propId);
String provider = indexSetting.providerName();
String indexName = "index-" + counter;
creator.create(schemaWrite, descriptor, provider, indexName);
IndexDescriptor index = transaction.kernelTransaction().schemaRead().indexGetForName(indexName);
// when
commit();
// then
assertEquals(provider, indexingService.getIndexProxy(index).getDescriptor().getIndexProvider().name());
counter++;
}
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class FullScanStoreViewTest method getOrCreateIds.
private void getOrCreateIds() throws KernelException {
try (Transaction tx = graphDb.beginTx()) {
TokenWrite tokenWrite = ((InternalTransaction) tx).kernelTransaction().tokenWrite();
labelId = tokenWrite.labelGetOrCreateForName("Person");
relTypeId = tokenWrite.relationshipTypeGetOrCreateForName("Knows");
propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName("name");
relPropertyKeyId = tokenWrite.propertyKeyGetOrCreateForName("duration");
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.
the class SchemaStorageIT method initStorage.
@BeforeEach
void initStorage() throws Exception {
try (Transaction transaction = db.beginTx()) {
TokenWrite tokenWrite = ((InternalTransaction) transaction).kernelTransaction().tokenWrite();
tokenWrite.propertyKeyGetOrCreateForName(PROP1);
tokenWrite.propertyKeyGetOrCreateForName(PROP2);
tokenWrite.labelGetOrCreateForName(LABEL1);
tokenWrite.labelGetOrCreateForName(LABEL2);
tokenWrite.relationshipTypeGetOrCreateForName(TYPE1);
transaction.commit();
}
schemaStore = storageEngine.testAccessNeoStores().getSchemaStore();
storage = new SchemaStorage(schemaStore, tokenHolders, () -> KernelVersion.LATEST);
}
Aggregations