lots of futzing with nhibernate to make it more efficient. I
don't think this works, but I don't want to loose the work before the weekend, and it doesn't break the build.0.6.0-stable
parent
0c84c27265
commit
17fd6cf661
|
@ -49,6 +49,7 @@ namespace OpenSim.Data.NHibernate
|
|||
|
||||
private Configuration cfg;
|
||||
private ISessionFactory factory;
|
||||
private ISession session;
|
||||
|
||||
public override void Initialise()
|
||||
{
|
||||
|
@ -87,17 +88,16 @@ namespace OpenSim.Data.NHibernate
|
|||
cfg.AddInputStream(stream);
|
||||
|
||||
factory = cfg.BuildSessionFactory();
|
||||
|
||||
session = factory.OpenSession();
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "AssetStore");
|
||||
m.Update();
|
||||
|
||||
}
|
||||
|
||||
override public AssetBase FetchAsset(LLUUID uuid)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -109,15 +109,12 @@ namespace OpenSim.Data.NHibernate
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public void CreateAsset(AssetBase asset)
|
||||
{
|
||||
if (!ExistsAsset(asset.FullID))
|
||||
{
|
||||
m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
session.Save(asset);
|
||||
|
@ -125,13 +122,10 @@ namespace OpenSim.Data.NHibernate
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public void UpdateAsset(AssetBase asset)
|
||||
{
|
||||
if (ExistsAsset(asset.FullID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -140,7 +134,6 @@ namespace OpenSim.Data.NHibernate
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LogAssetLoad(AssetBase asset)
|
||||
{
|
||||
|
|
|
@ -48,6 +48,7 @@ namespace OpenSim.Data.NHibernate
|
|||
|
||||
private Configuration cfg;
|
||||
private ISessionFactory factory;
|
||||
private ISession session;
|
||||
|
||||
/// <summary>
|
||||
/// Initialises the interface
|
||||
|
@ -76,6 +77,7 @@ namespace OpenSim.Data.NHibernate
|
|||
cfg.AddAssembly("OpenSim.Data.NHibernate");
|
||||
|
||||
factory = cfg.BuildSessionFactory();
|
||||
session = factory.OpenSession();
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
|
@ -98,8 +100,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// <param name="item">The UUID of the item to be returned</param>
|
||||
/// <returns>A class containing item information</returns>
|
||||
public InventoryItemBase getInventoryItem(LLUUID item)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -111,7 +111,6 @@ namespace OpenSim.Data.NHibernate
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inventory item based on item
|
||||
|
@ -120,8 +119,6 @@ namespace OpenSim.Data.NHibernate
|
|||
public void addInventoryItem(InventoryItemBase item)
|
||||
{
|
||||
if (!ExistsItem(item.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -129,7 +126,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists, updating instead", item.ID);
|
||||
|
@ -144,8 +140,6 @@ namespace OpenSim.Data.NHibernate
|
|||
public void updateInventoryItem(InventoryItemBase item)
|
||||
{
|
||||
if (ExistsItem(item.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -153,7 +147,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("Attempted to add Inventory Item {0} that already exists", item.ID);
|
||||
|
@ -165,8 +158,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void deleteInventoryItem(LLUUID itemID)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -174,7 +165,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an inventory folder by its UUID
|
||||
|
@ -182,8 +172,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// <param name="folder">The UUID of the folder to be returned</param>
|
||||
/// <returns>A class containing folder information</returns>
|
||||
public InventoryFolderBase getInventoryFolder(LLUUID folder)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -195,7 +183,6 @@ namespace OpenSim.Data.NHibernate
|
|||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inventory folder based on folder
|
||||
|
@ -204,8 +191,6 @@ namespace OpenSim.Data.NHibernate
|
|||
public void addInventoryFolder(InventoryFolderBase folder)
|
||||
{
|
||||
if (!ExistsFolder(folder.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -213,7 +198,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists, updating instead", folder.ID);
|
||||
|
@ -228,8 +212,6 @@ namespace OpenSim.Data.NHibernate
|
|||
public void updateInventoryFolder(InventoryFolderBase folder)
|
||||
{
|
||||
if (ExistsFolder(folder.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -237,7 +219,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("Attempted to add Inventory Folder {0} that already exists", folder.ID);
|
||||
|
@ -249,8 +230,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// </summary>
|
||||
/// <param name="folder"></param>
|
||||
public void deleteInventoryFolder(LLUUID folderID)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
|
@ -258,7 +237,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// useful private methods
|
||||
private bool ExistsItem(LLUUID uuid)
|
||||
|
@ -328,8 +306,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// <param name="folderID">The UUID of the target folder</param>
|
||||
/// <returns>A List of InventoryItemBase items</returns>
|
||||
public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
// try {
|
||||
ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
|
||||
|
@ -340,12 +316,11 @@ namespace OpenSim.Data.NHibernate
|
|||
list.Add(item);
|
||||
}
|
||||
return list;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// return new List<InventoryItemBase>();
|
||||
// }
|
||||
}
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// return new List<InventoryItemBase>();
|
||||
// }
|
||||
}
|
||||
|
||||
public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
|
||||
|
@ -355,8 +330,6 @@ namespace OpenSim.Data.NHibernate
|
|||
|
||||
// see InventoryItemBase.getUserRootFolder
|
||||
public InventoryFolderBase getUserRootFolder(LLUUID user)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
|
||||
criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
|
||||
|
@ -368,7 +341,6 @@ namespace OpenSim.Data.NHibernate
|
|||
m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a list of all the child folders of a parent folder
|
||||
|
@ -377,9 +349,6 @@ namespace OpenSim.Data.NHibernate
|
|||
/// <param name="parentID">ID of parent</param>
|
||||
private void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
|
||||
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
|
||||
criteria.Add(Expression.Eq("ParentID", parentID));
|
||||
foreach (InventoryFolderBase item in criteria.List())
|
||||
|
@ -387,7 +356,6 @@ namespace OpenSim.Data.NHibernate
|
|||
folders.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of inventory folders contained in the folder 'parentID'
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace OpenSim.Data.NHibernate
|
|||
|
||||
private Configuration cfg;
|
||||
private ISessionFactory factory;
|
||||
private ISession session;
|
||||
|
||||
public override void Initialise(string connect)
|
||||
{
|
||||
|
@ -75,6 +76,7 @@ namespace OpenSim.Data.NHibernate
|
|||
cfg.AddAssembly("OpenSim.Data.NHibernate");
|
||||
|
||||
factory = cfg.BuildSessionFactory();
|
||||
session = factory.OpenSession();
|
||||
|
||||
// This actually does the roll forward assembly stuff
|
||||
Assembly assem = GetType().Assembly;
|
||||
|
@ -86,12 +88,9 @@ namespace OpenSim.Data.NHibernate
|
|||
{
|
||||
UserProfileData user = null;
|
||||
try
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
|
||||
}
|
||||
}
|
||||
catch (Exception) {}
|
||||
|
||||
return (user != null);
|
||||
|
@ -101,28 +100,20 @@ namespace OpenSim.Data.NHibernate
|
|||
{
|
||||
UserProfileData user;
|
||||
// TODO: I'm sure I'll have to do something silly here
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
|
||||
user.CurrentAgent = GetAgentByUUID(uuid);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
override public void AddNewUserProfile(UserProfileData profile)
|
||||
{
|
||||
if (!ExistsUser(profile.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
session.Save(profile);
|
||||
SetAgentData(profile.ID, profile.CurrentAgent, session);
|
||||
SetAgentData(profile.ID, profile.CurrentAgent);
|
||||
// TODO: save agent
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
session.Transaction.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,7 +122,7 @@ namespace OpenSim.Data.NHibernate
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetAgentData(LLUUID uuid, UserAgentData agent, ISession session)
|
||||
private void SetAgentData(LLUUID uuid, UserAgentData agent)
|
||||
{
|
||||
if (agent == null)
|
||||
{
|
||||
|
@ -140,32 +131,24 @@ namespace OpenSim.Data.NHibernate
|
|||
else
|
||||
{
|
||||
UserAgentData old = session.Load(typeof(UserAgentData), uuid) as UserAgentData;
|
||||
if (old == null)
|
||||
if (old != null)
|
||||
{
|
||||
session.Delete(old);
|
||||
}
|
||||
|
||||
session.Save(agent);
|
||||
}
|
||||
else
|
||||
{
|
||||
session.Update(agent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
override public bool UpdateUserProfile(UserProfileData profile)
|
||||
{
|
||||
if (ExistsUser(profile.ID))
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
session.Update(profile);
|
||||
SetAgentData(profile.ID, profile.CurrentAgent, session);
|
||||
transaction.Commit();
|
||||
SetAgentData(profile.ID, profile.CurrentAgent);
|
||||
session.Transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.ErrorFormat("Attempted to update User {0} {1} that doesn't exist, updating instead", profile.FirstName, profile.SurName);
|
||||
|
@ -176,37 +159,28 @@ namespace OpenSim.Data.NHibernate
|
|||
|
||||
override public void AddNewUserAgent(UserAgentData agent)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
UserAgentData old = session.Load(typeof(UserAgentData), agent.ProfileID) as UserAgentData;
|
||||
|
||||
if (old == null) {
|
||||
session.Save(agent);
|
||||
transaction.Commit();
|
||||
}
|
||||
session.Transaction.Commit();
|
||||
} else {
|
||||
UpdateUserAgent(agent);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUserAgent(UserAgentData agent)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
session.Update(agent);
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
session.Transaction.Commit();
|
||||
}
|
||||
|
||||
override public UserAgentData GetAgentByUUID(LLUUID uuid)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
return session.Load(typeof(UserAgentData), uuid) as UserAgentData;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
|
@ -214,8 +188,6 @@ namespace OpenSim.Data.NHibernate
|
|||
}
|
||||
|
||||
override public UserProfileData GetUserByName(string fname, string lname)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
|
||||
criteria.Add(Expression.Eq("FirstName", fname));
|
||||
|
@ -227,7 +199,6 @@ namespace OpenSim.Data.NHibernate
|
|||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
override public UserAgentData GetAgentByName(string fname, string lname)
|
||||
{
|
||||
|
@ -246,8 +217,6 @@ namespace OpenSim.Data.NHibernate
|
|||
querysplit = query.Split(' ');
|
||||
|
||||
if (querysplit.Length == 2)
|
||||
{
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
|
||||
criteria.Add(Expression.Like("FirstName", querysplit[0]));
|
||||
|
@ -261,7 +230,6 @@ namespace OpenSim.Data.NHibernate
|
|||
results.Add(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -281,20 +249,17 @@ namespace OpenSim.Data.NHibernate
|
|||
{
|
||||
AvatarAppearance appearance;
|
||||
// TODO: I'm sure I'll have to do something silly here
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
appearance = session.Load(typeof(AvatarAppearance), user) as AvatarAppearance;
|
||||
}
|
||||
|
||||
return appearance;
|
||||
}
|
||||
|
||||
private bool ExistsAppearance(LLUUID uuid)
|
||||
{
|
||||
AvatarAppearance appearance;
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
|
||||
appearance = session.Load(typeof(AvatarAppearance), uuid) as AvatarAppearance;
|
||||
}
|
||||
|
||||
return (appearance == null) ? false : true;
|
||||
}
|
||||
|
||||
|
@ -302,8 +267,7 @@ namespace OpenSim.Data.NHibernate
|
|||
public override void UpdateUserAppearance(LLUUID user, AvatarAppearance appearance)
|
||||
{
|
||||
bool exists = ExistsAppearance(user);
|
||||
using (ISession session = factory.OpenSession())
|
||||
{
|
||||
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
if (exists)
|
||||
|
@ -317,7 +281,6 @@ namespace OpenSim.Data.NHibernate
|
|||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public void AddAttachment(LLUUID user, LLUUID item)
|
||||
{
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
<property name="EveryOnePermissions" type="System.UInt32" />
|
||||
<property name="GroupID" index="item_group_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
|
||||
<property name="GroupOwned" type="boolean" />
|
||||
<property name="SalePrice" type="Int32" />
|
||||
<property name="SaleType" type="Int16" />
|
||||
<property name="Flags" type="Int32" />
|
||||
<property name="SalePrice" type="System.Int32" />
|
||||
<property name="SaleType" type="System.Byte" />
|
||||
<property name="Flags" type="Syste.UInt32" />
|
||||
<property name="CreationDate" type="Int32" />
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue