From cbf9fcfac591bd8c8fcbccaa562c7a5fa05c4d9c Mon Sep 17 00:00:00 2001
From: lbsa71
Date: Fri, 11 Apr 2008 09:56:22 +0000
Subject: * Discerned between AddProfile and UpdateProfile in region
registration
:: Believe it or not, but INSERT/UPDATE is actually a better pattern than REPLACE, since, with INSERT/UPDATE you can catch erroneous UPDATES to non-INSERTed items as well as catch erroneous re-INSERTS. in 95% of the cases, you SHOULD have a clear INSERT context, and a clear and separate UPDATE context. If you think your case falls within the 5%, maybe you should re-evaluate your code. ::
---
OpenSim/Data/DB4o/DB4oGridData.cs | 5 +++
OpenSim/Data/GridDataBase.cs | 1 +
OpenSim/Data/IGridData.cs | 2 +
OpenSim/Data/MSSQL/MSSQLGridData.cs | 81 ++++++++++++++++++++++++++++++----
OpenSim/Data/MySQL/MySQLGridData.cs | 5 +++
OpenSim/Data/SQLite/SQLiteGridData.cs | 5 +++
OpenSim/Grid/GridServer/GridManager.cs | 12 ++++-
7 files changed, 102 insertions(+), 9 deletions(-)
diff --git a/OpenSim/Data/DB4o/DB4oGridData.cs b/OpenSim/Data/DB4o/DB4oGridData.cs
index 797fdd4..c388cb6 100644
--- a/OpenSim/Data/DB4o/DB4oGridData.cs
+++ b/OpenSim/Data/DB4o/DB4oGridData.cs
@@ -125,6 +125,11 @@ namespace OpenSim.Data.DB4o
}
}
+ override public DataResponse UpdateProfile(RegionProfileData profile)
+ {
+ return AddProfile(profile);
+ }
+
///
/// Authenticates a new region using the shared secrets. NOT SECURE.
///
diff --git a/OpenSim/Data/GridDataBase.cs b/OpenSim/Data/GridDataBase.cs
index 004ec9b..5648c34 100644
--- a/OpenSim/Data/GridDataBase.cs
+++ b/OpenSim/Data/GridDataBase.cs
@@ -18,5 +18,6 @@ namespace OpenSim.Data
public abstract string getVersion();
public abstract DataResponse AddProfile(RegionProfileData profile);
public abstract ReservationData GetReservationAtPoint(uint x, uint y);
+ public abstract DataResponse UpdateProfile(RegionProfileData profile);
}
}
diff --git a/OpenSim/Data/IGridData.cs b/OpenSim/Data/IGridData.cs
index feb372e..c924031 100644
--- a/OpenSim/Data/IGridData.cs
+++ b/OpenSim/Data/IGridData.cs
@@ -113,6 +113,8 @@ namespace OpenSim.Data
/// RESPONSE_OK if successful, error if not.
DataResponse AddProfile(RegionProfileData profile);
+ DataResponse UpdateProfile(RegionProfileData profile);
+
ReservationData GetReservationAtPoint(uint x, uint y);
}
}
diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs
index 03af53c..5617900 100644
--- a/OpenSim/Data/MSSQL/MSSQLGridData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs
@@ -228,19 +228,19 @@ namespace OpenSim.Data.MSSQL
/// A dataresponse enum indicating success
override public DataResponse AddProfile(RegionProfileData profile)
{
- try
+ if (insertRegionRow(profile))
{
- if (GetProfileByLLUUID(profile.UUID) != null)
- {
- return DataResponse.RESPONSE_OK;
- }
+ return DataResponse.RESPONSE_OK;
}
- catch (Exception)
+ else
{
- System.Console.WriteLine("No regions found. Create new one.");
+ return DataResponse.RESPONSE_ERROR;
}
+ }
- if (insertRegionRow(profile))
+ public override DataResponse UpdateProfile(RegionProfileData profile)
+ {
+ if (updateRegionRow(profile))
{
return DataResponse.RESPONSE_OK;
}
@@ -250,6 +250,71 @@ namespace OpenSim.Data.MSSQL
}
}
+ public bool updateRegionRow(RegionProfileData profile)
+ {
+ //Insert new region
+ string sql =
+ "UPDATE " + m_regionsTableName + @" SET
+ [regionHandle]=@regionHandle, [regionName]=@regionName,
+ [regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
+ [regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
+ [locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
+ [westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
+ [northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
+ [regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
+ [regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
+ [regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
+ [serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid
+ where [uuid]=@uuid";
+
+ Dictionary parameters = new Dictionary();
+
+ parameters["regionHandle"] = profile.regionHandle.ToString();
+ parameters["regionName"] = profile.regionName;
+ parameters["uuid"] = profile.UUID.ToString();
+ parameters["regionRecvKey"] = profile.regionRecvKey;
+ parameters["regionSecret"] = profile.regionSecret;
+ parameters["regionSendKey"] = profile.regionSendKey;
+ parameters["regionDataURI"] = profile.regionDataURI;
+ parameters["serverIP"] = profile.serverIP;
+ parameters["serverPort"] = profile.serverPort.ToString();
+ parameters["serverURI"] = profile.serverURI;
+ parameters["locX"] = profile.regionLocX.ToString();
+ parameters["locY"] = profile.regionLocY.ToString();
+ parameters["locZ"] = profile.regionLocZ.ToString();
+ parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
+ parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
+ parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
+ parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
+ parameters["regionAssetURI"] = profile.regionAssetURI;
+ parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
+ parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
+ parameters["regionUserURI"] = profile.regionUserURI;
+ parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
+ parameters["regionUserSendKey"] = profile.regionUserSendKey;
+ parameters["regionMapTexture"] = profile.regionMapTextureID.ToString();
+ parameters["serverHttpPort"] = profile.httpPort.ToString();
+ parameters["serverRemotingPort"] = profile.remotingPort.ToString();
+ parameters["owner_uuid"] = profile.owner_uuid.ToString();
+
+ bool returnval = false;
+
+ try
+ {
+ IDbCommand result = database.Query(sql, parameters);
+
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
+
+ result.Dispose();
+ }
+ catch (Exception e)
+ {
+ m_log.Error("MSSQLManager : " + e.ToString());
+ }
+
+ return returnval;
+ }
///
/// Creates a new region in the database
///
diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs
index 610dfaf..639f899 100644
--- a/OpenSim/Data/MySQL/MySQLGridData.cs
+++ b/OpenSim/Data/MySQL/MySQLGridData.cs
@@ -309,6 +309,11 @@ namespace OpenSim.Data.MySQL
}
}
+ override public DataResponse UpdateProfile(RegionProfileData profile)
+ {
+ return AddProfile(profile);
+ }
+
///
/// Deletes a profile from the database
///
diff --git a/OpenSim/Data/SQLite/SQLiteGridData.cs b/OpenSim/Data/SQLite/SQLiteGridData.cs
index c52eb29..f07b98f 100644
--- a/OpenSim/Data/SQLite/SQLiteGridData.cs
+++ b/OpenSim/Data/SQLite/SQLiteGridData.cs
@@ -188,6 +188,11 @@ namespace OpenSim.Data.SQLite
}
}
+ override public DataResponse UpdateProfile(RegionProfileData profile)
+ {
+ return AddProfile(profile);
+ }
+
///
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
///
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
index 5ca8cf7..7b41f6e 100644
--- a/OpenSim/Grid/GridServer/GridManager.cs
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -333,7 +333,17 @@ namespace OpenSim.Grid.GridServer
{
try
{
- DataResponse insertResponse = kvp.Value.AddProfile(sim);
+ DataResponse insertResponse;
+
+ if( existingSim == null )
+ {
+ insertResponse = kvp.Value.AddProfile(sim);
+ }
+ else
+ {
+ insertResponse = kvp.Value.UpdateProfile(sim);
+ }
+
switch (insertResponse)
{
case DataResponse.RESPONSE_OK:
--
cgit v1.1