db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r638077 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc: tasks/Backup.java tasks/Browse.java tasks/Purge.java tasks/Refresh.java utils/DbTasks.java
Date Mon, 17 Mar 2008 21:49:50 GMT
Author: myrnavl
Date: Mon Mar 17 14:49:47 2008
New Revision: 638077

URL: http://svn.apache.org/viewvc?rev=638077&view=rev
Log:
DERBY-3448 ; adjusting re-setting of auto-commit state and isolation level.
  Reinstating modifications of revision 636829, plus additional changes to
  enable build.
  Patch contributed by Manjula Kutty.
 

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java
    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/tasks/Backup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java?rev=638077&r1=638076&r2=638077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Backup.java
Mon Mar 17 14:49:47 2008
@@ -28,15 +28,16 @@
 import org.apache.derbyTesting.system.mailjdbc.utils.DbTasks;
 import org.apache.derbyTesting.system.mailjdbc.utils.LogFile;
 
-public class Backup extends Thread {
+public class Backup extends Thread{
 	private boolean isRunning = false;
 
 	private DbTasks dbtasks = new DbTasks();
 
-	private Connection conn = DbTasks.getConnection("BACKUP", "Backup");
-
-	public Backup(String name) {
+	private Connection conn = null;
+	
+	public Backup(String name)throws Exception{
 		setName(name);
+		conn = DbTasks.getConnection("BACKUP", "Backup");
 	}
 
 	public void run() {
@@ -74,12 +75,12 @@
 		}
 	}
 
-	public void DoCompress() {
+	public void DoCompress() throws Exception{
 		dbtasks.compressTable(conn, "INBOX", this.getName());
 		dbtasks.compressTable(conn, "ATTACH", this.getName());
 	}
 
-	public void DoBackup() {
+	public void DoBackup() throws Exception{
 		dbtasks.Backup(conn, this.getName());
 	}
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java?rev=638077&r1=638076&r2=638077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Browse.java
Mon Mar 17 14:49:47 2008
@@ -32,11 +32,11 @@
 public class Browse extends Thread {
 	private DbTasks dbtasks = new DbTasks();
 
-	private Connection conn = DbTasks.getConnection("BROWSE", "Browse");
-
-	public Browse(String name) {
+	private Connection conn = null;
+	public Browse(String name) throws Exception{
 		//sets the name of the thread
 		setName(name);
+		conn = DbTasks.getConnection("BROWSE", "Browse");
 	}
 
 	public void run() {
@@ -69,16 +69,16 @@
 
 	}
 
-	public void readInbox(Connection conn, String thread_name) {
+	public void readInbox(Connection conn, String thread_name) throws Exception{
 		dbtasks.readMail(conn, thread_name);
 		dbtasks.totals();
 	}
 
-	public void deleteMailByUser(Connection conn, String thread_name) {
+	public void deleteMailByUser(Connection conn, String thread_name) throws Exception{
 		dbtasks.deleteMailByUser(conn, thread_name);
 	}
 
-	public void moveToFolders(Connection conn, String thread_name) {
+	public void moveToFolders(Connection conn, String thread_name) throws Exception{
 		dbtasks.moveToFolders(conn, thread_name);
 	}
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java?rev=638077&r1=638076&r2=638077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Purge.java
Mon Mar 17 14:49:47 2008
@@ -35,11 +35,11 @@
 	//and deletes them.
 	private DbTasks dbtasks = new DbTasks();
 
-	private Connection conn = DbTasks.getConnection("PURGE", "Purge");
-
-	public Purge(String name) {
+	private Connection conn = null;
+	public Purge(String name) throws Exception{
 		//Sets the thread name
 		setName(name);
+		conn = DbTasks.getConnection("PURGE", "Purge");
 	}
 
 	public void run() {
@@ -63,11 +63,11 @@
 		}
 	}
 
-	public void purgeFromInbox(Connection conn) {
+	public void purgeFromInbox(Connection conn) throws Exception{
 		dbtasks.deleteMailByExp(conn, this.getName());
 	}
 
-	public void DoDbSizeCheck() {
+	public void DoDbSizeCheck() throws Exception{
 		dbtasks.checkDbSize(conn, this.getName());
 	}
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java?rev=638077&r1=638076&r2=638077&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/mailjdbc/tasks/Refresh.java
Mon Mar 17 14:49:47 2008
@@ -35,11 +35,12 @@
 
 	private DbTasks dbtasks = new DbTasks();
 
-	private Connection conn = DbTasks.getConnection("REFRESH", "Refresh");
+	private Connection conn = null;
 
-	public Refresh(String name) {
+	public Refresh(String name) throws Exception{
 		//sets the thread name
 		setName(name);
+		conn = DbTasks.getConnection("REFRESH", "Refresh");
 	}
 
 	public void run() {

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=638077&r1=638076&r2=638077&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
Mon Mar 17 14:49:47 2008
@@ -37,19 +37,15 @@
 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;
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.system.mailjdbc.MailJdbc;
-
 public class DbTasks {
 
 	public static LogFile log = new LogFile("performance.out");
 
-	static boolean saveAutoCommit;
-
 	private static int id_count = 0;
 
 	public static int insert_count = 0;
@@ -72,7 +68,7 @@
 			MailJdbc.logAct
 					.logMsg("\n\n*****************************************************");
 			// setting the properties like user, password etc for both the
-			// database and the backup datatbase
+			// database and the backup database
 			setSystemProperty("database", "jdbc:derby:mailsdb;create=true");
 			setSystemProperty("ij.user", "REFRESH");
 			setSystemProperty("ij.password", "Refresh");
@@ -112,7 +108,7 @@
 
 	}
 
-	public static Connection getConnection(String usr, String passwd) {
+	public  static Connection getConnection(String usr, String passwd){
 		try {
 			// Returns the Connection object
 			Class.forName(System.getProperty("driver")).newInstance();
@@ -130,20 +126,20 @@
 		}
 	}
 
-	public void readMail(Connection conn, String thread_name) {
+	public void readMail(Connection conn, String thread_name) throws Exception{
 		// This function will be reading mails from the inbox.
-		// Getiing the number of rows in the table and getting the
+		// Getting 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();
@@ -177,14 +173,8 @@
 					+ "SQL Exception while reading : " + sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				errorPrint(sq);
-				sq.printStackTrace();
-			}
+			conn.rollback();
+			throw sqe;
 		}
 		try {
 			int attach_id = 0;
@@ -229,7 +219,6 @@
 			rs.close();
 			stmt.close();
 			conn.commit();
-			conn.setAutoCommit(saveAutoCommit);
 		} catch (SQLException sqe) {
 			MailJdbc.logAct
 					.logMsg(LogFile.ERROR
@@ -239,27 +228,25 @@
 							+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(sqe);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally{
+			conn.setAutoCommit(saveAutoCommit);
+			conn.setTransactionIsolation(saveIsolation);
 		}
 
 	}
 
-	public synchronized void deleteMailByUser(Connection conn,
-			String thread_name) {
+	public synchronized void deleteMailByUser (Connection conn,
+			String thread_name) throws Exception{
 		// 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);
@@ -296,29 +283,25 @@
 			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);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally{
+			conn.setAutoCommit(saveAutoCommit);
 		}
 	}
 
 	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);
@@ -339,30 +322,25 @@
 			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);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-				throw sqe;
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally{
+			conn.setAutoCommit(saveAutoCommit);
 		}
 
 	}
 
-	public void moveToFolders(Connection conn, String thread_name) {
+	public void moveToFolders(Connection conn, String thread_name) throws Exception{
 		// 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
@@ -395,23 +373,18 @@
 			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);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally{
+			conn.setAutoCommit(saveAutoCommit);
 		}
-
 	}
 
 	public void insertMail(Connection conn, String thread_name)
@@ -423,8 +396,9 @@
 		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);
@@ -462,8 +436,7 @@
 					}
 
 					rs.close();
-					conn
-							.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+					conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
 				} else
 					insertFirst.setInt(5, 0);
 				insertFirst
@@ -493,15 +466,8 @@
 					+ sqe.getMessage());
 			sqe.printStackTrace();
 			errorPrint(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;
-			}
+			conn.rollback();
+			throw sqe;
 		}
 		try {
 			PreparedStatement insertAttach = conn
@@ -544,28 +510,24 @@
 			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);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.INFO + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-				throw sqe;
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally{
+			conn.setTransactionIsolation(saveIsolation);
+			conn.setAutoCommit(saveAutoCommit);
 		}
 	}
 
-	public synchronized void deleteMailByExp(Connection conn, String thread_name) {
+	public synchronized void deleteMailByExp(Connection conn, String thread_name) throws Exception{
+		boolean saveAutoCommit = conn.getAutoCommit();
 		try {
 			// Deleting mails which are older than 1 day
-			saveAutoCommit = conn.getAutoCommit();
 			conn.setAutoCommit(false);
 			long s_delExp = System.currentTimeMillis();
 			Statement selExp = conn.createStatement();
@@ -585,30 +547,26 @@
 			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);
-			try {
-				conn.rollback();
-			} catch (SQLException sq) {
-				MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
-						+ "Exception while rolling back: " + sq);
-				sq.printStackTrace();
-				errorPrint(sq);
-			}
+			conn.rollback();
+			throw sqe;
+		}
+		finally {
+			conn.setAutoCommit(saveAutoCommit);
 		}
 	}
 
-	public void Backup(Connection conn, String thread_name) {
+	public void Backup(Connection conn, String thread_name) throws Exception{
 		// 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(?,
?)");
@@ -620,7 +578,6 @@
 			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: "
@@ -628,6 +585,9 @@
 			sqe.printStackTrace();
 			errorPrint(sqe);
 		}
+		finally{
+			conn.setAutoCommit(saveAutoCommit);
+		}
 		long e_backup = System.currentTimeMillis();
 		log.logMsg(LogFile.INFO + thread_name + " : "
 				+ "Time taken to do backup :"
@@ -636,8 +596,8 @@
 	}
 
 	public void compressTable(Connection conn, String tabname,
-			String thread_name)
-	// preiodically compresses the table to get back the free spaces available
+			String thread_name) throws Exception
+	// periodically compresses the table to get back the free spaces available
 	// after
 	// the deletion of some rows
 	{
@@ -645,8 +605,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(?, ?, ?, ?, ?)");
@@ -656,7 +616,6 @@
 			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 + " : "
@@ -665,6 +624,9 @@
 			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);
@@ -725,10 +687,10 @@
 
 	}
 
-	public void grantRevoke(Connection conn, String thread_name) {
+	public void grantRevoke(Connection conn, String thread_name) throws Exception{
+		boolean saveAutoCommit = conn.getAutoCommit();
 		try {
-			// Giving appropriate permission to eahc threads
-			saveAutoCommit = conn.getAutoCommit();
+			// Giving appropriate permission to each threads
 			Statement stmt = conn.createStatement();
 			stmt.execute(Statements.grantSel1);
 			stmt.execute(Statements.grantSel2);
@@ -752,7 +714,6 @@
 			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");
@@ -761,11 +722,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();
@@ -818,7 +779,7 @@
 					isAll0 = false;
 					break;
 				}
-			}
+			} 
 			if (isAll0 == true) {
 				buff.deleteCharAt(0);
 				for (int i = 0; i < buff.length(); i++) {



Mime
View raw message