Class AccessDatabase
- java.lang.Object
-
- org.apache.derby.impl.tools.planexporter.AccessDatabase
-
public class AccessDatabase extends java.lang.ObjectThis class will perform the database connection establishment, querying the database, shut downing the database. Created under DERBY-4587-PlanExporter tool
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.Connectionconnprivate TreeNode[]dataprivate intdepthprivate static intIDprivate static intINPUT_ROWSprivate static intNEXT_QUALIFIERSprivate static intNO_OF_OPENSprivate static intNO_OF_OUTPUT_ROWS_BY_SORTERprivate static intNODE_TYPEprivate static intP_IDprivate java.lang.Stringqueryprivate static intRETURNED_ROWSprivate static intSCAN_QUALIFIERSprivate static intSCAN_TYPEprivate static intSCANNED_OBJECTprivate java.lang.Stringschemaprivate booleanschemaExistsprivate static intSORT_TYPEprivate static intVISITED_PAGESprivate java.lang.StringxmlDetails
-
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 voidcloseConnection()closing the connection to the databaseprivate static java.sql.ConnectioncreateConnection(java.lang.String dbURL)private voidcreateXMLData(java.lang.String qry, int x)Create XML data based on the query that's passed in.voidcreateXMLFragment()This method creates the queries such that after execution of the query it will return XML data fragments.private static java.lang.StringescapeForXML(java.lang.String text)Escape characters that have a special meaning in XML.private java.lang.StringescapeInAttribute(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 voidfindChildren(int idx, int dep)private voidgetChildren(int currentLevel, java.lang.String id)TreeNode[]getData()intgetDepth()java.lang.StringgetQuery()java.lang.StringgetXmlString()Generating the XML treejava.lang.Stringindent(int j)booleaninitializeDataArray()voidmarkTheDepth()marking the depth of each elementprivate intnoOfNodes()private booleanschemaExists()Check if there is a schema in the database that matches the schema name that was passed in to this instance.private voidsetSchema()Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.java.lang.Stringstatement()java.lang.StringstmtID()java.lang.Stringtime()booleanverifySchemaExistance()
-
-
-
Field Detail
-
conn
private final java.sql.Connection conn
-
schema
private final java.lang.String schema
-
query
private final java.lang.String query
-
schemaExists
private final boolean schemaExists
-
data
private TreeNode[] data
-
depth
private int depth
-
xmlDetails
private java.lang.String xmlDetails
-
ID
private static final int ID
- See Also:
- Constant Field Values
-
P_ID
private static final int P_ID
- See Also:
- Constant Field Values
-
NODE_TYPE
private static final int NODE_TYPE
- See Also:
- Constant Field Values
-
NO_OF_OPENS
private static final int NO_OF_OPENS
- See Also:
- Constant Field Values
-
INPUT_ROWS
private static final int INPUT_ROWS
- See Also:
- Constant Field Values
-
RETURNED_ROWS
private static final int RETURNED_ROWS
- See Also:
- Constant Field Values
-
VISITED_PAGES
private static final int VISITED_PAGES
- See Also:
- Constant Field Values
-
SCAN_QUALIFIERS
private static final int SCAN_QUALIFIERS
- See Also:
- Constant Field Values
-
NEXT_QUALIFIERS
private static final int NEXT_QUALIFIERS
- See Also:
- Constant Field Values
-
SCANNED_OBJECT
private static final int SCANNED_OBJECT
- See Also:
- Constant Field Values
-
SCAN_TYPE
private static final int SCAN_TYPE
- See Also:
- Constant Field Values
-
SORT_TYPE
private static final int SORT_TYPE
- See Also:
- Constant Field Values
-
NO_OF_OUTPUT_ROWS_BY_SORTER
private static final int NO_OF_OUTPUT_ROWS_BY_SORTER
- See Also:
- Constant Field Values
-
-
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.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundExceptionjava.sql.SQLExceptionjava.lang.NoSuchMethodExceptionjava.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.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundExceptionjava.sql.SQLExceptionjava.lang.NoSuchMethodExceptionjava.lang.reflect.InvocationTargetException
-
setSchema
private void setSchema() throws java.sql.SQLExceptionSet 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.SQLExceptionCheck 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.SQLExceptionThis 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 nodeid- 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 indexdep- 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.SQLExceptionCreate 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
-
-