package core.stlmes.server.sale.dbhelp;

import CoreFS.SA01.CoreIComponent;

public class DbTrans extends CoreIComponent
{
	private java.sql.Connection conn = null;
	private String daoName = core.stlmes.server.sale.constdefine.ConstDef.daoName;

	public DbTrans()
	{

	}

	public DbTrans( String daoName )
	{
		this.daoName = daoName;
	}

	public String getDaoName()
	{
		return daoName;
	}

	public void setDaoName(String daoName)
	{
		this.daoName = daoName;
	}

	private String ErrMsg = "";

	public String getErrMsg()
	{
		return ErrMsg;
	}

	public void setErrMsg(String errMsg)
	{
		ErrMsg = errMsg;
	}

	public java.sql.Connection getConn()
	{
		return conn;
	}

	public void beginTransaction() throws java.sql.SQLException
	{
		conn = this.getDao(daoName).getConnection();
		conn.setAutoCommit(false);

	}

	public void commit()
	{
		try
		{
			if (this.getErrMsg().length() > 0) rollback();
			else
			{
				this.conn.commit();
				this.conn.close();

			}
		}
		catch (java.lang.Exception ex)
		{
		}
	}

	public void rollback()
	{
		try
		{

			this.conn.rollback();
			this.conn.close();
		}
		catch (java.lang.Exception ex)
		{
		}

	}

	protected void finalize()
	{
		try
		{
			if (conn != null)
			{
				conn.close();
			}
			try
			{
				super.finalize();
			}
			catch (Throwable e)
			{
				e.printStackTrace();
			}
		}
		catch (Exception ex)
		{
		}
	}

}
