Class DBMSMetadata


  • public class DBMSMetadata
    extends java.lang.Object
    Wrap JDBC connection for use by PMD: DBURI parameters specify the source code to be passed to PMD.
    Author:
    sturton
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.sql.CallableStatement callableStatement
      CallableStatement to return source code.
      protected java.sql.Connection connection
      Connection management
      protected DBURI dburi
      DBURI
      protected java.lang.String returnSourceCodeObjectsStatement
      Procedural statement to return list of source code objects.
      protected java.lang.String returnSourceCodeStatement
      Procedural statement to return source code.
      protected int returnType
      Types value representing the type returned by callableStatement Currently only java.sql.Types.String and java.sql.Types.Clob are supported
    • Constructor Summary

      Constructors 
      Constructor Description
      DBMSMetadata​(java.lang.String user, java.lang.String password, DBURI dbURI)
      Define database connection and source code to retrieve with explicit database username and password.
      DBMSMetadata​(java.sql.Connection c)
      Minimal constructor
      DBMSMetadata​(java.util.Properties properties, DBURI dbURI)
      Define database connection and source code to retrieve with database properties.
      DBMSMetadata​(DBURI dbURI)
      Define database connection and source code to retrieve.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.sql.Connection getConnection()
      Return JDBC Connection for direct JDBC access to the specified database.
      java.io.Reader getSourceCode​(java.lang.String objectType, java.lang.String name, java.lang.String schema)
      return source code text
      java.io.Reader getSourceCode​(SourceObject sourceObject)
      Return source code text from the database.
      java.util.List<SourceObject> getSourceObjectList()
      Return all source code objects associated with any associated DBURI.
      java.util.List<SourceObject> getSourceObjectList​(java.util.List<java.lang.String> languages, java.util.List<java.lang.String> schemas, java.util.List<java.lang.String> sourceCodeTypes, java.util.List<java.lang.String> sourceCodeNames)
      Return all source code objects associated with the specified languages, schemas, source code types and source code names.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dburi

        protected DBURI dburi
        DBURI
      • connection

        protected java.sql.Connection connection
        Connection management
      • returnSourceCodeObjectsStatement

        protected java.lang.String returnSourceCodeObjectsStatement
        Procedural statement to return list of source code objects.
      • returnSourceCodeStatement

        protected java.lang.String returnSourceCodeStatement
        Procedural statement to return source code.
      • callableStatement

        protected java.sql.CallableStatement callableStatement
        CallableStatement to return source code.
      • returnType

        protected int returnType
        Types value representing the type returned by callableStatement Currently only java.sql.Types.String and java.sql.Types.Clob are supported
    • Constructor Detail

      • DBMSMetadata

        public DBMSMetadata​(java.sql.Connection c)
                     throws java.sql.SQLException
        Minimal constructor
        Parameters:
        c - JDBC Connection
        Throws:
        java.sql.SQLException
      • DBMSMetadata

        public DBMSMetadata​(java.lang.String user,
                            java.lang.String password,
                            DBURI dbURI)
                     throws java.sql.SQLException,
                            java.net.MalformedURLException,
                            java.lang.ClassNotFoundException
        Define database connection and source code to retrieve with explicit database username and password.
        Parameters:
        user - Database username
        password - Database password
        dbURI - DBURI containing JDBC connection plus parameters to specify source code.
        Throws:
        java.sql.SQLException - on failing to create JDBC connection
        java.net.MalformedURLException - on attempting to connect with malformed JDBC URL
        java.lang.ClassNotFoundException - on failing to locate the JDBC driver class.
      • DBMSMetadata

        public DBMSMetadata​(java.util.Properties properties,
                            DBURI dbURI)
                     throws java.sql.SQLException,
                            java.net.MalformedURLException,
                            java.lang.ClassNotFoundException
        Define database connection and source code to retrieve with database properties.
        Parameters:
        properties - database settings such as database username, password
        dbURI - DBURI containing JDBC connection plus parameters to specify source code.
        Throws:
        java.sql.SQLException - on failing to create JDBC connection
        java.net.MalformedURLException - on attempting to connect with malformed JDBC URL
        java.lang.ClassNotFoundException - on failing to locate the JDBC driver class.
      • DBMSMetadata

        public DBMSMetadata​(DBURI dbURI)
                     throws java.sql.SQLException,
                            java.lang.ClassNotFoundException
        Define database connection and source code to retrieve.

        This constructor is reliant on database username and password embedded in the JDBC URL or defaulted from the DBURI's DriverType.

        Parameters:
        dbURI - DBURI containing JDBC connection plus parameters to specify source code.
        Throws:
        java.sql.SQLException - on failing to create JDBC connection
        java.lang.ClassNotFoundException - on failing to locate the JDBC driver class.
    • Method Detail

      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Return JDBC Connection for direct JDBC access to the specified database.
        Returns:
        I=JDBC Connection
        Throws:
        java.sql.SQLException
      • getSourceCode

        public java.io.Reader getSourceCode​(SourceObject sourceObject)
                                     throws java.sql.SQLException
        Return source code text from the database.
        Parameters:
        sourceObject - object
        Returns:
        source code
        Throws:
        java.sql.SQLException
      • getSourceCode

        public java.io.Reader getSourceCode​(java.lang.String objectType,
                                            java.lang.String name,
                                            java.lang.String schema)
                                     throws java.sql.SQLException
        return source code text
        Parameters:
        objectType -
        name - Source Code name
        schema - Owner of the code
        Returns:
        Source code text.
        Throws:
        java.sql.SQLException - on failing to retrieve the source Code text
      • getSourceObjectList

        public java.util.List<SourceObject> getSourceObjectList()
        Return all source code objects associated with any associated DBURI.
        Returns:
      • getSourceObjectList

        public java.util.List<SourceObject> getSourceObjectList​(java.util.List<java.lang.String> languages,
                                                                java.util.List<java.lang.String> schemas,
                                                                java.util.List<java.lang.String> sourceCodeTypes,
                                                                java.util.List<java.lang.String> sourceCodeNames)
        Return all source code objects associated with the specified languages, schemas, source code types and source code names.

        Each parameter may be null and the appropriate field from any related DBURI is assigned, defaulting to the normal SQL wildcard expression ("%").

        Parameters:
        languages - Optional list of languages to search for
        schemas - Optional list of schemas to search for
        sourceCodeTypes - Optional list of source code types to search for
        sourceCodeNames - Optional list of source code names to search for