//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.workflow.coreImpl.store;
import java.sql.Connection;
import java.sql.SQLException;

import org.huihoo.workflow.TransactionException;
import org.huihoo.workflow.WorkflowDatabase;
import org.huihoo.workflow.WorkflowTransaction;

public class WorkflowTransactionImpl implements WorkflowTransaction
{
	private Connection workflowConnection;
	private WorkflowDatabase database;
	public WorkflowTransactionImpl(WorkflowDatabase database, Connection connection_)
	{
		this.database = database;
		this.workflowConnection = connection_;
	}
	public Connection getConnection()
	{
		return workflowConnection;
	}
	public WorkflowDatabase getDatabase()
	{
		return database;
	}
	
	public void commit() throws TransactionException
	{
		try
		{
			getConnection().commit();
		}
		catch (SQLException sqlex)
		{
			throw new TransactionException(sqlex);
		}
	}
	public void rollback() throws TransactionException
	{
		try
		{
			getConnection().rollback();
		}
		catch (SQLException sqlex)
		{
			throw new TransactionException(sqlex);
		}
	}
	
	public void release() throws TransactionException
	{
		try
		{
			getConnection().close();
		}
		catch (SQLException sqlex)
		{
			throw new TransactionException(sqlex);
		}
	}
}
