db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r636892 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/utils/DbTasks.java
Date Thu, 13 Mar 2008 20:56:14 GMT
Author: myrnavl
Date: Thu Mar 13 13:56:13 2008
New Revision: 636892

URL: http://svn.apache.org/viewvc?rev=636892&view=rev
Log:
DERBY-3448 - backing out revision 636829, it doesn't actually build.

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=636892&r1=636891&r2=636892&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
Thu Mar 13 13:56:13 2008
@@ -37,6 +37,7 @@
 import java.sql.Statement;
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Properties;
 import java.util.Random;
 import org.apache.derbyTesting.functionTests.util.streams.CharAlphabet;
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader;
@@ -47,6 +48,8 @@
 
 	public static LogFile log = new LogFile("performance.out");
 
+	static boolean saveAutoCommit;
+
 	private static int id_count = 0;
 
 	public static int insert_count = 0;
@@ -69,7 +72,7 @@
 			MailJdbc.logAct
 					.logMsg("\n\n*****************************************************");
 			// setting the properties like user, password etc for both the
-			// database and the backup database
+			// database and the backup datatbase
 			setSystemProperty("database", "jdbc:derby:mailsdb;create=true");
 			setSystemProperty("ij.user", "REFRESH");
 			setSystemProperty("ij.password", "Refresh");
@@ -127,20 +130,20 @@
 		}
 	}
 
-	public void readMail(Connection conn, String thread_name) throws Exception{
+	public void readMail(Connection conn, String thread_name) {
 		// This function will be reading mails from the inbox.
-		// Getting the number of rows in the table and getting the
+		// Getiing the number of rows in the table and getting the
 		// size of the attachment (Blob) for a randomly selected row
-		boolean saveAutoCommit = conn.getAutoCommit();
-		int saveIsolation = conn.getTransactionIsolation();
 		Statement stmt = null;
 		Statement stmt1 = null;
 		int count = 0;
 		int count1 = 0;
 		long size = 0;
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
-			conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+			conn
+					.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
 			long s_select = System.currentTimeMillis();
 			stmt = conn.createStatement();
 			stmt1 = conn.createStatement();
@@ -174,8 +177,14 @@
 					+ "SQL Exception while reading : " + sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				errorPrint(sq);
+				sq.printStackTrace();
+			}
 		}
 		try {
 			int attach_id = 0;
@@ -220,6 +229,7 @@
 			rs.close();
 			stmt.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct
 					.logMsg(LogFile.ERROR
@@ -229,25 +239,27 @@
 							+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally{
-			conn.setAutoCommit(saveAutoCommit);
-			conn.setTransactionIsolation(saveIsolation);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
 		}
 
 	}
 
-	public synchronized void deleteMailByUser (Connection conn,
-			String thread_name) throws Exception{
+	public synchronized void deleteMailByUser(Connection conn,
+			String thread_name) {
 		// Delete done by the user. Thre user will mark the mails to be deleted
 		// and then
-		boolean saveAutoCommit = conn.getAutoCommit();
 		int id_count = 0;
 		int id = 0;
 		int for_id = 0;
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			PreparedStatement updateUser = conn
 					.prepareStatement(Statements.updateStr);
@@ -284,25 +296,29 @@
 			updateUser.close();
 			stmt.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "Exception while deleting mail by user: "
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally{
-			conn.setAutoCommit(saveAutoCommit);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
 		}
 	}
 
 	public void deleteMailByThread(Connection conn, String thread_name)
 			throws Exception {
 		// Deleting mails which are marked to be deleted
-		boolean saveAutoCommit = conn.getAutoCommit();
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			PreparedStatement deleteThread = conn
 					.prepareStatement(Statements.deleteStr);
@@ -323,25 +339,30 @@
 			rs.close();
 			stmt.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "Exception while deleting mail by Thread: "
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally{
-			conn.setAutoCommit(saveAutoCommit);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
 		}
 
 	}
 
-	public void moveToFolders(Connection conn, String thread_name) throws Exception{
+	public void moveToFolders(Connection conn, String thread_name) {
 		// Changing the folder id of randomly selected rows
-		boolean saveAutoCommit = conn.getAutoCommit();
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			Statement stmt = conn.createStatement();
 			PreparedStatement moveToFolder = conn
@@ -374,18 +395,23 @@
 			moveToFolder.close();
 			rs.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "Exception while moving mail to folders: "
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally{
-			conn.setAutoCommit(saveAutoCommit);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
 		}
+
 	}
 
 	public void insertMail(Connection conn, String thread_name)
@@ -397,9 +423,8 @@
 		int num = Rn.nextInt(10 - 1);
 		InputStream streamIn = null;
 		Reader streamReader = null;
-		boolean saveAutoCommit = conn.getAutoCommit();
-		int saveIsolation = conn.getTransactionIsolation();
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			PreparedStatement insertFirst = conn.prepareStatement(
 					Statements.insertStr, Statement.RETURN_GENERATED_KEYS);
@@ -437,7 +462,8 @@
 					}
 
 					rs.close();
-					conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+					conn
+							.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
 				} else
 					insertFirst.setInt(5, 0);
 				insertFirst
@@ -467,8 +493,15 @@
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
 		}
 		try {
 			PreparedStatement insertAttach = conn
@@ -511,24 +544,28 @@
 			stmt1.close();
 			insertAttach.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Error while inserting attachments:" + sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally{
-			conn.setTransactionIsolation(saveIsolation);
-			conn.setAutoCommit(saveAutoCommit);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+				throw sqe;
+			}
 		}
 	}
 
