Top Description Fields Constructors Methods
org.apache.derby.impl.tools.ij

public Class utilMain

extends Object
Class Inheritance
Imports
org.apache.derby.tools.JDBCDisplayUtil, org.apache.derby.iapi.tools.i18n.*, org.apache.derby.shared.common.info.ProductVersionHolder, .ProductGenusNames, java.util.List, .Stack, .Hashtable, java.io.InputStream, .FileInputStream, .BufferedInputStream, .FileNotFoundException, .StringReader, java.sql.DriverManager, .Driver, .Connection, .SQLException, .ResultSet, .Statement, .PreparedStatement

This class is utilities specific to the two ij Main's. This factoring enables sharing the functionality for single and dual connection ij runs.

Field Summary

Modifier and TypeField and Description
public static final int
pack-priv UCode_CharStream
private StatementFinder[]
pack-priv ConnectionEnv[]
private int
private boolean
private boolean
private Hashtable<K, V>
private final String
ijExceptionTrace

Value of the system property ij.execptionTrace

pack-priv ij
pack-priv ijTokenManager
private boolean
pack-priv LocalizedResource
private boolean
private final int
pack-priv Stack<StatementFinder>
private LocalizedOutput
private final boolean
showErrorCode

True if to display the error code when displaying a SQLException.

Constructor Summary

AccessConstructor and Description
pack-priv
utilMain(int
The number of connections/users to test.
numConnections
,
LocalizedOutput out)

Set up the test to run with 'numConnections' connections/users.

pack-priv
utilMain(int
The number of connections/users to test.
numConnections
,
LocalizedOutput out, boolean loadSystemProperties)

Set up the test to run with 'numConnections' connections/users.

public
utilMain(int
The number of connections/users to test.
numConnections
,
LocalizedOutput out, Hashtable<K, V>
A list of errors to ignore. If null, all errors are printed out and nothing is fatal. If non-null, if an error is hit and it is in this list, it is silently ignore. Otherwise, an ijFatalException is thrown. ignoreErrors is used for stress tests.
ignoreErrors
)

Set up the test to run with 'numConnections' connections/users.

Method Summary

Modifier and TypeMethod and Description
pack-priv ijResult

Returns:

NULL.
absolute
(ResultSet
The specified ResultSet.
rs
,
int
The row # to move to. (Negative means from the end of the result set.)
row
)

Position on the specified row of the specified ResultSet.

pack-priv ijResult

Returns:

NULL.
afterLast
(ResultSet
The specified ResultSet.
rs
)

Position after the last row of the specified ResultSet and return NULL to the user.

pack-priv ijResult

Returns:

NULL.
beforeFirst
(ResultSet
The specified ResultSet.
rs
)

Position before the first row of the specified ResultSet and return NULL to the user.

private void
checkScrollableCursor(ResultSet
the ResultSet to check
rs
,
String
which operation this is checked for
operation
)

Check that the cursor is scrollable.

private void
cleanupGo(LocalizedInput[] in)

Perform cleanup after a script has been run.

private void
private boolean
doCatch(String command)

catch processing on failed commands.

pack-priv static void
doPrompt(boolean newStatement, LocalizedOutput out, String tag)

REMIND: eventually this might be part of StatementFinder, used at each carriage return to show that it is still "live" when it is reading multi-line input.

private void
doTrace(Throwable t)

stack trace dumper

pack-priv ijResult

Returns:

The first row of the ResultSet.
first
(ResultSet
The specified ResultSet.
rs
)

Position on the first row of the specified ResultSet and return that row to the user.

pack-priv int

Returns:

The current row number
getCurrentRowNumber
(ResultSet
The specified ResultSet.
rs
)

Get the current row number

public void
go(LocalizedInput[]
source for input to ij
in
,
LocalizedOutput
sink for output from ij
out
)

run ij over the specified input, sending output to the specified output.

public int
goScript(Connection conn, LocalizedInput in)

Support to run a script.

private void
handleSQLException(LocalizedOutput out, SQLException e)

This routine displays SQL exceptions and decides whether they are fatal or not, based on the ignoreErrors field.

public void
initFromEnvironment()

Initialize the connections from the environment.

pack-priv ijResult

Returns:

