* Adds a grid db implementation and unit tests to the NHibernate module
0.6.3-post-fixes
Justin Clarke Casey 2009-01-20 18:38:51 +00:00
parent 84a4a9ecf7
commit 37f7c5a0ea
10 changed files with 461 additions and 42 deletions

View File

@ -77,6 +77,7 @@ Patches
* Salahzar Stenvaag
* sempuki
* tglion
* tlaukkan/Tommil
* tyre
* Vytek
* webmage (IBM)

View File

@ -0,0 +1,241 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using System.Reflection;
using OpenSim.Framework;
using NHibernate;
using NHibernate.Criterion;
using System.Collections;
using OpenMetaverse;
namespace OpenSim.Data.NHibernate
{
/// <summary>
/// A GridData Interface to the NHibernate database
/// </summary>
public class NHibernateGridData : GridDataBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public NHibernateManager manager;
public override void Initialise()
{
m_log.Info("[NHibernateGridData]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException(Name);
}
public override void Initialise(string connect)
{
m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateGridData");
manager = new NHibernateManager(connect, "GridStore");
}
/***********************************************************************
*
* Public Interface Functions
*
**********************************************************************/
public override void Dispose() { }
/// <summary>
/// The plugin being loaded
/// </summary>
/// <returns>A string containing the plugin name</returns>
public override string Name
{
get { return "NHibernate Grid Data Interface"; }
}
/// <summary>
/// The plugins version
/// </summary>
/// <returns>A string containing the plugin version</returns>
public override string Version
{
get
{
Module module = GetType().Module;
Version dllVersion = module.Assembly.GetName().Version;
return string.Format("{0}.{1}.{2}.{3}",
dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
}
}
public override bool AuthenticateSim(OpenMetaverse.UUID UUID, ulong regionHandle, string simrecvkey)
{
bool throwHissyFit = false; // Should be true by 1.0
if (throwHissyFit)
throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
RegionProfileData data = GetProfileByUUID(UUID);
return (regionHandle == data.regionHandle && simrecvkey == data.regionSecret);
}
public override ReservationData GetReservationAtPoint(uint x, uint y)
{
throw new NotImplementedException();
}
public override DataResponse AddProfile(RegionProfileData profile)
{
if (manager.Load(typeof(RegionProfileData), profile.Uuid) == null)
{
manager.Save(profile);
return DataResponse.RESPONSE_OK;
}
else
{
return DataResponse.RESPONSE_ERROR;
}
}
public override DataResponse UpdateProfile(RegionProfileData profile)
{
if (manager.Load(typeof(RegionProfileData), profile.Uuid) != null)
{
manager.Update(profile);
return DataResponse.RESPONSE_OK;
}
else
{
return DataResponse.RESPONSE_ERROR;
}
}
public override DataResponse DeleteProfile(string uuid)
{
RegionProfileData regionProfileData = (RegionProfileData)manager.Load(typeof(RegionProfileData), new UUID(uuid));
if (regionProfileData != null)
{
manager.Delete(regionProfileData);
return DataResponse.RESPONSE_OK;
}
return DataResponse.RESPONSE_ERROR;
}
public override RegionProfileData GetProfileByUUID(OpenMetaverse.UUID UUID)
{
return (RegionProfileData)manager.Load(typeof(RegionProfileData), UUID);
}
public override RegionProfileData GetProfileByHandle(ulong regionHandle)
{
using (ISession session = manager.GetSession())
{
ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
criteria.Add(Expression.Eq("RegionHandle", regionHandle));
IList regions = criteria.List();
if (regions.Count == 1)
{
return (RegionProfileData)regions[0];
}
else
{
return null;
}
}
}
public override RegionProfileData GetProfileByString(string regionName)
{
using (ISession session = manager.GetSession())
{
ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
criteria.Add(Expression.Eq("RegionName", regionName));
IList regions = criteria.List();
if (regions.Count == 1)
{
return (RegionProfileData)regions[0];
}
else
{
return null;
}
}
}
public override RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax)
{
using (ISession session = manager.GetSession())
{
ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
criteria.Add(Expression.Ge("RegionLocX", Xmin));
criteria.Add(Expression.Ge("RegionLocY", Ymin));
criteria.Add(Expression.Le("RegionLocX", Xmax));
criteria.Add(Expression.Le("RegionLocY", Ymax));
IList regions = criteria.List();
RegionProfileData[] regionArray = new RegionProfileData[regions.Count];
for(int i=0;i<regionArray.Length;i++)
{
regionArray[i] = (RegionProfileData)regions[i];
}
return regionArray;
}
}
public override List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum)
{
using (ISession session = manager.GetSession())
{
ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
criteria.SetMaxResults((int)maxNum);
criteria.Add(Expression.Like("RegionName", namePrefix, MatchMode.Start));
IList regions = criteria.List();
List<RegionProfileData> regionList = new List<RegionProfileData>();
foreach (RegionProfileData regionProfileData in regions)
{
regionList.Add(regionProfileData);
}
return regionList;
}
}
}
}

