diff options
author | Justin Clarke Casey | 2008-01-05 19:46:00 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-01-05 19:46:00 +0000 |
commit | 52666e64c830001a7af85afe66657bb04e415d27 (patch) | |
tree | 7cefb8a331172447da92a9b62e8d6d76ac73ce04 | |
parent | Inventory subfolders working again in grid mode. (diff) | |
download | opensim-SC_OLD-52666e64c830001a7af85afe66657bb04e415d27.zip opensim-SC_OLD-52666e64c830001a7af85afe66657bb04e415d27.tar.gz opensim-SC_OLD-52666e64c830001a7af85afe66657bb04e415d27.tar.bz2 opensim-SC_OLD-52666e64c830001a7af85afe66657bb04e415d27.tar.xz |
Prim inventory storage phase 2. Add a prim inventory script item to sqlite experimentally. This is not yet enabled in the codebase. No user functionality yet - next
phase is to write the code to restore the script in prim inventory on region load
-rw-r--r-- | OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | 135 |
1 files changed, 129 insertions, 6 deletions
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index b5a231e..5dac92f 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | |||
@@ -52,6 +52,7 @@ namespace OpenSim.DataStore.MonoSqlite | |||
52 | private DataSet ds; | 52 | private DataSet ds; |
53 | private SqliteDataAdapter primDa; | 53 | private SqliteDataAdapter primDa; |
54 | private SqliteDataAdapter shapeDa; | 54 | private SqliteDataAdapter shapeDa; |
55 | private SqliteDataAdapter itemsDa; | ||
55 | private SqliteDataAdapter terrainDa; | 56 | private SqliteDataAdapter terrainDa; |
56 | private SqliteDataAdapter landDa; | 57 | private SqliteDataAdapter landDa; |
57 | private SqliteDataAdapter landAccessListDa; | 58 | private SqliteDataAdapter landAccessListDa; |
@@ -88,8 +89,11 @@ namespace OpenSim.DataStore.MonoSqlite | |||
88 | 89 | ||
89 | SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); | 90 | SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); |
90 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); | 91 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); |
91 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); | 92 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); |
92 | 93 | ||
94 | SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, conn); | ||
95 | itemsDa = new SqliteDataAdapter(itemsSelectCmd); | ||
96 | |||
93 | SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn); | 97 | SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, conn); |
94 | terrainDa = new SqliteDataAdapter(terrainSelectCmd); | 98 | terrainDa = new SqliteDataAdapter(terrainSelectCmd); |
95 | 99 | ||
@@ -112,6 +116,12 @@ namespace OpenSim.DataStore.MonoSqlite | |||
112 | 116 | ||
113 | ds.Tables.Add(createShapeTable()); | 117 | ds.Tables.Add(createShapeTable()); |
114 | setupShapeCommands(shapeDa, conn); | 118 | setupShapeCommands(shapeDa, conn); |
119 | |||
120 | if (persistPrimInventories) | ||
121 | { | ||
122 | ds.Tables.Add(createItemsTable()); | ||
123 | setupItemsCommands(itemsDa, conn); | ||
124 | } | ||
115 | 125 | ||
116 | ds.Tables.Add(createTerrainTable()); | 126 | ds.Tables.Add(createTerrainTable()); |
117 | setupTerrainCommands(terrainDa, conn); | 127 | setupTerrainCommands(terrainDa, conn); |
@@ -489,6 +499,7 @@ namespace OpenSim.DataStore.MonoSqlite | |||
489 | { | 499 | { |
490 | primDa.Update(ds, "prims"); | 500 | primDa.Update(ds, "prims"); |
491 | shapeDa.Update(ds, "primshapes"); | 501 | shapeDa.Update(ds, "primshapes"); |
502 | itemsDa.Update(ds, "primitems"); | ||
492 | terrainDa.Update(ds, "terrain"); | 503 | terrainDa.Update(ds, "terrain"); |
493 | landDa.Update(ds, "land"); | 504 | landDa.Update(ds, "land"); |
494 | landAccessListDa.Update(ds, "landaccesslist"); | 505 | landAccessListDa.Update(ds, "landaccesslist"); |
@@ -635,11 +646,13 @@ namespace OpenSim.DataStore.MonoSqlite | |||
635 | { | 646 | { |
636 | DataTable items = new DataTable("primitems"); | 647 | DataTable items = new DataTable("primitems"); |
637 | 648 | ||
638 | createCol(items, "UUID", typeof (String)); | 649 | createCol(items, "itemID", typeof (String)); |
639 | createCol(items, "invType", typeof (Int32)); | 650 | createCol(items, "primID", typeof (String)); |
640 | createCol(items, "assetID", typeof (String)); | 651 | createCol(items, "assetID", typeof (String)); |
641 | createCol(items, "assetType", typeof (Int32)); | ||
642 | createCol(items, "parentFolderID", typeof (String)); | 652 | createCol(items, "parentFolderID", typeof (String)); |
653 | |||
654 | createCol(items, "invType", typeof (String)); | ||
655 | createCol(items, "assetType", typeof (String)); | ||
643 | 656 | ||
644 | createCol(items, "name", typeof (String)); | 657 | createCol(items, "name", typeof (String)); |
645 | createCol(items, "description", typeof (String)); | 658 | createCol(items, "description", typeof (String)); |
@@ -656,7 +669,7 @@ namespace OpenSim.DataStore.MonoSqlite | |||
656 | createCol(items, "everyonePermissions", typeof (Int32)); | 669 | createCol(items, "everyonePermissions", typeof (Int32)); |
657 | createCol(items, "groupPermissions", typeof (Int32)); | 670 | createCol(items, "groupPermissions", typeof (Int32)); |
658 | 671 | ||
659 | items.PrimaryKey = new DataColumn[] {items.Columns["UUID"]}; | 672 | items.PrimaryKey = new DataColumn[] {items.Columns["itemID"]}; |
660 | 673 | ||
661 | return items; | 674 | return items; |
662 | } | 675 | } |
@@ -971,6 +984,30 @@ namespace OpenSim.DataStore.MonoSqlite | |||
971 | row["SitTargetOrientY"] = sitTargetOrient.Y; | 984 | row["SitTargetOrientY"] = sitTargetOrient.Y; |
972 | row["SitTargetOrientZ"] = sitTargetOrient.Z; | 985 | row["SitTargetOrientZ"] = sitTargetOrient.Z; |
973 | } | 986 | } |
987 | |||
988 | private void fillItemRow(DataRow row, SceneObjectPart.TaskInventoryItem taskItem) | ||
989 | { | ||
990 | row["itemID"] = taskItem.item_id; | ||
991 | row["primID"] = taskItem.ParentPartID; | ||
992 | row["assetID"] = taskItem.asset_id; | ||
993 | row["parentFolderID"] = taskItem.parent_id; | ||
994 | |||
995 | row["invType"] = taskItem.inv_type; | ||
996 | row["assetType"] = taskItem.type; | ||
997 | |||
998 | row["name"] = taskItem.name; | ||
999 | row["description"] = taskItem.desc; | ||
1000 | row["creationDate"] = taskItem.creation_date; | ||
1001 | row["creatorID"] = taskItem.creator_id; | ||
1002 | row["ownerID"] = taskItem.owner_id; | ||
1003 | row["lastOwnerID"] = taskItem.last_owner_id; | ||
1004 | row["groupID"] = taskItem.group_id; | ||
1005 | row["nextPermissions"] = taskItem.next_owner_mask; | ||
1006 | row["currentPermissions"] = taskItem.owner_mask; | ||
1007 | row["basePermissions"] = taskItem.base_mask; | ||
1008 | row["everyonePermissions"] = taskItem.everyone_mask; | ||
1009 | row["groupPermissions"] = taskItem.group_mask; | ||
1010 | } | ||
974 | 1011 | ||
975 | private void fillLandRow(DataRow row, LandData land, LLUUID regionUUID) | 1012 | private void fillLandRow(DataRow row, LandData land, LLUUID regionUUID) |
976 | { | 1013 | { |
@@ -1137,6 +1174,78 @@ namespace OpenSim.DataStore.MonoSqlite | |||
1137 | { | 1174 | { |
1138 | fillShapeRow(shapeRow, prim); | 1175 | fillShapeRow(shapeRow, prim); |
1139 | } | 1176 | } |
1177 | |||
1178 | if (persistPrimInventories) | ||
1179 | { | ||
1180 | addPrimInventory(prim.UUID, prim.TaskInventory); | ||
1181 | } | ||
1182 | } | ||
1183 | |||
1184 | /// <summary> | ||
1185 | /// Persist prim inventory. Deletes, updates and inserts rows. | ||
1186 | /// </summary> | ||
1187 | /// <param name="primID"></param> | ||
1188 | /// <param name="items"></param> | ||
1189 | /// <returns></returns> | ||
1190 | private void addPrimInventory(LLUUID primID, Dictionary<LLUUID, SceneObjectPart.TaskInventoryItem> items) | ||
1191 | { | ||
1192 | MainLog.Instance.Verbose("DATASTORE", "Entered addPrimInventory with prim ID {0}", primID); | ||
1193 | |||
1194 | // Find all existing inventory rows for this prim | ||
1195 | DataTable dbItems = ds.Tables["primitems"]; | ||
1196 | |||
1197 | String sql = String.Format("primID = '{0}'", primID); | ||
1198 | DataRow[] dbItemRows = dbItems.Select(sql); | ||
1199 | |||
1200 | // Build structures for manipulation purposes | ||
1201 | IDictionary<String, DataRow> dbItemsToRemove = new Dictionary<String, DataRow>(); | ||
1202 | ICollection<SceneObjectPart.TaskInventoryItem> itemsToAdd | ||
1203 | = new List<SceneObjectPart.TaskInventoryItem>(); | ||
1204 | |||
1205 | foreach (DataRow row in dbItemRows) | ||
1206 | { | ||
1207 | dbItemsToRemove.Add((String)row["itemID"], row); | ||
1208 | } | ||
1209 | |||
1210 | // Eliminate rows from the deletion set which already exist for this prim's inventory | ||
1211 | // TODO Very temporary, need to take account of simple metadata changes soon | ||
1212 | foreach (LLUUID itemId in items.Keys) | ||
1213 | { | ||
1214 | String rawItemId = itemId.ToString(); | ||
1215 | |||
1216 | if (dbItemsToRemove.ContainsKey(rawItemId)) | ||
1217 | { | ||
1218 | dbItemsToRemove.Remove(rawItemId); | ||
1219 | } | ||
1220 | else | ||
1221 | { | ||
1222 | itemsToAdd.Add(items[itemId]); | ||
1223 | } | ||
1224 | } | ||
1225 | |||
1226 | // Delete excess rows | ||
1227 | foreach (DataRow row in dbItemsToRemove.Values) | ||
1228 | { | ||
1229 | MainLog.Instance.Verbose( | ||
1230 | "DATASTORE", | ||
1231 | "Removing item {0}, {1} from prim ID {2}", | ||
1232 | row["name"], row["itemID"], row["primID"]); | ||
1233 | |||
1234 | row.Delete(); | ||
1235 | } | ||
1236 | |||
1237 | // Insert items not already present | ||
1238 | foreach (SceneObjectPart.TaskInventoryItem newItem in itemsToAdd) | ||
1239 | { | ||
1240 | MainLog.Instance.Verbose( | ||
1241 | "DATASTORE", | ||
1242 | "Adding item {0}, {1} to prim ID {1}", | ||
1243 | newItem.name, newItem.item_id, newItem.ParentPartID); | ||
1244 | |||
1245 | DataRow newItemRow = dbItems.NewRow(); | ||
1246 | fillItemRow(newItemRow, newItem); | ||
1247 | dbItems.Rows.Add(newItemRow); | ||
1248 | } | ||
1140 | } | 1249 | } |
1141 | 1250 | ||
1142 | /*********************************************************************** | 1251 | /*********************************************************************** |
@@ -1263,6 +1372,20 @@ namespace OpenSim.DataStore.MonoSqlite | |||
1263 | param.SourceVersion = DataRowVersion.Current; | 1372 | param.SourceVersion = DataRowVersion.Current; |
1264 | return param; | 1373 | return param; |
1265 | } | 1374 | } |
1375 | |||
1376 | private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
1377 | { | ||
1378 | da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]); | ||
1379 | da.InsertCommand.Connection = conn; | ||
1380 | |||
1381 | da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]); | ||
1382 | da.UpdateCommand.Connection = conn; | ||
1383 | |||
1384 | SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID"); | ||
1385 | delete.Parameters.Add(createSqliteParameter("itemID", typeof (String))); | ||
1386 | delete.Connection = conn; | ||
1387 | da.DeleteCommand = delete; | ||
1388 | } | ||
1266 | 1389 | ||
1267 | private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn) | 1390 | private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn) |
1268 | { | 1391 | { |
@@ -1561,4 +1684,4 @@ namespace OpenSim.DataStore.MonoSqlite | |||
1561 | } | 1684 | } |
1562 | } | 1685 | } |
1563 | } | 1686 | } |
1564 | } \ No newline at end of file | 1687 | } |