public StatementLocksFactory select() { StatementLocksFactory statementLocksFactory; String serviceName = StatementLocksFactory.class.getSimpleName(); List<StatementLocksFactory> factories = serviceLoadFactories(); if ( factories.isEmpty() ) { statementLocksFactory = new SimpleStatementLocksFactory(); log.info( "No services implementing " + serviceName + " found. " + "Using " + SimpleStatementLocksFactory.class.getSimpleName() ); } else if ( factories.size() == 1 ) { statementLocksFactory = factories.get( 0 ); log.info( "Found single implementation of " + serviceName + ". Namely " + statementLocksFactory.getClass().getSimpleName() ); } else { throw new IllegalStateException( "Found more than one implementation of " + serviceName + ": " + factories ); } statementLocksFactory.initialize( locks, config ); return statementLocksFactory; }
TransactionId lastCommittedTransaction = transactionIdStore.getLastCommittedTransaction(); KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() );
@Test public void loadSimpleStatementLocksFactoryWhenNoServices() { Locks locks = mock( Locks.class ); Locks.Client locksClient = mock( Client.class ); when( locks.newClient() ).thenReturn( locksClient ); StatementLocksFactorySelector loader = newLoader( locks ); StatementLocksFactory factory = loader.select(); StatementLocks statementLocks = factory.newInstance(); assertThat( factory, instanceOf( SimpleStatementLocksFactory.class ) ); assertThat( statementLocks, instanceOf( SimpleStatementLocks.class ) ); assertSame( locksClient, statementLocks.optimistic() ); assertSame( locksClient, statementLocks.pessimistic() ); }
@Test public void loadSingleAvailableFactory() { Locks locks = mock( Locks.class ); StatementLocksFactory factory = mock( StatementLocksFactory.class ); StatementLocksFactorySelector loader = newLoader( locks, factory ); StatementLocksFactory loadedFactory = loader.select(); assertSame( factory, loadedFactory ); verify( factory ).initialize( same( locks ), any( Config.class ) ); }
when( statementLocks.optimistic() ).thenReturn( locks ); when( statementLocks.pessimistic() ).thenReturn( locks ); when( locksFactory.newInstance() ).thenReturn( statementLocks );
public StatementLocksFactory select() { StatementLocksFactory statementLocksFactory; String serviceName = StatementLocksFactory.class.getSimpleName(); List<StatementLocksFactory> factories = serviceLoadFactories(); if ( factories.isEmpty() ) { statementLocksFactory = new SimpleStatementLocksFactory(); log.info( "No services implementing " + serviceName + " found. " + "Using " + SimpleStatementLocksFactory.class.getSimpleName() ); } else if ( factories.size() == 1 ) { statementLocksFactory = factories.get( 0 ); log.info( "Found single implementation of " + serviceName + ". Namely " + statementLocksFactory.getClass().getSimpleName() ); } else { throw new IllegalStateException( "Found more than one implementation of " + serviceName + ": " + factories ); } statementLocksFactory.initialize( locks, config ); return statementLocksFactory; }
TransactionId lastCommittedTransaction = transactionIdStore.getLastCommittedTransaction(); KernelTransactionImplementation tx = localTxPool.acquire(); StatementLocks statementLocks = statementLocksFactory.newInstance(); tx.initialize( lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, securityContext, timeout, userTransactionIdCounter.incrementAndGet() );