aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.SQLite
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-01-21 16:42:53 +0000
committerJustin Clarke Casey2008-01-21 16:42:53 +0000
commit46fe6e2f978ef03a20768e629e9cd2437c707bba (patch)
tree613fc4e709fb7736e5f462c9bc7da99ae3a636d1 /OpenSim/Framework/Data.SQLite
parentcomment out use of the TribalMedia data mapper layer (diff)
downloadopensim-SC_OLD-46fe6e2f978ef03a20768e629e9cd2437c707bba.zip
opensim-SC_OLD-46fe6e2f978ef03a20768e629e9cd2437c707bba.tar.gz
opensim-SC_OLD-46fe6e2f978ef03a20768e629e9cd2437c707bba.tar.bz2
opensim-SC_OLD-46fe6e2f978ef03a20768e629e9cd2437c707bba.tar.xz
* Scripts edited within a prim will now be persisted correctly
* On restart the latest save will be restored rather than the very first dragged in scripts * Also add previously missed out database commits to separate prim inventory commit path (sigh)
Diffstat (limited to 'OpenSim/Framework/Data.SQLite')
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs93
1 files changed, 32 insertions, 61 deletions
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs
index 0035311..6553192 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs
@@ -209,7 +209,6 @@ namespace OpenSim.Framework.Data.SQLite
209 209
210 DataTable prims = ds.Tables["prims"]; 210 DataTable prims = ds.Tables["prims"];
211 DataTable shapes = ds.Tables["primshapes"]; 211 DataTable shapes = ds.Tables["primshapes"];
212 DataTable items = ds.Tables["primitems"];
213 212
214 string selectExp = "SceneGroupID = '" + Util.ToRawUuidString(obj) + "'"; 213 string selectExp = "SceneGroupID = '" + Util.ToRawUuidString(obj) + "'";
215 lock (ds) 214 lock (ds)
@@ -227,14 +226,7 @@ namespace OpenSim.Framework.Data.SQLite
227 226
228 if (persistPrimInventories) 227 if (persistPrimInventories)
229 { 228 {
230 // Remove items rows 229 RemoveItems(uuid);
231 String sql = String.Format("primID = '{0}'", uuid);
232 DataRow[] itemRows = items.Select(sql);
233
234 foreach (DataRow itemRow in itemRows)
235 {
236 itemRow.Delete();
237 }
238 } 230 }
239 231
240 // Remove prim row 232 // Remove prim row
@@ -246,6 +238,23 @@ namespace OpenSim.Framework.Data.SQLite
246 } 238 }
247 239
248 /// <summary> 240 /// <summary>
241 /// Remove all persisted items of the given prim.
242 /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
243 /// </summary>
244 private void RemoveItems(LLUUID uuid)
245 {
246 DataTable items = ds.Tables["primitems"];
247
248 String sql = String.Format("primID = '{0}'", uuid);
249 DataRow[] itemRows = items.Select(sql);
250
251 foreach (DataRow itemRow in itemRows)
252 {
253 itemRow.Delete();
254 }
255 }
256
257 /// <summary>
249 /// Load persisted objects from region storage. 258 /// Load persisted objects from region storage.
250 /// </summary> 259 /// </summary>
251 /// <param name="regionUUID"></param> 260 /// <param name="regionUUID"></param>
@@ -1251,74 +1260,36 @@ namespace OpenSim.Framework.Data.SQLite
1251 } 1260 }
1252 1261
1253 // see IRegionDatastore 1262 // see IRegionDatastore
1254 public void StorePrimInventory(LLUUID primID, IDictionary<LLUUID, TaskInventoryItem> items) 1263 public void StorePrimInventory(LLUUID primID, ICollection<TaskInventoryItem> items)
1255 { 1264 {
1256 if (!persistPrimInventories) 1265 if (!persistPrimInventories)
1257 return; 1266 return;
1258 1267
1259 MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); 1268 MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID);
1260 1269
1270 DataTable dbItems = ds.Tables["primitems"];
1271
1272 // For now, we're just going to crudely remove all the previous inventory items
1273 // no matter whether they have changed or not, and replace them with the current set.
1261 lock (ds) 1274 lock (ds)
1262 { 1275 {
1263 // Find all existing inventory rows for this prim 1276 RemoveItems(primID);
1264 DataTable dbItems = ds.Tables["primitems"];
1265
1266 String sql = String.Format("primID = '{0}'", primID);
1267 DataRow[] dbItemRows = dbItems.Select(sql);
1268
1269 // Build structures for manipulation purposes
1270 IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
1271 ICollection<TaskInventoryItem> itemsToAdd
1272 = new List<TaskInventoryItem>();
1273 1277
1274 foreach (DataRow row in dbItemRows) 1278 // repalce with current inventory details
1279 foreach (TaskInventoryItem newItem in items)
1275 { 1280 {
1276 dbItemsToRemove.Add((String)row["itemID"], row); 1281// MainLog.Instance.Verbose(
1277 } 1282// "DATASTORE",
1278 1283// "Adding item {0}, {1} to prim ID {2}",
1279 // Eliminate rows from the deletion set which already exist for this prim's inventory 1284// newItem.Name, newItem.ItemID, newItem.ParentPartID);
1280 // TODO Very temporary, need to take account of simple metadata changes soon
1281 lock (items)
1282 {
1283 foreach (LLUUID itemId in items.Keys)
1284 {
1285 String rawItemId = itemId.ToString();
1286
1287 if (dbItemsToRemove.ContainsKey(rawItemId))
1288 {
1289 dbItemsToRemove.Remove(rawItemId);
1290 }
1291 else
1292 {
1293 itemsToAdd.Add(items[itemId]);
1294 }
1295 }
1296 }
1297
1298 // Delete excess rows
1299 foreach (DataRow row in dbItemsToRemove.Values)
1300 {
1301 MainLog.Instance.Verbose(
1302 "DATASTORE",
1303 "Removing item {0}, {1} from prim ID {2}",
1304 row["name"], row["itemID"], row["primID"]);
1305
1306 row.Delete();
1307 }
1308
1309 // Insert items not already present
1310 foreach (TaskInventoryItem newItem in itemsToAdd)
1311 {
1312 MainLog.Instance.Verbose(
1313 "DATASTORE",
1314 "Adding item {0}, {1} to prim ID {2}",
1315 newItem.Name, newItem.ItemID, newItem.ParentPartID);
1316 1285
1317 DataRow newItemRow = dbItems.NewRow(); 1286 DataRow newItemRow = dbItems.NewRow();
1318 fillItemRow(newItemRow, newItem); 1287 fillItemRow(newItemRow, newItem);
1319 dbItems.Rows.Add(newItemRow); 1288 dbItems.Rows.Add(newItemRow);
1320 } 1289 }
1321 } 1290 }
1291
1292 Commit();
1322 } 1293 }
1323 1294
1324 /*********************************************************************** 1295 /***********************************************************************