db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r985762 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/tests/lang/ tools/org/apache/derby/impl/tools/planexporter/ tools/org/apache/derby/tools/
Date Sun, 15 Aug 2010 21:14:45 GMT
Author: bpendleton
Date: Sun Aug 15 21:14:44 2010
New Revision: 985762

URL: http://svn.apache.org/viewvc?rev=985762&view=rev
Log:
DERBY-4587: Tools for improved analysis of query plans

This patch was contributed by C.S. Nirmal J. Fernando (nirmal070125 at gmail dot com)

This patch adds a check to see that the specified schema exists in the
database, cleans up the handling of the PrivilegedActionException when
security policy is not granted, and adds newline whitespace to the XML
output for the <stmt_id> and time fields.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/AccessDatabase.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
    db/derby/code/trunk/java/tools/org/apache/derby/tools/PlanExporter.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java?rev=985762&r1=985761&r2=985762&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
Sun Aug 15 21:14:44 2010
@@ -720,6 +720,37 @@ public class XplainStatisticsTest extend
     	return lst.item(node).getAttributes().getNamedItem(attribute).getNodeValue();
     }
 
+    public void testPlanExporterSchemaExistence()
+	throws Exception
+    {
+	AccessDatabase access = 
+    		new AccessDatabase(getConnection(), "NoSuchSchema", "nostmt"); 
+	assertTrue( "Unexpectedly thought schema exists",
+		! access.verifySchemaExistance() );
+    }
+
+    public void testPlanExporterIllegalFileAccess()
+	throws Exception
+    {
+	AccessDatabase access = 
+    		new AccessDatabase(getConnection(), "NoSuchSchema", "nostmt"); 
+    	CreateXMLFile xml_file = new CreateXMLFile(access); 
+	try
+	{
+    		xml_file.writeTheXMLFile("nostmt", "notime", null,
+			"/illegal.xml", null);
+		fail("Expected exception for illegal file access");
+	}
+	catch (java.security.AccessControlException ace)
+	{
+		// Expected this exception to be thrown
+	}
+	catch (Exception e)
+	{
+		e.printStackTrace();
+		fail(e.getMessage());
+	}
+    }
     
     /**
      * Verify that XPLAIN style captures basic statistics and timings.

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/AccessDatabase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/AccessDatabase.java?rev=985762&r1=985761&r2=985762&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/AccessDatabase.java
(original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/AccessDatabase.java
Sun Aug 15 21:14:44 2010
@@ -125,6 +125,17 @@ public class AccessDatabase {
 
     }
 
+    public boolean verifySchemaExistance() throws SQLException{
+    	boolean found=false;
+    	ResultSet result = conn.getMetaData().getSchemas();
+    	while(result.next()){
+    		if(result.getString(1).equals(schema)){
+    			found=true;
+    			break;
+    		}
+    	}	
+    	return found;
+    }
     /**
      * <p>
      * This method creates the queries such that after execution
@@ -474,7 +485,7 @@ public class AccessDatabase {
         results.close();
         stmt.close();
 
-        return time;
+        return time+"\n";
     }
 
     /**
@@ -482,7 +493,7 @@ public class AccessDatabase {
      * @return stmt_id as a XML element
      */
     public String stmtID(){
-        return "<stmt_id>"+getQuery()+"</stmt_id>";
+        return "<stmt_id>"+getQuery()+"</stmt_id>\n";
     }
 
     /**

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java?rev=985762&r1=985761&r2=985762&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
(original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
Sun Aug 15 21:14:44 2010
@@ -55,7 +55,7 @@ public class CreateXMLFile {
      */
     public void writeTheXMLFile(String stmt, String time,
             TreeNode[] data, final String file_name, String xsl_sheet_name)
