You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/08/18 19:09:05 UTC

svn commit: r432641 - /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java

Author: rhillegas
Date: Fri Aug 18 10:09:04 2006
New Revision: 432641

URL: http://svn.apache.org/viewvc?rev=432641&view=rev
Log:
DERBY-1725: Merge trunk into 10.2 branch from 430830 through 430856.

Modified:
    db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java?rev=432641&r1=432640&r2=432641&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java Fri Aug 18 10:09:04 2006
@@ -146,6 +146,116 @@
 	}
 	
 	/**
+	 * Drop a database schema by dropping all objects in it
+	 * and then executing DROP SCHEMA. If the schema is
+	 * APP it is cleaned but DROP SCHEMA is not executed.
+	 * 
+	 * TODO: Handle dependencies by looping in some intelligent
+	 * way until everything can be dropped.
+	 * 
+	 * TODO: Drop Functions
+	 * TODO: Drop Synonyms
+	 * 
+	 * @param dmd DatabaseMetaData object for database
+	 * @param schema Name of the schema
+	 * @throws SQLException database error
+	 */
+	public static void dropSchema(DatabaseMetaData dmd, String schema) throws SQLException
+	{		
+		Connection conn = dmd.getConnection();
+		Assert.assertFalse(conn.getAutoCommit());
+		Statement s = dmd.getConnection().createStatement();
+		// Procedures first
+		ResultSet rs = dmd.getProcedures((String) null,
+				schema, (String) null);
+		
+		dropUsingDMD(s, rs, schema, "PROCEDURE_NAME", "PROCEDURE");
+		
+		// Views
+		rs = dmd.getTables((String) null, schema, (String) null,
+				new String[] {"VIEW"});
+		
+		dropUsingDMD(s, rs, schema, "TABLE_NAME", "VIEW");
+		
+		// Tables
+		rs = dmd.getTables((String) null, schema, (String) null,
+				new String[] {"TABLE"});
+		
+		dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE");
+		
+		// Finally drop the schema if it is not APP
+		if (!schema.equals("APP")) {
+			s.execute("DROP SCHEMA " + JDBC.escape(schema) + " RESTRICT");
+		}
+		conn.commit();
+		s.close();
+	}
+	
+	/**
+	 * DROP a set of objects based upon a ResultSet from a
+	 * DatabaseMetaData call.
+	 * 
+	 * TODO: Handle errors to ensure all objects are dropped,
+	 * probably requires interaction with its caller.
+	 * 
+	 * @param s Statement object used to execute the DROP commands.
+	 * @param rs DatabaseMetaData ResultSet
+	 * @param schema Schema the objects are contained in
+	 * @param mdColumn The column name used to extract the object's
+	 * name from rs
+	 * @param dropType The keyword to use after DROP in the SQL statement
+	 * @throws SQLException database errors.
+	 */
+	private static void dropUsingDMD(
+			Statement s, ResultSet rs, String schema,
+			String mdColumn,
+			String dropType) throws SQLException
+	{
+		String dropLeadIn = "DROP " + dropType + " ";
+		
+		s.clearBatch();
+		int batchCount = 0;
+		while (rs.next())
+		{
+			String view = rs.getString(mdColumn);
+			s.addBatch(dropLeadIn + JDBC.escape(schema, view));
+			batchCount++;
+		}
+		rs.close();
+		int[] results;
+		try {
+		    results = s.executeBatch();
+		    Assert.assertNotNull(results);
+		    Assert.assertEquals("Incorrect result length from executeBatch",
+		    		batchCount, results.length);
+		} catch (BatchUpdateException batchException) {
+			results = batchException.getUpdateCounts();
+			Assert.assertNotNull(results);
+			Assert.assertTrue("Too many results in BatchUpdateException",
+					results.length <= batchCount);
+		}
+		
+		boolean hadError = false;
+		boolean didDrop = false;
+		for (int i = 0; i < results.length; i++)
+		{
+			int result = results[i];
+			if (result == -3 /* Statement.EXECUTE_FAILED*/)
+				hadError = true;
+			else if (result == -2/*Statement.SUCCESS_NO_INFO*/)
+				didDrop = true;
+			else if (result >= 0)
+				didDrop = true;
+			else
+				Assert.fail("Negative executeBatch status");
+		}
+		
+		// Commit any work we did do.
+		s.getConnection().commit();
+		s.clearBatch();
+	}
+	
+	/**
 	 * Assert all columns in the ResultSetMetaData match the
 	 * table's defintion through DatabaseMetadDta. Only works
 	 * if the complete select list correspond to columns from
@@ -207,5 +317,22 @@
 			}
 		}
 		rs.close();
+	}
+	
+	/**
+	 * Escape a non-qualified name so that it is suitable
+	 * for use in a SQL query executed by JDBC.
+	 */
+	public static String escape(String name)
+	{
+		return "\"" + name + "\"";
+	}	
+	/**
+	 * Escape a schama-qualified name so that it is suitable
+	 * for use in a SQL query executed by JDBC.
+	 */
+	public static String escape(String schema, String name)
+	{
+		return "\"" + schema + "\".\"" + name + "\"";
 	}
 }



