public class TransactionHelper
{
public static OracleTransaction ora_Transaction = null;
public static OracleCommand ora_Command { get; set; }
public static OracleConnection ora_Conn = null;

private static string ls_XMLFile = "SysInfo.xml";//配置文檔
private static string ls_SectionName = "";
private static Action initAction = () =>
{
#region 初始化Transaction
if (string.IsNullOrEmpty(ls_SectionName)) ls_SectionName = "DBConn_EMES";
ora_Command = new OracleCommand();
ora_Conn = OracleHelper.DBOpen_Ora(ls_SectionName);
ora_Conn.Open();
ora_Command.Connection = ora_Conn;
ora_Transaction = ora_Conn.BeginTransaction();
ora_Command.Transaction = ora_Transaction;
#endregion
};
private static Action disAction = () =>
{
#region 銷毀 Transaction

if (ora_Command != null) ora_Command.Dispose();
ora_Command = null; ora_Transaction = null;

if (ora_Conn != null)
{
if (ora_Conn.State == ConnectionState.Open) ora_Conn.Close();
ora_Conn.Dispose();
}
ora_Conn = null;
#endregion
};

public TransactionHelper()
{
try
{
if (ora_Conn == null)
{
initAction.Invoke();
}
}
catch (Exception ex)
{
StringBuilder lo_StringBuilder = new StringBuilder(ex.Message.ToString());
ECCHelper.ClassHelper.WriteLog(lo_StringBuilder);
disAction.Invoke();
}
//if (ora_Conn.State == ConnectionState.Open) ora_Conn.Close();
//ora_Conn.Dispose();

}

public void executeNoneQueryCommand(string sqlCommand)
{
try
{
ora_Command.CommandText = sqlCommand;
ora_Command.ExecuteNonQuery();
}
catch (Exception ex)
{
StringBuilder lo_StringBuilder = new StringBuilder(ex.Message.ToString());
ECCHelper.ClassHelper.WriteLog(lo_StringBuilder);
disAction.Invoke();
throw ex;
}
}

/// <summary>
/// 初始調用 OracleCommnad
/// </summary>
public OracleCommand InitCommand()
{
return ora_Command;
}

/// <summary>
/// 銷毀
/// </summary>
/// <returns></returns>
public bool CommitTransaction()
{
try
{
if (ora_Transaction != null)
{
ora_Transaction.Commit(); return true;
}
else { ora_Transaction.Rollback(); return false; }
}
catch (Exception ex)
{
if (ora_Transaction != null) ora_Transaction.Rollback();
StringBuilder lo_StringBuilder = new StringBuilder(ex.Message.ToString());
ECCHelper.ClassHelper.WriteLog(lo_StringBuilder);
return false;
}
finally
{
disAction.Invoke();
}
}

}

TransactionHelper的更多相关文章

  1. GC Ergonomics间接引发的锁等待超时问题排查分析

    1. 问题背景 上周线上某模块出现锁等待超时,如下图所示: 我虽然不是该模块负责人,但出于好奇,也一起帮忙排查定位问题. 这里的业务背景就是在执行到某个地方时,需要去表中插入一批数据,这批数据需要根据 ...

  2. format ZKFC失败

    at org.apache.hadoop.ha.ActiveStandbyElector$WatcherWithClientRef.waitForZKConnectionEvent(ActiveSta ...

  3. Known BREAKING CHANGES from NH3.3.3.GA to 4.0.0

    Build 4.0.0.Alpha1 =============================   ** Known BREAKING CHANGES from NH3.3.3.GA to 4.0. ...

  4. NHibernate利用Mindscape.NHibernateModelDesigner实现数据库与实体之间的转换及操作

    环境: &nbsp&nbspVisual Studio 2010 一.Mindscape.NhibernateModelDesigner安装 &nbsp&nbsp在打开 ...

随机推荐

  1. 内存对齐 align

    /* 地址对齐:指的是存放数据的首地址%N==0,而且整个结构体的大小%M(结构体的有效对齐值)==0 1 数据类型的自身对齐值:char:1 short:2 int,flolat,double:4 ...

  2. Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(四)之Operators

    At the lowest level, data in Java is manipulated using operators Using Java Operators An operator ta ...

  3. day18作业

    作业: # 1.编写课上讲解的有参装饰器准备明天默写 def auth(file_type): def outer(func): def inter(*args,**kwargs): if file_ ...

  4. stand up meeting 12-10

    今天项目会议正好利用了大家上课前的十五分钟,大家对项目进度和项目中所遇到的问题进行了沟通. 由于天赋同学与重阳小组沟通及时有效,在mapping的过程中直接将单词本中的type与我们单词挑战中的que ...

  5. stand up meeting 12/23/2015

    part 组员                工作              工作耗时/h 明日计划 工作耗时/h    UI 冯晓云  基本完成单词本显示页面的设计和实现    4 完善页面切换   ...

  6. Git敏捷开发--stash命令

    save 执行git stash,默认以commit info保存当前的stash信息 当在某个commit下,执行多次stash时,无法友好地区分每个stash的改动.save 命令可以清晰地标识每 ...

  7. 今天我们来谈谈jquery,

    ---恢复内容开始--- 首先从jquery的两种写法开始: 1.$(document).ready(function(){}); 首先我们的jquery是用来操作DOM节点的,所以必须等到文档加载完 ...

  8. 理解java容器底层原理--手动实现HashSet

    HashSet的底层其实就是HashMap,换句话说HashSet就是简化版的HashMap. 直接上代码: package com.xzlf.collection2; import java.uti ...

  9. window servet 2012 r2 配置php服务器环境

    绑定:https://jingyan.baidu.com/article/0bc808fc2c6a851bd485b92a.html 配置环境:http://www.jb51.net/article/ ...

  10. 监控CPU与GPU的工具

    1.sensor:可以显示包括cpu在内的所有传感器的当前读数 使用sensors可以检测到cpu的温度,风扇的风速度,电压等. 2.Glances使用Python写的跨平台的curses的检测工具. ...