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
Sean Dague 2008-06-20 20:23:55 +00:00
parent 0c84c27265
commit 17fd6cf661
4 changed files with 136 additions and 212 deletions

View File

@ -49,6 +49,7 @@ namespace OpenSim.Data.NHibernate
private Configuration cfg;
private ISessionFactory factory;
private ISession session;
public override void Initialise()
{
@ -87,27 +88,25 @@ 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
{
try
{
return session.Load(typeof(AssetBase), uuid) as AssetBase;
}
catch (Exception e)
{
m_log.Error("[NHIBERNATE] issue loading asset", e);
return null;
}
return session.Load(typeof(AssetBase), uuid) as AssetBase;
}
catch (Exception e)
{
m_log.Error("[NHIBERNATE] issue loading asset", e);
return null;
}
}
@ -116,13 +115,10 @@ namespace OpenSim.Data.NHibernate
if (!ExistsAsset(asset.FullID))
{
m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(asset);
transaction.Commit();
}
session.Save(asset);
transaction.Commit();
}
}
}
@ -131,13 +127,10 @@ namespace OpenSim.Data.NHibernate
{
if (ExistsAsset(asset.FullID))
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Update(asset);
transaction.Commit();
}
session.Update(asset);
transaction.Commit();
}
}
}

View File

@ -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;
@ -99,17 +101,14 @@ namespace OpenSim.Data.NHibernate
/// <returns>A class containing item information</returns>
public InventoryItemBase getInventoryItem(LLUUID item)
{
using (ISession session = factory.OpenSession())
try
{
try
{
return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
}
catch
{
m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
return null;
}
return session.Load(typeof(InventoryItemBase), item) as InventoryItemBase;
}
catch
{
m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
return null;
}
}
@ -121,13 +120,10 @@ namespace OpenSim.Data.NHibernate
{
if (!ExistsItem(item.ID))
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(item);
transaction.Commit();
}
session.Save(item);
transaction.Commit();
}
}
else
@ -145,13 +141,10 @@ namespace OpenSim.Data.NHibernate
{
if (ExistsItem(item.ID))
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Update(item);
transaction.Commit();
}
session.Update(item);
transaction.Commit();
}
}
else
@ -166,13 +159,10 @@ namespace OpenSim.Data.NHibernate
/// <param name="item"></param>
public void deleteInventoryItem(LLUUID itemID)
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete(itemID);
transaction.Commit();
}
session.Delete(itemID);
transaction.Commit();
}
}
@ -183,17 +173,14 @@ namespace OpenSim.Data.NHibernate
/// <returns>A class containing folder information</returns>
public InventoryFolderBase getInventoryFolder(LLUUID folder)
{
using (ISession session = factory.OpenSession())
try
{
try
{
return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
}
catch
{
m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
return null;
}
return session.Load(typeof(InventoryFolderBase), folder) as InventoryFolderBase;
}
catch
{
m_log.ErrorFormat("Couldn't find inventory item: {0}", folder);
return null;
}
}
@ -205,13 +192,10 @@ namespace OpenSim.Data.NHibernate
{
if (!ExistsFolder(folder.ID))
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(folder);
transaction.Commit();
}
session.Save(folder);
transaction.Commit();
}
}
else
@ -229,13 +213,10 @@ namespace OpenSim.Data.NHibernate
{
if (ExistsFolder(folder.ID))
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Update(folder);
transaction.Commit();
}
session.Update(folder);
transaction.Commit();
}
}
else
@ -250,13 +231,10 @@ namespace OpenSim.Data.NHibernate
/// <param name="folder"></param>
public void deleteInventoryFolder(LLUUID folderID)
{
using (ISession session = factory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Delete(folderID.ToString());
transaction.Commit();
}
session.Delete(folderID.ToString());
transaction.Commit();
}
}
@ -329,23 +307,20 @@ namespace OpenSim.Data.NHibernate
/// <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));
criteria.Add(Expression.Eq("Folder", folderID));
List<InventoryItemBase> list = new List<InventoryItemBase>();
foreach (InventoryItemBase item in criteria.List())
{
// try {
ICriteria criteria = session.CreateCriteria(typeof(InventoryItemBase));
criteria.Add(Expression.Eq("Folder", folderID));
List<InventoryItemBase> list = new List<InventoryItemBase>();
foreach (InventoryItemBase item in criteria.List())
{
list.Add(item);
}
return list;
// }
// catch
// {
// return new List<InventoryItemBase>();
// }
list.Add(item);
}
return list;
// }
// catch
// {
// return new List<InventoryItemBase>();
// }
}
public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
@ -356,18 +331,15 @@ 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));
criteria.Add(Expression.Eq("Owner", user));
foreach (InventoryFolderBase folder in criteria.List())
{
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
criteria.Add(Expression.Eq("ParentID", LLUUID.Zero));
criteria.Add(Expression.Eq("Owner", user));
foreach (InventoryFolderBase folder in criteria.List())
{
return folder;
}
m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
return null;
return folder;
}
m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
return null;
}
/// <summary>
@ -377,15 +349,11 @@ 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())
{
ICriteria criteria = session.CreateCriteria(typeof(InventoryFolderBase));
criteria.Add(Expression.Eq("ParentID", parentID));
foreach (InventoryFolderBase item in criteria.List())
{
folders.Add(item);
}
folders.Add(item);
}
}

