aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs
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.MySQL/MySQLDataStore.cs
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 '')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLDataStore.cs106
1 files changed, 32 insertions, 74 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 /***********************************************************************