-    throws IOException, PrivilegedActionException {
+    throws IOException {
 
         String defaultXML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
         String embedXSL="";
@@ -68,8 +68,9 @@ public class CreateXMLFile {
         String childTagStart = "<details>\n";
         String childTagEnd = "</details>\n";
 
-        DataOutputStream dos =
-            new DataOutputStream(
+        DataOutputStream dos;
+		try {
+			dos = new DataOutputStream(
                     new BufferedOutputStream(
                             (OutputStream)AccessController.doPrivileged
                             (new java.security.PrivilegedExceptionAction(){
@@ -90,5 +91,8 @@ public class CreateXMLFile {
         dos.write((access.indent(0)+childTagEnd).getBytes());
         dos.write(parentTagEnd.getBytes());
         dos.close();
+		} catch (PrivilegedActionException pae) {
+			throw (IOException)pae.getCause(); 
+		}
     }
 }

Modified: db/derby/code/trunk/java/tools/org/apache/derby/tools/PlanExporter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/tools/PlanExporter.java?rev=985762&r1=985761&r2=985762&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/tools/PlanExporter.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/tools/PlanExporter.java Sun Aug 15 21:14:44
2010
@@ -53,134 +53,146 @@ public class PlanExporter {
 
                 AccessDatabase access = new AccessDatabase(dbURL, args[1], args[2]);
                 access.createConnection();
-                if(access.initializeDataArray()){
-                    access.createXMLFragment();
-                    access.markTheDepth();
-                    String stmt=access.statement();
-                    String time=access.time();
-                    access.closeConnection();
-
-                    //advanced XSL feature
-                    //possible occurrences are
-                    //-adv -xml {path} -xsl {path} or
-                    //-adv -xsl {path} -xml {path}
-                    if(args.length==8 &&
-                        args[3].equalsIgnoreCase("-adv")){
-                        int opt1=selectArg(args[4]);
-                        int opt2=selectArg(args[6]);
-                        if(opt1==1 && opt2==3){
-                            if(args[7].toUpperCase().endsWith(".XSL"))
-                                generateXML(access,args[5],stmt,time,args[7]);
-                            else
-                                generateXML(access,args[5],stmt,time,args[7]+".xsl");
-                        }
-                        else if(opt1==3 && opt2==1){
-                            if(args[5].toUpperCase().endsWith(".XSL"))
-                                generateXML(access,args[7],stmt,time,args[5]);
-                            else
-                                generateXML(access,args[7],stmt,time,args[5]+".xsl");
-                        }
-                        else
-                            printHelp();
-                    }
-                    //possible occurrences are -xml {path} or -html {path}
-                    else if(args.length==5){
-                        int opt=selectArg(args[3]);
-                        if(opt==0 || opt==3)
-                            printHelp();
-                        else if(opt==1)
-                            generateXML(access,args[4],stmt,time,null);
-                        else{
-                            generateXML(access,"temp.xml",stmt,time,null);
-                            generateHTML("temp.xml",args[4],xslStyleSheetName,true);
-                            deleteFile("temp.xml");
-                        }
-                    }
-                    //possible occurrences are
-                    //-xml {path} and -html {path}
-                    //-html {path} and -xml {path}
-                    //-html {path} and -xsl {path}
-                    //-xsl {path} and -html {path}
-                    else if(args.length==7){
-                        int opt1=selectArg(args[3]);
-                        int opt2=selectArg(args[5]);
-                        if(opt1==0 || opt2==0)
-                            printHelp();
-                        else if(opt1==1 && opt2==2){
-                            generateXML(access,args[4],stmt,time,null);
-                            generateHTML(args[4],args[6],xslStyleSheetName,true);
-                        }
-                        else if(opt1==2 && opt2==1){
-                            generateXML(access,args[6],stmt,time,null);
-                            generateHTML(args[6],args[4],xslStyleSheetName,true);
-                        }
-                        else if(opt1==2 && opt2==3){
-                            generateXML(access,"temp.xml",stmt,time,null);
-                            generateHTML("temp.xml",args[4],args[6],false);
-                            deleteFile("temp.xml");
-                        }
-                        else if(opt1==3 && opt2==2){
-                            generateXML(access,"temp.xml",stmt,time,null);
-                            generateHTML("temp.xml",args[6],args[4],false);
-                            deleteFile("temp.xml");
-                        }
-                        else
-                            printHelp();
-                    }
-                    //possible occurrences are
-                    //-xml {path} and -html {path} and -xsl {path}
-                    //-html {path} and -xsl {path} and -xml {path}
-                    //-xsl {path} and -xml {path} and -html {path}
-                    //-xml {path} and -xsl {path} and -html {path}
-                    //-html {path} and -xml {path} and -xsl {path}
-                    //-xsl {path} and -html {path} and -xml {path}
-                    else if(args.length==9){
-                        int opt1=selectArg(args[3]);
-                        int opt2=selectArg(args[5]);
-                        int opt3=selectArg(args[7]);
-                        if(opt1==0 || opt2==0 || opt3==0)
-                            printHelp();
-                        else if(opt1==1 && opt2==2 && opt3==3){
-                            generateXML(access,args[4],stmt,time,null);
-                            generateHTML(args[4],args[6],args[8],false);
-                        }
-                        else if(opt1==2 && opt2==3 && opt3==1){
-                            generateXML(access,args[8],stmt,time,null);
-                            generateHTML(args[8],args[4],args[6],false);
-                        }
-                        else if(opt1==3 && opt2==1 && opt3==2){
-                            generateXML(access,args[6],stmt,time,null);
-                            generateHTML(args[6],args[8],args[4],false);
-                        }
-                        else if(opt1==1 && opt2==3 && opt3==2){
-                            generateXML(access,args[4],stmt,time,null);
-                            generateHTML(args[4],args[8],args[6],false);
-                        }
-                        else if(opt1==2 && opt2==1 && opt3==3){
-                            generateXML(access,args[6],stmt,time,null);
-                            generateHTML(args[6],args[4],args[8],false);
-                        }
-                        else if(opt1==3 && opt2==2 && opt3==1){
-                            generateXML(access,args[8],stmt,time,null);
-                            generateHTML(args[8],args[6],args[4],false);
-                        }
-                        else
-                            printHelp();
-                    }
-                    else
-                        printHelp();
+                
+                if(access.verifySchemaExistance()){
+                
+                	if(access.initializeDataArray()){
+                		access.createXMLFragment();
+                		access.markTheDepth();
+                		String stmt=access.statement();
+                		String time=access.time();
+                		access.closeConnection();
+
+                		//advanced XSL feature
+                		//possible occurrences are
+                		//-adv -xml {path} -xsl {path} or
+                		//-adv -xsl {path} -xml {path}
+                		if(args.length==8 &&
+                				args[3].equalsIgnoreCase("-adv")){
+                			int opt1=selectArg(args[4]);
+                			int opt2=selectArg(args[6]);
+                			if(opt1==1 && opt2==3){
+                				if(args[7].toUpperCase().endsWith(".XSL"))
+                					generateXML(access,args[5],stmt,time,args[7]);
+                				else
+                					generateXML(access,args[5],stmt,time,args[7]+".xsl");
+                			}
+                			else if(opt1==3 && opt2==1){
+                				if(args[5].toUpperCase().endsWith(".XSL"))
+                					generateXML(access,args[7],stmt,time,args[5]);
+                				else
+                					generateXML(access,args[7],stmt,time,args[5]+".xsl");
+                			}
+                			else
+                				printHelp();
+                		}
+                		//possible occurrences are -xml {path} or -html {path}
+                		else if(args.length==5){
+                			int opt=selectArg(args[3]);
+                			if(opt==0 || opt==3)
+                				printHelp();
+                			else if(opt==1)
+                				generateXML(access,args[4],stmt,time,null);
+                			else{
+                				generateXML(access,"temp.xml",stmt,time,null);
+                				generateHTML("temp.xml",args[4],xslStyleSheetName,true);
+                				deleteFile("temp.xml");
+                			}
+                		}
+                		//possible occurrences are
+                		//-xml {path} and -html {path}
+                		//-html {path} and -xml {path}
+                		//-html {path} and -xsl {path}
+                		//-xsl {path} and -html {path}
+                		else if(args.length==7){
+                			int opt1=selectArg(args[3]);
+                			int opt2=selectArg(args[5]);
+                			if(opt1==0 || opt2==0)
+                				printHelp();
+                			else if(opt1==1 && opt2==2){
+                				generateXML(access,args[4],stmt,time,null);
+                				generateHTML(args[4],args[6],xslStyleSheetName,true);
+                			}
+                			else if(opt1==2 && opt2==1){
+                				generateXML(access,args[6],stmt,time,null);
+                				generateHTML(args[6],args[4],xslStyleSheetName,true);
+                			}
+                			else if(opt1==2 && opt2==3){
+                				generateXML(access,"temp.xml",stmt,time,null);
+                				generateHTML("temp.xml",args[4],args[6],false);
+                				deleteFile("temp.xml");
+                			}
+                			else if(opt1==3 && opt2==2){
+                				generateXML(access,"temp.xml",stmt,time,null);
+                				generateHTML("temp.xml",args[6],args[4],false);
+                				deleteFile("temp.xml");
+                			}
+                			else
+                				printHelp();
+                		}
+                		//possible occurrences are
+                		//-xml {path} and -html {path} and -xsl {path}
+                		//-html {path} and -xsl {path} and -xml {path}
+                		//-xsl {path} and -xml {path} and -html {path}
+                		//-xml {path} and -xsl {path} and -html {path}
+                		//-html {path} and -xml {path} and -xsl {path}
+                		//-xsl {path} and -html {path} and -xml {path}
+                		else if(args.length==9){
+                			int opt1=selectArg(args[3]);
+                			int opt2=selectArg(args[5]);
+                			int opt3=selectArg(args[7]);
+                			if(opt1==0 || opt2==0 || opt3==0)
+                				printHelp();
+                			else if(opt1==1 && opt2==2 && opt3==3){
+                				generateXML(access,args[4],stmt,time,null);
+                				generateHTML(args[4],args[6],args[8],false);
+                			}
+                			else if(opt1==2 && opt2==3 && opt3==1){
+                				generateXML(access,args[8],stmt,time,null);
+                				generateHTML(args[8],args[4],args[6],false);
+                			}
+                			else if(opt1==3 && opt2==1 && opt3==2){
+                				generateXML(access,args[6],stmt,time,null);
+                				generateHTML(args[6],args[8],args[4],false);
+                			}
+                			else if(opt1==1 && opt2==3 && opt3==2){
+                				generateXML(access,args[4],stmt,time,null);
+                				generateHTML(args[4],args[8],args[6],false);
+                			}
+                			else if(opt1==2 && opt2==1 && opt3==3){
+                				generateXML(access,args[6],stmt,time,null);
+                				generateHTML(args[6],args[4],args[8],false);
+                			}
+                			else if(opt1==3 && opt2==2 && opt3==1){
+                				generateXML(access,args[8],stmt,time,null);
+                				generateHTML(args[8],args[6],args[4],false);
+                			}
+                			else
+                				printHelp();
+                		}
+                		else
+                			printHelp();
+                	}
+                	else{
+                		System.out.println(
+                				"====================================================\n" +
+                				"--- An Error Occured: No Statistics has Captured ---\n" +
+                				"-- Possible reasons:                              --\n" +
+                				"-- 1) The statement executed is a DDL statement.  --\n" +
+                				"-- Statistics will not capture for DDL statements --\n" +
+                				"-- by the Derby.                                  --\n" +
+                				"-- 2) The statement ID entered is incorrect.      --\n" +
+                				"-- 3) Schema specified does not exist.            --\n" +
+                				"====================================================\n"
+                		);
+                	}
                 }
                 else{
-                    System.out.println(
-                            "====================================================\n" +
-                            "--- An Error Occured: No Statistics has Captured ---\n" +
-                            "-- Possible reasons:                                --\n" +
-                            "-- 1) The statement executed is a DDL statement.  --\n" +
-                            "-- Statistics will not capture for DDL statements --\n" +
-                            "-- by the Derby.                                  --\n" +
-                            "-- 2) The statement ID entered is incorrect.       --\n" +
-                            "====================================================\n"
-                    );
+                	System.out.println(
+            				"====================================================\n" +
+            				"---              An Error Occured:               ---\n" +
+            				"-------   Specified Schema does not exist.   -------\n" +
+            				"======================================================");
                 }
             }
             else



Mime
View raw message