aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLRegionData.cs206
1 files changed, 104 insertions, 102 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLRegionData.cs b/OpenSim/Data/MSSQL/MSSQLRegionData.cs
index b942f00..8b808d3 100644
--- a/OpenSim/Data/MSSQL/MSSQLRegionData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLRegionData.cs
@@ -44,14 +44,19 @@ namespace OpenSim.Data.MSSQL
44 /// </summary> 44 /// </summary>
45 public class MSSQLRegionDataStore : IRegionDataStore 45 public class MSSQLRegionDataStore : IRegionDataStore
46 { 46 {
47 private const string _migrationStore = "RegionStore";
48
47 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 49 // private static FileSystemDataStore Instance = new FileSystemDataStore();
48 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 51
52 /// <summary>
53 /// The database manager
54 /// </summary>
50 private MSSQLManager _Database; 55 private MSSQLManager _Database;
51 56
52// private const string _PrimSelect = "SELECT * FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID = @UUID)"; 57 /// <summary>
53// private const string _ShapeSelect = "SELECT * FROM PRIMSHAPES WHERE UUID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID = @UUID))"; 58 /// Const for the prim store..
54// private const string _ItemsSelect = "SELECT * FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID = @UUID))"; 59 /// </summary>
55 private const string _PrimSelect = "SELECT * FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID))"; 60 private const string _PrimSelect = "SELECT * FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID))";
56 private const string _ShapeSelect = "SELECT * FROM PRIMSHAPES WHERE UUID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID)))"; 61 private const string _ShapeSelect = "SELECT * FROM PRIMSHAPES WHERE UUID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID)))";
57 private const string _ItemsSelect = "SELECT * FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID)))"; 62 private const string _ItemsSelect = "SELECT * FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID AND (SceneGroupID LIKE @SceneGroupID OR UUID IN (@UUID)))";
@@ -81,31 +86,14 @@ namespace OpenSim.Data.MSSQL
81 string settingUserId = iniFile.ParseFileReadValue("user_id"); 86 string settingUserId = iniFile.ParseFileReadValue("user_id");
82 string settingPassword = iniFile.ParseFileReadValue("password"); 87 string settingPassword = iniFile.ParseFileReadValue("password");
83 88
84 _Database = 89 _Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
85 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
86 settingPassword);
87
88
89 SqlConnectionStringBuilder conBuilder = new SqlConnectionStringBuilder();
90 conBuilder.DataSource = settingDataSource;
91 conBuilder.InitialCatalog = settingInitialCatalog;
92 conBuilder.PersistSecurityInfo = Convert.ToBoolean(settingPersistSecurityInfo);
93 conBuilder.UserID = settingUserId;
94 conBuilder.Password = settingPassword;
95 conBuilder.ApplicationName = Assembly.GetEntryAssembly().Location;
96
97 connectionString = conBuilder.ToString();
98 } 90 }
99 91
100 //Migration settings 92 //Migration settings
101 Assembly assem = GetType().Assembly; 93 _Database.CheckMigration(_migrationStore);
102 94
103 using (SqlConnection connection = _Database.DatabaseConnection()) 95 using (SqlConnection connection = _Database.DatabaseConnection())
104 { 96 {
105 MSSQLMigration m = new MSSQLMigration(connection, assem, "RegionStore");
106
107 m.Update();
108
109 //Create Dataset. Not filled!!! 97 //Create Dataset. Not filled!!!
110 _PrimsDataSet = new DataSet("primsdata"); 98 _PrimsDataSet = new DataSet("primsdata");
111 99
@@ -243,7 +231,7 @@ namespace OpenSim.Data.MSSQL
243 catch (Exception e) 231 catch (Exception e)
244 { 232 {
245 _Log.Error("[REGION DB]: Failed create prim object, exception and data follows"); 233 _Log.Error("[REGION DB]: Failed create prim object, exception and data follows");
246 _Log.Info("[REGION DB]: " + e.ToString()); 234 _Log.Info("[REGION DB]: " + e.Message);
247 foreach (DataColumn col in prims.Columns) 235 foreach (DataColumn col in prims.Columns)
248 { 236 {
249 _Log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); 237 _Log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
@@ -259,71 +247,76 @@ namespace OpenSim.Data.MSSQL
259 247
260 #region Experimental 248 #region Experimental
261 249
262// 250 //
263// //Get all prims 251 // //Get all prims
264// string sql = "select * from prims where RegionUUID = @RegionUUID"; 252 // string sql = "select * from prims where RegionUUID = @RegionUUID";
265// 253 //
266// using (AutoClosingSqlCommand cmdPrims = _Database.Query(sql)) 254 // using (AutoClosingSqlCommand cmdPrims = _Database.Query(sql))
267// { 255 // {
268// cmdPrims.Parameters.AddWithValue("@RegionUUID", regionUUID.ToString()); 256 // cmdPrims.Parameters.AddWithValue("@RegionUUID", regionUUID.ToString());
269// using (SqlDataReader readerPrims = cmdPrims.ExecuteReader()) 257 // using (SqlDataReader readerPrims = cmdPrims.ExecuteReader())
270// { 258 // {
271// while (readerPrims.Read()) 259 // while (readerPrims.Read())
272// { 260 // {
273// string uuid = (string)readerPrims["UUID"]; 261 // string uuid = (string)readerPrims["UUID"];
274// string objID = (string)readerPrims["SceneGroupID"]; 262 // string objID = (string)readerPrims["SceneGroupID"];
275// SceneObjectPart prim = buildPrim(readerPrims); 263 // SceneObjectPart prim = buildPrim(readerPrims);
276// 264 //
277// //Setting default shape, will change shape ltr 265 // //Setting default shape, will change shape ltr
278// prim.Shape = PrimitiveBaseShape.Default; 266 // prim.Shape = PrimitiveBaseShape.Default;
279// 267 //
280// //Load inventory items of prim 268 // //Load inventory items of prim
281// //LoadItems(prim); 269 // //LoadItems(prim);
282// 270 //
283// if (uuid == objID) 271 // if (uuid == objID)
284// { 272 // {
285// SceneObjectGroup group = new SceneObjectGroup(); 273 // SceneObjectGroup group = new SceneObjectGroup();
286// 274 //
287// group.AddPart(prim); 275 // group.AddPart(prim);
288// group.RootPart = prim; 276 // group.RootPart = prim;
289// 277 //
290// createdObjects.Add(group.UUID, group); 278 // createdObjects.Add(group.UUID, group);
291// retvals.Add(group); 279 // retvals.Add(group);
292// } 280 // }
293// else 281 // else
294// { 282 // {
295// createdObjects[new UUID(objID)].AddPart(prim); 283 // createdObjects[new UUID(objID)].AddPart(prim);
296// } 284 // }
297// } 285 // }
298// } 286 // }
299// } 287 // }
300// m_log.Info("[REGION DB]: Loaded " + retvals.Count + " prim objects for region: " + regionUUID); 288 // m_log.Info("[REGION DB]: Loaded " + retvals.Count + " prim objects for region: " + regionUUID);
301// 289 //
302// //Find all shapes related with prims 290 // //Find all shapes related with prims
303// sql = "select * from primshapes"; 291 // sql = "select * from primshapes";
304// using (AutoClosingSqlCommand cmdShapes = _Database.Query(sql)) 292 // using (AutoClosingSqlCommand cmdShapes = _Database.Query(sql))
305// { 293 // {
306// using (SqlDataReader readerShapes = cmdShapes.ExecuteReader()) 294 // using (SqlDataReader readerShapes = cmdShapes.ExecuteReader())
307// { 295 // {
308// while (readerShapes.Read()) 296 // while (readerShapes.Read())
309// { 297 // {
310// UUID UUID = new UUID((string) readerShapes["UUID"]); 298 // UUID UUID = new UUID((string) readerShapes["UUID"]);
311// 299 //
312// foreach (SceneObjectGroup objectGroup in createdObjects.Values) 300 // foreach (SceneObjectGroup objectGroup in createdObjects.Values)
313// { 301 // {
314// if (objectGroup.Children.ContainsKey(UUID)) 302 // if (objectGroup.Children.ContainsKey(UUID))
315// { 303 // {
316// objectGroup.Children[UUID].Shape = buildShape(readerShapes); 304 // objectGroup.Children[UUID].Shape = buildShape(readerShapes);
317// } 305 // }
318// } 306 // }
319// } 307 // }
320// } 308 // }
321// } 309 // }
322// return retvals; 310 // return retvals;
323 311
324 #endregion 312 #endregion
325 } 313 }
326 314
315 /// <summary>
316 /// Stores all object's details apart from inventory
317 /// </summary>
318 /// <param name="obj"></param>
319 /// <param name="regionUUID"></param>
327 public void StoreObject(SceneObjectGroup obj, UUID regionUUID) 320 public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
328 { 321 {
329 //Retrieve all values of current region, and current scene/or prims 322 //Retrieve all values of current region, and current scene/or prims
@@ -375,10 +368,6 @@ namespace OpenSim.Data.MSSQL
375 } 368 }
376 } 369 }
377 } 370 }
378 else
379 {
380 // m_log.Info("[DATASTORE]: Ignoring Physical obj: " + obj.UUID + " in region: " + regionUUID);
381 }
382 } 371 }
383 372
384 //Save changes 373 //Save changes
@@ -430,7 +419,7 @@ namespace OpenSim.Data.MSSQL
430 //TODO add index on PrimID in DB, if not already exist 419 //TODO add index on PrimID in DB, if not already exist
431 using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID")) 420 using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID"))
432 { 421 {
433 cmd.Parameters.AddWithValue("@primID", primID.ToString()); 422 cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
434 cmd.ExecuteNonQuery(); 423 cmd.ExecuteNonQuery();
435 } 424 }
436 425
@@ -470,7 +459,7 @@ namespace OpenSim.Data.MSSQL
470 459
471 using (SqlDataReader reader = cmd.ExecuteReader()) 460 using (SqlDataReader reader = cmd.ExecuteReader())
472 { 461 {
473 int rev = 0; 462 int rev;
474 if (reader.Read()) 463 if (reader.Read())
475 { 464 {
476 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]); 465 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
@@ -509,22 +498,21 @@ namespace OpenSim.Data.MSSQL
509 string sql = "delete from terrain where RegionUUID=@RegionUUID"; 498 string sql = "delete from terrain where RegionUUID=@RegionUUID";
510 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 499 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
511 { 500 {
512 cmd.Parameters.AddWithValue("@RegionUUID", regionID.ToString()); 501 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
513 cmd.ExecuteNonQuery(); 502 cmd.ExecuteNonQuery();
514 } 503 }
515 504
516 sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + 505 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
517 " values(@RegionUUID, @Revision, @Heightfield)";
518 506
519 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 507 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
520 { 508 {
521 cmd.Parameters.AddWithValue("@RegionUUID", regionID.ToString()); 509 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
522 cmd.Parameters.AddWithValue("@Revision", revision); 510 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
523 cmd.Parameters.AddWithValue("@Heightfield", serializeTerrain(terrain)); 511 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
524 cmd.ExecuteNonQuery(); 512 cmd.ExecuteNonQuery();
525 } 513 }
526 514
527 _Log.Info("[REGION DB]: Stored terrain revision r" + revision); 515 _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
528 } 516 }
529 517
530 /// <summary> 518 /// <summary>
@@ -541,12 +529,13 @@ namespace OpenSim.Data.MSSQL
541 //Retrieve all land data from region 529 //Retrieve all land data from region
542 using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql)) 530 using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql))
543 { 531 {
544 cmdLandData.Parameters.AddWithValue("@RegionUUID", regionUUID.ToString()); 532 cmdLandData.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
545 533
546 using (SqlDataReader readerLandData = cmdLandData.ExecuteReader()) 534 using (SqlDataReader readerLandData = cmdLandData.ExecuteReader())
547 { 535 {
548 while (readerLandData.Read()) 536 while (readerLandData.Read())
549 { 537 {
538 // LandData data = buildLandData(readerLandData);
550 landDataForRegion.Add(buildLandData(readerLandData)); 539 landDataForRegion.Add(buildLandData(readerLandData));
551 } 540 }
552 } 541 }
@@ -558,7 +547,7 @@ namespace OpenSim.Data.MSSQL
558 sql = "select * from landaccesslist where LandUUID = @LandUUID"; 547 sql = "select * from landaccesslist where LandUUID = @LandUUID";
559 using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql)) 548 using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql))
560 { 549 {
561 cmdAccessList.Parameters.AddWithValue("@LandUUID", landData.GlobalID.ToString()); 550 cmdAccessList.Parameters.Add(_Database.CreateParameter("@LandUUID", landData.GlobalID));
562 using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader()) 551 using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader())
563 { 552 {
564 while (readerAccessList.Read()) 553 while (readerAccessList.Read())
@@ -643,7 +632,7 @@ VALUES
643 RegionSettings regionSettings; 632 RegionSettings regionSettings;
644 using (AutoClosingSqlCommand cmd = _Database.Query(sql)) 633 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
645 { 634 {
646 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID.ToString())); 635 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
647 using (SqlDataReader reader = cmd.ExecuteReader()) 636 using (SqlDataReader reader = cmd.ExecuteReader())
648 { 637 {
649 if (reader.Read()) 638 if (reader.Read())
@@ -674,7 +663,7 @@ VALUES
674 public void StoreRegionSettings(RegionSettings regionSettings) 663 public void StoreRegionSettings(RegionSettings regionSettings)
675 { 664 {
676 //Little check if regionUUID already exist in DB 665 //Little check if regionUUID already exist in DB
677 string regionUUID = null; 666 string regionUUID;
678 using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID")) 667 using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID"))
679 { 668 {
680 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID)); 669 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
@@ -724,7 +713,7 @@ VALUES
724 { 713 {
725 DataTable dbItems = _PrimsDataSet.Tables["primitems"]; 714 DataTable dbItems = _PrimsDataSet.Tables["primitems"];
726 715
727 String sql = String.Format("primID = '{0}'", prim.UUID.ToString()); 716 String sql = String.Format("primID = '{0}'", prim.UUID);
728 DataRow[] dbItemRows = dbItems.Select(sql); 717 DataRow[] dbItemRows = dbItems.Select(sql);
729 718
730 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); 719 IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
@@ -1446,6 +1435,12 @@ VALUES
1446 1435
1447 #endregion 1436 #endregion
1448 1437
1438 /// <summary>
1439 /// Retrieves the prims data for region.
1440 /// </summary>
1441 /// <param name="regionUUID">The region UUID.</param>
1442 /// <param name="sceneGroupID">The scene group ID.</param>
1443 /// <param name="primID">The prim ID.</param>
1449 private void RetrievePrimsDataForRegion(UUID regionUUID, UUID sceneGroupID, string primID) 1444 private void RetrievePrimsDataForRegion(UUID regionUUID, UUID sceneGroupID, string primID)
1450 { 1445 {
1451 using (SqlConnection connection = _Database.DatabaseConnection()) 1446 using (SqlConnection connection = _Database.DatabaseConnection())
@@ -1482,6 +1477,9 @@ VALUES
1482 } 1477 }
1483 } 1478 }
1484 1479
1480 /// <summary>
1481 /// Commits the dataset.
1482 /// </summary>
1485 private void CommitDataSet() 1483 private void CommitDataSet()
1486 { 1484 {
1487 lock (_PrimsDataSet) 1485 lock (_PrimsDataSet)
@@ -1513,6 +1511,10 @@ VALUES
1513 } 1511 }
1514 } 1512 }
1515 1513
1514 /// <summary>
1515 /// Create commands for a dataadapter.
1516 /// </summary>
1517 /// <param name="dataAdapter">The data adapter.</param>
1516 private static void SetupCommands(SqlDataAdapter dataAdapter) 1518 private static void SetupCommands(SqlDataAdapter dataAdapter)
1517 { 1519 {
1518 SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); 1520 SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);