1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Data;
|
21
|
|
using Seasar.Extension.ADO;
|
22
|
|
using Seasar.Extension.Tx.Impl;
|
23
|
|
using Seasar.Framework.Exceptions;
|
24
|
|
using Seasar.Framework.Log;
|
25
|
|
|
26
|
|
namespace Seasar.Framework.Util
|
27
|
|
{
|
28
|
|
public sealed class DataSourceUtil
|
29
|
|
{
|
30
|
|
private static readonly Logger logger = Logger.GetLogger(typeof(DataSourceUtil));
|
31
|
|
|
32
|
0
|
private DataSourceUtil()
|
33
|
|
{
|
34
|
|
}
|
35
|
|
|
36
|
82
|
public static IDbConnection GetConnection(IDataSource dataSource)
|
37
|
|
{
|
38
|
82
|
try
|
39
|
|
{
|
40
|
82
|
IDbConnection cn = dataSource.GetConnection();
|
41
|
82
|
if(cn.State != ConnectionState.Open)
|
42
|
|
{
|
43
|
47
|
cn.Open();
|
44
|
47
|
logger.Log("DSSR0007", null);
|
45
|
|
}
|
46
|
82
|
return cn;
|
47
|
|
}
|
48
|
|
catch(Exception ex)
|
49
|
|
{
|
50
|
0
|
throw new SQLRuntimeException(ex);
|
51
|
|
}
|
52
|
|
}
|
53
|
|
|
54
|
37
|
public static void CloseConnection(IDataSource dataSource, IDbConnection cn)
|
55
|
|
{
|
56
|
37
|
try
|
57
|
|
{
|
58
|
37
|
if(dataSource is TxDataSource)
|
59
|
|
{
|
60
|
37
|
TxDataSource txDataSoure = dataSource as TxDataSource;
|
61
|
37
|
if(txDataSoure.Context.IsInTransaction) return;
|
62
|
|
}
|
63
|
2
|
ConnectionUtil.Close(cn);
|
64
|
|
}
|
65
|
|
catch(Exception ex)
|
66
|
|
{
|
67
|
0
|
throw new SQLRuntimeException(ex);
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|
71
|
40
|
public static void SetTransaction(IDataSource dataSource, IDbCommand cmd)
|
72
|
|
{
|
73
|
40
|
if(dataSource is TxDataSource)
|
74
|
|
{
|
75
|
40
|
TxDataSource txDataSource = dataSource as TxDataSource;
|
76
|
40
|
if(txDataSource.Context.IsInTransaction)
|
77
|
38
|
cmd.Transaction = txDataSource.Context.Current.Transaction;
|
78
|
|
}
|
79
|
|
}
|
80
|
|
}
|
81
|
|
}
|
82
|
|
|