Package org.apache.derby.impl.tools.ij
Class util
java.lang.Object
org.apache.derby.impl.tools.ij.util
- All Implemented Interfaces:
PrivilegedAction<String>
Methods used to control setup for apps as
well as display some internal ij structures.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static void
DisplayVector
(LocalizedOutput out, Vector v) Display a vector of strings to the out stream.static String
Find the argument that follows the specified parameter.static Connection
getDataSourceConnection
(String dsName, String user, String password, String dbName, boolean firstTime) Returns a connection obtained using the DataSource.static String
getFileArg
(String[] args) Return the name of the ij command file or null if none is specified.static String
getInputResourceNameArg
(String[] args) Return the name of a resource containing input commands or null iff none has been specified.static boolean
getPropertyArg
(String[] 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.(package private) static InputStream
getResourceAsStream
(String resourceName) Convenience routine to get a resource as a BufferedInputStream.static String
getSelectedSchema
(Connection theConnection) Selects the current schema from the given connection.(package private) static final String
getSystemProperty
(String propertyName) static boolean
invalidArgs
(String[] args) Verify the ij line arguments command arguments.private static boolean
Used to determine if this is a JCC testing framework So that retrieveMessages can be sent.(package private) static void
loadDriver
(String driverClass) Load a driver given a class name.static void
loadDriverIfKnown
(String jdbcProtocol) Find the appropriate driver and load it, given a JDBC URL.private static void
loadWithTrimmedValues
(InputStream iStr, Properties 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.(package private) 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 "/").final String
run()
static void
setupDataSource
(Object ds, String dbName, boolean firstTime) Sets up a data source with values specified in ij.dataSource.* properties or passed as parameters of this methodstatic Connection
Utility interface that defaults driver and database to null.static Connection
Utility interface that defaults connInfo to nullstatic Connection
startJBMS
(String defaultDriver, String defaultURL, Properties connInfo) This will look for the System properties "ij.driver" and "ij.database" and return a java.sql.Connection if it successfully connects.static Properties
updateConnInfo
(String user, String password, Properties connInfo) (package private) static void
Usage
(LocalizedOutput out) print a usage message for invocations of main().
-
Field Details
-
STRING_P
-
INT_P
-
key
-
protocolDrivers
-
-
Constructor Details
-
util
private util()
-
-
Method Details
-
getArg
Find the argument that follows the specified parameter.- Parameters:
param
- the parameter (e.g. "-p")args
- the argument list to consider.- Returns:
- the argument that follows the parameter, or null if not found
-
getPropertyArg
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
- the argument list to consider.- Returns:
- true if a property item was found and loaded.
- Throws:
IOException
- thrown if file not found
-
qualifyResourceName
Convenience routine to qualify a resource name with "ij.defaultPackageName" if it is not qualified (does not begin with a "/").- Parameters:
absolute
- true means return null if the name is not absolute and false means return partial names.
-
getResourceAsStream
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
- the name of the resource- Returns:
- a buffered stream for the resource if it exists and null otherwise.
-
getFileArg
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
- the argument list to consider.- Returns:
- the name of the first argument not preceded by "-p", null if none found.
- Throws:
IOException
- thrown if file not found
-
getInputResourceNameArg
Return the name of a resource containing input commands or null iff none has been specified. -
invalidArgs
Verify the ij line arguments command arguments. Also used to detect --help.- Returns:
- true if the args are invalid
- Only legal argument provided.
- Only specify a quantity once.
-
Usage
print a usage message for invocations of main(). -
setupDataSource
Sets up a data source with values specified in ij.dataSource.* properties or passed as parameters of this method- Parameters:
ds
- DataSource objectdbName
- Database NamefirstTime
- 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.- Throws:
Exception
-
getDataSourceConnection
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
- Data Source nameuser
- User namepassword
- PassworddbName
- Database NamefirstTime
- Indicates if the method is called first time. This is passed to setupDataSource method.- Throws:
SQLException
-
startJBMS
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
- the driver to use if no property value founddefaultURL
- the database URL to use if no property value foundconnInfo
- Connection attributes to pass to getConnection- Returns:
- a connection to the defaultURL if possible; null if not.
- Throws:
SQLException
- on failure to connect.ClassNotFoundException
- on failure to load driver.InstantiationException
- on failure to load driver.IllegalAccessException
- on failure to load driver.NoSuchMethodException
InvocationTargetException
-
updateConnInfo
-
startJBMS
public static Connection startJBMS() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetExceptionUtility interface that defaults driver and database to null.- Returns:
- a connection to the defaultURL if possible; null if not.
- Throws:
SQLException
- on failure to connect.ClassNotFoundException
- on failure to load driver.InstantiationException
- on failure to load driver.IllegalAccessException
- on failure to load driver.NoSuchMethodException
InvocationTargetException
-
startJBMS
public static Connection startJBMS(String defaultDriver, String defaultURL) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException Utility interface that defaults connInfo to null- Parameters:
defaultDriver
- the driver to use if no property value founddefaultURL
- the database URL to use if no property value found- Returns:
- a connection to the defaultURL if possible; null if not.
- Throws:
SQLException
- on failure to connect.ClassNotFoundException
- on failure to load driver.InstantiationException
- on failure to load driver.IllegalAccessException
- on failure to load driver.NoSuchMethodException
InvocationTargetException
-
DisplayVector
Display a vector of strings to the out stream. -
DisplayMulti
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.- Throws:
SQLException
- thrown on db errorijException
- thrown on ij error
-
getSystemProperty
-
run
- Specified by:
run
in interfacePrivilegedAction<String>
-
loadWithTrimmedValues
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
- An input stream from which the new properties are to be loaded (should already be initialized).prop
- 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.- Throws:
IOException
-
loadDriverIfKnown
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
- the protocol to try.- Throws:
ClassNotFoundException
- if unable to locate class for driver.InstantiationException
- if unable to create an instance.IllegalAccessException
- if driver class constructor not visible.NoSuchMethodException
InvocationTargetException
-
loadDriver
static void loadDriver(String driverClass) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException Load a driver given a class name.- Throws:
ClassNotFoundException
- if unable to locate class for driver.InstantiationException
- if unable to create an instance.IllegalAccessException
- if driver class constructor not visible.NoSuchMethodException
InvocationTargetException
-
isJCCFramework
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:
- true if the framework contains Net or JCC.
-
getSelectedSchema
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 to get current schema for- Returns:
- the current schema of the connection, or null if error.
- Throws:
SQLException
-