Top Description Fields Constructors Methods
org.apache.derby.impl.tools.planexporter

public Class AccessDatabase

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, java.sql.Connection, .DriverManager, .PreparedStatement, .ResultSet, .SQLException, org.apache.derby.iapi.tools.ToolUtils

This class will perform the database connection establishment, querying the database, shut downing the database. Created under DERBY-4587-PlanExporter tool

Field Summary

Modifier and TypeField and Description
private 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

AccessConstructor and Description
public
AccessDatabase(String dburl, String aSchema, String aQuery)

public
AccessDatabase(Connection aConn, String aSchema, String aQuery)

Method Summary

Modifier and TypeMethod and Description
public void
closeConnection()

closing the connection to the database

private static Connection
private void
createXMLData(String
query to be executed
qry
,
int x)

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.

public void
createXMLFragment()

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

private static String

Returns:

the text with special characters escaped
escapeForXML
(String
the text to escape
text
)

Escape characters that have a special meaning in XML.

private String

Returns:

modified string
escapeInAttribute
(String
attribute string to be checked
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
current element's index
idx
,
int
current examining depth
dep
)

private void
getChildren(int
level of the XML tree (0 based) of current node
currentLevel
,
String
current node's stmt_id
id
)

public TreeNode[]

Returns:

data array of TreeNode Objects
getData
()

public int
public String

Returns:

the stmt_id
getQuery
()

public String

Returns:

all xml elements as a String
getXmlString
()

Generating the XML tree

public String

Returns:

indent as a string
indent
(int
indent needed
j
)

public boolean

Returns:

whether the initialization is successful or not
initializeDataArray
()

public void
markTheDepth()

marking the depth of each element

private int

Returns:

total # of nodes
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.

public String

Returns:

the <statement> element
statement
()

public String

Returns:

stmt_id as a XML element
stmtID
()

public String

Returns:

XPLAIN_TIME of SYSXPLAIN_STATEMENTS
time
()

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connback to summary
private final Connection conn
databack to summary
private TreeNode[] data
depthback to summary
private int depth
IDback to summary
private static final int ID
INPUT_ROWSback to summary
private static final int INPUT_ROWS
NEXT_QUALIFIERSback to summary
private static final int NEXT_QUALIFIERS
NO_OF_OPENSback to summary
private static final int NO_OF_OPENS
NO_OF_OUTPUT_ROWS_BY_SORTERback to summary
private static final int NO_OF_OUTPUT_ROWS_BY_SORTER
NODE_TYPEback to summary
private static final int NODE_TYPE
P_IDback to summary
private static final int P_ID
queryback to summary
private final String query
RETURNED_ROWSback to summary
private static final int RETURNED_ROWS
SCAN_QUALIFIERSback to summary
private static final int SCAN_QUALIFIERS
SCAN_TYPEback to summary
private static final int SCAN_TYPE
SCANNED_OBJECTback to summary
private static final int SCANNED_OBJECT
schemaback to summary
private final String schema
schemaExistsback to summary
private final boolean schemaExists
SORT_TYPEback to summary
private static final int SORT_TYPE
VISITED_PAGESback to summary
private static final int VISITED_PAGES
xmlDetailsback to summary
private String xmlDetails

Constructor Detail

AccessDatabaseback to summary
public AccessDatabase(String dburl, String aSchema, String aQuery) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoSuchMethodException, InvocationTargetException
AccessDatabaseback to summary
public AccessDatabase(Connection aConn, String aSchema, String aQuery) throws SQLException

Method Detail

closeConnectionback to summary
public void closeConnection()

closing the connection to the database

createConnectionback to summary
private static Connection createConnection(String dbURL) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoSuchMethodException, InvocationTargetException
createXMLDataback to summary
private void createXMLData(String qry, int x) throws 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:String

query to be executed

createXMLFragmentback to summary
public void createXMLFragment() throws SQLException

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

escapeForXMLback to summary
private static String escapeForXML(String text)

Escape characters that have a special meaning in XML.

Parameters
text:String

the text to escape

Returns:String

the text with special characters escaped

escapeInAttributeback to summary
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. eg: scanned_object="A "quoted" table name";

Parameters
text:String

attribute string to be checked

Returns:String

modified string

findChildrenback to summary
private void findChildren(int idx, int dep)
Parameters
idx:int

current element's index

dep:int

current examining depth

getChildrenback to summary
private void getChildren(int currentLevel, String id)
Parameters
currentLevel:int

level of the XML tree (0 based) of current node

id:String

current node's stmt_id

getDataback to summary
public TreeNode[] getData()
Returns:TreeNode[]

data array of TreeNode Objects

getDepthback to summary
public int getDepth()
getQueryback to summary
public String getQuery()
Returns:String

the stmt_id

getXmlStringback to summary
public String getXmlString()

Generating the XML tree

Returns:String

all xml elements as a String

indentback to summary
public String indent(int j)
Parameters
j:int

indent needed

Returns:String

indent as a string

initializeDataArrayback to summary
public boolean initializeDataArray() throws SQLException
Returns:boolean

whether the initialization is successful or not

markTheDepthback to summary
public void markTheDepth()

marking the depth of each element

noOfNodesback to summary
private int noOfNodes() throws SQLException
Returns:int

total # of nodes

schemaExistsback to summary
private boolean schemaExists() throws SQLException

Check if there is a schema in the database that matches the schema name that was passed in to this instance.

setSchemaback to summary
private void setSchema() throws SQLException

Set the schema of the current connection to the XPLAIN schema in which the statistics can be found.

Exceptions
SQLException:
if an error happens while accessing the database
statementback to summary
public String statement() throws SQLException
Returns:String

the <statement> element

stmtIDback to summary
public String stmtID()
Returns:String

stmt_id as a XML element

timeback to summary
public String time() throws SQLException
Returns:String

XPLAIN_TIME of SYSXPLAIN_STATEMENTS

verifySchemaExistanceback to summary
public boolean verifySchemaExistance()