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

public final Class util

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.info.JVMInfo, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ModuleUtil, org.apache.derby.tools.JDBCDisplayUtil, org.apache.derby.iapi.tools.i18n.*, java.io.BufferedInputStream, .FileInputStream, .InputStream, .IOException, java.lang.reflect.InvocationTargetException, java.sql.Connection, .Driver, .DriverManager, .SQLException, .Statement, .PreparedStatement, .ResultSet, .ResultSetMetaData, .Types, java.util.Properties, .Vector, .Locale, javax.sql.DataSource

Methods used to control setup for apps as well as display some internal ij structures.
See Also
org.apache.derby.tools.JDBCDisplayUtil

Field Summary

Modifier and TypeField and Description
private static final Class<T>[]
private String
private static final String[][]
private static final Class<T>[]

Constructor Summary

AccessConstructor and Description
private
util()

Method Summary

Modifier and TypeMethod and Description
public static void
DisplayMulti(LocalizedOutput out, PreparedStatement ps, ResultSet rs, Connection conn)

Display a statement that takes parameters by stuffing it with rows from the result set and displaying each result each time through.

public static void
DisplayVector(LocalizedOutput out, Vector<E> v)

Display a vector of strings to the out stream.

public static String

Returns:

the argument that follows the parameter, or null if not found
getArg
(String
the parameter (e.g. "-p")
param
,
String[]
the argument list to consider.
args
)

Find the argument that follows the specified parameter.

public static Connection
getDataSourceConnection(String
Data Source name
dsName
,
String
User name
user
,
String
Password
password
,
String
Database Name
dbName
,
boolean
Indicates if the method is called first time. This is passed to setupDataSource method.
firstTime
)

Returns a connection obtained using the DataSource.

public static String

Returns:

the name of the first argument not preceded by "-p", null if none found.
getFileArg
(String[]
the argument list to consider.
args
)

Return the name of the ij command file or null if none is specified.

public static String
getInputResourceNameArg(String[] args)

Return the name of a resource containing input commands or null iff none has been specified.

public static boolean

Returns:

true if a property item was found and loaded.
getPropertyArg
(String[]
the argument list to consider.
args
)

ij is started with "-p[r] file OtherArgs"; the file contains properties to control the driver and database used to run ij, and can provide additional system properties.

pack-priv static InputStream

Returns:

a buffered stream for the resource if it exists and null otherwise.
getResourceAsStream
(String
the name of the resource
resourceName
)

Convenience routine to get a resource as a BufferedInputStream.

public static String

Returns:

the current schema of the connection, or null if error.
getSelectedSchema
(Connection
Connection to get current schema for
theConnection
)

Selects the current schema from the given connection.

pack-priv static final String
getSystemProperty(String propertyName)

public static boolean

Returns:

true if the args are invalid
  • Only legal argument provided.
  • Only specify a quantity once.
invalidArgs
(String[] args)

Verify the ij line arguments command arguments.

private static boolean

Returns:

true if the framework contains Net or JCC.
isJCCFramework
()

Used to determine if this is a JCC testing framework So that retrieveMessages can be sent.

pack-priv static void
loadDriver(String driverClass)

Load a driver given a class name.

public static void
loadDriverIfKnown(String
the protocol to try.
jdbcProtocol
)

Find the appropriate driver and load it, given a JDBC URL.

private static void
loadWithTrimmedValues(InputStream
An input stream from which the new properties are to be loaded (should already be initialized).
iStr
,
Properties
A set of properties to which the properties from iStr will be added (should already be initialized). Copied here to avoid dependency on an engine class.
prop
)

Read a set of properties from the received input stream, strip off any excess white space that exists in those property values, and then add those newly-read properties to the received Properties object; not explicitly removing the whitespace here can lead to problems.

pack-priv static String
qualifyResourceName(String resourceName, boolean
true means return null if the name is not absolute and false means return partial names.
absolute
)

Convenience routine to qualify a resource name with "ij.defaultPackageName" if it is not qualified (does not begin with a "/").

public final String
run()

public static void
setupDataSource(Object
DataSource object
ds
,
String
Database Name
dbName
,
boolean
If firstTime is false, ij.dataSource.createDatabase and ij.dataSource.databaseName properties will not be used. The value in parameter dbName will be used instead of ij.dataSource.databaseName.
firstTime
)

Sets up a data source with values specified in ij.dataSource.* properties or passed as parameters of this method

public static Connection

Returns:

a connection to the defaultURL if possible; null if not.
startJBMS
(String
the driver to use if no property value found
defaultDriver
,
String
the database URL to use if no property value found
defaultURL
,
Properties
Connection attributes to pass to getConnection
connInfo
)

