From a583d8ad70daad8c755c2f43e2f2af7bc5b7ee4d Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sat, 14 Feb 2009 19:47:02 +0000 Subject: Thank you kindly, TLaukkan (Tommil) for a patch that: * Created value object for EstateRegionLink for storing the estate region relationship. * Refactored slightly NHibernateManager and NHibernateXXXXData implementations for accesing nhibernate generated ID on insert. ** Changed NHibernateManager.Save method name to Insert as it does Insert. ** Changed NHibernateManager.Save return value object as ID can be both UUID and uint currently. ** Changed NHibernateManager.Load method Id parameter to object as it can be both UUID and uint. * Created NHibernateEstateData implementation. This is the actual estate storage. * Created NHibernate mapping files for both EstateSettings and EstateRegionLink * Created MigrationSyntaxDifferences.txt files to write notes about differences in migration scripts between different databases. * Created estate storage migration scripts for all four databases. * Created estate unit test classes for all four databases. * Updated one missing field to BasicEstateTest.cs * Tested NHibernate unit tests with NUnit GUI. Asset databases fail but that is not related to this patch. * Tested build with both Visual Studio and nant. * Executed build tests with nant succesfully. --- OpenSim/Data/NHibernate/EstateRegionLink.cs | 49 +++++++ OpenSim/Data/NHibernate/NHibernateAssetData.cs | 5 +- OpenSim/Data/NHibernate/NHibernateEstateData.cs | 161 +++++++++++++++++++++ OpenSim/Data/NHibernate/NHibernateGridData.cs | 2 +- OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 74 +++++----- OpenSim/Data/NHibernate/NHibernateManager.cs | 14 +- OpenSim/Data/NHibernate/NHibernateRegionData.cs | 10 +- OpenSim/Data/NHibernate/NHibernateUserData.cs | 10 +- .../NHibernate/Resources/EstateRegionLink.hbm.xml | 12 ++ .../NHibernate/Resources/EstateSettings.hbm.xml | 39 +++++ .../Resources/MigrationSyntaxDifferences.txt | 14 ++ .../Resources/MsSql2005Dialect/001_EstateStore.sql | 40 +++++ .../Resources/MySQLDialect/001_EstateStore.sql | 40 +++++ .../PostgreSQLDialect/001_EstateStore.sql | 40 +++++ .../Resources/SQLiteDialect/001_EstateStore.sql | 40 +++++ .../NHibernate/Tests/NHibernateMsSqlEstateTest.cs | 77 ++++++++++ .../NHibernate/Tests/NHibernateMySqlEstateTest.cs | 76 ++++++++++ .../Tests/NHibernatePostgreSQLEstateTest.cs | 76 ++++++++++ .../NHibernate/Tests/NHibernateSQLiteEstateTest.cs | 78 ++++++++++ OpenSim/Data/Tests/BasicEstateTest.cs | 3 + 20 files changed, 803 insertions(+), 57 deletions(-) create mode 100644 OpenSim/Data/NHibernate/EstateRegionLink.cs create mode 100644 OpenSim/Data/NHibernate/NHibernateEstateData.cs create mode 100644 OpenSim/Data/NHibernate/Resources/EstateRegionLink.hbm.xml create mode 100644 OpenSim/Data/NHibernate/Resources/EstateSettings.hbm.xml create mode 100644 OpenSim/Data/NHibernate/Resources/MigrationSyntaxDifferences.txt create mode 100644 OpenSim/Data/NHibernate/Resources/MsSql2005Dialect/001_EstateStore.sql create mode 100644 OpenSim/Data/NHibernate/Resources/MySQLDialect/001_EstateStore.sql create mode 100644 OpenSim/Data/NHibernate/Resources/PostgreSQLDialect/001_EstateStore.sql create mode 100644 OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_EstateStore.sql create mode 100644 OpenSim/Data/NHibernate/Tests/NHibernateMsSqlEstateTest.cs create mode 100644 OpenSim/Data/NHibernate/Tests/NHibernateMySqlEstateTest.cs create mode 100644 OpenSim/Data/NHibernate/Tests/NHibernatePostgreSQLEstateTest.cs create mode 100644 OpenSim/Data/NHibernate/Tests/NHibernateSQLiteEstateTest.cs (limited to 'OpenSim') diff --git a/OpenSim/Data/NHibernate/EstateRegionLink.cs b/OpenSim/Data/NHibernate/EstateRegionLink.cs new file mode 100644 index 0000000..cceced2 --- /dev/null +++ b/OpenSim/Data/NHibernate/EstateRegionLink.cs @@ -0,0 +1,49 @@ +?using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; + +namespace OpenSim.Data.NHibernate +{ + public class EstateRegionLink + { + private UUID estateRegionLinkID; + public UUID EstateRegionLinkID + { + get + { + return estateRegionLinkID; + } + set + { + estateRegionLinkID = value; + } + } + + private uint estateID; + public uint EstateID + { + get + { + return estateID; + } + set + { + estateID = value; + } + } + + private UUID regionID; + public UUID RegionID + { + get + { + return regionID; + } + set + { + regionID = value; + } + } + } +} diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index f4527bf..f8715cc 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -45,7 +45,8 @@ namespace OpenSim.Data.NHibernate public override void Initialise() { - Initialise("SQLiteDialect;SqliteClientDriver;URI=file:Asset.db,version=3"); + m_log.Info("[NHibernateGridData]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException(Name); } public override void Initialise(string connect) @@ -66,7 +67,7 @@ namespace OpenSim.Data.NHibernate AssetBase temp = (AssetBase)manager.Load(typeof(AssetBase), asset.Metadata.FullID); if (temp == null) { - manager.Save(asset); + manager.Insert(asset); } } diff --git a/OpenSim/Data/NHibernate/NHibernateEstateData.cs b/OpenSim/Data/NHibernate/NHibernateEstateData.cs new file mode 100644 index 0000000..59896dd --- /dev/null +++ b/OpenSim/Data/NHibernate/NHibernateEstateData.cs @@ -0,0 +1,161 @@ +/* + * 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.Reflection; +using log4net; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.Framework.Interfaces; +using NHibernate; +using NHibernate.Criterion; +using System.Collections; +using System; + +namespace OpenSim.Data.NHibernate +{ + /// + /// A User storage interface for the DB4o database system + /// + public class NHibernateEstateData : IEstateDataStore + { + + #region Fields + + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public NHibernateManager manager; + + public string Name + { + get { return "NHibernateEstateData"; } + } + + public string Version + { + get { return "0.1"; } + } + + #endregion + + #region Startup and shutdown. + + public void Initialise() + { + m_log.Info("[NHIBERNATE]: " + Name + " cannot be default-initialized!"); + throw new PluginNotInitialisedException(Name); + } + + public void Initialise(string connect) + { + + m_log.InfoFormat("[NHIBERNATE] Initializing " + Name + "."); + manager = new NHibernateManager(connect, "EstateStore"); + } + + public void Dispose() { } + + #endregion + + #region IEstateDataStore Members + + public EstateSettings LoadEstateSettings(UUID regionID) + { + EstateRegionLink link = LoadEstateRegionLink(regionID); + + // Ensure that estate settings exist for the link + if (link != null) + { + if (manager.Load(typeof(EstateSettings), link.EstateID) == null) + { + // Delete broken link + manager.Delete(link); + link = null; + } + } + + // If estate link does not exist create estate settings and link it to region. + if (link == null) + { + EstateSettings estateSettings = new EstateSettings(); + //estateSettings.EstateOwner = UUID.Random(); + //estateSettings.BlockDwell = false; + object identifier = manager.Insert(estateSettings); + + if (identifier == null) + { + // Saving failed. Error is logged in the manager. + return null; + } + + uint estateID = (uint)identifier; + link = new EstateRegionLink(); + link.EstateRegionLinkID = UUID.Random(); + link.RegionID = regionID; + link.EstateID = estateID; + manager.Insert(link); + } + + // Load estate settings according to the existing or created link. + return (EstateSettings)manager.Load(typeof(EstateSettings), link.EstateID); + } + + public void StoreEstateSettings(EstateSettings estateSettings) + { + // Estates are always updated when stored. + // Insert is always done via. load method as with the current API + // this is explicitly the only way to create region link. + manager.Update(estateSettings); + } + + #endregion + + #region Private Utility Methods + private EstateRegionLink LoadEstateRegionLink(UUID regionID) + { + ICriteria criteria = manager.GetSession().CreateCriteria(typeof(EstateRegionLink)); + criteria.Add(Expression.Eq("RegionID", regionID)); + IList links = criteria.List(); + + // Fail fast if more than one estate links exist + if (links.Count > 1) + { + m_log.Error("[NHIBERNATE]: Region had more than one estate linked: " + regionID); + throw new Exception("[NHIBERNATE]: Region had more than one estate linked: " + regionID); + } + + if (links.Count == 1) + { + return (EstateRegionLink)links[0]; + } + else + { + return null; + } + } + #endregion + } +} diff --git a/OpenSim/Data/NHibernate/NHibernateGridData.cs b/OpenSim/Data/NHibernate/NHibernateGridData.cs index 836c99e..e58d1ed 100644 --- a/OpenSim/Data/NHibernate/NHibernateGridData.cs +++ b/OpenSim/Data/NHibernate/NHibernateGridData.cs @@ -113,7 +113,7 @@ namespace OpenSim.Data.NHibernate { if (manager.Load(typeof(RegionProfileData), profile.Uuid) == null) { - manager.Save(profile); + manager.Insert(profile); return DataResponse.RESPONSE_OK; } else diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index 0129800..7657ae5 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs @@ -42,6 +42,34 @@ namespace OpenSim.Data.NHibernate public NHibernateManager manager; + /// + /// The plugin being loaded + /// + /// A string containing the plugin name + public string Name + { + get { return "NHibernate Inventory Data Interface"; } + } + + /// + /// The plugins version + /// + /// A string containing the plugin version + public string Version + { + get + { + Module module = GetType().Module; + // string dllName = module.Assembly.ManifestModule.Name; + Version dllVersion = module.Assembly.GetName().Version; + + + return + string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, + dllVersion.Revision); + } + } + public void Initialise() { m_log.Info("[NHibernateInventoryData]: " + Name + " cannot be default-initialized!"); @@ -57,6 +85,13 @@ namespace OpenSim.Data.NHibernate manager = new NHibernateManager(connect, "InventoryStore"); } + /// + /// Closes the interface + /// + public void Dispose() + { + } + /***************************************************************** * * Basic CRUD operations on Data @@ -92,7 +127,7 @@ namespace OpenSim.Data.NHibernate { if (!ExistsItem(item.ID)) { - manager.Save(item); + manager.Insert(item); } else { @@ -161,7 +196,7 @@ namespace OpenSim.Data.NHibernate { if (!ExistsFolder(folder.ID)) { - manager.Save(folder); + manager.Insert(folder); } else { @@ -220,41 +255,6 @@ namespace OpenSim.Data.NHibernate // TODO: DataSet commit } - /// - /// Closes the interface - /// - public void Dispose() - { - } - - /// - /// The plugin being loaded - /// - /// A string containing the plugin name - public string Name - { - get { return "NHibernate Inventory Data Interface"; } - } - - /// - /// The plugins version - /// - /// A string containing the plugin version - public string Version - { - get - { - Module module = GetType().Module; - // string dllName = module.Assembly.ManifestModule.Name; - Version dllVersion = module.Assembly.GetName().Version; - - - return - string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, - dllVersion.Revision); - } - } - // Move seems to be just update public void moveInventoryFolder(InventoryFolderBase folder) diff --git a/OpenSim/Data/NHibernate/NHibernateManager.cs b/OpenSim/Data/NHibernate/NHibernateManager.cs index 51467da..26bc219 100644 --- a/OpenSim/Data/NHibernate/NHibernateManager.cs +++ b/OpenSim/Data/NHibernate/NHibernateManager.cs @@ -131,25 +131,25 @@ namespace OpenSim.Data.NHibernate RunMigration(dialect, assembly, store); } - public object Load(Type type, UUID uuid) + public object Load(Type type, Object id) { using (IStatelessSession session = sessionFactory.OpenStatelessSession()) { object obj = null; try { - obj = session.Get(type.FullName, uuid); + obj = session.Get(type.FullName, id); } catch (Exception e) { - m_log.ErrorFormat("[NHIBERNATE] {0} of id {1} loading threw exception: "+ e.ToString(), type.Name, uuid); + m_log.ErrorFormat("[NHIBERNATE] {0} of id {1} loading threw exception: " + e.ToString(), type.Name, id); } return obj; } } - public bool Save(object obj) + public object Insert(object obj) { try { @@ -157,16 +157,16 @@ namespace OpenSim.Data.NHibernate { using (ITransaction transaction=session.BeginTransaction()) { - session.Insert(obj); + Object identifier=session.Insert(obj); transaction.Commit(); - return true; + return identifier; } } } catch (Exception e) { m_log.Error("[NHIBERNATE] issue inserting object ", e); - return false; + return null; } } diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs index 0cd3969..78db52d 100644 --- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs +++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs @@ -70,7 +70,7 @@ namespace OpenSim.Data.NHibernate } else { - manager.Save(rs); + manager.Insert(rs); } } @@ -82,7 +82,7 @@ namespace OpenSim.Data.NHibernate { regionSettings = new RegionSettings(); regionSettings.RegionUUID = regionUUID; - manager.Save(regionSettings); + manager.Insert(regionSettings); } regionSettings.OnSave += StoreRegionSettings; @@ -105,7 +105,7 @@ namespace OpenSim.Data.NHibernate else { m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID); - manager.Save(p); + manager.Insert(p); } } @@ -129,7 +129,7 @@ namespace OpenSim.Data.NHibernate else { m_log.InfoFormat("[NHIBERNATE] saving terrain {0}", t.RegionID); - manager.Save(t); + manager.Insert(t); } } @@ -394,7 +394,7 @@ namespace OpenSim.Data.NHibernate foreach (TaskInventoryItem i in items) { - manager.Save(i); + manager.Insert(i); } } diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs index 7dfdcb5..3f1f260 100644 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs @@ -102,7 +102,7 @@ namespace OpenSim.Data.NHibernate if (!ExistsUser(profile.ID)) { m_log.InfoFormat("[NHIBERNATE] AddNewUserProfile {0}", profile.ID); - manager.Save(profile); + manager.Insert(profile); // Agent should not be saved according to BasicUserTest.T015_UserPersistency() // SetAgentData(profile.ID, profile.CurrentAgent); @@ -169,7 +169,7 @@ namespace OpenSim.Data.NHibernate manager.Delete(old); } - manager.Save(agent); + manager.Insert(agent); } @@ -245,11 +245,11 @@ namespace OpenSim.Data.NHibernate { if (!FriendRelationExists(ownerId,friendId)) { - manager.Save(new UserFriend(UUID.Random(), ownerId, friendId, perms)); + manager.Insert(new UserFriend(UUID.Random(), ownerId, friendId, perms)); } if (!FriendRelationExists(friendId, ownerId)) { - manager.Save(new UserFriend(UUID.Random(), friendId, ownerId, perms)); + manager.Insert(new UserFriend(UUID.Random(), friendId, ownerId, perms)); } return; } @@ -426,7 +426,7 @@ namespace OpenSim.Data.NHibernate } else { - manager.Save(appearance); + manager.Insert(appearance); } } diff --git a/OpenSim/Data/NHibernate/Resources/EstateRegionLink.hbm.xml b/OpenSim/Data/NHibernate/Resources/EstateRegionLink.hbm.xml new file mode 100644 index 0000000..91bddee --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/EstateRegionLink.hbm.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/EstateSettings.hbm.xml b/OpenSim/Data/NHibernate/Resources/EstateSettings.hbm.xml new file mode 100644 index 0000000..1ff0f10 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/EstateSettings.hbm.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/MigrationSyntaxDifferences.txt b/OpenSim/Data/NHibernate/Resources/MigrationSyntaxDifferences.txt new file mode 100644 index 0000000..f3d86df --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/MigrationSyntaxDifferences.txt @@ -0,0 +1,14 @@ +?This file describes the differences in schema creation and migration scripts. + +MySQL is used as reference script against which differences are listed. + +Generally MySQL create table options should be removed for other databases. + +_PostgreSQL_ +* DOUBLE->DOUBLE PRECISION +* BIT->BOOLEAN + +_MsSql_ +* VARCHAR->NVARCHAR +* Remove DEFAULT-keywords +* DOUBLE->REAL diff --git a/OpenSim/Data/NHibernate/Resources/MsSql2005Dialect/001_EstateStore.sql b/OpenSim/Data/NHibernate/Resources/MsSql2005Dialect/001_EstateStore.sql new file mode 100644 index 0000000..893e2a2 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/MsSql2005Dialect/001_EstateStore.sql @@ -0,0 +1,40 @@ +CREATE TABLE EstateSettings ( + EstateID INT NOT NULL, + ParentEstateID INT NULL, + EstateOwnerID NVARCHAR(36) NULL, + Name NVARCHAR(64) NULL, + RedirectGridX INT NULL, + RedirectGridY INT NULL, + BillableFactor REAL NULL, + PricePerMeter INT NULL, + SunPosition REAL NULL, + + UseGlobalTime BIT NULL, + FixedSun BIT NULL, + AllowVoice BIT NULL, + AllowDirectTeleport BIT NULL, + ResetHomeOnTeleport BIT NULL, + PublicAccess BIT NULL, + DenyAnonymous BIT NULL, + DenyIdentified BIT NULL, + DenyTransacted BIT NULL, + DenyMinors BIT NULL, + BlockDwell BIT NULL, + EstateSkipScripts BIT NULL, + TaxFree BIT NULL, + AbuseEmailToEstateOwner BIT NULL, + + AbuseEmail NVARCHAR(255) NULL, + + PRIMARY KEY (EstateID) +); + +CREATE TABLE EstateRegionLink ( + EstateRegionLinkID NVARCHAR(36) NOT NULL, + EstateID INT NULL, + RegionID NVARCHAR(36) NULL, + PRIMARY KEY (EstateRegionLinkID) +); + +CREATE INDEX EstateRegionLinkEstateIDIndex ON EstateRegionLink (EstateID); +CREATE INDEX EstateRegionLinkERegionIDIndex ON EstateRegionLink (RegionID); diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_EstateStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_EstateStore.sql new file mode 100644 index 0000000..a791bc6 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_EstateStore.sql @@ -0,0 +1,40 @@ +CREATE TABLE EstateSettings ( + EstateID INT NOT NULL, + ParentEstateID INT DEFAULT NULL, + EstateOwnerID VARCHAR(36) DEFAULT NULL, + Name VARCHAR(64) DEFAULT NULL, + RedirectGridX INT DEFAULT NULL, + RedirectGridY INT DEFAULT NULL, + BillableFactor DOUBLE DEFAULT NULL, + PricePerMeter INT DEFAULT NULL, + SunPosition DOUBLE DEFAULT NULL, + + UseGlobalTime BIT DEFAULT NULL, + FixedSun BIT DEFAULT NULL, + AllowVoice BIT DEFAULT NULL, + AllowDirectTeleport BIT DEFAULT NULL, + ResetHomeOnTeleport BIT DEFAULT NULL, + PublicAccess BIT DEFAULT NULL, + DenyAnonymous BIT DEFAULT NULL, + DenyIdentified BIT DEFAULT NULL, + DenyTransacted BIT DEFAULT NULL, + DenyMinors BIT DEFAULT NULL, + BlockDwell BIT DEFAULT NULL, + EstateSkipScripts BIT DEFAULT NULL, + TaxFree BIT DEFAULT NULL, + AbuseEmailToEstateOwner BIT DEFAULT NULL, + + AbuseEmail VARCHAR(255) DEFAULT NULL, + + PRIMARY KEY (EstateID) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev. 1'; + +CREATE TABLE EstateRegionLink ( + EstateRegionLinkID VARCHAR(36) NOT NULL, + EstateID INT DEFAULT NULL, + RegionID VARCHAR(36) DEFAULT NULL, + PRIMARY KEY (EstateRegionLinkID) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Rev. 1'; + +CREATE INDEX EstateRegionLinkEstateIDIndex ON EstateRegionLink (EstateID); +CREATE INDEX EstateRegionLinkERegionIDIndex ON EstateRegionLink (RegionID); diff --git a/OpenSim/Data/NHibernate/Resources/PostgreSQLDialect/001_EstateStore.sql b/OpenSim/Data/NHibernate/Resources/PostgreSQLDialect/001_EstateStore.sql new file mode 100644 index 0000000..421a0c4 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/PostgreSQLDialect/001_EstateStore.sql @@ -0,0 +1,40 @@ +CREATE TABLE EstateSettings ( + EstateID INT NOT NULL, + ParentEstateID INT DEFAULT NULL, + EstateOwnerID VARCHAR(36) DEFAULT NULL, + Name VARCHAR(64) DEFAULT NULL, + RedirectGridX INT DEFAULT NULL, + RedirectGridY INT DEFAULT NULL, + BillableFactor DOUBLE PRECISION DEFAULT NULL, + PricePerMeter INT DEFAULT NULL, + SunPosition DOUBLE PRECISION DEFAULT NULL, + + UseGlobalTime BOOLEAN DEFAULT NULL, + FixedSun BOOLEAN DEFAULT NULL, + AllowVoice BOOLEAN DEFAULT NULL, + AllowDirectTeleport BOOLEAN DEFAULT NULL, + ResetHomeOnTeleport BOOLEAN DEFAULT NULL, + PublicAccess BOOLEAN DEFAULT NULL, + DenyAnonymous BOOLEAN DEFAULT NULL, + DenyIdentified BOOLEAN DEFAULT NULL, + DenyTransacted BOOLEAN DEFAULT NULL, + DenyMinors BOOLEAN DEFAULT NULL, + BlockDwell BOOLEAN DEFAULT NULL, + EstateSkipScripts BOOLEAN DEFAULT NULL, + TaxFree BOOLEAN DEFAULT NULL, + AbuseEmailToEstateOwner BOOLEAN DEFAULT NULL, + + AbuseEmail VARCHAR(255) DEFAULT NULL, + + PRIMARY KEY (EstateID) +); + +CREATE TABLE EstateRegionLink ( + EstateRegionLinkID VARCHAR(36) NOT NULL, + EstateID INT DEFAULT NULL, + RegionID VARCHAR(36) DEFAULT NULL, + PRIMARY KEY (EstateRegionLinkID) +); + +CREATE INDEX EstateRegionLinkEstateIDIndex ON EstateRegionLink (EstateID); +CREATE INDEX EstateRegionLinkERegionIDIndex ON EstateRegionLink (RegionID); diff --git a/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_EstateStore.sql b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_EstateStore.sql new file mode 100644 index 0000000..b16ae82 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_EstateStore.sql @@ -0,0 +1,40 @@ +CREATE TABLE EstateSettings ( + EstateID INT NOT NULL, + ParentEstateID INT DEFAULT NULL, + EstateOwnerID VARCHAR(36) DEFAULT NULL, + Name VARCHAR(64) DEFAULT NULL, + RedirectGridX INT DEFAULT NULL, + RedirectGridY INT DEFAULT NULL, + BillableFactor DOUBLE DEFAULT NULL, + PricePerMeter INT DEFAULT NULL, + SunPosition DOUBLE DEFAULT NULL, + + UseGlobalTime BIT DEFAULT NULL, + FixedSun BIT DEFAULT NULL, + AllowVoice BIT DEFAULT NULL, + AllowDirectTeleport BIT DEFAULT NULL, + ResetHomeOnTeleport BIT DEFAULT NULL, + PublicAccess BIT DEFAULT NULL, + DenyAnonymous BIT DEFAULT NULL, + DenyIdentified BIT DEFAULT NULL, + DenyTransacted BIT DEFAULT NULL, + DenyMinors BIT DEFAULT NULL, + BlockDwell BIT DEFAULT NULL, + EstateSkipScripts BIT DEFAULT NULL, + TaxFree BIT DEFAULT NULL, + AbuseEmailToEstateOwner BIT DEFAULT NULL, + + AbuseEmail VARCHAR(255) DEFAULT NULL, + + PRIMARY KEY (EstateID) +); + +CREATE TABLE EstateRegionLink ( + EstateRegionLinkID VARCHAR(36) NOT NULL, + EstateID INT DEFAULT NULL, + RegionID VARCHAR(36) DEFAULT NULL, + PRIMARY KEY (EstateRegionLinkID) +); + +CREATE INDEX EstateRegionLinkEstateIDIndex ON EstateRegionLink (EstateID); +CREATE INDEX EstateRegionLinkERegionIDIndex ON EstateRegionLink (RegionID); diff --git a/OpenSim/Data/NHibernate/Tests/NHibernateMsSqlEstateTest.cs b/OpenSim/Data/NHibernate/Tests/NHibernateMsSqlEstateTest.cs new file mode 100644 index 0000000..ea3c1eb --- /dev/null +++ b/OpenSim/Data/NHibernate/Tests/NHibernateMsSqlEstateTest.cs @@ -0,0 +1,77 @@ +/* + * 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 NUnit.Framework; +using OpenSim.Data.Tests; + +namespace OpenSim.Data.NHibernate.Tests +{ + [TestFixture] + public class NHibernateMsSqlEstateTest : BasicEstateTest + { + public string file; + public NHibernateManager database; + + [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 + { + string connect = "MsSql2005Dialect;SqlClientDriver;Data Source=127.0.0.1;Network Library=DBMSSOCN;Initial Catalog=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit"; + + db = new NHibernateEstateData(); + db.Initialise(connect); + database = ((NHibernateEstateData)db).manager; + } + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + Assert.Ignore(); + } + } + + [TestFixtureTearDown] + public void Cleanup() + { + if (db != null) + { + ((NHibernateEstateData)db).Dispose(); + } + if (database != null) + { + database.DropSchema(); + } + } + + } +} diff --git a/OpenSim/Data/NHibernate/Tests/NHibernateMySqlEstateTest.cs b/OpenSim/Data/NHibernate/Tests/NHibernateMySqlEstateTest.cs new file mode 100644 index 0000000..651ff4e --- /dev/null +++ b/OpenSim/Data/NHibernate/Tests/NHibernateMySqlEstateTest.cs @@ -0,0 +1,76 @@ +/* + * 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 NUnit.Framework; +using OpenSim.Data.Tests; + +namespace OpenSim.Data.NHibernate.Tests +{ + [TestFixture] + public class NHibernateMySQLEstateTest : BasicEstateTest + { + 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 NHibernateEstateData(); + db.Initialise(connect); + database = ((NHibernateEstateData)db).manager; + } + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + Assert.Ignore(); + } + } + + [TestFixtureTearDown] + public void Cleanup() + { + if (db != null) + { + ((NHibernateEstateData)db).Dispose(); + } + if (database != null) + { + database.DropSchema(); + } + } + + } +} diff --git a/OpenSim/Data/NHibernate/Tests/NHibernatePostgreSQLEstateTest.cs b/OpenSim/Data/NHibernate/Tests/NHibernatePostgreSQLEstateTest.cs new file mode 100644 index 0000000..1d113c7 --- /dev/null +++ b/OpenSim/Data/NHibernate/Tests/NHibernatePostgreSQLEstateTest.cs @@ -0,0 +1,76 @@ +/* + * 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 NUnit.Framework; +using OpenSim.Data.Tests; + +namespace OpenSim.Data.NHibernate.Tests +{ + [TestFixture] + public class NHibernatePostgreSQLEstateTest : BasicEstateTest + { + public string file; + public NHibernateManager database; + public string connect = "PostgreSQLDialect;NpgsqlDriver;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 NHibernateEstateData(); + db.Initialise(connect); + database = ((NHibernateEstateData)db).manager; + } + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + Assert.Ignore(); + } + } + + [TestFixtureTearDown] + public void Cleanup() + { + if (db != null) + { + ((NHibernateEstateData)db).Dispose(); + } + if (database != null) + { + database.DropSchema(); + } + } + + } +} diff --git a/OpenSim/Data/NHibernate/Tests/NHibernateSQLiteEstateTest.cs b/OpenSim/Data/NHibernate/Tests/NHibernateSQLiteEstateTest.cs new file mode 100644 index 0000000..86fb573 --- /dev/null +++ b/OpenSim/Data/NHibernate/Tests/NHibernateSQLiteEstateTest.cs @@ -0,0 +1,78 @@ +/* + * 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 NUnit.Framework; +using OpenSim.Data.Tests; + +namespace OpenSim.Data.NHibernate.Tests +{ + [TestFixture] + public class NHibernateSQLiteEstateTest : BasicEstateTest + { + public string file; + public NHibernateManager database; + + [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 + { + string connect = "SQLiteDialect;SQLite20Driver;Data Source=" + Path.GetTempFileName() + ".db;Version=3"; + + db = new NHibernateEstateData(); + db.Initialise(connect); + database = ((NHibernateEstateData)db).manager; + } + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + Assert.Ignore(); + } + } + + [TestFixtureTearDown] + public void Cleanup() + { + if (db != null) + { + ((NHibernateEstateData)db).Dispose(); + } + if (database != null) + { + database.DropSchema(); + } + } + + } +} diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/BasicEstateTest.cs index 24c25ec..d0f7a8b 100644 --- a/OpenSim/Data/Tests/BasicEstateTest.cs +++ b/OpenSim/Data/Tests/BasicEstateTest.cs @@ -73,6 +73,7 @@ namespace OpenSim.Data.Tests double sunPosition = 7; bool allowVoice = true; bool allowDirectTeleport = true; + bool resetHomeOnTeleport = true; bool denyAnonymous = true; bool denyIdentified = true; bool denyTransacted = true; @@ -103,6 +104,7 @@ namespace OpenSim.Data.Tests es.SunPosition = sunPosition; es.AllowVoice = allowVoice; es.AllowDirectTeleport = allowDirectTeleport; + es.ResetHomeOnTeleport = resetHomeOnTeleport; es.DenyAnonymous = denyAnonymous; es.DenyIdentified = denyIdentified; es.DenyTransacted = denyTransacted; @@ -133,6 +135,7 @@ namespace OpenSim.Data.Tests Assert.That(sunPosition, Is.EqualTo(nes.SunPosition)); Assert.That(allowVoice, Is.EqualTo(nes.AllowVoice)); Assert.That(allowDirectTeleport, Is.EqualTo(nes.AllowDirectTeleport)); + Assert.That(resetHomeOnTeleport, Is.EqualTo(nes.ResetHomeOnTeleport)); Assert.That(denyAnonymous, Is.EqualTo(nes.DenyAnonymous)); Assert.That(denyIdentified, Is.EqualTo(nes.DenyIdentified)); Assert.That(denyTransacted, Is.EqualTo(nes.DenyTransacted)); -- cgit v1.1