aboutsummaryrefslogtreecommitdiffstatshomepage
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
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)
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLDataStore.cs106
-rw-r--r--OpenSim/Framework/Data.SQLite/SQLiteRegionData.cs93
-rw-r--r--OpenSim/Region/Environment/Interfaces/IRegionDataStore.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs5
-rw-r--r--OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs2
-rw-r--r--OpenSim/Region/Storage/OpenSim.DataStore.NullStorage/NullDataStore.cs2
6 files changed, 71 insertions, 139 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs
index 47b3c43..2bd4e32 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs
@@ -167,7 +167,6 @@ namespace OpenSim.Framework.Data.MySQL
167 167
168 DataTable prims = m_primTable; 168 DataTable prims = m_primTable;
169 DataTable shapes = m_shapeTable; 169 DataTable shapes = m_shapeTable;
170 DataTable items = m_itemsTable;
171 170
172 string selectExp = "SceneGroupID = '" + Util.ToRawUuidString(obj) + "'"; 171 string selectExp = "SceneGroupID = '" + Util.ToRawUuidString(obj) + "'";
173 lock (m_dataSet) 172 lock (m_dataSet)
@@ -185,14 +184,7 @@ namespace OpenSim.Framework.Data.MySQL
185 184
186 if (persistPrimInventories) 185 if (persistPrimInventories)
187 { 186 {
188 // Remove items rows 187 RemoveItems(uuid);
189 String sql = String.Format("primID = '{0}'", uuid);
190 DataRow[] itemRows = items.Select(sql);
191
192 foreach (DataRow itemRow in itemRows)
193 {
194 itemRow.Delete();
195 }
196 } 188 }
197 189
198 // Remove prim row 190 // Remove prim row
@@ -204,6 +196,21 @@ namespace OpenSim.Framework.Data.MySQL
204 } 196 }
205 197
206 /// <summary> 198 /// <summary>
199 /// Remove all persisted items of the given prim.
200 /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
201 /// </summary>
202 private void RemoveItems(LLUUID uuid)
203 {
204 String sql = String.Format("primID = '{0}'", uuid);
205 DataRow[] itemRows = m_itemsTable.Select(sql);
206
207 foreach (DataRow itemRow in itemRows)
208 {
209 itemRow.Delete();
210 }
211 }
212
213 /// <summary>
207 /// Load persisted objects from region storage. 214 /// Load persisted objects from region storage.
208 /// </summary> 215 /// </summary>
209 public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) 216 public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
@@ -1196,83 +1203,34 @@ namespace OpenSim.Framework.Data.MySQL
1196 } 1203 }
1197 1204
1198 // see IRegionDatastore 1205 // see IRegionDatastore
1199 public void StorePrimInventory(LLUUID primID, IDictionary<LLUUID, TaskInventoryItem> items) 1206 public void StorePrimInventory(LLUUID primID, ICollection<TaskInventoryItem> items)
1200 { 1207 {
1201 if (!persistPrimInventories) 1208 if (!persistPrimInventories)
1202 return; 1209 return;
1203 1210
1204 MainLog.Instance.Verbose("DATASTORE", "Entered StorePrimInventory with prim ID {0}", primID); 1211 MainLog.Instance.Verbose("DATASTORE", "Persisting Prim Inventory with prim ID {0}", primID);
1205 1212
1213 // For now, we're just going to crudely remove all the previous inventory items
1214 // no matter whether they have changed or not, and replace them with the current set.
1206 lock (m_dataSet) 1215 lock (m_dataSet)
1207 { 1216 {
1208 // Find all existing inventory rows for this prim 1217 RemoveItems(primID);
1209 DataTable dbItems = m_itemsTable;
1210
1211 String sql = String.Format("primID = '{0}'", primID);
1212 DataRow[] dbItemRows = dbItems.Select(sql);
1213
1214 // Build structures for manipulation purposes
1215 IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>();
1216 ICollection<TaskInventoryItem> itemsToAdd = new List<TaskInventoryItem>();
1217
1218 foreach (DataRow row in dbItemRows)
1219 {
1220 // MainLog.Instance.Verbose(
1221 // "DATASTORE",
1222 // "Found item {0}, {1} in prim id {2}",
1223 // row["name"], row["itemID"], primID);
1224
1225 dbItemsToRemove.Add((String)row["itemID"], row);
1226 }
1227
1228 // Eliminate rows from the deletion set which already exist for this prim's inventory
1229 // TODO Very temporary, need to take account of simple metadata changes soon
1230 lock (items)
1231 {
1232 foreach (LLUUID itemId in items.Keys)
1233 {
1234 String rawItemId = itemId.ToString();
1235
1236 if (dbItemsToRemove.ContainsKey(rawItemId))
1237 {
1238 // MainLog.Instance.Verbose(
1239 // "DATASTORE",
1240 // "Discarding item {0}, {1} from remove candidates for prim id {2}",
1241 // items[itemId].Name, rawItemId, primID);
1242
1243 dbItemsToRemove.Remove(rawItemId);
1244 }
1245 else
1246 {
1247 itemsToAdd.Add(items[itemId]);
1248 }
1249 }
1250 }
1251
1252 // Delete excess rows
1253 foreach (DataRow row in dbItemsToRemove.Values)
1254 {
1255 MainLog.Instance.Verbose(
1256 "DATASTORE",
1257 "Removing item {0}, {1} from prim ID {2}",
1258 row["name"], row["itemID"], row["primID"]);
1259
1260 row.Delete();
1261 }
1262 1218
1263 // Insert items not already present 1219 // repalce with current inventory details
1264 foreach (TaskInventoryItem newItem in itemsToAdd) 1220 foreach (TaskInventoryItem newItem in items)
1265 { 1221 {
1266 MainLog.Instance.Verbose( 1222// MainLog.Instance.Verbose(
1267 "DATASTORE", 1223// "DATASTORE",
1268 "Adding item {0}, {1} to prim ID {2}", 1224// "Adding item {0}, {1} to prim ID {2}",
1269 newItem.Name, newItem.ItemID, newItem.ParentPartID); 1225// newItem.Name, newItem.ItemID, newItem.ParentPartID);
1270 1226
1271 DataRow newItemRow = dbItems.NewRow(); 1227 DataRow newItemRow = m_itemsTable.NewRow();
1272 fillItemRow(newItemRow, newItem); 1228 fillItemRow(newItemRow, newItem);
1273 dbItems.Rows.Add(newItemRow); 1229 m_itemsTable.Rows.Add(newItemRow);
1274 } 1230 }
1275 } 1231 }
1232
1233 Commit();
1276 } 1234 }
1277 1235
1278 /*********************************************************************** 1236 /***********************************************************************
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 /***********************************************************************
diff --git a/OpenSim/Region/Environment/Interfaces/IRegionDataStore.cs b/OpenSim/Region/Environment/Interfaces/IRegionDataStore.cs
index 47768b7..d0b5680 100644
--- a/OpenSim/Region/Environment/Interfaces/IRegionDataStore.cs
+++ b/OpenSim/Region/Environment/Interfaces/IRegionDataStore.cs
@@ -63,7 +63,7 @@ namespace OpenSim.Region.Environment.Interfaces
63 /// Store a prim's inventory 63 /// Store a prim's inventory
64 /// </summary> 64 /// </summary>
65 /// <returns></returns> 65 /// <returns></returns>
66 void StorePrimInventory(LLUUID primID, IDictionary<LLUUID, TaskInventoryItem> items); 66 void StorePrimInventory(LLUUID primID, ICollection<TaskInventoryItem> items);
67 67
68 List<SceneObjectGroup> LoadObjects(LLUUID regionUUID); 68 List<SceneObjectGroup> LoadObjects(LLUUID regionUUID);
69 69
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
index a700974..d4e2102 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -401,7 +401,10 @@ namespace OpenSim.Region.Environment.Scenes
401 { 401 {
402 if (HasInventoryChanged) 402 if (HasInventoryChanged)
403 { 403 {
404 datastore.StorePrimInventory(UUID, TaskInventory); 404 lock (TaskInventory)
405 {
406 datastore.StorePrimInventory(UUID, TaskInventory.Values);
407 }
405 408
406 HasInventoryChanged = false; 409 HasInventoryChanged = false;
407 } 410 }
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs
index 6aeb808..28df4e7 100644
--- a/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs
+++ b/OpenSim/Region/Storage/OpenSim.DataStore.MSSQL/MSSQLDataStore.cs
@@ -754,7 +754,7 @@ namespace OpenSim.DataStore.MSSQL
754 } 754 }
755 755
756 // see IRegionDatastore 756 // see IRegionDatastore
757 public void StorePrimInventory(LLUUID primID, IDictionary<LLUUID, TaskInventoryItem> items) 757 public void StorePrimInventory(LLUUID primID, ICollection<TaskInventoryItem> items)
758 { 758 {
759 // No implementation yet 759 // No implementation yet
760 } 760 }
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.NullStorage/NullDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.NullStorage/NullDataStore.cs
index 8039e51..29d64a2 100644
--- a/OpenSim/Region/Storage/OpenSim.DataStore.NullStorage/NullDataStore.cs
+++ b/OpenSim/Region/Storage/OpenSim.DataStore.NullStorage/NullDataStore.cs
@@ -51,7 +51,7 @@ namespace OpenSim.DataStore.NullStorage
51 } 51 }
52 52
53 // see IRegionDatastore 53 // see IRegionDatastore
54 public void StorePrimInventory(LLUUID primID, IDictionary<LLUUID, TaskInventoryItem> items) 54 public void StorePrimInventory(LLUUID primID, ICollection<TaskInventoryItem> items)
55 { 55 {
56 } 56 }
57 57