View File

@ -51,6 +51,7 @@ namespace OpenSim.Data.NHibernate
private Configuration cfg;
private ISessionFactory factory;
private ISession session;
public override void Initialise(string connect)
{
@ -75,7 +76,8 @@ 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;
Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "UserStore");
@ -87,10 +89,7 @@ namespace OpenSim.Data.NHibernate
UserProfileData user = null;
try
{
using (ISession session = factory.OpenSession())
{
user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
}
user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
}
catch (Exception) {}
@ -101,11 +100,9 @@ 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);
}
user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
user.CurrentAgent = GetAgentByUUID(uuid);
return user;
}
@ -113,16 +110,10 @@ namespace OpenSim.Data.NHibernate
{
if (!ExistsUser(profile.ID))
{
using (ISession session = factory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(profile);
SetAgentData(profile.ID, profile.CurrentAgent, session);
// TODO: save agent
transaction.Commit();
}
}
session.Save(profile);
SetAgentData(profile.ID, profile.CurrentAgent);
// TODO: save agent
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,14 +131,12 @@ namespace OpenSim.Data.NHibernate
else
{
UserAgentData old = session.Load(typeof(UserAgentData), uuid) as UserAgentData;
if (old == null)
if (old != null)
{
session.Save(agent);
}
else
{
session.Update(agent);
session.Delete(old);
}
session.Save(agent);
}
}
@ -155,16 +144,10 @@ namespace OpenSim.Data.NHibernate
{
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();
return true;
}
}
session.Update(profile);
SetAgentData(profile.ID, profile.CurrentAgent);
session.Transaction.Commit();
return true;
}
else
{
@ -176,36 +159,27 @@ namespace OpenSim.Data.NHibernate
override public void AddNewUserAgent(UserAgentData agent)
{
using (ISession session = factory.OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(agent);
transaction.Commit();
}
UserAgentData old = session.Load(typeof(UserAgentData), agent.ProfileID) as UserAgentData;
if (old == null) {
session.Save(agent);
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.Update(agent);
session.Transaction.Commit();
}
override public UserAgentData GetAgentByUUID(LLUUID uuid)
{
try
{
using (ISession session = factory.OpenSession())
{
return session.Load(typeof(UserAgentData), uuid) as UserAgentData;
}
return session.Load(typeof(UserAgentData), uuid) as UserAgentData;
}
catch
{
@ -215,18 +189,15 @@ 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));
criteria.Add(Expression.Eq("SurName", lname));
foreach (UserProfileData profile in criteria.List())
{
ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
criteria.Add(Expression.Eq("FirstName", fname));
criteria.Add(Expression.Eq("SurName", lname));
foreach (UserProfileData profile in criteria.List())
{
profile.CurrentAgent = GetAgentByUUID(profile.ID);
return profile;
}
return null;
profile.CurrentAgent = GetAgentByUUID(profile.ID);
return profile;
}
return null;
}
override public UserAgentData GetAgentByName(string fname, string lname)
@ -247,19 +218,16 @@ namespace OpenSim.Data.NHibernate
if (querysplit.Length == 2)
{
using (ISession session = factory.OpenSession())
ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
criteria.Add(Expression.Like("FirstName", querysplit[0]));
criteria.Add(Expression.Like("SurName", querysplit[1]));
foreach (UserProfileData profile in criteria.List())
{
ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
criteria.Add(Expression.Like("FirstName", querysplit[0]));
criteria.Add(Expression.Like("SurName", querysplit[1]));
foreach (UserProfileData profile in criteria.List())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = profile.ID;
user.firstName = profile.FirstName;
user.lastName = profile.SurName;
results.Add(user);
}
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = profile.ID;
user.firstName = profile.FirstName;
user.lastName = profile.SurName;
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;
}
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;
}
appearance = session.Load(typeof(AvatarAppearance), uuid) as AvatarAppearance;
return (appearance == null) ? false : true;
}
@ -302,20 +267,18 @@ 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())
{
using (ITransaction transaction = session.BeginTransaction())
if (exists)
{
if (exists)
{
session.Update(appearance);
}
else
{
session.Save(appearance);
}
transaction.Commit();
session.Update(appearance);
}
else
{
session.Save(appearance);
}
transaction.Commit();
}
}

View File

@ -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>