Class AccessDatabase


  • public class AccessDatabase
    extends java.lang.Object
    This class will perform the database connection establishment, querying the database, shut downing the database. Created under DERBY-4587-PlanExporter tool
    • Constructor Summary

      Constructors 
      Constructor Description
      AccessDatabase​(java.lang.String dburl, java.lang.String aSchema, java.lang.String aQuery)  
      AccessDatabase​(java.sql.Connection aConn, java.lang.String aSchema, java.lang.String aQuery)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closeConnection()
      closing the connection to the database
      private static java.sql.Connection createConnection​(java.lang.String dbURL)  
      private void createXMLData​(java.lang.String qry, int x)
      Create XML data based on the query that's passed in.
      void createXMLFragment()
      This method creates the queries such that after execution of the query it will return XML data fragments.
      private static java.lang.String escapeForXML​(java.lang.String text)
      Escape characters that have a special meaning in XML.
      private java.lang.String escapeInAttribute​(java.lang.String text)
      This method is needed since in the case of XML attributes we have to filter the quotation (") marks that is compulsory.
      private void findChildren​(int idx, int dep)  
      private void getChildren​(int currentLevel, java.lang.String id)  
      TreeNode[] getData()  
      int getDepth()  
      java.lang.String getQuery()  
      java.lang.String getXmlString()
      Generating the XML tree
      java.lang.String indent​(int j)  
      boolean initializeDataArray()  
      void markTheDepth()
      marking the depth of each element
      private int noOfNodes()  
      private boolean schemaExists()
      Check if there is a schema in the database that matches the schema name that was passed in to this instance.
      private void setSchema()
      Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.
      java.lang.String statement()  
      java.lang.String stmtID()  
      java.lang.String time()  
      boolean verifySchemaExistance()  
      • Methods inherited from class java.lang.Object

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

      • AccessDatabase

        public AccessDatabase​(java.lang.String dburl,
                              java.lang.String aSchema,
                              java.lang.String aQuery)
                       throws java.lang.InstantiationException,
                              java.lang.IllegalAccessException,
                              java.lang.ClassNotFoundException,
                              java.sql.SQLException,
                              java.lang.NoSuchMethodException,
                              java.lang.reflect.InvocationTargetException
        Parameters:
        dburl -
        aSchema -
        aQuery -
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.ClassNotFoundException
        java.sql.SQLException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
      • AccessDatabase

        public AccessDatabase​(java.sql.Connection aConn,
                              java.lang.String aSchema,
                              java.lang.String aQuery)
                       throws java.sql.SQLException
        Parameters:
        aConn -
        aSchema -
        aQuery -
        Throws:
        java.sql.SQLException
    • Method Detail

      • getQuery

        public java.lang.String getQuery()
        Returns:
        the stmt_id
      • getDepth

        public int getDepth()
      • createConnection

        private static java.sql.Connection createConnection​(java.lang.String dbURL)
                                                     throws java.lang.InstantiationException,
                                                            java.lang.IllegalAccessException,
                                                            java.lang.ClassNotFoundException,
                                                            java.sql.SQLException,
                                                            java.lang.NoSuchMethodException,
                                                            java.lang.reflect.InvocationTargetException
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.ClassNotFoundException
        java.sql.SQLException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
      • setSchema

        private void setSchema()
                        throws java.sql.SQLException
        Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.
        Throws:
        java.sql.SQLException - if an error happens while accessing the database
      • schemaExists

        private boolean schemaExists()
                              throws java.sql.SQLException
        Check if there is a schema in the database that matches the schema name that was passed in to this instance.
        Throws:
        java.sql.SQLException
      • verifySchemaExistance

        public boolean verifySchemaExistance()
      • createXMLFragment

        public void createXMLFragment()
                               throws java.sql.SQLException

        This method creates the queries such that after execution of the query it will return XML data fragments.

        Throws:
        java.sql.SQLException
      • getXmlString

        public java.lang.String getXmlString()
        Generating the XML tree
        Returns:
        all xml elements as a String
      • getChildren

        private void getChildren​(int currentLevel,
                                 java.lang.String id)
        Parameters:
        currentLevel - level of the XML tree (0 based) of current node
        id - current node's stmt_id
      • indent

        public java.lang.String indent​(int j)
        Parameters:
        j - indent needed
        Returns:
        indent as a string
      • markTheDepth

        public void markTheDepth()
        marking the depth of each element
      • findChildren

        private void findChildren​(int idx,
                                  int dep)
        Parameters:
        idx - current element's index
        dep - current examining depth
      • initializeDataArray

        public boolean initializeDataArray()
                                    throws java.sql.SQLException
        Returns:
        whether the initialization is successful or not
        Throws:
        java.sql.SQLException
      • createXMLData

        private void createXMLData​(java.lang.String qry,
                                   int x)
                            throws java.sql.SQLException
        Create XML data based on the query that's passed in. The query should have exactly one parameter, which will be initialized to the statement id before the query is executed.
        Parameters:
        qry - query to be executed
        Throws:
        java.sql.SQLException
      • noOfNodes

        private int noOfNodes()
                       throws java.sql.SQLException
        Returns:
        total # of nodes
        Throws:
        java.sql.SQLException
      • statement

        public java.lang.String statement()
                                   throws java.sql.SQLException
        Returns:
        the <statement> element
        Throws:
        java.sql.SQLException
      • escapeForXML

        private static java.lang.String escapeForXML​(java.lang.String text)
        Escape characters that have a special meaning in XML.
        Parameters:
        text - the text to escape
        Returns:
        the text with special characters escaped
      • escapeInAttribute

        private java.lang.String escapeInAttribute​(java.lang.String text)
        This method is needed since in the case of XML attributes we have to filter the quotation (") marks that is compulsory. eg: scanned_object="A "quoted" table name";
        Parameters:
        text - attribute string to be checked
        Returns:
        modified string
      • time

        public java.lang.String time()
                              throws java.sql.SQLException
        Returns:
        XPLAIN_TIME of SYSXPLAIN_STATEMENTS
        Throws:
        java.sql.SQLException
      • stmtID

        public java.lang.String stmtID()
        Returns:
        stmt_id as a XML element
      • closeConnection

        public void closeConnection()
        closing the connection to the database
      • getData

        public TreeNode[] getData()
        Returns:
        data array of TreeNode Objects