org.apache.derbyTesting.perf.clients
Class BankTransactionClient

java.lang.Object
  extended by org.apache.derbyTesting.perf.clients.BankTransactionClient
All Implemented Interfaces:
Client

public class BankTransactionClient
extends java.lang.Object
implements Client

This class implements a client thread which performs bank transactions. The transactions are intended to perform the same operations as the transactions specified by the TPC-B benchmark.


Field Summary
private  int accountsPerBranch
          The number of accounts per branch.
private  int branches
          The number of branches in the database.
private  java.sql.Connection conn
          The connection on which the operations are performed.
private  java.util.Random random
          Random number generator.
private  java.sql.PreparedStatement retrieveAccountBalance
          Statement that retrieves the current account balance.
private  int tellersPerBranch
          The number of tellers per branch.
private  java.sql.PreparedStatement updateAccount
          Statement that updates the balance of the account.
private  java.sql.PreparedStatement updateBranch
          Statement that updated the balance of the branch.
private  java.sql.PreparedStatement updateHistory
          Statement that updated the history table.
private  java.sql.PreparedStatement updateTeller
          Statement that updates the balance of the teller.
 
Constructor Summary
BankTransactionClient(int scale)
          Create a client that works on a database with the default number of tellers and accounts per branch.
BankTransactionClient(int branches, int tellersPerBranch, int accountsPerBranch)
          Create a client that works on a database with the given number of branches, tellers and accounts.
 
Method Summary
 void doWork()
          Perform a single transaction with a profile like the one specified in Clause 1.2 of the TPC-B specification.
private  int fetchAccountId(int branchId)
          Generate a random account id based on the specified branch.
private  int fetchBranchId(int tellerId)
          Find the branch the specified teller belongs to.
private  int fetchDelta()
          Generate a random delta value between -99999 and +99999, both inclusive (TPC-B specification, Clause 5.3.6).
private  int fetchTellerId()
          Generate a random teller id.
 void init(java.sql.Connection c)
          Initialize the connection and the statements used by the test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

private final java.util.Random random
Random number generator.


branches

private final int branches
The number of branches in the database.


tellersPerBranch

private final int tellersPerBranch
The number of tellers per branch.


accountsPerBranch

private final int accountsPerBranch
The number of accounts per branch.


conn

private java.sql.Connection conn
The connection on which the operations are performed.


updateAccount

private java.sql.PreparedStatement updateAccount
Statement that updates the balance of the account.


updateHistory

private java.sql.PreparedStatement updateHistory
Statement that updated the history table.


updateTeller

private java.sql.PreparedStatement updateTeller
Statement that updates the balance of the teller.


updateBranch

private java.sql.PreparedStatement updateBranch
Statement that updated the balance of the branch.


retrieveAccountBalance

private java.sql.PreparedStatement retrieveAccountBalance
Statement that retrieves the current account balance.

Constructor Detail

BankTransactionClient

public BankTransactionClient(int branches,
                             int tellersPerBranch,
                             int accountsPerBranch)
Create a client that works on a database with the given number of branches, tellers and accounts.

Parameters:
branches - the number of branches in the database
tellersPerBranch - the number of tellers per branch
accountsPerBranch - the number of accounts per branch

BankTransactionClient

public BankTransactionClient(int scale)
Create a client that works on a database with the default number of tellers and accounts per branch.

Parameters:
scale - the scale factor for the database (equal to the number of branches)
See Also:
BankAccountFiller.BankAccountFiller(int)
Method Detail

init

public void init(java.sql.Connection c)
          throws java.sql.SQLException
Initialize the connection and the statements used by the test.

Specified by:
init in interface Client
Parameters:
c - a connection which can be used by this client
Throws:
java.sql.SQLException - if a database error occurs

doWork

public void doWork()
            throws java.sql.SQLException
Perform a single transaction with a profile like the one specified in Clause 1.2 of the TPC-B specification.

Specified by:
doWork in interface Client
Throws:
java.sql.SQLException - if a database error occurs

fetchTellerId

private int fetchTellerId()
Generate a random teller id.


fetchBranchId

private int fetchBranchId(int tellerId)
Find the branch the specified teller belongs to.

Parameters:
tellerId - the id of the teller
Returns:
the id of the branch for this teller

fetchAccountId

private int fetchAccountId(int branchId)
Generate a random account id based on the specified branch. Per Clause 5.3.5 of the TPC-B specification, the accounts should be fetched from the selected branch 85% of the time (or always if that's the only branch), and from another branch the rest of the time.

Parameters:
branchId - the id of the selected branch
Returns:
the id of a random account

fetchDelta

private int fetchDelta()
Generate a random delta value between -99999 and +99999, both inclusive (TPC-B specification, Clause 5.3.6). The delta value specifies how much the balance should increase or decrease.

Returns:
a random value in the range [-99999,+99999]

Built on Thu 2009-11-26 18:42:53-0800, from revision 884739

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.