View File

@ -140,9 +140,9 @@ namespace OpenSim.Data.NHibernate
{
obj = session.Get(type.FullName, uuid);
}
catch (Exception)
catch (Exception e)
{
m_log.ErrorFormat("[NHIBERNATE] {0} not found with ID {1} ", type.Name, uuid);
m_log.ErrorFormat("[NHIBERNATE] {0} of id {1} loading threw exception: "+ e.ToString(), type.Name, uuid);
}
return obj;
}

View File

@ -1,5 +1,5 @@
create table Regions (
Uuid NVARCHAR(255) not null,
Uuid NVARCHAR(36) not null,
RegionHandle BIGINT null,
RegionName NVARCHAR(32) null,
RegionRecvKey NVARCHAR(128) null,
@ -24,9 +24,9 @@ create table Regions (
RegionUserSendKey NVARCHAR(128) null,
ServerHttpPort INT null,
ServerRemotingPort INT null,
RegionMapTextureID NVARCHAR(255) null,
Owner_uuid NVARCHAR(255) null,
OriginUUID NVARCHAR(255) null,
RegionMapTextureID NVARCHAR(36) null,
Owner_uuid NVARCHAR(36) null,
OriginUUID NVARCHAR(36) null,
primary key (Uuid)
)
create index region_handle on Regions (RegionHandle)

View File

@ -24,10 +24,10 @@ CREATE TABLE Regions (
RegionUserURI VARCHAR(255) DEFAULT NULL,
RegionUserRecvKey VARCHAR(128) DEFAULT NULL,
RegionUserSendKey VARCHAR(128) DEFAULT NULL,
RegionMapTexture VARCHAR(36) DEFAULT NULL,
RegionMapTextureId VARCHAR(36) DEFAULT NULL,
ServerHttpPort INT DEFAULT NULL,
ServerRemotingPort INT DEFAULT NULL,
PRIMARY KEY (uuid),
PRIMARY KEY (RegionID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev. 1';
CREATE INDEX RegionNameIndex ON Regions (RegionName);

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Data.RegionProfileData, OpenSim.Data" table="Regions" lazy="false">
<id name="Uuid" column="RegionID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="Owner_uuid" column="OwnerID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate" />
<property name="OriginUUID" column="OriginID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate" />
<property name="RegionHandle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="RegionName" type="String" length="32" />
<property name="RegionRecvKey" type="String" length="128" />
<property name="RegionSendKey" type="String" length="128" />
<property name="RegionSecret" type="String" length="128" />
<property name="RegionDataURI" type="String" length="255" />
<property name="ServerIP" type="String" length="64" />
<property name="ServerPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="ServerURI" type="String" length="255" />
<property name="RegionLocX" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="RegionLocY" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="RegionLocZ" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="EastOverrideHandle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="WestOverrideHandle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="SouthOverrideHandle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="NorthOverrideHandle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="RegionAssetURI" type="String" length="255" />
<property name="RegionAssetRecvKey" type="String" length="128" />
<property name="RegionAssetSendKey" type="String" length="128" />
<property name="RegionUserURI" type="String" length="255" />
<property name="RegionUserRecvKey" type="String" length="128" />
<property name="RegionUserSendKey" type="String" length="128" />
<property name="RegionMapTextureID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate" />
<property name="ServerHttpPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="ServerRemotingPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
</class>
</hibernate-mapping>

View File

@ -141,36 +141,5 @@
<property name="Flags" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="InvType" type="System.Int32" />
</class>
<class name="OpenSim.Data.RegionProfileData, OpenSim.Data" table="Regions" lazy="false">
<id name="Uuid" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="RegionHandle" index="region_handle" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="RegionName" index="region_name" type="String" length="32"/>
<property name="RegionRecvKey" type="String" length="128"/>
<property name="RegionSendKey" type="String" length="128"/>
<property name="RegionSecret" type="String" length="128"/>
<property name="RegionDataURI" type="String" length="255"/>
<property name="ServerIP" type="String" length="64"/>
<property name="ServerPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="ServerURI" type="String" length="255"/>
<property name="RegionLocX" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="RegionLocY" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="RegionLocZ" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="EastOverrideHandle" index="overrideHandles" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="WestOverrideHandle" index="overrideHandles" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="SouthOverrideHandle" index="overrideHandles" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="NorthOverrideHandle" index="overrideHandles" type="OpenSim.Data.NHibernate.UInt64Type, OpenSim.Data.NHibernate" />
<property name="RegionAssetURI" type="String" length="255"/>
<property name="RegionAssetRecvKey" type="String" length="128"/>
<property name="RegionAssetSendKey" type="String" length="128"/>
<property name="RegionUserURI" type="String" length="255"/>
<property name="RegionUserRecvKey" type="String" length="128"/>
<property name="RegionUserSendKey" type="String" length="128"/>
<property name="ServerHttpPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="ServerRemotingPort" type="OpenSim.Data.NHibernate.UInt32Type, OpenSim.Data.NHibernate" />
<property name="RegionMapTextureID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate"/>
<property name="Owner_uuid" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate"/>
<property name="OriginUUID" type="OpenSim.Data.NHibernate.UUIDUserType, OpenSim.Data.NHibernate"/>
</class>
</hibernate-mapping>

View File

@ -22,12 +22,12 @@ CREATE TABLE Regions (
RegionUserURI VARCHAR(255) DEFAULT NULL,
RegionUserRecvKey VARCHAR(128) DEFAULT NULL,
RegionUserSendKey VARCHAR(128) DEFAULT NULL,
regionMapTexture VARCHAR(36) DEFAULT NULL,
RegionMapTextureId VARCHAR(36) DEFAULT NULL,
ServerHttpPort INT DEFAULT NULL,
ServerRemotingPort INT DEFAULT NULL,
OwnerID VARCHAR(36) DEFAULT NULL,
OriginID VARCHAR(36) DEFAULT NULL,
PRIMARY KEY (uuid),
PRIMARY KEY (RegionId)
);
CREATE INDEX RegionNameIndex ON Regions (RegionName);

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.IO;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenSim.Framework;
using OpenSim.Data.Tests;
using OpenSim.Region.Environment.Scenes;
using OpenMetaverse;
using OpenSim.Data.NHibernate;
namespace OpenSim.Data.NHibernate.Tests
{
[TestFixture]
public class NHibernateMySQLGridTest : BasicGridTest
{
public string file;
public NHibernateManager database;
public string connect = "MySQL5Dialect;MySqlDataDriver;Server=localhost;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit";
[TestFixtureSetUp]
public void Init()
{
SuperInit();
// If we manage to connect to the database with the user
// and password above it is our test database, and run
// these tests. If anything goes wrong, ignore these
// tests.
try
{
db = new NHibernateGridData();
db.Initialise(connect);
database = ((NHibernateGridData)db).manager;
}
catch (Exception e)
{
System.Console.WriteLine("Exception {0}", e);
Assert.Ignore();
}
}
[TestFixtureTearDown]
public void Cleanup()
{
if (db != null)
{
db.Dispose();
}
if (database != null)
{
database.DropSchema();
}
}
}
}

View File

@ -0,0 +1,82 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.IO;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenSim.Framework;
using OpenSim.Data.Tests;
using OpenSim.Region.Environment.Scenes;
using OpenMetaverse;
using OpenSim.Data.NHibernate;
namespace OpenSim.Data.NHibernate.Tests
{
[TestFixture]
public class NHibernateSQLiteGridTest : BasicGridTest
{
public string file;
public NHibernateManager database;
public string connect = "SQLiteDialect;SQLite20Driver;Data Source=" + Path.GetTempFileName() + ".db;Version=3";
[TestFixtureSetUp]
public void Init()
{
SuperInit();
// If we manage to connect to the database with the user
// and password above it is our test database, and run
// these tests. If anything goes wrong, ignore these
// tests.
try
{
db = new NHibernateGridData();
db.Initialise(connect);
database = ((NHibernateGridData)db).manager;
}
catch (Exception e)
{
System.Console.WriteLine("Exception {0}", e);
Assert.Ignore();
}
}
[TestFixtureTearDown]
public void Cleanup()
{
if (db != null)
{
db.Dispose();
}
if (database != null)
{
database.DropSchema();
}
}
}
}