The last row of the ResultSet.
last
(ResultSet
The specified ResultSet.
rs
)

Position on the last row of the specified ResultSet and return that row to the user.

pack-priv void
newInput(String fileName)

pack-priv void
newResourceInput(String resourceName)

pack-priv ijResult

Returns:

The previous row of the ResultSet.
previous
(ResultSet
The specified ResultSet.
rs
)

Position on the previous row of the specified ResultSet and return that row to the user.

pack-priv ijResult

Returns:

NULL.
relative
(ResultSet
The specified ResultSet.
rs
,
int
The # of rows to move. (Negative means toward the beginning of the result set.)
row
)

Move the cursor position by the specified amount.

private int

Returns:

The number of errors seen in the script.
runScriptGuts
()

Run the guts of the script.

pack-priv void
setMtUse(boolean b)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFEREDFILESIZEback to summary
public static final int BUFFEREDFILESIZE
charStreamback to summary
pack-priv UCode_CharStream charStream
commandGrabberback to summary
private StatementFinder[] commandGrabber
connEnvback to summary
pack-priv ConnectionEnv[] connEnv
currCEback to summary
private int currCE
fileInputback to summary
private boolean fileInput
firstRunback to summary
private boolean firstRun
ignoreErrorsback to summary
private Hashtable<K, V> ignoreErrors
ijExceptionTraceback to summary
private final String ijExceptionTrace

Value of the system property ij.execptionTrace

ijParserback to summary
pack-priv ij ijParser
ijTokMgrback to summary
pack-priv ijTokenManager ijTokMgr
initialFileInputback to summary
private boolean initialFileInput
langUtilback to summary
pack-priv LocalizedResource langUtil
mtUseback to summary
private boolean mtUse
numConnectionsback to summary
private final int numConnections
oldGrabbersback to summary
pack-priv Stack<StatementFinder> oldGrabbers
outback to summary
private LocalizedOutput out
showErrorCodeback to summary
private final boolean showErrorCode

True if to display the error code when displaying a SQLException.

Constructor Detail

utilMainback to summary
pack-priv utilMain(int numConnections, LocalizedOutput out) throws ijFatalException

Set up the test to run with 'numConnections' connections/users.

Parameters
numConnections:int

The number of connections/users to test.

utilMainback to summary
pack-priv utilMain(int numConnections, LocalizedOutput out, boolean loadSystemProperties) throws ijFatalException

Set up the test to run with 'numConnections' connections/users. This overload allows the choice of whether the system properties will be used or not.

Parameters
numConnections:int

The number of connections/users to test.

utilMainback to summary
public utilMain(int numConnections, LocalizedOutput out, Hashtable<K, V> ignoreErrors) throws ijFatalException

Set up the test to run with 'numConnections' connections/users.

Parameters
numConnections:int

The number of connections/users to test.

ignoreErrors:Hashtable<K, V>

A list of errors to ignore. If null, all errors are printed out and nothing is fatal. If non-null, if an error is hit and it is in this list, it is silently ignore. Otherwise, an ijFatalException is thrown. ignoreErrors is used for stress tests.

Method Detail

absoluteback to summary
pack-priv ijResult absolute(ResultSet rs, int row) throws SQLException

Position on the specified row of the specified ResultSet.

Parameters
rs:ResultSet

The specified ResultSet.

row:int

The row # to move to. (Negative means from the end of the result set.)

Returns:ijResult

NULL.

Exceptions
SQLException:
thrown on error. (absolute() not supported pre-JDBC2.0)
afterLastback to summary
pack-priv ijResult afterLast(ResultSet rs) throws SQLException

Position after the last row of the specified ResultSet and return NULL to the user.

Parameters
rs:ResultSet

The specified ResultSet.

Returns:ijResult

NULL.

Exceptions
SQLException:
thrown on error. (afterLast() not supported pre-JDBC2.0)
beforeFirstback to summary
pack-priv ijResult beforeFirst(ResultSet rs) throws SQLException

Position before the first row of the specified ResultSet and return NULL to the user.

Parameters
rs:ResultSet

The specified ResultSet.

Returns:ijResult

NULL.

