@Description( "Create a Property" ) @Procedure( name = "db.createProperty", mode = WRITE ) public void createProperty( @Name( "newProperty" ) String newProperty ) throws IllegalTokenNameException { tx.tokenWrite().propertyKeyGetOrCreateForName( newProperty ); }
private int[] getOrCreatePropertyIds( String[] propertyKeyNames ) throws ProcedureException { int[] propertyKeyIds = new int[propertyKeyNames.length]; for ( int i = 0; i < propertyKeyIds.length; i++ ) { try { propertyKeyIds[i] = ktx.tokenWrite().propertyKeyGetOrCreateForName( propertyKeyNames[i] ); } catch ( IllegalTokenNameException e ) { throw new ProcedureException( e.status(), e, e.getMessage() ); } } return propertyKeyIds; }
@Before public void createKeys() throws Exception { TokenWrite tokenWrite = tokenWriteInNewTransaction(); this.labelId = tokenWrite.labelGetOrCreateForName( "Person" ); this.propertyId1 = tokenWrite.propertyKeyGetOrCreateForName( "foo" ); this.propertyId2 = tokenWrite.propertyKeyGetOrCreateForName( "bar" ); commit(); }
@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 void getOrCreateIds() throws KernelException { try ( Transaction tx = graphDb.beginTx() ) { ThreadToStatementContextBridge bridge = graphDb.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ); TokenWrite tokenWrite = bridge.getKernelTransactionBoundToThisThread( true ).tokenWrite(); labelId = tokenWrite.labelGetOrCreateForName( "Person" ); relTypeId = tokenWrite.relationshipTypeGetOrCreateForName( "Knows" ); propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName( "name" ); relPropertyKeyId = tokenWrite.propertyKeyGetOrCreateForName( "duration" ); tx.success(); } }
@Override protected void createCompositeIndex( GraphDatabaseService graphDb, String label, String... properties ) throws Exception { GraphDatabaseAPI internal = (GraphDatabaseAPI) graphDb; KernelTransaction ktx = internal.getDependencyResolver() .resolveDependency( ThreadToStatementContextBridge.class ) .getKernelTransactionBoundToThisThread( true ); SchemaWrite schemaWrite = ktx.schemaWrite(); TokenWrite token = ktx.tokenWrite(); schemaWrite.indexCreate( SchemaDescriptorFactory.forLabel( token.labelGetOrCreateForName( "Person" ), token.propertyKeyGetOrCreateForName( "firstname" ), token.propertyKeyGetOrCreateForName( "surname" ) ) ); } }
@Test public void listPropertyKeys() throws Throwable { // Given TokenWrite ops = tokenWriteInNewTransaction(); ops.propertyKeyGetOrCreateForName( "MyProp" ); commit(); // When RawIterator<Object[],ProcedureException> stream = procs().procedureCallRead( procs().procedureGet( procedureName( "db", "propertyKeys" ) ).id(), new Object[0] ); // Then assertThat( asList( stream ), contains( equalTo( new Object[]{"MyProp"} ) ) ); }
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; }
@BeforeClass public static void initStorage() throws Exception { try ( Transaction transaction = db.beginTx() ) { TokenWrite tokenWrite = getTransaction().tokenWrite(); tokenWrite.propertyKeyGetOrCreateForName( PROP1 ); tokenWrite.propertyKeyGetOrCreateForName( PROP2 ); tokenWrite.labelGetOrCreateForName( LABEL1 ); tokenWrite.labelGetOrCreateForName( LABEL2 ); tokenWrite.relationshipTypeGetOrCreateForName( TYPE1 ); transaction.success(); } SchemaStore schemaStore = resolveDependency( RecordStorageEngine.class ).testAccessNeoStores().getSchemaStore(); storage = new SchemaStorage( schemaStore ); }
private void createConstraint( String label, String propertyKey ) throws KernelException { int labelId; int propertyKeyId; TokenWrite tokenWrite = tokenWriteInNewTransaction(); labelId = tokenWrite.labelGetOrCreateForName( label ); propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName( propertyKey ); commit(); SchemaWrite schemaWrite = schemaWriteInNewTransaction(); schemaWrite.uniquePropertyConstraintCreate( forLabel( labelId, propertyKeyId ) ); commit(); } }
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 ); } }
@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(); }
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; } }
private long createPersonNode( KernelTransaction ktx, Object value ) throws KernelException { int labelId = ktx.tokenWrite().labelGetOrCreateForName( PERSON_LABEL ); int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName( NAME_PROPERTY ); long nodeId = ktx.dataWrite().nodeCreate(); ktx.dataWrite().nodeAddLabel( nodeId, labelId ); ktx.dataWrite().nodeSetProperty( nodeId, propertyKeyId, Values.of( value ) ); return nodeId; }
private long constrainedNode( String labelName, String propertyKey, Object propertyValue ) throws KernelException { long node; { Transaction transaction = newTransaction( AnonymousContext.writeToken() ); int label = transaction.tokenWrite().labelGetOrCreateForName( labelName ); node = transaction.dataWrite().nodeCreate(); transaction.dataWrite().nodeAddLabel( node, label ); int key = transaction.tokenWrite().propertyKeyGetOrCreateForName( propertyKey ); transaction.dataWrite().nodeSetProperty( node, key, Values.of( propertyValue ) ); commit(); } createConstraint( labelName, propertyKey ); return node; }