Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

nserverdemo
Class NsSampleWork  view NsSampleWork download NsSampleWork.java

java.lang.Object
  extended bynserverdemo.NsSampleWork

class NsSampleWork
extends java.lang.Object

NsSampleWork class represents all the work done in the sample demo program. It includes getting a connection to the database, creating and loading of schema, preparing and execution of SQL statements (insert, select, update, delete )


Field Summary
static int counter
           
protected  java.lang.String dbUrl
           
(package private)  java.sql.PreparedStatement delete
           
(package private)  java.sql.PreparedStatement getMaxKey
           
(package private)  java.sql.PreparedStatement insert
           
(package private) static java.lang.Integer lock
           
protected  java.util.Properties properties
           
(package private)  java.io.PrintWriter pw
           
(package private)  java.sql.PreparedStatement select
           
protected  int thread_id
           
(package private)  java.sql.PreparedStatement update
           
 
Constructor Summary
(package private) NsSampleWork(int id, java.lang.String dbURL, java.util.Properties properties, java.io.PrintWriter pw)
          dbUrl is the database url to connect to
 
Method Summary
static void checkAndCreateSchema(java.sql.Connection conn, java.io.PrintWriter pw)
          Create necessary schema if schema not already created
 void cleanup()
          close resources
 void closeConnection(java.sql.Connection conn)
          close connection
static int deleteRow(java.sql.PreparedStatement ps, long deleteRow)
          Delete row from table deleteRow is the value of the t_key of the row to be deleted return number of rows deleted
 void doIUDOperation()
          Perform an insert or an update or delete operation
 int doSelectOperation(long selectWhat)
          executing a select and retrieving the results select the row with t_key value as 'selectWhat'
 void doWork()
          Opens a connection and executes DML (insert, select, update, delete) operations
 java.sql.Connection getConnection(java.lang.String dbUrl, java.util.Properties properties)
          gets a database connection If the dbUrl is trying to connect to the Derby NetNsSampleWork server using JCC then the jcc driver must be already loaded before calling this method, else there will be an error return jcc connection if no error, else null
static int insertRow(java.sql.PreparedStatement ps)
          Generates random values and performs the inserts into the database
static void loadSchema(java.sql.Connection conn, int rowsToInsert, java.io.PrintWriter pw)
          Loads schema , inserts 'rowsToInsert' number of rows into the table
 void prepareStmts(java.sql.Connection conn)
          prepare required sql statements
 void setIsolationLevel(java.sql.Connection conn, int level)
          set the connection to this isolation level
static int updateRow(java.sql.PreparedStatement ps, long updateWhere)
          update a row in the table updateWhere is the value of the t_key row which needs to be updated return number of rows updated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thread_id

protected int thread_id

dbUrl

protected java.lang.String dbUrl

properties

protected java.util.Properties properties

pw

java.io.PrintWriter pw

select

java.sql.PreparedStatement select

insert

java.sql.PreparedStatement insert

delete

java.sql.PreparedStatement delete

update

java.sql.PreparedStatement update

getMaxKey

java.sql.PreparedStatement getMaxKey

counter

public static int counter

lock

static java.lang.Integer lock
Constructor Detail

NsSampleWork

NsSampleWork(int id,
             java.lang.String dbURL,
             java.util.Properties properties,
             java.io.PrintWriter pw)
dbUrl is the database url to connect to

Method Detail

getConnection

public java.sql.Connection getConnection(java.lang.String dbUrl,
                                         java.util.Properties properties)
gets a database connection If the dbUrl is trying to connect to the Derby NetNsSampleWork server using JCC then the jcc driver must be already loaded before calling this method, else there will be an error return jcc connection if no error, else null


setIsolationLevel

public void setIsolationLevel(java.sql.Connection conn,
                              int level)
set the connection to this isolation level


closeConnection

public void closeConnection(java.sql.Connection conn)
close connection


prepareStmts

public void prepareStmts(java.sql.Connection conn)
prepare required sql statements


doSelectOperation

public int doSelectOperation(long selectWhat)
executing a select and retrieving the results select the row with t_key value as 'selectWhat'


doWork

public void doWork()
Opens a connection and executes DML (insert, select, update, delete) operations


cleanup

public void cleanup()
close resources


doIUDOperation

public void doIUDOperation()
Perform an insert or an update or delete operation


checkAndCreateSchema

public static void checkAndCreateSchema(java.sql.Connection conn,
                                        java.io.PrintWriter pw)
Create necessary schema if schema not already created


loadSchema

public static void loadSchema(java.sql.Connection conn,
                              int rowsToInsert,
                              java.io.PrintWriter pw)
Loads schema , inserts 'rowsToInsert' number of rows into the table


insertRow

public static int insertRow(java.sql.PreparedStatement ps)
Generates random values and performs the inserts into the database


updateRow

public static int updateRow(java.sql.PreparedStatement ps,
                            long updateWhere)
update a row in the table updateWhere is the value of the t_key row which needs to be updated return number of rows updated


deleteRow

public static int deleteRow(java.sql.PreparedStatement ps,
                            long deleteRow)
Delete row from table deleteRow is the value of the t_key of the row to be deleted return number of rows deleted