db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r631402 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
Date Tue, 26 Feb 2008 22:03:09 GMT
Author: djd
Date: Tue Feb 26 14:03:05 2008
New Revision: 631402

URL: http://svn.apache.org/viewvc?rev=631402&view=rev
Log:
DERBY-3448 Minor cleanup of DbTasks class

 - no need to implement Thread since it is never used as a thread
 - don't set system property for authorization as it is set in the required derby.properties
 - fix mt issue for getting connections (remove shared properties object)
 - don't have if != null checks for objects that cannot be null.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java?rev=631402&r1=631401&r2=631402&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
Tue Feb 26 14:03:05 2008
@@ -44,7 +44,7 @@
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
 
-public class DbTasks extends Thread {
+public class DbTasks {
 
 	public static LogFile log = new LogFile("performance.out");
 
@@ -62,10 +62,8 @@
 
 	public static Random Rn = new Random();
 
-	public static Properties prop = new Properties();
-
 	public static void jdbcLoad(String driverType) {
-		setSystemProperty("derby.database.sqlAuthorization", "true");
+
 		if (driverType.equalsIgnoreCase("embedded")) {
 			setSystemProperty("driver", "org.apache.derby.jdbc.EmbeddedDriver");
 			MailJdbc.logAct
@@ -118,10 +116,9 @@
 		try {
 			// Returns the Connection object
 			Class.forName(System.getProperty("driver")).newInstance();
-			prop.setProperty("user", usr);
-			prop.setProperty("password", passwd);
+
 			Connection con = DriverManager.getConnection(System
-					.getProperty("database"), prop);
+					.getProperty("database"), usr, passwd);
 			return con;
 		} catch (Exception e) {
 			log.logMsg(LogFile.ERROR
@@ -172,12 +169,9 @@
 			log.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Time taken to scan the entire REFRESH.INBOX for count :"
 					+ PerfTime.readableTime(e_select - s_select));
-			if (rs != null)
-				rs.close();
-			if (stmt != null)
-				stmt1.close();
-			if (rs1 != null)
-				rs1.close();
+			rs.close();
+			stmt1.close();
+			rs1.close();
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "SQL Exception while reading : " + sqe.getMessage());
@@ -210,8 +204,7 @@
 			} else
 				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 						+ "no attachment");
-			if (rs != null)
-				rs.close();
+			rs.close();
 
 			long end = System.currentTimeMillis();
 			log.logMsg(LogFile.INFO + thread_name + " : "
@@ -233,10 +226,8 @@
 			log.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Time taken to get the clob :"
 					+ PerfTime.readableTime(end_t - start_t));
-			if (rs != null)
-				rs.close();
-			if (stmt != null)
-				stmt.close();
+			rs.close();
+			stmt.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -301,12 +292,9 @@
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ "The number of mails marked to be deleted  by user:"
 					+ delete_count);
-			if (rs != null)
-				rs.close();
-			if (updateUser != null)
-				updateUser.close();
-			if (stmt != null)
-				stmt.close();
+			rs.close();
+			updateUser.close();
+			stmt.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -347,12 +335,9 @@
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : " + count
 					+ " rows deleted");
 			delete_count = delete_count + count;
-			if (deleteThread != null)
-				deleteThread.close();
-			if (rs != null)
-				rs.close();
-			if (stmt != null)
-				stmt.close();
+			deleteThread.close();
+			rs.close();
+			stmt.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -406,12 +391,9 @@
 						+ "Mail with id : " + message_id
 						+ " is moved to folder with id : " + folder_id);
 			}
-			if (stmt != null)
-				stmt.close();
-			if (moveToFolder != null)
-				moveToFolder.close();
-			if (rs != null)
-				rs.close();
+			stmt.close();
+			moveToFolder.close();
+			rs.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -479,8 +461,7 @@
 						insertFirst.setInt(5, rs.getInt(1) + 1);
 					}
 
-					if (rs != null)
-						rs.close();
+					rs.close();
 					conn
 							.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
 				} else
@@ -495,8 +476,7 @@
 					insert_count = insert_count + 1;
 				}
 			}
-			if (insertFirst != null)
-				insertFirst.close();
+			insertFirst.close();
 			conn.commit();
 			streamReader.close();
 
@@ -559,14 +539,10 @@
 					+ "Time taken to insert " + row_count + "attachments :"
 					+ PerfTime.readableTime(a_end - a_start));
 			id_count++;
-			if (rs != null)
-				rs.close();
-			if (stmt != null)
-				stmt.close();
-			if (stmt1 != null)
-				stmt1.close();
-			if (insertAttach != null)
-				insertAttach.close();
+			rs.close();
+			stmt.close();
+			stmt1.close();
+			insertAttach.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -606,10 +582,8 @@
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ " number of mails deleted : " + count);
 			delete_count = delete_count + count;
-			if (deleteExp != null)
-				deleteExp.close();
-			if (selExp != null)
-				selExp.close();
+			deleteExp.close();
+			selExp.close();
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
@@ -735,20 +709,14 @@
 											+ idArray.get(i));
 
 				}
-				if (rs1 != null)
-					rs1.close();
+				rs1.close();
 			}
 			delete_count = delete_count + del_count;
-			if (rs != null)
-				rs.close();
-			if (stmt != null)
-				stmt.close();
-			if (stmt1 != null)
-				stmt1.close();
-			if (stmt2 != null)
-				stmt2.close();
-			if (stmt3 != null)
-				stmt3.close();
+			rs.close();
+			stmt.close();
+			stmt1.close();
+			stmt2.close();
+			stmt3.close();
 		} catch (Exception fe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " :  "
 					+ fe.getMessage());
@@ -785,8 +753,7 @@
 			stmt.execute(Statements.grantExe5);
 			conn.commit();
 			conn.setAutoCommit(saveAutoCommit);
-			if (stmt != null)
-				stmt.close();
+			stmt.close();
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Finished Granting permissions");
 		} catch (Throwable sqe) {



Mime
View raw message