Top Description Inners Fields Constructors Methods
org.apache.derby.tools

public Class SignatureChecker

extends Object
Class Inheritance
Imports
java.sql.Connection, .DatabaseMetaData, .DriverManager, .PreparedStatement, .ResultSet, .SQLException, java.util.ArrayList, org.apache.derby.iapi.tools.i18n.LocalizedResource

This class shows which user declared SQL functions and procedures cannot be matched with Java methods.

To run from the command-line, enter the following if running on J2SE:

java org.apache.derby.tools.SignatureChecker CONNECTION_URL_TO_DATABASE

And enter the following if running on J2ME:

java org.apache.derby.tools.SignatureChecker DATABASE_NAME

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv class

Field Summary

Modifier and TypeField and Description
private final boolean
private final ArrayList<SignatureChecker.SQLRoutine>
private static LocalizedResource
private final SignatureChecker.ParsedArgs
private final ArrayList<SignatureChecker.SQLRoutine>
private static final String[]
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
checkSignature(Connection
The connection to the database
conn
,
String
The SQL to prepare
query
,
String
the signature: printed if prepare fails
readableSignature
)

Prepared a routine invocation in order to check whether it matches a Java method.

private void
countFunctionArgs(DatabaseMetaData
the database metadata of the database
dbmd
)

Count up the arguments to the user-coded procedures.

private void
countProcedureArgs(DatabaseMetaData
the database metadata of the database
dbmd
)

Count up the arguments to the user-coded procedures in _procedures and update that data structure accordingly

private void
execute()

Get a connection to a database and then match the signatures of routines in that database.

private void
findFunctions(DatabaseMetaData
the database metadata of the database
dbmd
)

Find all of the user-declared functions.

private void
findProcedures(DatabaseMetaData
the database metadata of the database
dbmd
)

Find all of the user-declared procedures.

private static String

Returns:

A localized message
formatMessage
(String
The message key by which we located the localized text
key
,
Object...
Any arguments to the localized text to be filled in
args
)

Format a localizable message.

private SignatureChecker.SQLRoutine

Returns:

a function descriptor
getFunction
(int
The index of the procedure in _functions.
idx
)

Get a function descriptor from _functions .

private Connection

Returns:

a connection to the database
getJ2SEConnection
()

We use reflection to get the J2SE connection so that references to DriverManager will not generate linkage errors on old J2ME platforms which may resolve references eagerly.

private static LocalizedResource

Returns:

localized resource
getMessageFormatter
()

Get the message resource.

private SignatureChecker.SQLRoutine

Returns:

a procedure descriptor
getProcedure
(int
The index of the procedure in _procedures.
idx
)

Get a procedure descriptor from _procedures.

private boolean

Returns:

true if the schema is a system schema
isSystemSchema
(String
the schema to check
schema
)

Return true if the schema is a system schema.

public static void
main(String[] args)

private String

Returns:

human readable string
makeReadableSignature
(SignatureChecker.SQLRoutine
the routine for which we want a signature
routine
)

Make a human readable signature for a routine.

private void
matchFunctions(Connection
The connection to use to access the database
conn
)

Match the signatures of functions in this database.

private void
matchProcedures(Connection
The connection to use to access the database
conn
)

Match the signatures of procedures in this database.

private void
matchSignatures(Connection
This connection
conn
)

Match the signatures of routines in the database attached to this connection.

private PreparedStatement
private static void
private static void
private static void
private void
putFunction(String
The schema of the function
schema
,
String
The name of the function
name
,
boolean
true iff the function is a table function
isTableFunction
)

Store a function descriptor.

private void
putProcedure(String
schema of the procedure
schema
,
String
of a procedure
name
)

Store a procedure descriptor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_debuggingback to summary
private final boolean _debugging
_functionsback to summary
private final ArrayList<SignatureChecker.SQLRoutine> _functions
_messageFormatterback to summary
private static LocalizedResource _messageFormatter
_parsedArgsback to summary
private final SignatureChecker.ParsedArgs _parsedArgs
_proceduresback to summary
private final ArrayList<SignatureChecker.SQLRoutine> _procedures
SYSTEM_SCHEMASback to summary
private static final String[] SYSTEM_SCHEMAS
WILDCARDback to summary
private static final String WILDCARD

Constructor Detail

SignatureCheckerback to summary
private SignatureChecker(SignatureChecker.ParsedArgs parsedArgs)

Method Detail

checkSignatureback to summary
private void checkSignature(Connection conn, String query, String readableSignature)

Prepared a routine invocation in order to check whether it matches a Java method.

Parameters
conn:Connection

The connection to the database

query:String

The SQL to prepare

readableSignature:String

the signature: printed if prepare fails

countFunctionArgsback to summary
private void countFunctionArgs(DatabaseMetaData dbmd) throws SQLException

Count up the arguments to the user-coded procedures. We use reflection to look up the getFunctionColumns() method because that method does not appear in the JSR169 api for DatabaseMetaData. Update _functions.

Parameters
dbmd:DatabaseMetaData

the database metadata of the database

countProcedureArgsback to summary
private void countProcedureArgs(DatabaseMetaData dbmd) throws SQLException

Count up the arguments to the user-coded procedures in _procedures and update that data structure accordingly

Parameters
dbmd:DatabaseMetaData

