@Override public Statement statement() { return statementContext.get(); }
private void setUpMocks() { queryService = mock( GraphDatabaseQueryService.class ); DependencyResolver resolver = mock( DependencyResolver.class ); txBridge = mock( ThreadToStatementContextBridge.class ); initialStatement = mock( KernelStatement.class ); statistics = new ConfiguredExecutionStatistics(); QueryRegistryOperations queryRegistryOperations = mock( QueryRegistryOperations.class ); InternalTransaction internalTransaction = mock( InternalTransaction.class ); when( internalTransaction.terminationReason() ).thenReturn( Optional.empty() ); when( initialStatement.queryRegistration() ).thenReturn( queryRegistryOperations ); when( queryService.getDependencyResolver() ).thenReturn( resolver ); when( resolver.resolveDependency( ThreadToStatementContextBridge.class ) ).thenReturn( txBridge ); when( queryService.beginTransaction( any(), any() ) ).thenReturn( internalTransaction ); KernelTransaction mockTransaction = mockTransaction( initialStatement ); when( txBridge.get() ).thenReturn( initialStatement ); when( txBridge.getKernelTransactionBoundToThisThread(true ) ).thenReturn( mockTransaction ); }
@Override public Relationship getRelationshipById( long id ) { if ( id < 0 ) { throw new NotFoundException( format( "Relationship %d not found", id ), new EntityNotFoundException( EntityType.RELATIONSHIP, id ) ); } KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); assertTransactionOpen( ktx ); try ( Statement ignore = statementContext.get() ) { if ( !ktx.dataRead().relationshipExists( id ) ) { throw new NotFoundException( format( "Relationship %d not found", id ), new EntityNotFoundException( EntityType.RELATIONSHIP, id ) ); } return newRelationshipProxy( id ); } }
@Before public void before() { ThreadToStatementContextBridge bridge = mock( ThreadToStatementContextBridge.class ); Statement statement = mock( Statement.class ); when( bridge.get() ).thenReturn( statement ); kernelTransaction = spy( KernelTransaction.class ); locks = mock( Locks.class ); when(kernelTransaction.locks()).thenReturn( locks ); placeboTx = new PlaceboTransaction( kernelTransaction ); resource = mock( Node.class ); when( resource.getId() ).thenReturn( 1L ); }
when( queryService.beginTransaction( transactionType, securityContext ) ).thenReturn( secondTransaction ); when( txBridge.getKernelTransactionBoundToThisThread( true ) ).thenReturn( initialKTX, initialKTX, secondKTX ); when( txBridge.get() ).thenReturn( secondStatement ); when( secondStatement.queryRegistration() ).thenReturn( secondQueryRegistry );
private KernelStatement getKernelStatement( GraphDatabaseAPI db ) { ThreadToStatementContextBridge statementBridge = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ); return (KernelStatement) statementBridge.get(); } }
@Override public Relationship getRelationshipById( long id ) { if ( id < 0 ) { throw new NotFoundException( format( "Relationship %d not found", id ), new EntityNotFoundException( EntityType.RELATIONSHIP, id ) ); } KernelTransaction ktx = statementContext.getKernelTransactionBoundToThisThread( true ); assertTransactionOpen( ktx ); try ( Statement ignore = statementContext.get() ) { if ( !ktx.dataRead().relationshipExists( id ) ) { throw new NotFoundException( format( "Relationship %d not found", id ), new EntityNotFoundException( EntityType.RELATIONSHIP, id ) ); } return newRelationshipProxy( id ); } }
@Override public void cleanForReuse() { // close the old statement reference after the statement has been "upgraded" // to either a schema data or a schema statement, so that the locks are "handed over". statement.queryRegistration().unregisterExecutingQuery( executingQuery ); statement.close(); statement = txBridge.get(); statement.queryRegistration().registerExecutingQuery( executingQuery ); }
@BeforeEach void setUp() { queryService = mock( GraphDatabaseQueryService.class ); DependencyResolver resolver = mock( DependencyResolver.class ); Statement statement = mock( Statement.class, RETURNS_DEEP_STUBS ); ThreadToStatementContextBridge contextBridge = mock( ThreadToStatementContextBridge.class ); when( spi.queryService() ).thenReturn( queryService ); when( spi.resolver() ).thenReturn( resolver ); when( resolver.resolveDependency( ThreadToStatementContextBridge.class ) ).thenReturn( contextBridge ); when( contextBridge.get() ).thenReturn( statement ); Config config = Config.defaults(); when( resolver.resolveDependency( Config.class ) ).thenReturn( config ); graphDatabaseFacade.init( spi, contextBridge, config, mockedTokenHolders() ); }
@Before public void setup() throws PropertyKeyIdNotFoundKernelException { when( transaction.tokenRead() ).thenReturn( tokenRead ); when( bridge.get() ).thenReturn( stmt ); when( tokenRead.propertyKeyName( anyInt() ) ).thenAnswer( invocationOnMock -> { int id = invocationOnMock.getArgument( 0 ); return ops.propertyKeyTokenHolder().getTokenById( id ).name(); } ); }
QueryRegistryOperations registryOperations = mock( QueryRegistryOperations.class ); when( statement.queryRegistration() ).thenReturn( registryOperations ); when( statementBridge.get() ).thenReturn( statement ); when( kernelTransaction.securityContext() ).thenReturn( loginContext.authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ) ); when( kernelTransaction.transactionType() ).thenReturn( type );
private void runTransaction( LoginContext loginContext, Map<String,Object> metaData ) { try ( Transaction transaction = db.beginTransaction( KernelTransaction.Type.explicit, loginContext ); Statement statement = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class ).get() ) { statement.queryRegistration().setMetaData( metaData ); db.createNode(); transaction.success(); } }
@Override public Statement statement() { return statementContext.get(); }
@Override public Statement statement() { return txBridge.get(); }
@Override public void cleanForReuse() { // close the old statement reference after the statement has been "upgraded" // to either a schema data or a schema statement, so that the locks are "handed over". statement.queryRegistration().unregisterExecutingQuery( executingQuery ); statement.close(); statement = txBridge.get(); statement.queryRegistration().registerExecutingQuery( executingQuery ); }
private static KernelStatement statementOn( GraphDatabaseService db ) { DependencyResolver resolver = ((GraphDatabaseAPI) db).getDependencyResolver(); ThreadToStatementContextBridge bridge = resolver.resolveDependency( ThreadToStatementContextBridge.class ); return (KernelStatement) bridge.get(); }
int propertyNameId; try (Transaction tx = db.beginTx()) { propertyNameId = ctx.get().tokenWriteOperations().propertyKeyGetOrCreateForName(algorithm.getPropertyName()); tx.success(); } catch (IllegalTokenNameException e) {
@Override public void compute(String label, String type, int iterations) { degree = new int[nodeCount]; Arrays.fill(degree, -1); try ( Transaction tx = db.beginTx()) { ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class); ReadOperations ops = ctx.get().readOperations(); int labelId = ops.labelGetForName(label); int relationshipTypeId = ops.relationshipTypeGetForName(type); PrimitiveLongIterator it = ops.nodesGetForLabel(labelId); int totalCount = nodeCount; runOperations(pool, it, totalCount, ops, new OpsRunner() { public void run(int id) throws EntityNotFoundException { degree[id] = ops.nodeGetDegree(id, direction, relationshipTypeId); } }); tx.success(); } catch (Exception e) { e.printStackTrace(); } }
public void run() { try (Transaction tx = db.beginTx()) { DataWriteOperations ops = ctx.get().dataWriteOperations(); for (long i = 0; i < WRITE_BATCH; i++) { long node = i + start; if (node >= nodes) break; double value = algorithm.getResult(node); if (value > 0) { ops.nodeSetProperty(node, DefinedProperty.doubleProperty(propertyNameId, value)); } } tx.success(); } catch (AutoIndexingKernelException | ConstraintValidationKernelException | InvalidTransactionTypeKernelException | EntityNotFoundException e) { e.printStackTrace(); } } });
@Override public void compute(String label, String type, int iterations) { float[] src = new float[nodes]; dst = new float[nodes]; try ( Transaction tx = db.beginTx()) { ThreadToStatementContextBridge ctx = this.db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class); ReadOperations ops = ctx.get().readOperations(); int labelId = ops.labelGetForName(label); int typeId = ops.relationshipTypeGetForName(type); int[] degrees = computeDegrees(ops,labelId, typeId); RelationshipVisitor<RuntimeException> visitor = new RelationshipVisitor<RuntimeException>() { public void visit(long relId, int relTypeId, long startNode, long endNode) throws RuntimeException { if (relTypeId == typeId) { dst[((int) endNode)] += src[(int) startNode]; } } }; for (int iteration = 0; iteration < iterations; iteration++) { startIteration(src, dst, degrees); PrimitiveLongIterator rels = ops.relationshipsGetAll(); while (rels.hasNext()) { ops.relationshipVisit(rels.next(), visitor); } } tx.success(); } catch (EntityNotFoundException e) { e.printStackTrace(); } }