Class SignatureChecker
- java.lang.Object
-
- org.apache.derby.tools.SignatureChecker
-
public class SignatureChecker extends java.lang.ObjectThis 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_DATABASEAnd enter the following if running on J2ME:
java org.apache.derby.tools.SignatureChecker DATABASE_NAME
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSignatureChecker.ParsedArgs(package private) classSignatureChecker.SQLRoutine
-
Field Summary
Fields Modifier and Type Field Description private boolean_debuggingprivate java.util.ArrayList<SignatureChecker.SQLRoutine>_functionsprivate static LocalizedResource_messageFormatterprivate SignatureChecker.ParsedArgs_parsedArgsprivate java.util.ArrayList<SignatureChecker.SQLRoutine>_proceduresprivate static java.lang.String[]SYSTEM_SCHEMASprivate static java.lang.StringWILDCARD
-
Constructor Summary
Constructors Modifier Constructor Description privateSignatureChecker(SignatureChecker.ParsedArgs parsedArgs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckSignature(java.sql.Connection conn, java.lang.String query, java.lang.String readableSignature)Prepared a routine invocation in order to check whether it matches a Java method.private voidcountFunctionArgs(java.sql.DatabaseMetaData dbmd)Count up the arguments to the user-coded procedures.private voidcountProcedureArgs(java.sql.DatabaseMetaData dbmd)Count up the arguments to the user-coded procedures in_proceduresand update that data structure accordinglyprivate voidexecute()Get a connection to a database and then match the signatures of routines in that database.private voidfindFunctions(java.sql.DatabaseMetaData dbmd)Find all of the user-declared functions.private voidfindProcedures(java.sql.DatabaseMetaData dbmd)Find all of the user-declared procedures.private static java.lang.StringformatMessage(java.lang.String key, java.lang.Object... args)Format a localizable message.private SignatureChecker.SQLRoutinegetFunction(int idx)Get a function descriptor from_functions.private java.sql.ConnectiongetJ2SEConnection()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 LocalizedResourcegetMessageFormatter()Get the message resource.private SignatureChecker.SQLRoutinegetProcedure(int idx)Get a procedure descriptor from_procedures.private booleanisSystemSchema(java.lang.String schema)Return true if the schema is a system schema.static voidmain(java.lang.String[] args)private java.lang.StringmakeReadableSignature(SignatureChecker.SQLRoutine routine)Make a human readable signature for a routine.private voidmatchFunctions(java.sql.Connection conn)Match the signatures of functions in this database.private voidmatchProcedures(java.sql.Connection conn)Match the signatures of procedures in this database.private voidmatchSignatures(java.sql.Connection conn)Match the signatures of routines in the database attached to this connection.private java.sql.PreparedStatementprepareStatement(java.sql.Connection conn, java.lang.String text)private static voidprintln(java.lang.String text)private static voidprintThrowable(java.lang.Throwable t)private static voidprintUsage()private voidputFunction(java.lang.String schema, java.lang.String name, boolean isTableFunction)Store a function descriptor.private voidputProcedure(java.lang.String schema, java.lang.String name)Store a procedure descriptor.
-
-
-
Field Detail
-
WILDCARD
private static final java.lang.String WILDCARD
- See Also:
- Constant Field Values
-
SYSTEM_SCHEMAS
private static final java.lang.String[] SYSTEM_SCHEMAS
-
_parsedArgs
private final SignatureChecker.ParsedArgs _parsedArgs
-
_procedures
private final java.util.ArrayList<SignatureChecker.SQLRoutine> _procedures
-
_functions
private final java.util.ArrayList<SignatureChecker.SQLRoutine> _functions
-
_debugging
private final boolean _debugging
- See Also:
- Constant Field Values
-
_messageFormatter
private static LocalizedResource _messageFormatter
-
-
Constructor Detail
-
SignatureChecker
private SignatureChecker(SignatureChecker.ParsedArgs parsedArgs)
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
execute
private void execute()
Get a connection to a database and then match the signatures of routines in that database.
-
matchSignatures
private void matchSignatures(java.sql.Connection conn) throws java.sql.SQLExceptionMatch the signatures of routines in the database attached to this connection.
- Parameters:
conn- This connection- Throws:
java.sql.SQLException
-
matchProcedures
private void matchProcedures(java.sql.Connection conn) throws java.sql.SQLExceptionMatch the signatures of procedures in this database.
- Parameters:
conn- The connection to use to access the database- Throws:
java.sql.SQLException
-
matchFunctions
private void matchFunctions(java.sql.Connection conn) throws java.sql.SQLExceptionMatch the signatures of functions in this database.
- Parameters:
conn- The connection to use to access the database- Throws:
java.sql.SQLException
-
makeReadableSignature
private java.lang.String makeReadableSignature(SignatureChecker.SQLRoutine routine)
Make a human readable signature for a routine. This can be used in error messages.
- Parameters:
routine- the routine for which we want a signature- Returns:
- human readable string
-
findProcedures
private void findProcedures(java.sql.DatabaseMetaData dbmd) throws java.sql.SQLExceptionFind all of the user-declared procedures.
- Parameters:
dbmd- the database metadata of the database- Throws:
java.sql.SQLException
-
countProcedureArgs
private void countProcedureArgs(java.sql.DatabaseMetaData dbmd) throws java.sql.SQLExceptionCount up the arguments to the user-coded procedures in
_proceduresand update that data structure accordingly- Parameters:
dbmd- the database metadata of the database- Throws:
java.sql.SQLException
-
findFunctions
private void findFunctions(java.sql.DatabaseMetaData dbmd) throws java.sql.SQLExceptionFind 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- the database metadata of the database- Throws:
java.sql.SQLException
-
countFunctionArgs
private void countFunctionArgs(java.sql.DatabaseMetaData dbmd) throws java.sql.SQLExceptionCount 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- the database metadata of the database- Throws:
java.sql.SQLException
-
checkSignature
private void checkSignature(java.sql.Connection conn, java.lang.String query, java.lang.String readableSignature)Prepared a routine invocation in order to check whether it matches a Java method.
- Parameters:
conn- The connection to the databasequery- The SQL to preparereadableSignature- the signature: printed if prepare fails
-
getJ2SEConnection
private java.sql.Connection getJ2SEConnection() throws java.sql.SQLExceptionWe 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:
- a connection to the database
- Throws:
java.sql.SQLException
-
prepareStatement
private java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, java.lang.String text) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
printUsage
private static void printUsage()
-
printThrowable
private static void printThrowable(java.lang.Throwable t)
-
println
private static void println(java.lang.String text)
-
isSystemSchema
private boolean isSystemSchema(java.lang.String schema)
Return true if the schema is a system schema.- Parameters:
schema- the schema to check- Returns:
trueif the schema is a system schema
-
putProcedure
private void putProcedure(java.lang.String schema, java.lang.String name)Store a procedure descriptor. Updates_procedures.- Parameters:
schema- schema of the procedurename- of a procedure
-
getProcedure
private SignatureChecker.SQLRoutine getProcedure(int idx)
Get a procedure descriptor from_procedures.- Parameters:
idx- The index of the procedure in_procedures.- Returns:
- a procedure descriptor
-
putFunction
private void putFunction(java.lang.String schema, java.lang.String name, boolean isTableFunction)Store a function descriptor. Updates_functions.- Parameters:
schema- The schema of the functionname- The name of the functionisTableFunction-trueiff the function is a table function
-
getFunction
private SignatureChecker.SQLRoutine getFunction(int idx)
Get a function descriptor from_functions.- Parameters:
idx- The index of the procedure in_functions.- Returns:
- a function descriptor
-
formatMessage
private static java.lang.String formatMessage(java.lang.String key, java.lang.Object... args)Format a localizable message.- Parameters:
key- The message key by which we located the localized textargs- Any arguments to the localized text to be filled in- Returns:
- A localized message
-
getMessageFormatter
private static LocalizedResource getMessageFormatter()
Get the message resource.- Returns:
- localized resource
-
-