* 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. ::
0.6.0-stable
lbsa71 2008-04-11 09:56:22 +00:00
parent 00b8e04ece
commit cbf9fcfac5
7 changed files with 106 additions and 13 deletions

View File

@ -125,6 +125,11 @@ namespace OpenSim.Data.DB4o
} }
} }
override public DataResponse UpdateProfile(RegionProfileData profile)
{
return AddProfile(profile);
}
/// <summary> /// <summary>
/// Authenticates a new region using the shared secrets. NOT SECURE. /// Authenticates a new region using the shared secrets. NOT SECURE.
/// </summary> /// </summary>

View File

@ -18,5 +18,6 @@ namespace OpenSim.Data
public abstract string getVersion(); public abstract string getVersion();
public abstract DataResponse AddProfile(RegionProfileData profile); public abstract DataResponse AddProfile(RegionProfileData profile);
public abstract ReservationData GetReservationAtPoint(uint x, uint y); public abstract ReservationData GetReservationAtPoint(uint x, uint y);
public abstract DataResponse UpdateProfile(RegionProfileData profile);
} }
} }

View File

@ -113,6 +113,8 @@ namespace OpenSim.Data
/// <returns>RESPONSE_OK if successful, error if not.</returns> /// <returns>RESPONSE_OK if successful, error if not.</returns>
DataResponse AddProfile(RegionProfileData profile); DataResponse AddProfile(RegionProfileData profile);
DataResponse UpdateProfile(RegionProfileData profile);
ReservationData GetReservationAtPoint(uint x, uint y); ReservationData GetReservationAtPoint(uint x, uint y);
} }
} }

View File

@ -228,18 +228,6 @@ namespace OpenSim.Data.MSSQL
/// <returns>A dataresponse enum indicating success</returns> /// <returns>A dataresponse enum indicating success</returns>
override public DataResponse AddProfile(RegionProfileData profile) override public DataResponse AddProfile(RegionProfileData profile)
{ {
try
{
if (GetProfileByLLUUID(profile.UUID) != null)
{
return DataResponse.RESPONSE_OK;
}
}
catch (Exception)
{
System.Console.WriteLine("No regions found. Create new one.");
}
if (insertRegionRow(profile)) if (insertRegionRow(profile))
{ {
return DataResponse.RESPONSE_OK; return DataResponse.RESPONSE_OK;
@ -250,6 +238,83 @@ namespace OpenSim.Data.MSSQL
} }
} }
public override DataResponse UpdateProfile(RegionProfileData profile)
{
if (updateRegionRow(profile))
{
return DataResponse.RESPONSE_OK;
}
else
{
return DataResponse.RESPONSE_ERROR;
}
}
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<string, string> parameters = new Dictionary<string, string>();
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;
}
/// <summary> /// <summary>
/// Creates a new region in the database /// Creates a new region in the database
/// </summary> /// </summary>

View File

@ -309,6 +309,11 @@ namespace OpenSim.Data.MySQL
} }
} }
override public DataResponse UpdateProfile(RegionProfileData profile)
{
return AddProfile(profile);
}
/// <summary> /// <summary>
/// Deletes a profile from the database /// Deletes a profile from the database
/// </summary> /// </summary>

View File

@ -188,6 +188,11 @@ namespace OpenSim.Data.SQLite
} }
} }
override public DataResponse UpdateProfile(RegionProfileData profile)
{
return AddProfile(profile);
}
/// <summary> /// <summary>
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary> /// </summary>

View File

@ -333,7 +333,17 @@ namespace OpenSim.Grid.GridServer
{ {
try 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) switch (insertResponse)
{ {
case DataResponse.RESPONSE_OK: case DataResponse.RESPONSE_OK: