From 40f34aeffd64e2aa81cecb2e861f60d6e8886198 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sun, 11 Jan 2009 18:24:16 +0000 Subject: Thank you kindly, Tlaukkan (Tommil) for a patch that: Fixed all NHibernate unit tests by implementing missing persistency methods, tables, columns and fixing bugs in the existing implementation. Two minor changes to classes outside NHibernate module: Added Scene instantiation for SceneObjectGroup in OpenSim.Data.Tests.BasicRegionTest as this was required by the NHibernate persistency. In the process added also mock constructor to Scene which only populates RegionInfo in the scene which is used by ScenePart.RegionUUID. NHibernate module is still in experimental state and has not been tested at opensim region or ugaim runtime configuration. Adding unit tests to build is not yet advisable nor using NHibernate module in any production setup. --- OpenSim/Data/NHibernate/ColorUserType.cs | 106 ++++++++++++ OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 7 + OpenSim/Data/NHibernate/NHibernateRegionData.cs | 37 +++- OpenSim/Data/NHibernate/NHibernateUserData.cs | 188 ++++++++++++++++++++- .../Resources/MySQLDialect/001_RegionStore.sql | 80 +++++---- .../Resources/MySQLDialect/001_UserStore.sql | 102 ++++++----- .../Resources/MySQLDialect/003_RegionStore.sql | 72 ++++++-- .../NHibernate/Resources/RegionSettings.hbm.xml | 56 ++++++ .../Data/NHibernate/Resources/RegionStore.hbm.xml | 12 +- .../Resources/SQLiteDialect/001_RegionStore.sql | 60 ++++++- .../Resources/SQLiteDialect/001_UserStore.sql | 39 ++++- .../NHibernate/Resources/UserAgentData.hbm.xml | 17 +- .../NHibernate/Resources/UserAppearance.hbm.xml | 1 + .../Data/NHibernate/Resources/UserFriend.hbm.xml | 11 ++ .../NHibernate/Resources/UserProfileData.hbm.xml | 16 +- OpenSim/Data/NHibernate/UserFriend.cs | 28 +++ OpenSim/Data/Tests/BasicRegionTest.cs | 48 ++++-- OpenSim/Region/Environment/Scenes/Scene.cs | 11 ++ 18 files changed, 761 insertions(+), 130 deletions(-) create mode 100644 OpenSim/Data/NHibernate/ColorUserType.cs create mode 100644 OpenSim/Data/NHibernate/Resources/RegionSettings.hbm.xml create mode 100644 OpenSim/Data/NHibernate/Resources/UserFriend.hbm.xml create mode 100644 OpenSim/Data/NHibernate/UserFriend.cs (limited to 'OpenSim') diff --git a/OpenSim/Data/NHibernate/ColorUserType.cs b/OpenSim/Data/NHibernate/ColorUserType.cs new file mode 100644 index 0000000..4676585 --- /dev/null +++ b/OpenSim/Data/NHibernate/ColorUserType.cs @@ -0,0 +1,106 @@ +/* + * 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.Data; +using OpenMetaverse; +using OpenSim.Framework; +using NHibernate; +using NHibernate.SqlTypes; +using NHibernate.UserTypes; +using System.Drawing; + +namespace OpenSim.Data.NHibernate +{ + [Serializable] + public class ColorUserType : IUserType + { + public object Assemble(object cached, object owner) + { + return cached; + } + + bool IUserType.Equals(object color1, object color2) + { + return color1.Equals(color2); + } + + public object DeepCopy(object color) + { + return color; + } + + public object Disassemble(object color) + { + return color; + } + + public int GetHashCode(object color) + { + return (color == null) ? 0 : color.GetHashCode(); + } + + public bool IsMutable + { + get { return false; } + } + + public object NullSafeGet(IDataReader rs, string[] names, object owner) + { + Color color=Color.Empty; + + int ord = rs.GetOrdinal(names[0]); + if (!rs.IsDBNull(ord)) + { + color = Color.FromArgb(rs.GetInt32(ord)); + } + + return color; + } + + public void NullSafeSet(IDbCommand cmd, object obj, int index) + { + Color color = (Color)obj; + ((IDataParameter)cmd.Parameters[index]).Value = color.ToArgb(); + } + + public object Replace(object original, object target, object owner) + { + return original; + } + + public Type ReturnedType + { + get { return typeof(Color); } + } + + public SqlType[] SqlTypes + { + get { return new SqlType [] { NHibernateUtil.Int32.SqlType }; } + } + } +} diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index dc98d11..e648396 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs @@ -344,7 +344,14 @@ namespace OpenSim.Data.NHibernate // See IInventoryDataPlugin public List getFolderHierarchy(UUID parentID) { + if (parentID == UUID.Zero) + { + // Zero UUID is not a real parent folder. + return new List(); + } + List folders = new List(); + getInventoryFolders(ref folders, parentID); for (int i = 0; i < folders.Count; i++) diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs index 871013b..b8b1863 100644 --- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs +++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs @@ -67,11 +67,31 @@ namespace OpenSim.Data.NHibernate public void StoreRegionSettings(RegionSettings rs) { + RegionSettings oldRegionSettings = (RegionSettings)manager.Load(typeof(RegionSettings), rs.RegionUUID); + if (oldRegionSettings != null) + { + manager.Update(rs); + } + else + { + manager.Save(rs); + } } public RegionSettings LoadRegionSettings(UUID regionUUID) { - return null; + RegionSettings regionSettings = (RegionSettings) manager.Load(typeof(RegionSettings), regionUUID); + + if (regionSettings == null) + { + regionSettings = new RegionSettings(); + regionSettings.RegionUUID = regionUUID; + manager.Save(regionSettings); + } + + regionSettings.OnSave += StoreRegionSettings; + + return regionSettings; } // This looks inefficient, but it turns out that it isn't @@ -84,7 +104,7 @@ namespace OpenSim.Data.NHibernate if (old != null) { m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID); - manager.Update(old); + manager.Update(p); } else { @@ -108,7 +128,7 @@ namespace OpenSim.Data.NHibernate if (old != null) { m_log.InfoFormat("[NHIBERNATE] updating terrain {0}", t.RegionID); - manager.Update(old); + manager.Update(t); } else { @@ -131,6 +151,14 @@ namespace OpenSim.Data.NHibernate /// the region UUID public void StoreObject(SceneObjectGroup obj, UUID regionUUID) { + uint flags = obj.RootPart.GetEffectiveObjectFlags(); + + // Eligibility check + if ((flags & (uint)PrimFlags.Temporary) != 0) + return; + if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) + return; + try { foreach (SceneObjectPart part in obj.Children.Values) @@ -199,7 +227,8 @@ namespace OpenSim.Data.NHibernate ICriteria criteria = manager.GetSession().CreateCriteria(typeof(SceneObjectPart)); criteria.Add(Expression.Eq("RegionID", regionUUID)); - criteria.AddOrder( Order.Asc("ParentID") ); + criteria.AddOrder(Order.Asc("ParentID")); + criteria.AddOrder(Order.Asc("LinkNum")); foreach (SceneObjectPart p in criteria.List()) { // root part diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs index e0f6db7..6076f90 100644 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs @@ -97,11 +97,18 @@ namespace OpenSim.Data.NHibernate override public void AddNewUserProfile(UserProfileData profile) { + if (profile.ID == UUID.Zero) + { + m_log.ErrorFormat("[NHIBERNATE] Attempted to add User {0} {1} with zero UUID, throwintg exception as this is programming error ", profile.FirstName, profile.SurName); + return; + } + if (!ExistsUser(profile.ID)) { m_log.InfoFormat("[NHIBERNATE] AddNewUserProfile {0}", profile.ID); manager.Save(profile); - SetAgentData(profile.ID, profile.CurrentAgent); + // Agent should not be saved according to BasicUserTest.T015_UserPersistency() + // SetAgentData(profile.ID, profile.CurrentAgent); } else @@ -131,7 +138,8 @@ namespace OpenSim.Data.NHibernate if (ExistsUser(profile.ID)) { manager.Update(profile); - SetAgentData(profile.ID, profile.CurrentAgent); + // Agent should not be saved according to BasicUserTest.T015_UserPersistency() + // SetAgentData(profile.ID, profile.CurrentAgent); return true; } else @@ -144,6 +152,19 @@ namespace OpenSim.Data.NHibernate override public void AddNewUserAgent(UserAgentData agent) { + if (agent.ProfileID == UUID.Zero) + { + m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero user id. Agent session id: {0}", agent.SessionID); + return; + } + + if (agent.SessionID == UUID.Zero) + { + m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero session id. User profile id: {0}", agent.SessionID); + return; + } + + UserAgentData old = (UserAgentData)manager.Load(typeof(UserAgentData), agent.ProfileID); if (old != null) { @@ -214,12 +235,163 @@ namespace OpenSim.Data.NHibernate } // TODO: actually implement these - public override void StoreWebLoginKey(UUID agentID, UUID webLoginKey) { return; } - public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) { return; } - public override void RemoveUserFriend(UUID friendlistowner, UUID friend) { return; } - public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) { return; } - public override List GetUserFriendList(UUID friendlistowner) { return new List(); } - public override Dictionary GetFriendRegionInfos (List uuids) { return new Dictionary(); } + public override void StoreWebLoginKey(UUID agentID, UUID webLoginKey) + { + UserProfileData user=GetUserByUUID(agentID); + user.WebLoginKey = webLoginKey; + UpdateUserProfile(user); + return; + } + + public override void AddNewUserFriend(UUID ownerId, UUID friendId, uint perms) + { + if (!FriendRelationExists(ownerId,friendId)) + { + manager.Save(new UserFriend(UUID.Random(), ownerId, friendId, perms)); + } + if (!FriendRelationExists(friendId, ownerId)) + { + manager.Save(new UserFriend(UUID.Random(), friendId, ownerId, perms)); + } + return; + } + + private bool FriendRelationExists(UUID ownerId, UUID friendId) + { + using (ISession session = manager.GetSession()) + { + ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); + criteria.Add(Expression.Eq("OwnerID", ownerId)); + criteria.Add(Expression.Eq("FriendID", friendId)); + return criteria.List().Count > 0; + } + } + + public override void RemoveUserFriend(UUID ownerId, UUID friendId) + { + using (ISession session = manager.GetSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + + { + ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); + criteria.Add(Expression.Eq("OwnerID", ownerId)); + criteria.Add(Expression.Eq("FriendID", friendId)); + + foreach (UserFriend userFriend in criteria.List()) + { + session.Delete(userFriend); + } + } + + { + ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); + criteria.Add(Expression.Eq("OwnerID", friendId)); + criteria.Add(Expression.Eq("FriendID", ownerId)); + + foreach (UserFriend userFriend in criteria.List()) + { + session.Delete(userFriend); + } + } + + transaction.Commit(); + } + } + return; + } + + + public override void UpdateUserFriendPerms(UUID ownerId, UUID friendId, uint perms) + { + using (ISession session = manager.GetSession()) + { + using (ITransaction transaction = session.BeginTransaction()) + { + { + ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); + criteria.Add(Expression.Eq("OwnerID", ownerId)); + criteria.Add(Expression.Eq("FriendID", friendId)); + + foreach (UserFriend userFriend in criteria.List()) + { + userFriend.FriendPermissions = perms; + session.Update(userFriend); + } + } + transaction.Commit(); + } + } + return; + } + + public override List GetUserFriendList(UUID ownerId) + { + List friendList=new List(); + Dictionary friendListItemDictionary = new Dictionary(); + + using (ISession session = manager.GetSession()) + { + ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); + criteria.Add(Expression.Or( + Expression.Eq("OwnerID", ownerId), + Expression.Eq("FriendID", ownerId) + )); + + foreach (UserFriend userFriend in criteria.List()) + { + if (userFriend.OwnerID == ownerId) + { + FriendListItem friendListItem = new FriendListItem(); + friendListItem.FriendListOwner = userFriend.OwnerID; + friendListItem.Friend = userFriend.FriendID; + friendListItem.FriendPerms = userFriend.FriendPermissions; + friendListItemDictionary.Add(userFriend.FriendID, friendListItem); + friendList.Add(friendListItem); + } + } + + // Reading permissions to other direction + foreach (UserFriend userFriend in criteria.List()) + { + if (userFriend.FriendID == ownerId) + { + //Ignore if there is no reverse relation existing. + //if (friendListItemDictionary.ContainsKey(userFriend.OwnerID)) + { + FriendListItem friendListItem = friendListItemDictionary[userFriend.OwnerID]; + friendListItem.FriendListOwnerPerms = userFriend.FriendPermissions; + } + } + } + + } + + return friendList; + } + + + public override Dictionary GetFriendRegionInfos (List friendsIds) + { + Dictionary friendRegionInfos=new Dictionary(); + + foreach(UUID friendId in friendsIds) + { + UserAgentData agent=GetAgentByUUID(friendId); + if (agent != null) + { + FriendRegionInfo fri = new FriendRegionInfo(); + fri.isOnline = agent.AgentOnline; + fri.regionHandle = agent.Handle; + + friendRegionInfos[friendId] = fri; + } + } + + return friendRegionInfos; + } + public override bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return true; } public override bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return true; } diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_RegionStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_RegionStore.sql index 99a5227..158ebb4 100644 --- a/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_RegionStore.sql +++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_RegionStore.sql @@ -1,8 +1,15 @@ CREATE TABLE `Prims` ( + `UUID` char(36) NOT NULL default '', + `RegionID` char(36) default NULL, + `GroupID` char(36) default NULL, `ParentID` int(11) default NULL, + `ParentUUID` char(36) default NULL, + `OwnerID` char(36) default NULL, + `LastOwnerID` char(36) default NULL, + `CreatorID` char(36) default NULL, `CreationDate` int(11) default NULL, + `LinkNum` int(11) default NULL, `Name` varchar(255) default NULL, - `ParentUUID` char(36) default NULL, `Text` varchar(255) default NULL, `Description` varchar(255) default NULL, `SitName` varchar(255) default NULL, @@ -13,43 +20,43 @@ CREATE TABLE `Prims` ( `GroupMask` int(11) default NULL, `EveryoneMask` int(11) default NULL, `BaseMask` int(11) default NULL, - `PositionX` float default NULL, - `PositionY` float default NULL, - `PositionZ` float default NULL, - `GroupPositionX` float default NULL, - `GroupPositionY` float default NULL, - `GroupPositionZ` float default NULL, - `VelocityX` float default NULL, - `VelocityY` float default NULL, - `VelocityZ` float default NULL, - `AngularVelocityX` float default NULL, - `AngularVelocityY` float default NULL, - `AngularVelocityZ` float default NULL, - `AccelerationX` float default NULL, - `AccelerationY` float default NULL, - `AccelerationZ` float default NULL, - `RotationX` float default NULL, - `RotationY` float default NULL, - `RotationZ` float default NULL, - `RotationW` float default NULL, - `SitTargetOffsetX` float default NULL, - `SitTargetOffsetY` float default NULL, - `SitTargetOffsetZ` float default NULL, - `SitTargetOrientW` float default NULL, - `SitTargetOrientX` float default NULL, - `SitTargetOrientY` float default NULL, - `SitTargetOrientZ` float default NULL, - `UUID` char(36) NOT NULL default '', - `RegionID` char(36) default NULL, - `CreatorID` char(36) default NULL, - `OwnerID` char(36) default NULL, - `GroupID` char(36) default NULL, - `LastOwnerID` char(36) default NULL, + `Material` int(1) default NULL, + `ScriptAccessPin` int(11) default NULL, + `TextureAnimation` blob, + `ParticleSystem` blob, + `ClickAction` int(1) default NULL, + `Color` int(11) default NULL, + `PositionX` double default NULL, + `PositionY` double default NULL, + `PositionZ` double default NULL, + `GroupPositionX` double default NULL, + `GroupPositionY` double default NULL, + `GroupPositionZ` double default NULL, + `VelocityX` double default NULL, + `VelocityY` double default NULL, + `VelocityZ` double default NULL, + `AngularVelocityX` double default NULL, + `AngularVelocityY` double default NULL, + `AngularVelocityZ` double default NULL, + `AccelerationX` double default NULL, + `AccelerationY` double default NULL, + `AccelerationZ` double default NULL, + `RotationX` double default NULL, + `RotationY` double default NULL, + `RotationZ` double default NULL, + `RotationW` double default NULL, + `SitTargetOffsetX` double default NULL, + `SitTargetOffsetY` double default NULL, + `SitTargetOffsetZ` double default NULL, + `SitTargetOrientW` double default NULL, + `SitTargetOrientX` double default NULL, + `SitTargetOrientY` double default NULL, + `SitTargetOrientZ` double default NULL, -- this is the shape `Shape` int(11) default NULL, - `ScaleX` float default NULL, - `ScaleY` float default NULL, - `ScaleZ` float default NULL, + `ScaleX` double default NULL, + `ScaleY` double default NULL, + `ScaleZ` double default NULL, `PCode` int(11) default NULL, `PathBegin` int(11) default NULL, `PathEnd` int(11) default NULL, @@ -77,3 +84,4 @@ CREATE TABLE `Prims` ( KEY `prims_parentuuid` (`ParentUUID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_UserStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_UserStore.sql index 5db5d29..a66f5b8 100644 --- a/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_UserStore.sql +++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/001_UserStore.sql @@ -1,12 +1,12 @@ START TRANSACTION; CREATE TABLE `UserAgents` ( - `ProfileID` varchar(255) NOT NULL, + `ProfileID` varchar(36) NOT NULL, `AgentIP` varchar(24) default NULL, `AgentPort` int(11) default NULL, `AgentOnline` tinyint(1) default NULL, - `SessionID` varchar(255) default NULL, - `SecureSessionID` varchar(255) default NULL, + `SessionID` varchar(36) default NULL, + `SecureSessionID` varchar(36) default NULL, `InitialRegion` varchar(255) default NULL, `Region` varchar(255) default NULL, `LoginTime` int(11) default NULL, @@ -15,16 +15,21 @@ CREATE TABLE `UserAgents` ( `PositionX` float default NULL, `PositionY` float default NULL, `PositionZ` float default NULL, + `LookAtX` float default NULL, + `LookAtY` float default NULL, + `LookAtZ` float default NULL, PRIMARY KEY (`ProfileID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `UserProfiles` ( - `ID` varchar(255) NOT NULL, + `ID` varchar(36) NOT NULL, + `WebLoginKey` varchar(36) default NULL, `FirstName` varchar(32) default NULL, `SurName` varchar(32) default NULL, + `Email` varchar(250) default NULL, `PasswordHash` varchar(32) default NULL, `PasswordSalt` varchar(32) default NULL, - `WebLoginKey` varchar(255) default NULL, + `HomeRegionID` varchar(36) default NULL, `HomeRegionX` int(11) default NULL, `HomeRegionY` int(11) default NULL, `HomeLocationX` float default NULL, @@ -35,50 +40,67 @@ CREATE TABLE `UserProfiles` ( `HomeLookAtZ` float default NULL, `Created` int(11) default NULL, `LastLogin` int(11) default NULL, - `RootInventoryFolderID` varchar(255) default NULL, `UserInventoryURI` varchar(255) default NULL, `UserAssetURI` varchar(255) default NULL, - `Image` varchar(255) default NULL, - `FirstLifeImage` varchar(255) default NULL, - `AboutText` varchar(255) default NULL, - `FirstLifeAboutText` varchar(255) default NULL, + `Image` varchar(36) default NULL, + `FirstLifeImage` varchar(36) default NULL, + `AboutText` text default NULL, + `FirstLifeAboutText` text default NULL, + `CanDoMask` int(11) default NULL, + `WantDoMask` int(11) default NULL, + `UserFlags` int(11) default NULL, + `GodLevel` int(11) default NULL, + `CustomType` varchar(32) default NULL, + `Partner` varchar(36) default NULL, + `RootInventoryFolderID` varchar(36) default NULL, PRIMARY KEY (`ID`), - KEY `user_surname` (`SurName`), - KEY `user_firstname` (`FirstName`) + INDEX `UserSurnameIndex` (`SurName`), + INDEX `UserFirstNameIndex` (`FirstName`), + UNIQUE INDEX `UserFullNameIndex` (`SurName`,`FirstName`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `UserAppearances` ( - `Owner` varchar(255) NOT NULL, - `BodyItem` varchar(255) default NULL, - `BodyAsset` varchar(255) default NULL, - `SkinItem` varchar(255) default NULL, - `SkinAsset` varchar(255) default NULL, - `HairItem` varchar(255) default NULL, - `HairAsset` varchar(255) default NULL, - `EyesItem` varchar(255) default NULL, - `EyesAsset` varchar(255) default NULL, - `ShirtItem` varchar(255) default NULL, - `ShirtAsset` varchar(255) default NULL, - `PantsItem` varchar(255) default NULL, - `PantsAsset` varchar(255) default NULL, - `ShoesItem` varchar(255) default NULL, - `ShoesAsset` varchar(255) default NULL, - `SocksItem` varchar(255) default NULL, - `SocksAsset` varchar(255) default NULL, - `JacketItem` varchar(255) default NULL, - `JacketAsset` varchar(255) default NULL, - `GlovesItem` varchar(255) default NULL, - `GlovesAsset` varchar(255) default NULL, - `UnderShirtItem` varchar(255) default NULL, - `UnderShirtAsset` varchar(255) default NULL, - `UnderPantsItem` varchar(255) default NULL, - `UnderPantsAsset` varchar(255) default NULL, - `SkirtItem` varchar(255) default NULL, - `SkirtAsset` varchar(255) default NULL, + `Owner` varchar(36) NOT NULL, + `BodyItem` varchar(36) default NULL, + `BodyAsset` varchar(36) default NULL, + `SkinItem` varchar(36) default NULL, + `SkinAsset` varchar(36) default NULL, + `HairItem` varchar(36) default NULL, + `HairAsset` varchar(36) default NULL, + `EyesItem` varchar(36) default NULL, + `EyesAsset` varchar(36) default NULL, + `ShirtItem` varchar(36) default NULL, + `ShirtAsset` varchar(36) default NULL, + `PantsItem` varchar(36) default NULL, + `PantsAsset` varchar(36) default NULL, + `ShoesItem` varchar(36) default NULL, + `ShoesAsset` varchar(36) default NULL, + `SocksItem` varchar(36) default NULL, + `SocksAsset` varchar(36) default NULL, + `JacketItem` varchar(36) default NULL, + `JacketAsset` varchar(36) default NULL, + `GlovesItem` varchar(36) default NULL, + `GlovesAsset` varchar(36) default NULL, + `UnderShirtItem` varchar(36) default NULL, + `UnderShirtAsset` varchar(36) default NULL, + `UnderPantsItem` varchar(36) default NULL, + `UnderPantsAsset` varchar(36) default NULL, + `SkirtItem` varchar(36) default NULL, + `SkirtAsset` varchar(36) default NULL, `Texture` longblob, `VisualParams` longblob, `Serial` int(11) default NULL, + `AvatarHeight` float default NULL, PRIMARY KEY (`Owner`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -COMMIT; \ No newline at end of file +CREATE TABLE `UserFriends` ( + `UserFriendID` VARCHAR(36) NOT NULL, + `OwnerID` VARCHAR(36) NOT NULL, + `FriendID` VARCHAR(36) NOT NULL, + `FriendPermissions` INT(11) NOT NULL, + PRIMARY KEY (`UserFriendID`), + UNIQUE INDEX (`OwnerID`,`FriendID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +COMMIT; diff --git a/OpenSim/Data/NHibernate/Resources/MySQLDialect/003_RegionStore.sql b/OpenSim/Data/NHibernate/Resources/MySQLDialect/003_RegionStore.sql index 230e93c..e30287b 100644 --- a/OpenSim/Data/NHibernate/Resources/MySQLDialect/003_RegionStore.sql +++ b/OpenSim/Data/NHibernate/Resources/MySQLDialect/003_RegionStore.sql @@ -1,26 +1,78 @@ BEGIN; CREATE TABLE `PrimItems` ( + `ItemID` char(36) NOT NULL default '', + `GroupID` char(36) default NULL, + `PrimID` char(36) default NULL, + `ParentFolderID` char(36) default NULL, + `AssetID` char(36) default NULL, + `OwnerID` char(36) default NULL, + `LastOwnerID` char(36) default NULL, + `CreatorID` char(36) default NULL, + `CreationDate` bigint(20) default NULL, `InvType` int(11) default NULL, `Name` varchar(255) default NULL, `Description` varchar(255) default NULL, - `CreationDate` bigint(20) default NULL, `NextPermissions` int(11) default NULL, `CurrentPermissions` int(11) default NULL, `BasePermissions` int(11) default NULL, `EveryonePermissions` int(11) default NULL, `GroupPermissions` int(11) default NULL, `Flags` int(11) NOT NULL default '0', - `ItemID` char(36) NOT NULL default '', - `PrimID` char(36) default NULL, - `AssetID` char(36) default NULL, - `ParentFolderID` char(36) default NULL, - `CreatorID` char(36) default NULL, - `OwnerID` char(36) default NULL, - `GroupID` char(36) default NULL, - `LastOwnerID` char(36) default NULL, PRIMARY KEY (`ItemID`), KEY `primitems_primid` (`PrimID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -COMMIT; \ No newline at end of file +CREATE TABLE RegionSettings ( + `RegionID` char(36) default NULL, + + `BlockTerraform` bit(1) default NULL, + `BlockFly` bit(1) default NULL, + `AllowDamage` bit(1) default NULL, + `RestrictPushing` bit(1) default NULL, + `AllowLandResell` bit(1) default NULL, + `AllowLandJoinDivide` bit(1) default NULL, + `BlockShowInSearch` bit(1) default NULL, + + `AgentLimit` int(11) default NULL, + `ObjectBonus` double default NULL, + `Maturity` int(11) default NULL, + + `DisableScripts` bit(1) default NULL, + `DisableCollisions` bit(1) default NULL, + `DisablePhysics` bit(1) default NULL, + + `TerrainTexture1` char(36) default NULL, + `TerrainTexture2` char(36) default NULL, + `TerrainTexture3` char(36) default NULL, + `TerrainTexture4` char(36) default NULL, + + `Elevation1NW` double default NULL, + `Elevation2NW` double default NULL, + `Elevation1NE` double default NULL, + `Elevation2NE` double default NULL, + `Elevation1SE` double default NULL, + `Elevation2SE` double default NULL, + `Elevation1SW` double default NULL, + `Elevation2SW` double default NULL, + + `WaterHeight` double default NULL, + `TerrainRaiseLimit` double default NULL, + `TerrainLowerLimit` double default NULL, + + `UseEstateSun` bit(1) default NULL, + `Sandbox` bit(1) default NULL, + + `SunVectorX` double default NULL, + `SunVectorY` double default NULL, + `SunVectorZ` double default NULL, + + `FixedSun` bit(1) default NULL, + `SunPosition` double default NULL, + + `Covenant` char(36) default NULL, + + PRIMARY KEY (RegionID) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +COMMIT; diff --git a/OpenSim/Data/NHibernate/Resources/RegionSettings.hbm.xml b/OpenSim/Data/NHibernate/Resources/RegionSettings.hbm.xml new file mode 100644 index 0000000..5cfccba --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/RegionSettings.hbm.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml b/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml index 1851904..3144b0b 100644 --- a/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/RegionStore.hbm.xml @@ -13,12 +13,14 @@ - + + - + + @@ -26,6 +28,12 @@ + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_RegionStore.sql b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_RegionStore.sql index d557b9a..eaa0964 100644 --- a/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_RegionStore.sql +++ b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_RegionStore.sql @@ -2,25 +2,32 @@ BEGIN TRANSACTION; create table Prims ( UUID TEXT not null, + RegionID TEXT, + GroupID TEXT, ParentID INTEGER, ParentUUID TEXT, - RegionID TEXT, + OwnerID TEXT, + LastOwnerID TEXT, + CreatorID TEXT, CreationDate INTEGER, + LinkNum INTEGER, Name TEXT, Text TEXT, Description TEXT, SitName TEXT, TouchName TEXT, ObjectFlags INTEGER, - CreatorID TEXT, - OwnerID TEXT, - GroupID TEXT, - LastOwnerID TEXT, OwnerMask INTEGER, NextOwnerMask INTEGER, GroupMask INTEGER, EveryoneMask INTEGER, BaseMask INTEGER, + Material INTEGER, + ScriptAccessPin INTEGER, + TextureAnimation BLOB, + ParticleSystem BLOB, + ClickAction INTEGER, + Color INTEGER, PositionX NUMERIC, PositionY NUMERIC, PositionZ NUMERIC, @@ -99,4 +106,45 @@ create table PrimItems ( primary key (ItemID) ); -COMMIT; \ No newline at end of file +CREATE TABLE RegionSettings ( + RegionID TEXT not null, + BlockTerraform BIT, + BlockFly BIT, + AllowDamage BIT, + RestrictPushing BIT, + AllowLandResell BIT, + AllowLandJoinDivide BIT, + BlockShowInSearch BIT, + AgentLimit INTEGER, + ObjectBonus NUMERIC, + Maturity INTEGER, + DisableScripts BIT, + DisableCollisions BIT, + DisablePhysics BIT, + TerrainTexture1 TEXT, + TerrainTexture2 TEXT, + TerrainTexture3 TEXT, + TerrainTexture4 TEXT, + Elevation1NW NUMERIC, + Elevation2NW NUMERIC, + Elevation1NE NUMERIC, + Elevation2NE NUMERIC, + Elevation1SE NUMERIC, + Elevation2SE NUMERIC, + Elevation1SW NUMERIC, + Elevation2SW NUMERIC, + WaterHeight NUMERIC, + TerrainRaiseLimit NUMERIC, + TerrainLowerLimit NUMERIC, + UseEstateSun BIT, + Sandbox BIT, + SunVectorX NUMERIC, + SunVectorY NUMERIC, + SunVectorZ NUMERIC, + FixedSun BIT, + SunPosition NUMERIC, + Covenant TEXT, + primary key (RegionID) +); + +COMMIT; diff --git a/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_UserStore.sql b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_UserStore.sql index 8d1ba5c..c5e42d5 100644 --- a/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_UserStore.sql +++ b/OpenSim/Data/NHibernate/Resources/SQLiteDialect/001_UserStore.sql @@ -12,15 +12,24 @@ create table UserAgents ( LoginTime INTEGER, LogoutTime INTEGER, Handle INTEGER, + PositionX NUMERIC, + PositionY NUMERIC, + PositionZ NUMERIC, + LookAtX NUMERIC, + LookAtY NUMERIC, + LookAtZ NUMERIC, primary key (ProfileID) ); + create table UserProfiles ( ID TEXT not null, + WebLoginKey TEXT, FirstName TEXT, SurName TEXT, + Email TEXT, PasswordHash TEXT, PasswordSalt TEXT, - WebLoginKey TEXT, + HomeRegionID TEXT, HomeRegionX INTEGER, HomeRegionY INTEGER, HomeLocationX NUMERIC, @@ -31,15 +40,22 @@ create table UserProfiles ( HomeLookAtZ NUMERIC, Created INTEGER, LastLogin INTEGER, - RootInventoryFolderID TEXT, UserInventoryURI TEXT, UserAssetURI TEXT, Image TEXT, FirstLifeImage TEXT, AboutText TEXT, FirstLifeAboutText TEXT, + RootInventoryFolderID TEXT, + `CanDoMask` INTEGER, + `WantDoMask` INTEGER, + `UserFlags` INTEGER, + `GodLevel` INTEGER, + `CustomType` TEXT, + `Partner` TEXT, primary key (ID) ); + create table UserAppearances ( Owner TEXT not null, BodyItem TEXT, @@ -71,9 +87,22 @@ create table UserAppearances ( Texture BLOB, VisualParams BLOB, Serial INTEGER, + AvatarHeight NUMERIC, primary key (Owner) ); -create index user_firstname on UserProfiles (FirstName); -create index user_surname on UserProfiles (SurName); -COMMIT; \ No newline at end of file + +CREATE TABLE UserFriends ( + UserFriendID TEXT, + OwnerID TEXT, + FriendID TEXT, + FriendPermissions INTEGER, + primary key (UserFriendID) +); + +create index UserFirstNameIndex on UserProfiles (FirstName); +create index UserSurnameIndex on UserProfiles (SurName); +create unique index UserFullNameIndex on UserProfiles (FirstName,SurName); +create unique index UserFriendsOwnerFriendIndex on UserFriends (OwnerID,FriendID); + +COMMIT; diff --git a/OpenSim/Data/NHibernate/Resources/UserAgentData.hbm.xml b/OpenSim/Data/NHibernate/Resources/UserAgentData.hbm.xml index e10fb8f..70b6998 100644 --- a/OpenSim/Data/NHibernate/Resources/UserAgentData.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/UserAgentData.hbm.xml @@ -4,6 +4,7 @@ + @@ -14,8 +15,18 @@ - + + + + + + + + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/UserAppearance.hbm.xml b/OpenSim/Data/NHibernate/Resources/UserAppearance.hbm.xml index b633c34..21e547f 100644 --- a/OpenSim/Data/NHibernate/Resources/UserAppearance.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/UserAppearance.hbm.xml @@ -33,5 +33,6 @@ + diff --git a/OpenSim/Data/NHibernate/Resources/UserFriend.hbm.xml b/OpenSim/Data/NHibernate/Resources/UserFriend.hbm.xml new file mode 100644 index 0000000..70961b0 --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/UserFriend.hbm.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/OpenSim/Data/NHibernate/Resources/UserProfileData.hbm.xml b/OpenSim/Data/NHibernate/Resources/UserProfileData.hbm.xml index 740a9f1..5b1f9b0 100644 --- a/OpenSim/Data/NHibernate/Resources/UserProfileData.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/UserProfileData.hbm.xml @@ -4,11 +4,13 @@ - - + + + + - + @@ -19,12 +21,18 @@ - + + + + + + + diff --git a/OpenSim/Data/NHibernate/UserFriend.cs b/OpenSim/Data/NHibernate/UserFriend.cs new file mode 100644 index 0000000..c16b3c8 --- /dev/null +++ b/OpenSim/Data/NHibernate/UserFriend.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; + +namespace OpenSim.Data.NHibernate +{ + public class UserFriend + { + public UserFriend() + { + } + + public UserFriend(UUID userFriendID, UUID ownerID, UUID friendID, uint friendPermissions) + { + this.UserFriendID = userFriendID; + this.OwnerID = ownerID; + this.FriendID = friendID; + this.FriendPermissions = friendPermissions; + } + + public UUID UserFriendID { get; set; } + public UUID OwnerID { get; set; } + public UUID FriendID { get; set; } + public uint FriendPermissions { get; set; } + + } +} diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs index e5c6132..a0591fa 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/BasicRegionTest.cs @@ -130,8 +130,8 @@ namespace OpenSim.Data.Tests [Test] public void T010_StoreSimpleObject() { - SceneObjectGroup sog = NewSOG("object1", prim1); - SceneObjectGroup sog2 = NewSOG("object2", prim2); + SceneObjectGroup sog = NewSOG("object1", prim1, region1); + SceneObjectGroup sog2 = NewSOG("object2", prim2, region1); // in case the objects don't store try @@ -183,7 +183,7 @@ namespace OpenSim.Data.Tests SceneObjectPart p1 = NewSOP("SoP 1",tmp1); SceneObjectPart p2 = NewSOP("SoP 2",tmp2); SceneObjectPart p3 = NewSOP("SoP 3",tmp3); - SceneObjectGroup sog = NewSOG("Sop 0",tmp0); + SceneObjectGroup sog = NewSOG("Sop 0", tmp0, newregion); sog.AddPart(p1); sog.AddPart(p2); sog.AddPart(p3); @@ -246,7 +246,14 @@ namespace OpenSim.Data.Tests pbshap = PrimitiveBaseShape.Default; Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next()); byte updatef = (byte) random.Next(127); - + + RegionInfo regionInfo = new RegionInfo(); + regionInfo.RegionID = region3; + regionInfo.RegionLocX = 0; + regionInfo.RegionLocY = 0; + + Scene scene = new Scene(regionInfo); + SceneObjectPart sop = new SceneObjectPart(); sop.RegionHandle = regionh; sop.UUID = uuid; @@ -313,9 +320,10 @@ namespace OpenSim.Data.Tests Assert.That(updatef,Is.EqualTo(sop.UpdateFlag)); // This is necessary or object will not be inserted in DB - sop.ObjectFlags = 0; - + sop.ObjectFlags = 0; + SceneObjectGroup sog = new SceneObjectGroup(); + sog.SetScene(scene); // Reguired by nhibernate database module. sog.SetRootPart(sop); // Inserts group in DB @@ -365,7 +373,6 @@ namespace OpenSim.Data.Tests [Test] public void T014_UpdateObject() { - string text1 = "object1 text"; SceneObjectGroup sog = FindSOG("object1", region1); sog.RootPart.Text = text1; @@ -373,8 +380,7 @@ namespace OpenSim.Data.Tests sog = FindSOG("object1", region1); Assert.That(text1, Is.EqualTo(sog.RootPart.Text)); - - + // Creates random values UUID creator = new UUID(); creator = UUID.Random(); @@ -474,7 +480,7 @@ namespace OpenSim.Data.Tests { UUID id = UUID.Random(); Dictionary mydic = new Dictionary(); - SceneObjectGroup sog = NewSOG("Test SOG",id); + SceneObjectGroup sog = NewSOG("Test SOG", id, region4); mydic.Add(sog.RootPart.UUID,sog.RootPart); for (int i=0;i<30;i++) { @@ -888,9 +894,18 @@ namespace OpenSim.Data.Tests { SceneObjectPart p = sog.RootPart; if (p.Name == name) { + RegionInfo regionInfo = new RegionInfo(); + regionInfo.RegionID = r; + regionInfo.RegionLocX = 0; + regionInfo.RegionLocY = 0; + + Scene scene = new Scene(regionInfo); + sog.SetScene(scene); + return sog; } } + return null; } @@ -906,8 +921,15 @@ namespace OpenSim.Data.Tests // causes the application to crash at the database layer because of null values // in NOT NULL fields // - private SceneObjectGroup NewSOG(string name, UUID uuid) + private SceneObjectGroup NewSOG(string name, UUID uuid, UUID regionId) { + RegionInfo regionInfo = new RegionInfo(); + regionInfo.RegionID = regionId; + regionInfo.RegionLocX = 0; + regionInfo.RegionLocY = 0; + + Scene scene = new Scene(regionInfo); + SceneObjectPart sop = new SceneObjectPart(); sop.Name = name; sop.Description = name; @@ -916,9 +938,11 @@ namespace OpenSim.Data.Tests sop.TouchName = RandomName(); sop.UUID = uuid; sop.Shape = PrimitiveBaseShape.Default; - + SceneObjectGroup sog = new SceneObjectGroup(); + sog.SetScene(scene); sog.SetRootPart(sop); + return sog; } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 3b4b719..37ff645 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -404,6 +404,17 @@ namespace OpenSim.Region.Environment.Scenes } } + /// + /// Mock constructor for scene group persistency unit tests. + /// SceneObjectGroup RegionId property is delegated to Scene. + /// + /// + public Scene(RegionInfo regInfo) + { + m_regInfo = regInfo; + m_eventManager = new EventManager(); + } + #endregion #region Startup / Close Methods -- cgit v1.1