aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs125
1 files changed, 69 insertions, 56 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
index a85ab4d..4187078 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteAssetData.cs
@@ -26,15 +26,11 @@
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO;
30using libsecondlife;
31using OpenSim.Framework;
32using System.Data; 29using System.Data;
33using System.Data.SqlTypes; 30using System.Reflection;
31using libsecondlife;
34using Mono.Data.SqliteClient; 32using Mono.Data.SqliteClient;
35using OpenSim.Framework.Console; 33using OpenSim.Framework.Console;
36using OpenSim.Framework;
37using OpenSim.Framework.Interfaces;
38 34
39namespace OpenSim.Framework.Data.SQLite 35namespace OpenSim.Framework.Data.SQLite
40{ 36{
@@ -46,11 +42,11 @@ namespace OpenSim.Framework.Data.SQLite
46 /// <summary> 42 /// <summary>
47 /// The database manager 43 /// The database manager
48 /// </summary> 44 /// </summary>
49
50 /// <summary> 45 /// <summary>
51 /// Artificial constructor called upon plugin load 46 /// Artificial constructor called upon plugin load
52 /// </summary> 47 /// </summary>
53 private const string assetSelect = "select * from assets"; 48 private const string assetSelect = "select * from assets";
49
54 private DataSet ds; 50 private DataSet ds;
55 private SqliteDataAdapter da; 51 private SqliteDataAdapter da;
56 52
@@ -58,13 +54,14 @@ namespace OpenSim.Framework.Data.SQLite
58 { 54 {
59 SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3"); 55 SqliteConnection conn = new SqliteConnection("URI=file:" + dbfile + ",version=3");
60 TestTables(conn); 56 TestTables(conn);
61 57
62 ds = new DataSet(); 58 ds = new DataSet();
63 da = new SqliteDataAdapter(new SqliteCommand(assetSelect, conn)); 59 da = new SqliteDataAdapter(new SqliteCommand(assetSelect, conn));
64 60
65 lock (ds) { 61 lock (ds)
62 {
66 ds.Tables.Add(createAssetsTable()); 63 ds.Tables.Add(createAssetsTable());
67 64
68 setupAssetCommands(da, conn); 65 setupAssetCommands(da, conn);
69 try 66 try
70 { 67 {
@@ -75,11 +72,11 @@ namespace OpenSim.Framework.Data.SQLite
75 MainLog.Instance.Verbose("AssetStorage", "Caught fill error on asset table"); 72 MainLog.Instance.Verbose("AssetStorage", "Caught fill error on asset table");
76 } 73 }
77 } 74 }
78 75
79 return; 76 return;
80 } 77 }
81 78
82 public AssetBase FetchAsset(LLUUID uuid) 79 public AssetBase FetchAsset(LLUUID uuid)
83 { 80 {
84 AssetBase asset = new AssetBase(); 81 AssetBase asset = new AssetBase();
85 DataRow row = ds.Tables["assets"].Rows.Find(uuid); 82 DataRow row = ds.Tables["assets"].Rows.Find(uuid);
@@ -92,27 +89,28 @@ namespace OpenSim.Framework.Data.SQLite
92 return null; 89 return null;
93 } 90 }
94 } 91 }
95 92
96 public void CreateAsset(AssetBase asset) 93 public void CreateAsset(AssetBase asset)
97 { 94 {
98 // no difference for now 95 // no difference for now
99 UpdateAsset(asset); 96 UpdateAsset(asset);
100 } 97 }
101 98
102 public void UpdateAsset(AssetBase asset) 99 public void UpdateAsset(AssetBase asset)
103 { 100 {
104 LogAssetLoad(asset); 101 LogAssetLoad(asset);
105 102
106 DataTable assets = ds.Tables["assets"]; 103 DataTable assets = ds.Tables["assets"];
107 lock(ds) { 104 lock (ds)
105 {
108 DataRow row = assets.Rows.Find(asset.FullID); 106 DataRow row = assets.Rows.Find(asset.FullID);
109 if (row == null) 107 if (row == null)
110 { 108 {
111 row = assets.NewRow(); 109 row = assets.NewRow();
112 fillAssetRow(row, asset); 110 fillAssetRow(row, asset);
113 assets.Rows.Add(row); 111 assets.Rows.Add(row);
114 } 112 }
115 else 113 else
116 { 114 {
117 fillAssetRow(row, asset); 115 fillAssetRow(row, asset);
118 } 116 }
@@ -124,9 +122,10 @@ namespace OpenSim.Framework.Data.SQLite
124 string temporary = asset.Temporary ? "Temporary" : "Stored"; 122 string temporary = asset.Temporary ? "Temporary" : "Stored";
125 string local = asset.Local ? "Local" : "Remote"; 123 string local = asset.Local ? "Local" : "Remote";
126 124
127 MainLog.Instance.Verbose("ASSETSTORAGE", 125 MainLog.Instance.Verbose("ASSETSTORAGE",
128 string.Format("Loaded {6} {5} Asset: [{0}][{3}/{4}] \"{1}\":{2} ({7} bytes)", 126 string.Format("Loaded {6} {5} Asset: [{0}][{3}/{4}] \"{1}\":{2} ({7} bytes)",
129 asset.FullID, asset.Name, asset.Description, asset.Type, asset.InvType, temporary, local, asset.Data.Length) ); 127 asset.FullID, asset.Name, asset.Description, asset.Type,
128 asset.InvType, temporary, local, asset.Data.Length));
130 } 129 }
131 130
132 public bool ExistsAsset(LLUUID uuid) 131 public bool ExistsAsset(LLUUID uuid)
@@ -137,23 +136,26 @@ namespace OpenSim.Framework.Data.SQLite
137 136
138 public void DeleteAsset(LLUUID uuid) 137 public void DeleteAsset(LLUUID uuid)
139 { 138 {
140 lock (ds) { 139 lock (ds)
140 {
141 DataRow row = ds.Tables["assets"].Rows.Find(uuid); 141 DataRow row = ds.Tables["assets"].Rows.Find(uuid);
142 if (row != null) { 142 if (row != null)
143 {
143 row.Delete(); 144 row.Delete();
144 } 145 }
145 } 146 }
146 } 147 }
147 148
148 public void CommitAssets() // force a sync to the database 149 public void CommitAssets() // force a sync to the database
149 { 150 {
150 MainLog.Instance.Verbose("AssetStorage", "Attempting commit"); 151 MainLog.Instance.Verbose("AssetStorage", "Attempting commit");
151 lock (ds) { 152 lock (ds)
153 {
152 da.Update(ds, "assets"); 154 da.Update(ds, "assets");
153 ds.AcceptChanges(); 155 ds.AcceptChanges();
154 } 156 }
155 } 157 }
156 158
157 /*********************************************************************** 159 /***********************************************************************
158 * 160 *
159 * Database Definition Functions 161 * Database Definition Functions
@@ -161,24 +163,24 @@ namespace OpenSim.Framework.Data.SQLite
161 * This should be db agnostic as we define them in ADO.NET terms 163 * This should be db agnostic as we define them in ADO.NET terms
162 * 164 *
163 **********************************************************************/ 165 **********************************************************************/
164 166
165 private DataTable createAssetsTable() 167 private DataTable createAssetsTable()
166 { 168 {
167 DataTable assets = new DataTable("assets"); 169 DataTable assets = new DataTable("assets");
168 170
169 createCol(assets, "UUID", typeof(System.String)); 171 createCol(assets, "UUID", typeof (String));
170 createCol(assets, "Name", typeof(System.String)); 172 createCol(assets, "Name", typeof (String));
171 createCol(assets, "Description", typeof(System.String)); 173 createCol(assets, "Description", typeof (String));
172 createCol(assets, "Type", typeof(System.Int32)); 174 createCol(assets, "Type", typeof (Int32));
173 createCol(assets, "InvType", typeof(System.Int32)); 175 createCol(assets, "InvType", typeof (Int32));
174 createCol(assets, "Local", typeof(System.Boolean)); 176 createCol(assets, "Local", typeof (Boolean));
175 createCol(assets, "Temporary", typeof(System.Boolean)); 177 createCol(assets, "Temporary", typeof (Boolean));
176 createCol(assets, "Data", typeof(System.Byte[])); 178 createCol(assets, "Data", typeof (Byte[]));
177 // Add in contraints 179 // Add in contraints
178 assets.PrimaryKey = new DataColumn[] { assets.Columns["UUID"] }; 180 assets.PrimaryKey = new DataColumn[] {assets.Columns["UUID"]};
179 return assets; 181 return assets;
180 } 182 }
181 183
182 /*********************************************************************** 184 /***********************************************************************
183 * 185 *
184 * Convert between ADO.NET <=> OpenSim Objects 186 * Convert between ADO.NET <=> OpenSim Objects
@@ -193,19 +195,19 @@ namespace OpenSim.Framework.Data.SQLite
193 // interesting has to be done to actually get these values 195 // interesting has to be done to actually get these values
194 // back out. Not enough time to figure it out yet. 196 // back out. Not enough time to figure it out yet.
195 AssetBase asset = new AssetBase(); 197 AssetBase asset = new AssetBase();
196 198
197 asset.FullID = new LLUUID((String)row["UUID"]); 199 asset.FullID = new LLUUID((String) row["UUID"]);
198 asset.Name = (String)row["Name"]; 200 asset.Name = (String) row["Name"];
199 asset.Description = (String)row["Description"]; 201 asset.Description = (String) row["Description"];
200 asset.Type = Convert.ToSByte(row["Type"]); 202 asset.Type = Convert.ToSByte(row["Type"]);
201 asset.InvType = Convert.ToSByte(row["InvType"]); 203 asset.InvType = Convert.ToSByte(row["InvType"]);
202 asset.Local = Convert.ToBoolean(row["Local"]); 204 asset.Local = Convert.ToBoolean(row["Local"]);
203 asset.Temporary = Convert.ToBoolean(row["Temporary"]); 205 asset.Temporary = Convert.ToBoolean(row["Temporary"]);
204 asset.Data = (byte[])row["Data"]; 206 asset.Data = (byte[]) row["Data"];
205 return asset; 207 return asset;
206 } 208 }
207 209
208 210
209 private void fillAssetRow(DataRow row, AssetBase asset) 211 private void fillAssetRow(DataRow row, AssetBase asset)
210 { 212 {
211 row["UUID"] = asset.FullID; 213 row["UUID"] = asset.FullID;
@@ -225,8 +227,10 @@ namespace OpenSim.Framework.Data.SQLite
225 row["Data"] = asset.Data; 227 row["Data"] = asset.Data;
226 228
227 // ADO.NET doesn't handle NULL very well 229 // ADO.NET doesn't handle NULL very well
228 foreach (DataColumn col in ds.Tables["assets"].Columns) { 230 foreach (DataColumn col in ds.Tables["assets"].Columns)
229 if (row[col] == null) { 231 {
232 if (row[col] == null)
233 {
230 row[col] = ""; 234 row[col] = "";
231 } 235 }
232 } 236 }
@@ -250,18 +254,18 @@ namespace OpenSim.Framework.Data.SQLite
250 da.UpdateCommand.Connection = conn; 254 da.UpdateCommand.Connection = conn;
251 255
252 SqliteCommand delete = new SqliteCommand("delete from assets where UUID = :UUID"); 256 SqliteCommand delete = new SqliteCommand("delete from assets where UUID = :UUID");
253 delete.Parameters.Add(createSqliteParameter("UUID", typeof(System.String))); 257 delete.Parameters.Add(createSqliteParameter("UUID", typeof (String)));
254 delete.Connection = conn; 258 delete.Connection = conn;
255 da.DeleteCommand = delete; 259 da.DeleteCommand = delete;
256 } 260 }
257 261
258 private void InitDB(SqliteConnection conn) 262 private void InitDB(SqliteConnection conn)
259 { 263 {
260 string createAssets = defineTable(createAssetsTable()); 264 string createAssets = defineTable(createAssetsTable());
261 SqliteCommand pcmd = new SqliteCommand(createAssets, conn); 265 SqliteCommand pcmd = new SqliteCommand(createAssets, conn);
262 conn.Open(); 266 conn.Open();
263 pcmd.ExecuteNonQuery(); 267 pcmd.ExecuteNonQuery();
264 conn.Close(); 268 conn.Close();
265 } 269 }
266 270
267 private bool TestTables(SqliteConnection conn) 271 private bool TestTables(SqliteConnection conn)
@@ -269,9 +273,12 @@ namespace OpenSim.Framework.Data.SQLite
269 SqliteCommand cmd = new SqliteCommand(assetSelect, conn); 273 SqliteCommand cmd = new SqliteCommand(assetSelect, conn);
270 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd); 274 SqliteDataAdapter pDa = new SqliteDataAdapter(cmd);
271 DataSet tmpDS = new DataSet(); 275 DataSet tmpDS = new DataSet();
272 try { 276 try
277 {
273 pDa.Fill(tmpDS, "assets"); 278 pDa.Fill(tmpDS, "assets");
274 } catch (Mono.Data.SqliteClient.SqliteSyntaxException) { 279 }
280 catch (SqliteSyntaxException)
281 {
275 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating"); 282 MainLog.Instance.Verbose("DATASTORE", "SQLite Database doesn't exist... creating");
276 InitDB(conn); 283 InitDB(conn);
277 } 284 }
@@ -279,14 +286,18 @@ namespace OpenSim.Framework.Data.SQLite
279 } 286 }
280 287
281 #region IPlugin interface 288 #region IPlugin interface
282 public string Version { 289
290 public string Version
291 {
283 get 292 get
284 { 293 {
285 System.Reflection.Module module = this.GetType().Module; 294 Module module = GetType().Module;
286 string dllName = module.Assembly.ManifestModule.Name; 295 string dllName = module.Assembly.ManifestModule.Name;
287 Version dllVersion = module.Assembly.GetName().Version; 296 Version dllVersion = module.Assembly.GetName().Version;
288 297
289 return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); 298 return
299 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
300 dllVersion.Revision);
290 } 301 }
291 } 302 }
292 303
@@ -295,9 +306,11 @@ namespace OpenSim.Framework.Data.SQLite
295 Initialise("AssetStorage.db", ""); 306 Initialise("AssetStorage.db", "");
296 } 307 }
297 308
298 public string Name { 309 public string Name
310 {
299 get { return "SQLite Asset storage engine"; } 311 get { return "SQLite Asset storage engine"; }
300 } 312 }
313
301 #endregion 314 #endregion
302 } 315 }
303} 316} \ No newline at end of file