Class AccessDatabase
java.lang.Object
org.apache.derby.impl.tools.planexporter.AccessDatabase
This class will perform the database connection establishment,
querying the database, shut downing the database.
Created under DERBY-4587-PlanExporter tool
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Connection
private TreeNode[]
private int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private final String
private static final int
private static final int
private static final int
private static final int
private final String
private final boolean
private static final int
private static final int
private String
-
Constructor Summary
ConstructorsConstructorDescriptionAccessDatabase
(String dburl, String aSchema, String aQuery) AccessDatabase
(Connection aConn, String aSchema, String aQuery) -
Method Summary
Modifier and TypeMethodDescriptionvoid
closing the connection to the databaseprivate static Connection
createConnection
(String dbURL) private void
createXMLData
(String qry, int x) Create XML data based on the query that's passed in.void
This method creates the queries such that after execution of the query it will return XML data fragments.private static String
escapeForXML
(String text) Escape characters that have a special meaning in XML.private String
escapeInAttribute
(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, String id) TreeNode[]
getData()
int
getDepth()
getQuery()
Generating the XML treeindent
(int j) boolean
void
marking the depth of each elementprivate int
private boolean
Check if there is a schema in the database that matches the schema name that was passed in to this instance.private void
Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.stmtID()
time()
boolean
-
Field Details
-
conn
-
schema
-
query
-
schemaExists
private final boolean schemaExists -
data
-
depth
private int depth -
xmlDetails
-
ID
private static final int ID- See Also:
-
P_ID
private static final int P_ID- See Also:
-
NODE_TYPE
private static final int NODE_TYPE- See Also:
-
NO_OF_OPENS
private static final int NO_OF_OPENS- See Also:
-
INPUT_ROWS
private static final int INPUT_ROWS- See Also:
-
RETURNED_ROWS
private static final int RETURNED_ROWS- See Also:
-
VISITED_PAGES
private static final int VISITED_PAGES- See Also:
-
SCAN_QUALIFIERS
private static final int SCAN_QUALIFIERS- See Also:
-
NEXT_QUALIFIERS
private static final int NEXT_QUALIFIERS- See Also:
-
SCANNED_OBJECT
private static final int SCANNED_OBJECT- See Also:
-
SCAN_TYPE
private static final int SCAN_TYPE- See Also:
-
SORT_TYPE
private static final int SORT_TYPE- See Also:
-
NO_OF_OUTPUT_ROWS_BY_SORTER
private static final int NO_OF_OUTPUT_ROWS_BY_SORTER- See Also:
-
-
Constructor Details
-
AccessDatabase
public AccessDatabase(String dburl, String aSchema, String aQuery) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoSuchMethodException, InvocationTargetException - Parameters:
dburl
-aSchema
-aQuery
-- Throws:
InstantiationException
IllegalAccessException
ClassNotFoundException
SQLException
NoSuchMethodException
InvocationTargetException
-
AccessDatabase
- Parameters:
aConn
-aSchema
-aQuery
-- Throws:
SQLException
-
-
Method Details
-
getQuery
- Returns:
- the stmt_id
-
getDepth
public int getDepth() -
createConnection
private static Connection createConnection(String dbURL) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoSuchMethodException, InvocationTargetException -
setSchema
Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.- Throws:
SQLException
- if an error happens while accessing the database
-
schemaExists
Check if there is a schema in the database that matches the schema name that was passed in to this instance.- Throws:
SQLException
-
verifySchemaExistance
public boolean verifySchemaExistance() -
createXMLFragment
This method creates the queries such that after execution of the query it will return XML data fragments.
- Throws:
SQLException
-
getXmlString
Generating the XML tree- Returns:
- all xml elements as a String
-
getChildren
- Parameters:
currentLevel
- level of the XML tree (0 based) of current nodeid
- current node's stmt_id
-
indent
- 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
- Returns:
- whether the initialization is successful or not
- Throws:
SQLException
-
createXMLData
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:
SQLException
-
noOfNodes
- Returns:
- total # of nodes
- Throws:
SQLException
-
statement
- Returns:
- the <statement> element
- Throws:
SQLException
-
escapeForXML
Escape characters that have a special meaning in XML.- Parameters:
text
- the text to escape- Returns:
- the text with special characters escaped
-
escapeInAttribute
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
- Returns:
- XPLAIN_TIME of SYSXPLAIN_STATEMENTS
- Throws:
SQLException
-
stmtID
- Returns:
- stmt_id as a XML element
-
closeConnection
public void closeConnection()closing the connection to the database -
getData
- Returns:
- data array of TreeNode Objects
-