001 package com.sptci.rwt;
002
003 import java.sql.Connection;
004 import java.sql.DatabaseMetaData;
005 import java.sql.ParameterMetaData;
006 import java.sql.PreparedStatement;
007 import java.sql.ResultSet;
008 import java.sql.SQLException;
009
010 import java.util.logging.Level;
011
012 import java.util.ArrayList;
013 import java.util.Collection;
014
015 import com.sptci.util.CloseJDBCResources;
016
017 /**
018 * An analyser for analysing procedure type objects in the database. This
019 * is used to database engines that support the SQL92 standard information
020 * schema.
021 *
022 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
023 * @author Rakesh Vidyadharan 2007-11-03
024 * @version $Id: StandardProcedureAnalyser.java 4123 2008-05-25 21:49:01Z rakesh $
025 * @since Version 1.2
026 */
027 class StandardProcedureAnalyser extends AbstractProcedureAnalyser
028 {
029 /**
030 * Create a new instance of the class using the specified connection
031 * manager.
032 *
033 * @param manager The manager for obtaining database connections.
034 */
035 StandardProcedureAnalyser( final ConnectionManager manager )
036 {
037 super( manager );
038 }
039
040 /**
041 * Fetch additional meta data available from the <code>information
042 * schema</code> to the object.
043 *
044 * @see #getNames
045 * @param pmd The meta data object that is to be updated.
046 */
047 @Override
048 protected void getAdditionalAttributes( final ProcedureMetaData pmd )
049 {
050 Connection connection = null;
051 PreparedStatement statement = null;
052 ResultSet resultSet = null;
053
054 try
055 {
056 CatalogueSchema cs = getNames( pmd.getRoot() );
057 connection = manager.open();
058
059 if ( cs.getCatalogue() == null )
060 {
061 final String query = "select data_type, type_udt_name, routine_body, routine_definition from information_schema.routines where routine_schema = ? and routine_name = ?";
062 statement = connection.prepareStatement( query );
063 statement.setString( 1, cs.getSchema() );
064 statement.setString( 2, pmd.getName() );
065 }
066 else if ( cs.getSchema() == null )
067 {
068 final String query = "select data_type, type_udt_name, routine_body, routine_definition from information_schema.routines where routine_catalog = ? and routine_name = ?";
069 statement = connection.prepareStatement( query );
070 statement.setString( 1, cs.getCatalogue() );
071 statement.setString( 2, pmd.getName() );
072 }
073 else
074 {
075 final String query = "select data_type, type_udt_name, routine_body, routine_definition from information_schema.routines where routine_catalog = ? and routine_schema = ? and routine_name = ?";
076 statement = connection.prepareStatement( query );
077 statement.setString( 1, cs.getCatalogue() );
078 statement.setString( 2, cs.getSchema() );
079 statement.setString( 3, pmd.getName() );
080 }
081
082 resultSet = statement.executeQuery();
083 if ( resultSet.next() )
084 {
085 pmd.setDataType( resultSet.getString( "data_type" ) );
086 pmd.setUserDefinedType( resultSet.getString( "type_udt_name" ) );
087 pmd.setBody( resultSet.getString( "routine_body" ) );
088 pmd.setDefinition( resultSet.getString( "routine_definition" ) );
089 }
090 }
091 catch ( SQLException sex )
092 {
093 logger.log( Level.FINE,
094 "Error fetching procedure details from information_schema", sex );
095 }
096 finally
097 {
098 CloseJDBCResources.close( resultSet );
099 CloseJDBCResources.close( statement );
100 CloseJDBCResources.close( connection );
101 }
102 }
103 }