Exceptions
SQLException:
thrown on error. (beforeFirst() not supported pre-JDBC2.0)
checkScrollableCursorback to summary
private void checkScrollableCursor(ResultSet rs, String operation) throws ijException, SQLException

Check that the cursor is scrollable.

Parameters
rs:ResultSet

the ResultSet to check

operation:String

which operation this is checked for

Exceptions
ijException:
if the cursor isn't scrollable
SQLException:
if a database error occurs
cleanupGoback to summary
private void cleanupGo(LocalizedInput[] in)

Perform cleanup after a script has been run. Close the input streams if required and shutdown derby on an exit.

displayResultback to summary
private void displayResult(LocalizedOutput out, ijResult result, Connection conn) throws SQLException
doCatchback to summary
private boolean doCatch(String command)

catch processing on failed commands. This really ought to be in ij somehow, but it was easier to catch in Main.

doPromptback to summary
pack-priv static void doPrompt(boolean newStatement, LocalizedOutput out, String tag)

REMIND: eventually this might be part of StatementFinder, used at each carriage return to show that it is still "live" when it is reading multi-line input.

doTraceback to summary
private void doTrace(Throwable t)

stack trace dumper

firstback to summary
pack-priv ijResult first(ResultSet rs) throws SQLException

Position on the first row of the specified ResultSet and return that row to the user.

Parameters
rs:ResultSet

The specified ResultSet.

Returns:ijResult

The first row of the ResultSet.

Exceptions
SQLException:
thrown on error. (first() not supported pre-JDBC2.0)
getCurrentRowNumberback to summary
pack-priv int getCurrentRowNumber(ResultSet rs) throws SQLException

Get the current row number

Parameters
rs:ResultSet

The specified ResultSet.

Returns:int

The current row number

Exceptions
SQLException:
thrown on error. (getRow() not supported pre-JDBC2.0)
goback to summary
public void go(LocalizedInput[] in, LocalizedOutput out) throws ijFatalException

run ij over the specified input, sending output to the specified output. Any prior input and output will be lost.

Parameters
in:LocalizedInput[]

source for input to ij

out:LocalizedOutput

sink for output from ij

goScriptback to summary
public int goScript(Connection conn, LocalizedInput in)

Support to run a script. Performs minimal setup to set the passed in connection into the existing ij setup, ConnectionEnv.

handleSQLExceptionback to summary
private void handleSQLException(LocalizedOutput out, SQLException e) throws ijFatalException

This routine displays SQL exceptions and decides whether they are fatal or not, based on the ignoreErrors field. If they are fatal, an ijFatalException is thrown. Lifted from ij/util.java:ShowSQLException

initFromEnvironmentback to summary
public void initFromEnvironment()

Initialize the connections from the environment.

lastback to summary
pack-priv ijResult last(ResultSet rs) throws SQLException

Position on the last row of the specified ResultSet and return that row to the user.

Parameters
rs:ResultSet

The specified ResultSet.

Returns:ijResult

The last row of the ResultSet.

Exceptions
SQLException:
thrown on error. (last() not supported pre-JDBC2.0)
newInputback to summary
pack-priv void newInput(String fileName)
newResourceInputback to summary
pack-priv void newResourceInput(String resourceName)
previousback to summary
pack-priv ijResult previous(ResultSet rs) throws SQLException

Position on the previous row of the specified ResultSet and return that row to the user.

Parameters
rs:ResultSet

The specified ResultSet.

Returns:ijResult

The previous row of the ResultSet.

Exceptions
SQLException:
thrown on error. (previous() not supported pre-JDBC2.0)
relativeback to summary
pack-priv ijResult relative(ResultSet rs, int row) throws SQLException

Move the cursor position by the specified amount.

Parameters
rs:ResultSet

The specified ResultSet.

row:int

The # of rows to move. (Negative means toward the beginning of the result set.)

Returns:ijResult

NULL.

Exceptions
SQLException:
thrown on error. (relative() not supported pre-JDBC2.0)
runScriptGutsback to summary
private int runScriptGuts()

Run the guts of the script. Split out to allow calling from the full ij and the minimal goScript.

Returns:int

The number of errors seen in the script.

setMtUseback to summary
pack-priv void setMtUse(boolean b)
supportIJPropertiesback to summary
private void supportIJProperties(ConnectionEnv env)