@Override protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException { return transaction.tokenWrite().relationshipTypeCreateForName( name ); } }
@Override protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException { return transaction.tokenWrite().propertyKeyCreateForName( name ); } }
@Override protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException, TooManyLabelsException { return transaction.tokenWrite().labelCreateForName( name ); } }
protected TokenWrite tokenWriteInNewTransaction() throws KernelException { transaction = kernel.beginTransaction( implicit, AnonymousContext.writeToken() ); return transaction.tokenWrite(); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); }
private Pair<Long,Value> nodeWithProp( Transaction tx, Object value ) throws Exception { Write write = tx.dataWrite(); long node = write.nodeCreate(); write.nodeAddLabel( node, tx.tokenWrite().labelGetOrCreateForName( "Node" ) ); Value val = Values.of( value ); write.nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), val ); return Pair.of( node, val ); } }
private IndexDescriptor indexDescriptor( Label label, String propertyKey, boolean constraint ) throws TransactionFailureException, IllegalTokenNameException, TooManyLabelsException { try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { int labelId = tx.tokenWrite().labelGetOrCreateForName( label.name() ); int propertyKeyId = tx.tokenWrite().propertyKeyGetOrCreateForName( propertyKey ); SchemaDescriptor schema = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId ); IndexDescriptor descriptor = constraint ? IndexDescriptorFactory.uniqueForSchema( schema, PROVIDER_DESCRIPTOR ) : IndexDescriptorFactory.forSchema( schema, PROVIDER_DESCRIPTOR ); tx.success(); return descriptor; } }
@Test public void shouldFindConstraintsByLabel() throws Exception { // GIVEN addConstraints( "FOO", "prop1", "FOO", "prop2" ); try ( Transaction tx = beginTransaction() ) { int label = tx.tokenWrite().labelGetOrCreateForName( "FOO" ); //WHEN List<ConstraintDescriptor> constraints = asList( tx.schemaRead().constraintsGetForLabel( label ) ); // THEN assertThat( constraints, hasSize( 2 ) ); } }
@Test public void shouldBeAbleToWriteNewGraphProperty() throws Exception { int prop; try ( Transaction tx = beginTransaction() ) { prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "hello" ) ); } }
private long createLabeledNode( Transaction transaction, String label ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); int labelId = transaction.tokenWrite().labelGetOrCreateForName( label ); transaction.dataWrite().nodeAddLabel( node, labelId ); return node; }
private long createLabeledNode( Transaction transaction, String label, String key, Object value ) throws KernelException { long node = createLabeledNode( transaction, label ); int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) ); return node; }
private IndexReference createIndex( org.neo4j.internal.kernel.api.Transaction transaction ) throws SchemaKernelException, InvalidTransactionTypeKernelException { TokenWrite tokenWrite = transaction.tokenWrite(); SchemaWrite schemaWrite = transaction.schemaWrite(); LabelSchemaDescriptor schemaDescriptor = forLabel( tokenWrite.labelGetOrCreateForName( "hello" ), tokenWrite.propertyKeyGetOrCreateForName( "hepp" ) ); return schemaWrite.indexCreate( schemaDescriptor ); }
@Test public void shouldSeeNewGraphPropertyInTransaction() throws Exception { try ( Transaction tx = beginTransaction(); PropertyCursor cursor = tx.cursors().allocatePropertyCursor() ) { int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.dataRead().graphProperties( cursor ); assertTrue( cursor.next() ); assertThat( cursor.propertyKey(), equalTo( prop ) ); assertThat( cursor.propertyValue(), equalTo( stringValue( "hello" ) ) ); } }
private long createNode( Transaction transaction, String key, Object value ) throws KernelException { long node = transaction.dataWrite().nodeCreate(); int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( value ) ); return node; }
@Test public void shouldReturnRelsWhenAskingForRelsWhereOnlySomeTypesExistInCurrentRel() throws Exception { Transaction transaction = newTransaction( AnonymousContext.writeToken() ); int relType1 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type1" ); int relType2 = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "Type2" ); long refNode = transaction.dataWrite().nodeCreate(); long otherNode = transaction.dataWrite().nodeCreate(); long theRel = transaction.dataWrite().relationshipCreate( refNode, relType1, otherNode ); assertRels( nodeGetRelationships( transaction, refNode, OUTGOING, new int[]{relType2,relType1} ), theRel ); commit(); }
@Test public void shouldAllowNoopLabelUpdate() throws KernelException { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" ); transaction.dataWrite().nodeAddLabel( node, label ); // then should not throw exception commit(); }
@Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_RemoveLabel() throws Exception { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int label = transaction.tokenWrite().labelGetOrCreateForName( "Label1" ); transaction.dataWrite().nodeRemoveLabel( node, label ); createLabeledNode( transaction, "Label1", "key1", "value1" ); commit(); }
@Before public void before() throws Exception { db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder() .setConfig( GraphDatabaseSettings.record_id_batch_size, "1" ).newGraphDatabase(); kernel = db.getDependencyResolver().resolveDependency( Kernel.class ); stateHolder = new DatabaseSchemaState( NullLogProvider.getInstance() ); indexStoreView = indexStoreView(); try ( Transaction tx = kernel.beginTransaction( implicit, AUTH_DISABLED ) ) { labelId = tx.tokenWrite().labelGetOrCreateForName( FIRST.name() ); tx.tokenWrite().labelGetOrCreateForName( SECOND.name() ); tx.success(); } }
@Test public void shouldAllowNoopPropertyUpdate() throws KernelException { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int key = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" ); transaction.dataWrite().nodeSetProperty( node, key, Values.of( "value1" ) ); // then should not throw exception commit(); }
@Test public void shouldAllowRemoveAndAddConflictingDataInOneTransaction_ChangeProperty() throws Exception { // given long node = constrainedNode( "Label1", "key1", "value1" ); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); // when int propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( "key1" ); transaction.dataWrite().nodeSetProperty( node, propertyKeyId, Values.of( "value2" ) ); createLabeledNode( transaction, "Label1", "key1", "value1" ); commit(); }