diff options
author | Master ScienceSim | 2010-02-04 13:19:30 -0800 |
---|---|---|
committer | John Hurliman | 2010-02-05 18:07:59 -0800 |
commit | e1b5c612472b9d1acf47383c0bf75b555daff2e6 (patch) | |
tree | 083896698038fbdad59c2bd3adeba9b290c5ce1b /OpenSim/Data/MySQL/MySQLUserAccountData.cs | |
parent | Fixing an incorrect logging message in insertUserRow (diff) | |
download | opensim-SC_OLD-e1b5c612472b9d1acf47383c0bf75b555daff2e6.zip opensim-SC_OLD-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.gz opensim-SC_OLD-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.bz2 opensim-SC_OLD-e1b5c612472b9d1acf47383c0bf75b555daff2e6.tar.xz |
Updated MySQL connection management to use the MySQL connection pooling. This should accommodate various timeout problems that exist with the current connection pool code in a more general and standard way.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLUserAccountData.cs | 156 |
1 files changed, 80 insertions, 76 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index d48144d..3cb0010 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs | |||
@@ -38,16 +38,21 @@ namespace OpenSim.Data.MySQL | |||
38 | public class MySqlUserAccountData : MySqlFramework, IUserAccountData | 38 | public class MySqlUserAccountData : MySqlFramework, IUserAccountData |
39 | { | 39 | { |
40 | private string m_Realm; | 40 | private string m_Realm; |
41 | private List<string> m_ColumnNames = null; | 41 | private List<string> m_ColumnNames; |
42 | // private int m_LastExpire = 0; | 42 | // private string m_connectionString; |
43 | 43 | ||
44 | public MySqlUserAccountData(string connectionString, string realm) | 44 | public MySqlUserAccountData(string connectionString, string realm) |
45 | : base(connectionString) | 45 | : base(connectionString) |
46 | { | 46 | { |
47 | m_Realm = realm; | 47 | m_Realm = realm; |
48 | m_connectionString = connectionString; | ||
48 | 49 | ||
49 | Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore"); | 50 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
50 | m.Update(); | 51 | { |
52 | dbcon.Open(); | ||
53 | Migration m = new Migration(dbcon, GetType().Assembly, "UserStore"); | ||
54 | m.Update(); | ||
55 | } | ||
51 | } | 56 | } |
52 | 57 | ||
53 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) | 58 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) |
@@ -64,49 +69,49 @@ namespace OpenSim.Data.MySQL | |||
64 | if (scopeID != UUID.Zero) | 69 | if (scopeID != UUID.Zero) |
65 | command += " and ScopeID = ?scopeID"; | 70 | command += " and ScopeID = ?scopeID"; |
66 | 71 | ||
67 | MySqlCommand cmd = new MySqlCommand(command); | 72 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
73 | { | ||
74 | dbcon.Open(); | ||
75 | MySqlCommand cmd = new MySqlCommand(command, dbcon); | ||
68 | 76 | ||
69 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | 77 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); |
70 | cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); | 78 | cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); |
71 | 79 | ||
72 | IDataReader result = ExecuteReader(cmd); | 80 | IDataReader result = cmd.ExecuteReader(); |
73 | 81 | ||
74 | if (result.Read()) | 82 | if (result.Read()) |
75 | { | ||
76 | ret.PrincipalID = principalID; | ||
77 | UUID scope; | ||
78 | UUID.TryParse(result["ScopeID"].ToString(), out scope); | ||
79 | ret.ScopeID = scope; | ||
80 | |||
81 | if (m_ColumnNames == null) | ||
82 | { | 83 | { |
83 | m_ColumnNames = new List<string>(); | 84 | ret.PrincipalID = principalID; |
84 | 85 | UUID scope; | |
85 | DataTable schemaTable = result.GetSchemaTable(); | 86 | UUID.TryParse(result["ScopeID"].ToString(), out scope); |
86 | foreach (DataRow row in schemaTable.Rows) | 87 | ret.ScopeID = scope; |
87 | m_ColumnNames.Add(row["ColumnName"].ToString()); | 88 | |
89 | if (m_ColumnNames == null) | ||
90 | { | ||
91 | m_ColumnNames = new List<string>(); | ||
92 | |||
93 | DataTable schemaTable = result.GetSchemaTable(); | ||
94 | foreach (DataRow row in schemaTable.Rows) | ||
95 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
96 | } | ||
97 | |||
98 | foreach (string s in m_ColumnNames) | ||
99 | { | ||
100 | if (s == "UUID") | ||
101 | continue; | ||
102 | if (s == "ScopeID") | ||
103 | continue; | ||
104 | |||
105 | ret.Data[s] = result[s].ToString(); | ||
106 | } | ||
107 | |||
108 | return ret; | ||
88 | } | 109 | } |
89 | 110 | else | |
90 | foreach (string s in m_ColumnNames) | ||
91 | { | 111 | { |
92 | if (s == "UUID") | 112 | return null; |
93 | continue; | ||
94 | if (s == "ScopeID") | ||
95 | continue; | ||
96 | |||
97 | ret.Data[s] = result[s].ToString(); | ||
98 | } | 113 | } |
99 | |||
100 | result.Close(); | ||
101 | CloseReaderCommand(cmd); | ||
102 | |||
103 | return ret; | ||
104 | } | 114 | } |
105 | |||
106 | result.Close(); | ||
107 | CloseReaderCommand(cmd); | ||
108 | |||
109 | return null; | ||
110 | } | 115 | } |
111 | 116 | ||
112 | public bool Store(UserAccountData data) | 117 | public bool Store(UserAccountData data) |
@@ -118,61 +123,60 @@ namespace OpenSim.Data.MySQL | |||
118 | 123 | ||
119 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | 124 | string[] fields = new List<string>(data.Data.Keys).ToArray(); |
120 | 125 | ||
121 | MySqlCommand cmd = new MySqlCommand(); | 126 | using (MySqlCommand cmd = new MySqlCommand()) |
122 | |||
123 | string update = "update `"+m_Realm+"` set "; | ||
124 | bool first = true; | ||
125 | foreach (string field in fields) | ||
126 | { | 127 | { |
127 | if (!first) | 128 | string update = "update `" + m_Realm + "` set "; |
128 | update += ", "; | 129 | bool first = true; |
129 | update += "`" + field + "` = ?"+field; | 130 | foreach (string field in fields) |
130 | 131 | { | |
131 | first = false; | 132 | if (!first) |
132 | 133 | update += ", "; | |
133 | cmd.Parameters.AddWithValue("?"+field, data.Data[field]); | 134 | update += "`" + field + "` = ?" + field; |
134 | } | ||
135 | 135 | ||
136 | update += " where UUID = ?principalID"; | 136 | first = false; |
137 | 137 | ||
138 | if (data.ScopeID != UUID.Zero) | 138 | cmd.Parameters.AddWithValue("?" + field, data.Data[field]); |
139 | update += " and ScopeID = ?scopeID"; | 139 | } |
140 | 140 | ||
141 | cmd.CommandText = update; | 141 | update += " where UUID = ?principalID"; |
142 | cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); | ||
143 | cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); | ||
144 | 142 | ||
145 | if (ExecuteNonQuery(cmd) < 1) | 143 | if (data.ScopeID != UUID.Zero) |
146 | { | 144 | update += " and ScopeID = ?scopeID"; |
147 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + | ||
148 | String.Join("`, `", fields) + | ||
149 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | ||
150 | 145 | ||
151 | cmd.CommandText = insert; | 146 | cmd.CommandText = update; |
147 | cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); | ||
148 | cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); | ||
152 | 149 | ||
153 | if (ExecuteNonQuery(cmd) < 1) | 150 | if (ExecuteNonQuery(cmd) < 1) |
154 | { | 151 | { |
155 | cmd.Dispose(); | 152 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + |
156 | return false; | 153 | String.Join("`, `", fields) + |
154 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | ||
155 | |||
156 | cmd.CommandText = insert; | ||
157 | |||
158 | if (ExecuteNonQuery(cmd) < 1) | ||
159 | { | ||
160 | cmd.Dispose(); | ||
161 | return false; | ||
162 | } | ||
157 | } | 163 | } |
158 | } | 164 | } |
159 | 165 | ||
160 | cmd.Dispose(); | ||
161 | |||
162 | return true; | 166 | return true; |
163 | } | 167 | } |
164 | 168 | ||
165 | public bool SetDataItem(UUID principalID, string item, string value) | 169 | public bool SetDataItem(UUID principalID, string item, string value) |
166 | { | 170 | { |
167 | MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + | 171 | using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" + |
168 | "` set `" + item + "` = ?" + item + " where UUID = ?UUID"); | 172 | item + "` = ?" + item + " where UUID = ?UUID")) |
169 | 173 | { | |
170 | 174 | cmd.Parameters.AddWithValue("?" + item, value); | |
171 | cmd.Parameters.AddWithValue("?"+item, value); | 175 | cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); |
172 | cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); | ||
173 | 176 | ||
174 | if (ExecuteNonQuery(cmd) > 0) | 177 | if (ExecuteNonQuery(cmd) > 0) |
175 | return true; | 178 | return true; |
179 | } | ||
176 | 180 | ||
177 | return false; | 181 | return false; |
178 | } | 182 | } |