This will look for the System properties "ij.driver" and "ij.database" and return a java.sql.Connection if it successfully connects.

public static Connection

Returns:

a connection to the defaultURL if possible; null if not.
startJBMS
()

Utility interface that defaults driver and database to null.

public static Connection

Returns:

a connection to the defaultURL if possible; null if not.
startJBMS
(String
the driver to use if no property value found
defaultDriver
,
String
the database URL to use if no property value found
defaultURL
)

Utility interface that defaults connInfo to null

public static Properties
updateConnInfo(String user, String password, Properties connInfo)

pack-priv static void
Usage(LocalizedOutput out)

print a usage message for invocations of main().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INT_Pback to summary
private static final Class<T>[] INT_P
keyback to summary
private String key
protocolDriversback to summary
private static final String[][] protocolDrivers
STRING_Pback to summary
private static final Class<T>[] STRING_P

Constructor Detail

utilback to summary
private util()

Method Detail

DisplayMultiback to summary
public static void DisplayMulti(LocalizedOutput out, PreparedStatement ps, ResultSet rs, Connection conn) throws SQLException, ijException

Display a statement that takes parameters by stuffing it with rows from the result set and displaying each result each time through. Deal with autocommit behavior along the way.

Exceptions
SQLException:
thrown on db error
ijException:
thrown on ij error
DisplayVectorback to summary
public static void DisplayVector(LocalizedOutput out, Vector<E> v)

Display a vector of strings to the out stream.

getArgback to summary
public static String getArg(String param, String[] args)

Find the argument that follows the specified parameter.

Parameters
param:String

the parameter (e.g. "-p")

args:String[]

the argument list to consider.

Returns:String

the argument that follows the parameter, or null if not found

getDataSourceConnectionback to summary
public static Connection getDataSourceConnection(String dsName, String user, String password, String dbName, boolean firstTime) throws SQLException

Returns a connection obtained using the DataSource. This method will be called when ij.dataSource property is set. It uses ij.dataSource.* properties to get details for the connection.

Parameters
dsName:String

Data Source name

user:String

User name

password:String

Password

dbName:String

Database Name

firstTime:boolean

Indicates if the method is called first time. This is passed to setupDataSource method.

getFileArgback to summary
public static String getFileArg(String[] args) throws IOException

Return the name of the ij command file or null if none is specified. The command file may be proceeded with -f flag on the command line. Alternatively, the command file may be specified without a -f flag. In this case we assume the first unknown argument is the command file.

This should only be called after calling invalidArgs.

If there is no such argument, a null is returned.

Parameters
args:String[]

the argument list to consider.

Returns:String

the name of the first argument not preceded by "-p", null if none found.

Exceptions
IOException:
thrown if file not found
getInputResourceNameArgback to summary
public static String getInputResourceNameArg(String[] args)

Return the name of a resource containing input commands or null iff none has been specified.

getPropertyArgback to summary
public static boolean getPropertyArg(String[] args) throws IOException

ij is started with "-p[r] file OtherArgs"; the file contains properties to control the driver and database used to run ij, and can provide additional system properties.

getPropertyArg will look at the args and take out a "-p " pair, reading the file into the system properties.

If there was a -p without a following , no action is taken.

Parameters
args:String[]

the argument list to consider.

Returns:boolean

true if a property item was found and loaded.

Exceptions
IOException:
thrown if file not found
getResourceAsStreamback to summary
pack-priv static InputStream getResourceAsStream(String resourceName)

Convenience routine to get a resource as a BufferedInputStream. If the resourceName is not absolute (does not begin with a "/") this qualifies the name with the "ij.defaultResourcePackage" name.

Parameters
resourceName:String

the name of the resource

Returns:InputStream

a buffered stream for the resource if it exists and null otherwise.

getSelectedSchemaback to summary
public static String getSelectedSchema(Connection theConnection) throws SQLException

Selects the current schema from the given connection. As there are no way of getting current schema supported by all major DBMS-es, this method may return null.

Parameters
theConnection:Connection

Connection to get current schema for

Returns:String

the current schema of the connection, or null if error.

getSystemPropertyback to summary
pack-priv static final String getSystemProperty(String propertyName)
invalidArgsback to summary
public static boolean invalidArgs(String[] args)

Verify the ij line arguments command arguments. Also used to detect --help.

Returns:boolean

true if the args are invalid

  • Only legal argument provided.
  • Only specify a quantity once.
isJCCFrameworkback to summary
private static boolean isJCCFramework()

Used to determine if this is a JCC testing framework So that retrieveMessages can be sent. The plan is to have ij will retrieve messages by default and not look at the testing frameworks. So, ulitmately this function will look at the driver rather than the framework.

