@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(); }
private void createRelationship( long startNode, String type, long endNode, List<String> propKeys, List<Value> propValues ) throws Throwable { assert type != null && !type.equals( "" ); assert propKeys.size() == propValues.size(); Transaction transaction = newTransaction( AnonymousContext.writeToken() ); int typeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName( type ); long relId = transaction.dataWrite().relationshipCreate( startNode, typeId, endNode ); for ( int i = 0; i < propKeys.size(); i++ ) { String propKeyName = propKeys.get( i ); Value propValue = propValues.get( i ); int propKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( propKeyName ); transaction.dataWrite().relationshipSetProperty( relId, propKeyId, propValue ); } commit(); }
@Override protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException { return transaction.tokenWrite().propertyKeyCreateForName( name ); } }
@Before public void createLabelAndProperty() throws Exception { TokenWrite tokenWrites = tokenWriteInNewTransaction(); labelId = tokenWrites.labelGetOrCreateForName( LABEL ); labelId2 = tokenWrites.labelGetOrCreateForName( LABEL2 ); relType = tokenWrites.relationshipTypeGetOrCreateForName( REL_TYPE ); relType2 = tokenWrites.relationshipTypeGetOrCreateForName( REL_TYPE2 ); propertyKeyId = tokenWrites.propertyKeyGetOrCreateForName( PROPERTY_KEY ); propertyKeyId2 = tokenWrites.propertyKeyGetOrCreateForName( PROPERTY_KEY2 ); descriptor = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId ); descriptor2 = SchemaDescriptorFactory.forLabel( labelId, propertyKeyId2 ); commit(); executorService = Executors.newCachedThreadPool(); }
@Description( "Create a RelationshipType" ) @Procedure( name = "db.createRelationshipType", mode = WRITE ) public void createRelationshipType( @Name( "newRelationshipType" ) String newRelationshipType ) throws IllegalTokenNameException { tx.tokenWrite().relationshipTypeGetOrCreateForName( newRelationshipType ); }
@Description( "Create a Property" ) @Procedure( name = "db.createProperty", mode = WRITE ) public void createProperty( @Name( "newProperty" ) String newProperty ) throws IllegalTokenNameException { tx.tokenWrite().propertyKeyGetOrCreateForName( newProperty ); }
@Description( "Create a label" ) @Procedure( name = "db.createLabel", mode = WRITE ) public void createLabel( @Name( "newLabel" ) String newLabel ) throws IllegalTokenNameException, TooManyLabelsException { tx.tokenWrite().labelGetOrCreateForName( newLabel ); }
int labelIdPerson = transaction.tokenWrite().labelGetOrCreateForName( "Person" ); transaction.dataWrite().nodeAddLabel( nodeIdPerson, labelIdPerson ); long nodeIdLocation = transaction.dataWrite().nodeCreate(); int labelIdLocation = transaction.tokenWrite().labelGetOrCreateForName( "Location" ); transaction.dataWrite().nodeAddLabel( nodeIdLocation, labelIdLocation ); int relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName( "LIVES_IN" ); transaction.dataWrite().relationshipCreate( nodeIdPerson, relationshipTypeId, nodeIdLocation ); commit();
@Override protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException { return transaction.tokenWrite().relationshipTypeCreateForName( name ); } }
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(); } }
try ( Statement ignore = transaction.acquireStatement() ) int relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName( type.name() ); long relationshipId = transaction.dataWrite() .relationshipCreate( nodeId, relationshipTypeId, otherNode.getId() );
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; }
private int getOrCreateLabelId( String labelName ) throws ProcedureException { try { return ktx.tokenWrite().labelGetOrCreateForName( labelName ); } catch ( TooManyLabelsException | IllegalTokenNameException e ) { throw new ProcedureException( e.status(), e, e.getMessage() ); } }
@Test public void shouldDetectRelationshipDeletedInTransaction() throws Exception { // GIVEN long node; int relType; long deletedInTx, unaffected, addedInTx, addedAndRemovedInTx; try ( Transaction tx = beginTransaction() ) { node = tx.dataWrite().nodeCreate(); relType = tx.tokenWrite().relationshipTypeCreateForName( "REL_TYPE" ); deletedInTx = tx.dataWrite().relationshipCreate(node, relType, node); unaffected = tx.dataWrite().relationshipCreate(node, relType, node); tx.success(); } try ( Transaction tx = beginTransaction() ) { // WHEN addedInTx = tx.dataWrite().relationshipCreate(node, relType, node); addedAndRemovedInTx = tx.dataWrite().relationshipCreate(node, relType, node); tx.dataWrite().relationshipDelete( deletedInTx ); tx.dataWrite().relationshipDelete( addedAndRemovedInTx ); // THEN assertFalse( tx.dataRead().relationshipDeletedInTransaction( addedInTx ) ); assertFalse( tx.dataRead().relationshipDeletedInTransaction( unaffected ) ); assertTrue( tx.dataRead().relationshipDeletedInTransaction( addedAndRemovedInTx ) ); assertTrue( tx.dataRead().relationshipDeletedInTransaction( deletedInTx ) ); } }
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 testManualRelationshipIndexPopulation() throws Exception { RelationTypeSchemaDescriptor descriptor; try ( org.neo4j.internal.kernel.api.Transaction tx = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency( Kernel.class ).beginTransaction( explicit, AUTH_DISABLED ) ) { int foodId = tx.tokenWrite().relationshipTypeGetOrCreateForName( FOOD_LABEL ); int propertyId = tx.tokenWrite().propertyKeyGetOrCreateForName( PROPERTY_NAME ); descriptor = forRelType( foodId, propertyId ); tx.schemaWrite().indexCreate( descriptor ); tx.success(); } IndexingService indexingService = getIndexingService( database ); IndexProxy indexProxy = indexingService.getIndexProxy( descriptor ); waitIndexOnline( indexProxy ); assertEquals( InternalIndexState.ONLINE, indexProxy.getState() ); PopulationProgress progress = indexProxy.getIndexPopulationProgress(); assertEquals( progress.getCompleted(), progress.getTotal() ); }
@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 ); }
node = write.nodeCreate(); TokenWrite tokenWrite = tx.tokenWrite(); out = tokenWrite.relationshipTypeGetOrCreateForName( "OUT" ); in = tokenWrite.relationshipTypeGetOrCreateForName( "IN" ); loop = tokenWrite.relationshipTypeGetOrCreateForName( "LOOP" ); write.relationshipCreate( node, out,
@Override public void setProperty( String key, Object value ) { KernelTransaction transaction = safeAcquireTransaction(); int propertyKeyId; try { propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName( key ); } catch ( IllegalTokenNameException e ) { throw new IllegalArgumentException( format( "Invalid property key '%s'.", key ), e ); } try ( Statement ignore = transaction.acquireStatement() ) { transaction.dataWrite().graphSetProperty( propertyKeyId, Values.of( value, false ) ); } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@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 ) ); } }