Re: svn commit: r432641 - /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java

Posted by Daniel John Debrunner <dj...@apache.org>.
Knut Anders Hatlen wrote:

> Daniel John Debrunner <dj...@apache.org> writes:
> 
> 
>>rhillegas@apache.org wrote:
>>
>>
>>>Author: rhillegas
>>>Date: Fri Aug 18 10:09:04 2006
>>>New Revision: 432641
>>>
>>>URL: http://svn.apache.org/viewvc?rev=432641&view=rev
>>>Log:
>>>DERBY-1725: Merge trunk into 10.2 branch from 430830 through 430856.
>>
>>This is a problem with the mega merges, we lose the linkage to the
>>individual Jira entries. Had the svn log message contained the Jira
>>issue numbers for the changes in that range, then it would be easy to
>>tell from an individual Jira entry if the change made it into 10.2 or not.
> 
> 
> It would be good to run "svn log" with the revision range and add the
> output to the log message for the mega merge.
> 

> Rick, maybe you could generate these mega logs and update the log
> messages with "svn propedit svn:log --propedit -r N".
>

+1 Great idea - simple to do!

Dan.



Re: svn commit: r432641 - /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Daniel John Debrunner <dj...@apache.org> writes:

> rhillegas@apache.org wrote:
>
>> Author: rhillegas
>> Date: Fri Aug 18 10:09:04 2006
>> New Revision: 432641
>> 
>> URL: http://svn.apache.org/viewvc?rev=432641&view=rev
>> Log:
>> DERBY-1725: Merge trunk into 10.2 branch from 430830 through 430856.
>
> This is a problem with the mega merges, we lose the linkage to the
> individual Jira entries. Had the svn log message contained the Jira
> issue numbers for the changes in that range, then it would be easy to
> tell from an individual Jira entry if the change made it into 10.2 or not.

It would be good to run "svn log" with the revision range and add the
output to the log message for the mega merge.

% svn log -r 430830:430856     
------------------------------------------------------------------------
r430853 | djd | 2006-08-11 20:41:09 +0200 (Fri, 11 Aug 2006) | 2 lines

DERBY-1556 (partial) Add the initial implementation of a  utility method in the JUnit JDBC class to drop a schema
and all of its objects. Will be called by a test decorator I will be committing soon.
------------------------------------------------------------------------
r430855 | djd | 2006-08-11 20:48:59 +0200 (Fri, 11 Aug 2006) | 2 lines

DERBY-1556 (partial) Add TODO's for the JDBC.dropSchema() method that shows work still needs to
be done to drop function and synonyms.
------------------------------------------------------------------------


Rick, maybe you could generate these mega logs and update the log
messages with "svn propedit svn:log --propedit -r N".

-- 
Knut Anders

Re: svn commit: r432641 - /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JDBC.java

Posted by Daniel John Debrunner <dj...@apache.org>.
rhillegas@apache.org wrote:

> Author: rhillegas
> Date: Fri Aug 18 10:09:04 2006
> New Revision: 432641
> 
> URL: http://svn.apache.org/viewvc?rev=432641&view=rev
> Log:
> DERBY-1725: Merge trunk into 10.2 branch from 430830 through 430856.

This is a problem with the mega merges, we lose the linkage to the
individual Jira entries. Had the svn log message contained the Jira
issue numbers for the changes in that range, then it would be easy to
tell from an individual Jira entry if the change made it into 10.2 or not.

:-(

Dan.