aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLFramework.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLFramework.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLFramework.cs75
1 files changed, 50 insertions, 25 deletions
diff --git a/OpenSim/Data/MySQL/MySQLFramework.cs b/OpenSim/Data/MySQL/MySQLFramework.cs
index 34791cf..93662db 100644
--- a/OpenSim/Data/MySQL/MySQLFramework.cs
+++ b/OpenSim/Data/MySQL/MySQLFramework.cs
@@ -36,7 +36,7 @@ using MySql.Data.MySqlClient;
36namespace OpenSim.Data.MySQL 36namespace OpenSim.Data.MySQL
37{ 37{
38 /// <summary> 38 /// <summary>
39 /// A database interface class to a user profile storage system 39 /// Common code for a number of database modules
40 /// </summary> 40 /// </summary>
41 public class MySqlFramework 41 public class MySqlFramework
42 { 42 {
@@ -44,14 +44,24 @@ namespace OpenSim.Data.MySQL
44 log4net.LogManager.GetLogger( 44 log4net.LogManager.GetLogger(
45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 45 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected string m_connectionString; 47 protected string m_connectionString = String.Empty;
48 protected object m_dbLock = new object(); 48 protected MySqlTransaction m_trans = null;
49 49
50 // Constructor using a connection string. Instances constructed
51 // this way will open a new connection for each call.
50 protected MySqlFramework(string connectionString) 52 protected MySqlFramework(string connectionString)
51 { 53 {
52 m_connectionString = connectionString; 54 m_connectionString = connectionString;
53 } 55 }
54 56
57 // Constructor using a connection object. Instances constructed
58 // this way will use the connection object and never create
59 // new connections.
60 protected MySqlFramework(MySqlTransaction trans)
61 {
62 m_trans = trans;
63 }
64
55 ////////////////////////////////////////////////////////////// 65 //////////////////////////////////////////////////////////////
56 // 66 //
57 // All non queries are funneled through one connection 67 // All non queries are funneled through one connection
@@ -59,33 +69,48 @@ namespace OpenSim.Data.MySQL
59 // 69 //
60 protected int ExecuteNonQuery(MySqlCommand cmd) 70 protected int ExecuteNonQuery(MySqlCommand cmd)
61 { 71 {
62 lock (m_dbLock) 72 if (m_trans == null)
63 { 73 {
64 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 74 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
65 { 75 {
66 try 76 dbcon.Open();
67 { 77 return ExecuteNonQueryWithConnection(cmd, dbcon);
68 dbcon.Open(); 78 }
69 cmd.Connection = dbcon; 79 }
80 else
81 {
82 return ExecuteNonQueryWithTransaction(cmd, m_trans);
83 }
84 }
70 85
71 try 86 private int ExecuteNonQueryWithTransaction(MySqlCommand cmd, MySqlTransaction trans)
72 { 87 {
73 return cmd.ExecuteNonQuery(); 88 cmd.Transaction = trans;
74 } 89 return ExecuteNonQueryWithConnection(cmd, trans.Connection);
75 catch (Exception e) 90 }
76 { 91
77 m_log.Error(e.Message, e); 92 private int ExecuteNonQueryWithConnection(MySqlCommand cmd, MySqlConnection dbcon)
78 m_log.Error(Environment.StackTrace.ToString()); 93 {
79 return 0; 94 try
80 } 95 {
81 } 96 cmd.Connection = dbcon;
82 catch (Exception e) 97
83 { 98 try
84 m_log.Error(e.Message, e); 99 {
85 return 0; 100 return cmd.ExecuteNonQuery();
86 }
87 } 101 }
102 catch (Exception e)
103 {
104 m_log.Error(e.Message, e);
105 m_log.Error(Environment.StackTrace.ToString());
106 return 0;
107 }
108 }
109 catch (Exception e)
110 {
111 m_log.Error(e.Message, e);
112 return 0;
88 } 113 }
89 } 114 }
90 } 115 }
91} \ No newline at end of file 116}