Returns:boolean

true if the framework contains Net or JCC.

loadDriverback to summary
pack-priv static void loadDriver(String driverClass) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException

Load a driver given a class name.

Exceptions
ClassNotFoundException:
if unable to locate class for driver.
InstantiationException:
if unable to create an instance.
IllegalAccessException:
if driver class constructor not visible.
loadDriverIfKnownback to summary
public static void loadDriverIfKnown(String jdbcProtocol) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException

Find the appropriate driver and load it, given a JDBC URL. No action if no driver known for a given URL.

Parameters
jdbcProtocol:String

the protocol to try.

Exceptions
ClassNotFoundException:
if unable to locate class for driver.
InstantiationException:
if unable to create an instance.
IllegalAccessException:
if driver class constructor not visible.
loadWithTrimmedValuesback to summary
private static void loadWithTrimmedValues(InputStream iStr, Properties prop) throws IOException

Read a set of properties from the received input stream, strip off any excess white space that exists in those property values, and then add those newly-read properties to the received Properties object; not explicitly removing the whitespace here can lead to problems. This method exists because of the manner in which the jvm reads properties from file--extra spaces are ignored after a _key_, but if they exist at the _end_ of a property decl line (i.e. as part of a _value_), they are preserved, as outlined in the Java API: "Any whitespace after the key is skipped; if the first non- whitespace character after the key is = or :, then it is ignored and any whitespace characters after it are also skipped. All remaining characters on the line become part of the associated element string." Creates final properties set consisting of 'prop' plus all properties loaded from 'iStr' (with the extra whitespace (if any) removed from all values), will be returned via the parameter.

Parameters
iStr:InputStream

An input stream from which the new properties are to be loaded (should already be initialized).

prop:Properties

A set of properties to which the properties from iStr will be added (should already be initialized). Copied here to avoid dependency on an engine class.

qualifyResourceNameback to summary
pack-priv static String qualifyResourceName(String resourceName, boolean absolute)

Convenience routine to qualify a resource name with "ij.defaultPackageName" if it is not qualified (does not begin with a "/").

Parameters
absolute:boolean

true means return null if the name is not absolute and false means return partial names.

runback to summary
public final String run()
setupDataSourceback to summary
public static void setupDataSource(Object ds, String dbName, boolean firstTime) throws Exception

Sets up a data source with values specified in ij.dataSource.* properties or passed as parameters of this method

Parameters
ds:Object

DataSource object

dbName:String

Database Name

firstTime:boolean

If firstTime is false, ij.dataSource.createDatabase and ij.dataSource.databaseName properties will not be used. The value in parameter dbName will be used instead of ij.dataSource.databaseName.

startJBMSback to summary
public static Connection startJBMS(String defaultDriver, String defaultURL, Properties connInfo) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException

This will look for the System properties "ij.driver" and "ij.database" and return a java.sql.Connection if it successfully connects. The deprecated driver and database properties are examined first.

If no connection was possible, it will return a null.

Failure to load the driver class is quietly ignored.

Parameters
defaultDriver:String

the driver to use if no property value found

defaultURL:String

the database URL to use if no property value found

connInfo:Properties

Connection attributes to pass to getConnection

Returns:Connection

a connection to the defaultURL if possible; null if not.

Exceptions
SQLException:
on failure to connect.
ClassNotFoundException:
on failure to load driver.
InstantiationException:
on failure to load driver.
IllegalAccessException:
on failure to load driver.
startJBMSback to summary
public static Connection startJBMS() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException

Utility interface that defaults driver and database to null.

Returns:Connection

a connection to the defaultURL if possible; null if not.

Exceptions
SQLException:
on failure to connect.
ClassNotFoundException:
on failure to load driver.
InstantiationException:
on failure to load driver.
IllegalAccessException:
on failure to load driver.
startJBMSback to summary
public static Connection startJBMS(String defaultDriver, String defaultURL) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException

Utility interface that defaults connInfo to null

Parameters
defaultDriver:String

the driver to use if no property value found

defaultURL:String

the database URL to use if no property value found

Returns:Connection

a connection to the defaultURL if possible; null if not.

Exceptions
SQLException:
on failure to connect.
ClassNotFoundException:
on failure to load driver.
InstantiationException:
on failure to load driver.
IllegalAccessException:
on failure to load driver.
updateConnInfoback to summary
public static Properties updateConnInfo(String user, String password, Properties connInfo)
Usageback to summary
pack-priv static void Usage(LocalizedOutput out)

print a usage message for invocations of main().