/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.sandesha2.storage.jdbc;

import java.sql.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.sandesha2.storage.Transaction;
/*
 * Each transaction has its own DataBase connection with autocommit set to false
 * 
 * As there is no method to "release" a transaction, connections are closed on
 * commit or rollback.
 */
public class JDBCTransaction implements Transaction {
	private PersistentStorageManager pmgr = null;
	private Connection DbConnection = null;
	private boolean active = false;
	private Log log = LogFactory.getLog(getClass());
	
	public JDBCTransaction (PersistentStorageManager pmgr)
	{
		log.debug("new JDBCTransaction");
		try {
		  this.pmgr = pmgr;
		  DbConnection = pmgr.dbConnect();
		  DbConnection.setAutoCommit(false);
		  active = true;
		} catch (Exception ex) {}
	}
	
	public Connection getDbConnection()
	{
		return DbConnection;
	}
	
	private void freeTransaction()
	{
		try {
			DbConnection.close();
			pmgr.removeTransaction();
		} catch (Exception ex) {}
		
	}
		
	public void commit()
	{
		log.debug("commit JDBCTransaction");
		try {
		  DbConnection.commit();
		  freeTransaction();
		} catch (Exception ex) {}
		active = false;
	}
	
	public void rollback()
	{
		log.debug("rollback JDBCTransaction");
		try {
			  DbConnection.rollback();
			  freeTransaction();
			} catch (Exception ex) {}
		active = false;
	}
		
	public boolean isActive ()
	{
		return active;
	}
	
}

@@ -1343,17 +1343,17 @@
 nection 
-D
+d
 bConnect
@@ -1450,17 +1450,16 @@
 ss());%0D%0A
-%09
 %0D%0A%09publi
@@ -1582,25 +1582,25 @@
  pmgr;%0D%0A%09%09  
-D
+d
 bConnection 
@@ -1620,25 +1620,25 @@
 ect();%0D%0A%09%09  
-D
+d
 bConnection.
@@ -1709,25 +1709,24 @@
 ex) %7B%7D%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09public Co
@@ -1766,17 +1766,17 @@
 %09return 
-D
+d
 bConnect
@@ -1781,25 +1781,24 @@
 ction;%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09private v
@@ -1836,17 +1836,17 @@
 y %7B%0D%0A%09%09%09
-D
+d
 bConnect
@@ -1922,18 +1922,14 @@
 %7B%7D%0D%0A
-%09%09
 %0D%0A%09%7D%0D%0A
-%09%09
 %0D%0A%09p
@@ -2002,25 +2002,25 @@
 %09try %7B%0D%0A%09%09  
-D
+d
 bConnection.
@@ -2106,17 +2106,16 @@
 e;%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09publi
@@ -2193,17 +2193,17 @@
 %7B%0D%0A%09%09%09  
-D
+d
 bConnect

make the first letter lower case