Class AccessDatabase
- java.lang.Object
-
- org.apache.derby.impl.tools.planexporter.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
-
-
Field Summary
Fields Modifier and Type Field Description private java.sql.Connection
conn
private TreeNode[]
data
private int
depth
private static int
ID
private static int
INPUT_ROWS
private static int
NEXT_QUALIFIERS
private static int
NO_OF_OPENS
private static int
NO_OF_OUTPUT_ROWS_BY_SORTER
private static int
NODE_TYPE
private static int
P_ID
private java.lang.String
query
private static int
RETURNED_ROWS
private static int
SCAN_QUALIFIERS
private static int
SCAN_TYPE
private static int
SCANNED_OBJECT
private java.lang.String
schema
private boolean
schemaExists
private static int
SORT_TYPE
private static int
VISITED_PAGES
private java.lang.String
xmlDetails
-
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 databaseprivate 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 treejava.lang.String
indent(int j)
boolean
initializeDataArray()
void
markTheDepth()
marking the depth of each elementprivate 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()
-
-
-
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.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 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.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
-
-