aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLSimulationData.cs45
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs47
-rw-r--r--OpenSim/Data/SQLite/SQLiteSimulationData.cs40
3 files changed, 48 insertions, 84 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
index 8adddc9..dbfd16c 100644
--- a/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLSimulationData.cs
@@ -49,6 +49,7 @@ namespace OpenSim.Data.MSSQL
49 49
50 // private static FileSystemDataStore Instance = new FileSystemDataStore(); 50 // private static FileSystemDataStore Instance = new FileSystemDataStore();
51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private static string LogHeader = "[REGION DB MSSQL]";
52 53
53 /// <summary> 54 /// <summary>
54 /// The database manager 55 /// The database manager
@@ -569,15 +570,19 @@ ELSE
569 return terrain; 570 return terrain;
570 } 571 }
571 572
573 // Legacy entry point for when terrain was always a 256x256 hieghtmap
574 public void StoreTerrain(double[,] ter, UUID regionID)
575 {
576 StoreTerrain(new HeightmapTerrainData(ter), regionID);
577 }
578
572 /// <summary> 579 /// <summary>
573 /// Stores the terrain map to DB. 580 /// Stores the terrain map to DB.
574 /// </summary> 581 /// </summary>
575 /// <param name="terrain">terrain map data.</param> 582 /// <param name="terrain">terrain map data.</param>
576 /// <param name="regionID">regionID.</param> 583 /// <param name="regionID">regionID.</param>
577 public void StoreTerrain(double[,] terrain, UUID regionID) 584 public void StoreTerrain(TerrainData terrData, UUID regionID)
578 { 585 {
579 int revision = (int)DBTerrainRevision.Legacy256;
580
581 //Delete old terrain map 586 //Delete old terrain map
582 string sql = "delete from terrain where RegionUUID=@RegionUUID"; 587 string sql = "delete from terrain where RegionUUID=@RegionUUID";
583 using (SqlConnection conn = new SqlConnection(m_connectionString)) 588 using (SqlConnection conn = new SqlConnection(m_connectionString))
@@ -590,17 +595,21 @@ ELSE
590 595
591 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)"; 596 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
592 597
598 int terrainDBRevision;
599 Array terrainDBblob;
600 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
601
593 using (SqlConnection conn = new SqlConnection(m_connectionString)) 602 using (SqlConnection conn = new SqlConnection(m_connectionString))
594 using (SqlCommand cmd = new SqlCommand(sql, conn)) 603 using (SqlCommand cmd = new SqlCommand(sql, conn))
595 { 604 {
596 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID)); 605 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
597 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision)); 606 cmd.Parameters.Add(_Database.CreateParameter("@Revision", terrainDBRevision));
598 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain))); 607 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", terrainDBblob));
599 conn.Open(); 608 conn.Open();
600 cmd.ExecuteNonQuery(); 609 cmd.ExecuteNonQuery();
601 } 610 }
602 611
603 _Log.Info("[REGION DB]: Stored terrain revision r " + revision); 612 _Log.InfoFormat("{0} Stored terrain revision r={1}", LogHeader, terrainDBRevision);
604 } 613 }
605 614
606 /// <summary> 615 /// <summary>
@@ -1345,30 +1354,6 @@ VALUES
1345 #region Private Methods 1354 #region Private Methods
1346 1355
1347 /// <summary> 1356 /// <summary>
1348 /// Serializes the terrain data for storage in DB.
1349 /// </summary>
1350 /// <param name="val">terrain data</param>
1351 /// <returns></returns>
1352 private static Array serializeTerrain(double[,] val)
1353 {
1354 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
1355 BinaryWriter bw = new BinaryWriter(str);
1356
1357 // TODO: COMPATIBILITY - Add byte-order conversions
1358 for (int x = 0; x < (int)Constants.RegionSize; x++)
1359 for (int y = 0; y < (int)Constants.RegionSize; y++)
1360 {
1361 double height = val[x, y];
1362 if (height == 0.0)
1363 height = double.Epsilon;
1364
1365 bw.Write(height);
1366 }
1367
1368 return str.ToArray();
1369 }
1370
1371 /// <summary>
1372 /// Stores new regionsettings. 1357 /// Stores new regionsettings.
1373 /// </summary> 1358 /// </summary>
1374 /// <param name="regionSettings">The region settings.</param> 1359 /// <param name="regionSettings">The region settings.</param>
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index 5751dc8..4bd8617 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -48,6 +48,7 @@ namespace OpenSim.Data.MySQL
48 public class MySQLSimulationData : ISimulationDataStore 48 public class MySQLSimulationData : ISimulationDataStore
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 private static string LogHeader = "[REGION DB MYSQL]";
51 52
52 private string m_connectionString; 53 private string m_connectionString;
53 private object m_dbLock = new object(); 54 private object m_dbLock = new object();
@@ -91,7 +92,7 @@ namespace OpenSim.Data.MySQL
91 } 92 }
92 catch (Exception e) 93 catch (Exception e)
93 { 94 {
94 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message); 95 m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
95 throw; 96 throw;
96 } 97 }
97 98
@@ -572,11 +573,14 @@ namespace OpenSim.Data.MySQL
572 } 573 }
573 } 574 }
574 575
576 // Legacy entry point for when terrain was always a 256x256 hieghtmap
575 public void StoreTerrain(double[,] ter, UUID regionID) 577 public void StoreTerrain(double[,] ter, UUID regionID)
576 { 578 {
577 m_log.Info("[REGION DB]: Storing terrain"); 579 StoreTerrain(new HeightmapTerrainData(ter), regionID);
578 int revision = (int)DBTerrainRevision.Legacy256; 580 }
579 581
582 public void StoreTerrain(TerrainData terrData, UUID regionID)
583 {
580 lock (m_dbLock) 584 lock (m_dbLock)
581 { 585 {
582 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 586 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
@@ -590,11 +594,18 @@ namespace OpenSim.Data.MySQL
590 594
591 ExecuteNonQuery(cmd); 595 ExecuteNonQuery(cmd);
592 596
597 int terrainDBRevision;
598 Array terrainDBblob;
599 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
600
601 m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}",
602 LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision);
603
593 cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)" 604 cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)"
594 + "values (?RegionUUID, ?Revision, ?Heightfield)"; 605 + "values (?RegionUUID, ?Revision, ?Heightfield)";
595 606
596 cmd.Parameters.AddWithValue("Revision", revision); 607 cmd.Parameters.AddWithValue("Revision", terrainDBRevision);
597 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); 608 cmd.Parameters.AddWithValue("Heightfield", terrainDBblob);
598 609
599 ExecuteNonQuery(cmd); 610 ExecuteNonQuery(cmd);
600 } 611 }
@@ -1526,30 +1537,6 @@ namespace OpenSim.Data.MySQL
1526 } 1537 }
1527 1538
1528 /// <summary> 1539 /// <summary>
1529 ///
1530 /// </summary>
1531 /// <param name="val"></param>
1532 /// <returns></returns>
1533 private static Array SerializeTerrain(double[,] val)
1534 {
1535 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1536 BinaryWriter bw = new BinaryWriter(str);
1537
1538 // TODO: COMPATIBILITY - Add byte-order conversions
1539 for (int x = 0; x < (int)Constants.RegionSize; x++)
1540 for (int y = 0; y < (int)Constants.RegionSize; y++)
1541 {
1542 double height = val[x, y];
1543 if (height == 0.0)
1544 height = double.Epsilon;
1545
1546 bw.Write(height);
1547 }
1548
1549 return str.ToArray();
1550 }
1551
1552 /// <summary>
1553 /// Fill the prim command with prim values 1540 /// Fill the prim command with prim values
1554 /// </summary> 1541 /// </summary>
1555 /// <param name="row"></param> 1542 /// <param name="row"></param>
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
index b70af6b..cce59c1 100644
--- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs
+++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs
@@ -51,6 +51,7 @@ namespace OpenSim.Data.SQLite
51 public class SQLiteSimulationData : ISimulationDataStore 51 public class SQLiteSimulationData : ISimulationDataStore
52 { 52 {
53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 53 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 private static readonly string LogHeader = "[REGION DB SQLLITE]";
54 55
55 private const string primSelect = "select * from prims"; 56 private const string primSelect = "select * from prims";
56 private const string shapeSelect = "select * from primshapes"; 57 private const string shapeSelect = "select * from primshapes";
@@ -819,17 +820,21 @@ namespace OpenSim.Data.SQLite
819 prim.Inventory.RestoreInventoryItems(inventory); 820 prim.Inventory.RestoreInventoryItems(inventory);
820 } 821 }
821 822
823 // Legacy entry point for when terrain was always a 256x256 hieghtmap
824 public void StoreTerrain(double[,] ter, UUID regionID)
825 {
826 StoreTerrain(new HeightmapTerrainData(ter), regionID);
827 }
828
822 /// <summary> 829 /// <summary>
823 /// Store a terrain revision in region storage 830 /// Store a terrain revision in region storage
824 /// </summary> 831 /// </summary>
825 /// <param name="ter">terrain heightfield</param> 832 /// <param name="ter">terrain heightfield</param>
826 /// <param name="regionID">region UUID</param> 833 /// <param name="regionID">region UUID</param>
827 public void StoreTerrain(double[,] ter, UUID regionID) 834 public void StoreTerrain(TerrainData terrData, UUID regionID)
828 { 835 {
829 lock (ds) 836 lock (ds)
830 { 837 {
831 int revision = (int)DBTerrainRevision.Legacy256;
832
833 using ( 838 using (
834 SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn)) 839 SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn))
835 { 840 {
@@ -839,15 +844,20 @@ namespace OpenSim.Data.SQLite
839 844
840 // the following is an work around for .NET. The perf 845 // the following is an work around for .NET. The perf
841 // issues associated with it aren't as bad as you think. 846 // issues associated with it aren't as bad as you think.
842 m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
843 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + 847 String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
844 " values(:RegionUUID, :Revision, :Heightfield)"; 848 " values(:RegionUUID, :Revision, :Heightfield)";
845 849
850 int terrainDBRevision;
851 Array terrainDBblob;
852 terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
853
854 m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision);
855
846 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) 856 using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
847 { 857 {
848 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); 858 cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
849 cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); 859 cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision));
850 cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); 860 cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob));
851 cmd.ExecuteNonQuery(); 861 cmd.ExecuteNonQuery();
852 } 862 }
853 } 863 }
@@ -2006,24 +2016,6 @@ namespace OpenSim.Data.SQLite
2006 return entry; 2016 return entry;
2007 } 2017 }
2008 2018
2009 /// <summary>
2010 ///
2011 /// </summary>
2012 /// <param name="val"></param>
2013 /// <returns></returns>
2014 private static Array serializeTerrain(double[,] val)
2015 {
2016 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
2017 BinaryWriter bw = new BinaryWriter(str);
2018
2019 // TODO: COMPATIBILITY - Add byte-order conversions
2020 for (int x = 0; x < (int)Constants.RegionSize; x++)
2021 for (int y = 0; y < (int)Constants.RegionSize; y++)
2022 bw.Write(val[x, y]);
2023
2024 return str.ToArray();
2025 }
2026
2027 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) 2019 // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
2028 // { 2020 // {
2029 // row["RegionUUID"] = regionUUID; 2021 // row["RegionUUID"] = regionUUID;