the database metadata of the database

executeback to summary
private void execute()

Get a connection to a database and then match the signatures of routines in that database.

findFunctionsback to summary
private void findFunctions(DatabaseMetaData dbmd) throws SQLException

Find all of the user-declared functions. We use reflection to get our hands on getFunctions() because that method does not appear in the JSR169 api for DatabaseMetaData. Update _functions.

Parameters
dbmd:DatabaseMetaData

the database metadata of the database

findProceduresback to summary
private void findProcedures(DatabaseMetaData dbmd) throws SQLException

Find all of the user-declared procedures.

Parameters
dbmd:DatabaseMetaData

the database metadata of the database

formatMessageback to summary
private static String formatMessage(String key, Object... args)

Format a localizable message.

Parameters
key:String

The message key by which we located the localized text

args:Object[]

Any arguments to the localized text to be filled in

Returns:String

A localized message

getFunctionback to summary
private SignatureChecker.SQLRoutine getFunction(int idx)

Get a function descriptor from _functions .

Parameters
idx:int

The index of the procedure in _functions.

Returns:SignatureChecker.SQLRoutine

a function descriptor

getJ2SEConnectionback to summary
private Connection getJ2SEConnection() throws SQLException

We use reflection to get the J2SE connection so that references to DriverManager will not generate linkage errors on old J2ME platforms which may resolve references eagerly.

Returns:Connection

a connection to the database

getMessageFormatterback to summary
private static LocalizedResource getMessageFormatter()

Get the message resource.

Returns:LocalizedResource

localized resource

getProcedureback to summary
private SignatureChecker.SQLRoutine getProcedure(int idx)

Get a procedure descriptor from _procedures.

Parameters
idx:int

The index of the procedure in _procedures.

Returns:SignatureChecker.SQLRoutine

a procedure descriptor

isSystemSchemaback to summary
private boolean isSystemSchema(String schema)

Return true if the schema is a system schema.

Parameters
schema:String

the schema to check

Returns:boolean

true if the schema is a system schema

mainback to summary
public static void main(String[] args)
makeReadableSignatureback to summary
private String makeReadableSignature(SignatureChecker.SQLRoutine routine)

Make a human readable signature for a routine. This can be used in error messages.

Parameters
routine:SignatureChecker.SQLRoutine

the routine for which we want a signature

Returns:String

human readable string

matchFunctionsback to summary
private void matchFunctions(Connection conn) throws SQLException

Match the signatures of functions in this database.

Parameters
conn:Connection

The connection to use to access the database

matchProceduresback to summary
private void matchProcedures(Connection conn) throws SQLException

Match the signatures of procedures in this database.

Parameters
conn:Connection

The connection to use to access the database

matchSignaturesback to summary
private void matchSignatures(Connection conn) throws SQLException

Match the signatures of routines in the database attached to this connection.

Parameters
conn:Connection

This connection

prepareStatementback to summary
private PreparedStatement prepareStatement(Connection conn, String text) throws SQLException
printlnback to summary
private static void println(String text)
printThrowableback to summary
private static void printThrowable(Throwable t)
Annotations
@SuppressWarnings:CallToPrintStackTrace
printUsageback to summary
private static void printUsage()
putFunctionback to summary
private void putFunction(String schema, String name, boolean isTableFunction)

Store a function descriptor. Updates _functions.

Parameters
schema:String

The schema of the function

name:String

The name of the function

isTableFunction:boolean

true iff the function is a table function

putProcedureback to summary
private void putProcedure(String schema, String name)

Store a procedure descriptor. Updates _procedures.

Parameters
schema:String

schema of the procedure

name:String

of a procedure

org.apache.derby.tools back to summary

pack-priv Class SignatureChecker.ParsedArgs

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
public boolean
private void
parseArgs(String[] args)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_isValidback to summary
private boolean _isValid
_j2seConnectionUrlback to summary
private String _j2seConnectionUrl

Constructor Detail

ParsedArgsback to summary
public ParsedArgs(String[] args)

Method Detail

getJ2seConnectionUrlback to summary
public String getJ2seConnectionUrl()
isValidback to summary
public boolean isValid()
parseArgsback to summary
private void parseArgs(String[] args)
org.apache.derby.tools back to summary

pack-priv Class SignatureChecker.SQLRoutine

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ArrayList<String>
private final boolean
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
SQLRoutine(String schema, String name, boolean isTableFunction)

Method Summary

Modifier and TypeMethod and Description
public void
addArg(String typeName)

private String
public int
public String
getArgType(int idx)

public String
public String
public String
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_argListback to summary
private final ArrayList<String> _argList
_isTableFunctionback to summary
private final boolean _isTableFunction
_nameback to summary
private final String _name
_schemaback to summary
private final String _schema

Constructor Detail

SQLRoutineback to summary
public SQLRoutine(String schema, String name, boolean isTableFunction)

Method Detail

addArgback to summary
public void addArg(String typeName)
doubleQuoteback to summary
private String doubleQuote(String raw)
getArgCountback to summary
public int getArgCount()
getArgTypeback to summary
public String getArgType(int idx)
getNameback to summary
public String getName()
getQualifiedNameback to summary
public String getQualifiedName()
getSchemaback to summary
public String getSchema()
isTableFunctionback to summary
public boolean isTableFunction()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override