changing around types a bit to make stuff more readable for

me.
0.6.0-stable
Sean Dague 2008-04-09 13:43:35 +00:00
parent ea16221c1b
commit 750291447e
5 changed files with 48 additions and 46 deletions

View File

@ -99,8 +99,9 @@ namespace OpenSim.Data.NHibernate
{
using(ISession session = factory.OpenSession()) {
try {
return session.Load(typeof(InventoryItemBase), item.ToString()) as InventoryItemBase;
return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
} catch {
m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
return null;
}
}
@ -151,7 +152,7 @@ namespace OpenSim.Data.NHibernate
{
using(ISession session = factory.OpenSession()) {
using(ITransaction transaction = session.BeginTransaction()) {
session.Delete(itemID.ToString());
session.Delete(itemID);
transaction.Commit();
}
}
@ -167,8 +168,9 @@ namespace OpenSim.Data.NHibernate
{
using(ISession session = factory.OpenSession()) {
try {
return session.Load(typeof(InventoryFolderBase), folder.ToString()) as InventoryFolderBase;
return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
} catch {
m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
return null;
}
}
@ -296,8 +298,8 @@ namespace OpenSim.Data.NHibernate
{
using(ISession session = factory.OpenSession()) {
try {
IQuery query = session.CreateQuery("from InventoryItems i where i.parentFolderID = :parent");
query.SetString("parent", folderID.ToString());
IQuery query = session.CreateQuery("from InventoryItems i where i.Folder = :folder");
query.SetString("folder", folderID.ToString());
List<InventoryItemBase> list = new List<InventoryItemBase>();
foreach (InventoryItemBase item in query.List())
{
@ -318,21 +320,21 @@ namespace OpenSim.Data.NHibernate
// see InventoryItemBase.getUserRootFolder
public InventoryFolderBase getUserRootFolder(LLUUID user)
{
// using(ISession session = factory.OpenSession()) {
// try {
// IQuery query = session.CreateQuery("from InventoryItems i where i.parentFolderID = :parent");
// query.SetString("parent", folderID.ToString());
// List<InventoryItemBase> list = new List<InventoryItemBase>();
// foreach (InventoryItemBase item in query.List())
// {
// list.Add(item);
// }
// return list;
// } catch {
// return new List<InventoryItemBase>();
// }
// }
return new InventoryFolderBase();
using(ISession session = factory.OpenSession()) {
try {
IQuery query = session.CreateQuery("from InventoryFolders i where i.ParentID = :parent and i.Owner = :owner");
query.SetParameter("parent", LLUUID.Zero, NHibernateUtil.Custom(typeof(LLUUIDUserType)));
query.SetParameter("owner", user, NHibernateUtil.Custom(typeof(LLUUIDUserType)));
foreach (InventoryFolderBase folder in query.List())
{
return folder;
}
m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
return new InventoryFolderBase();
} catch {
return new InventoryFolderBase();
}
}
}
/// <summary>
@ -340,19 +342,19 @@ namespace OpenSim.Data.NHibernate
/// </summary>
/// <param name="folders">list where folders will be appended</param>
/// <param name="parentID">ID of parent</param>
protected void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
{
using(ISession session = factory.OpenSession()) {
try {
IQuery query = session.CreateQuery("from InventoryFolders i where i.parentFolderID = :parent");
query.SetString("parent", parentID.ToString());
// try {
IQuery query = session.CreateQuery("from InventoryFolders i where i.ParentID = :parent");
query.SetParameter("parent", parentID, NHibernateUtil.Custom(typeof(LLUUIDUserType)));
foreach (InventoryFolderBase item in query.List())
{
folders.Add(item);
}
} catch {
}
// } catch {
// m_log.ErrorFormat("Can't run getInventoryFolders for Folder ID: {0}", parentID);
// }
}
}
@ -364,7 +366,7 @@ namespace OpenSim.Data.NHibernate
public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
getInventoryFolders(ref folders, Util.ToRawUuidString(parentID));
getInventoryFolders(ref folders, parentID);
return folders;
}
@ -372,11 +374,11 @@ namespace OpenSim.Data.NHibernate
public List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID)
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
getInventoryFolders(ref folders, Util.ToRawUuidString(parentID));
getInventoryFolders(ref folders, parentID);
for (int i = 0; i < folders.Count; i++)
getInventoryFolders(ref folders, Util.ToRawUuidString(folders[i].ID));
getInventoryFolders(ref folders, folders[i].ID);
return folders;
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets" lazy="false">
<id name="FullID" column="UUID" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate">
<id name="FullID" column="UUID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="Type" type="SByte" />

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Framework.InventoryFolderBase, OpenSim.Framework" table="InventoryFolders" lazy="false">
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate">
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="Type" type="short" />
<property name="Version" type="short" />
<property name="ParentID" index="folder_parent_id" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="Owner" index="folder_owner_id" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="ParentID" index="folder_parent_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Owner" index="folder_owner_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Name" type="String" length="64" />
</class>
</hibernate-mapping>

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Framework.InventoryItemBase, OpenSim.Framework" table="InventoryItems" lazy="false">
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate">
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" />
</id>
<property name="InvType" type="int" />
<property name="AssetType" type="int" />
<property name="AssetID" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="Folder" index="item_folder_id" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="Owner" index="item_owner_id" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="Creator" type="OpenSim.Data.NHibernate.LLUUIDString, OpenSim.Data.NHibernate" />
<property name="AssetID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Folder" index="item_folder_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Owner" index="item_owner_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Creator" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Name" type="String" length="64" />
<property name="Description" type="String" length="64" />
<property name="NextPermissions" type="UInt32" />

View File

@ -1,5 +1,6 @@
using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using libsecondlife;
@ -7,14 +8,14 @@ using libsecondlife;
namespace OpenSim.Data.NHibernate
{
[Serializable]
public class LLUUIDString : IUserType
public class LLUUIDUserType: IUserType
{
public object Assemble(object cached, object owner)
{
return cached;
}
bool IUserType.Equals(object uuid1, object uuid2)
public bool IUserType.Equals(object uuid1, object uuid2)
{
return uuid1.Equals(uuid2);
}
@ -55,9 +56,8 @@ namespace OpenSim.Data.NHibernate
public void NullSafeSet(System.Data.IDbCommand cmd, object obj, int index)
{
LLUUID UUID = (LLUUID)obj;
((IDataParameter)cmd.Parameters[index]).Value = UUID.ToString();
System.Console.WriteLine("Setting UUID {0}", UUID.ToString());
LLUUID uuid = (LLUUID)obj;
((IDataParameter)cmd.Parameters[index]).Value = uuid.ToString();
}
public object Replace(object original, object target, object owner)
@ -72,7 +72,7 @@ namespace OpenSim.Data.NHibernate
public SqlType[] SqlTypes
{
get { return new SqlType [] { SqlTypeFactory.GetString(32) }; }
get { return new SqlType [] { NHibernateUtil.String.SqlType }; }
}
}
}