-	public synchronized void deleteMailByExp(Connection conn, String thread_name) throws Exception{
-		boolean saveAutoCommit = conn.getAutoCommit();
+	public synchronized void deleteMailByExp(Connection conn, String thread_name) {
 		try {
 			// Deleting mails which are older than 1 day
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			long s_delExp = System.currentTimeMillis();
 			Statement selExp = conn.createStatement();
@@ -548,26 +585,30 @@
 			deleteExp.close();
 			selExp.close();
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "Error while deleting mails by expiry manager: "
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			conn.rollback();
-			throw sqe;
-		}
-		finally {
-			conn.setAutoCommit(saveAutoCommit);
+			try {
+				conn.rollback();
+			} catch (SQLException sq) {
+				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
+						+ "Exception while rolling back: " + sq);
+				sq.printStackTrace();
+				errorPrint(sq);
+			}
 		}
 	}
 
-	public void Backup(Connection conn, String thread_name) throws Exception{
+	public void Backup(Connection conn, String thread_name) {
 		// when the backup thread kicks in, it will use this function to
 		// take the periodic backups
-		boolean saveAutoCommit = conn.getAutoCommit();
 		long s_backup = System.currentTimeMillis();
 		try {
+			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(true);
 			CallableStatement cs = conn
 					.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(?,
?)");
@@ -579,6 +620,7 @@
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Finished backing up the Database");
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 		} catch (Throwable sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
 					+ "Error while doing the backup system procedure: "
@@ -586,9 +628,6 @@
 			sqe.printStackTrace();
 			errorPrint(sqe);
 		}
-		finally{
-			conn.setAutoCommit(saveAutoCommit);
-		}
 		long e_backup = System.currentTimeMillis();
 		log.logMsg(LogFile.INFO + thread_name + " : "
 				+ "Time taken to do backup :"
@@ -597,8 +636,8 @@
 	}
 
 	public void compressTable(Connection conn, String tabname,
-			String thread_name) throws Exception
-	// periodically compresses the table to get back the free spaces available
+			String thread_name)
+	// preiodically compresses the table to get back the free spaces available
 	// after
 	// the deletion of some rows
 	{
@@ -606,8 +645,8 @@
 		long dbsize = databaseSize("mailsdb/seg0");
 		MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 				+ "dbsize before compress : " + dbsize);
-		boolean saveAutoCommit = conn.getAutoCommit();
 		try {
+			boolean saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(true);
 			CallableStatement cs = conn
 					.prepareCall("CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(?, ?, ?, ?, ?)");
@@ -617,6 +656,7 @@
 			cs.setShort(4, (short) 1);
 			cs.setShort(5, (short) 1);
 			cs.execute();
+			conn.setAutoCommit(saveAutoCommit);
 			cs.close();
 		} catch (Throwable sqe) {
 			MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
@@ -625,9 +665,6 @@
 			sqe.printStackTrace();
 			errorPrint(sqe);
 		}
-		finally{
-		    conn.setAutoCommit(saveAutoCommit);
-		}
 		long e_compress = System.currentTimeMillis();
 		MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 				+ "Finished Compressing the table: " + tabname);
@@ -688,10 +725,10 @@
 
 	}
 
-	public void grantRevoke(Connection conn, String thread_name) throws Exception{
-		boolean saveAutoCommit = conn.getAutoCommit();
+	public void grantRevoke(Connection conn, String thread_name) {
 		try {
-			// Giving appropriate permission to each threads
+			// Giving appropriate permission to eahc threads
+			saveAutoCommit = conn.getAutoCommit();
 			Statement stmt = conn.createStatement();
 			stmt.execute(Statements.grantSel1);
 			stmt.execute(Statements.grantSel2);
@@ -715,6 +752,7 @@
 			stmt.execute(Statements.grantExe4);
 			stmt.execute(Statements.grantExe5);
 			conn.commit();
+			conn.setAutoCommit(saveAutoCommit);
 			stmt.close();
 			MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
 					+ "Finished Granting permissions");
@@ -723,11 +761,11 @@
 					+ "Error while doing Grant Revoke: " + sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
+
 		}
-		finally {
-			conn.setAutoCommit(saveAutoCommit);
-		}
+
 	}
+
 	public static long databaseSize(String dbname) {
 		File dir = new File(dbname);
 		File[] files = dir.listFiles();
@@ -780,7 +818,7 @@
 					isAll0 = false;
 					break;
 				}
-			} 
+			}
 			if (isAll0 == true) {
 				buff.deleteCharAt(0);
 				for (int i = 0; i < buff.length(); i++) {



Mime
View raw message