clean up the nhibernate definitions to work with mysql

integrate migration support into nhibernate
0.6.0-stable
Sean Dague 2008-06-18 21:14:19 +00:00
parent b58dc7fb33
commit 6dea8f3435
8 changed files with 30 additions and 117 deletions

View File

@ -93,33 +93,6 @@ namespace OpenSim.Data.NHibernate
Assembly assem = GetType().Assembly; Assembly assem = GetType().Assembly;
Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "AssetStore"); Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "AssetStore");
m.Update(); m.Update();
}
private void InitDB()
{
string regex = @"no such table: Assets";
Regex RE = new Regex(regex, RegexOptions.Multiline);
try
{
using (ISession session = factory.OpenSession())
{
session.Load(typeof(AssetBase), LLUUID.Zero);
}
}
catch (ObjectNotFoundException)
{
// yes, we know it's not there, but that's ok
}
catch (ADOException e)
{
Match m = RE.Match(e.ToString());
if (m.Success)
{
// We don't have this table, so create it.
new SchemaExport(cfg).Create(true, true);
}
}
} }
override public AssetBase FetchAsset(LLUUID uuid) override public AssetBase FetchAsset(LLUUID uuid)

View File

@ -62,6 +62,7 @@ namespace OpenSim.Data.NHibernate
// TODO: make this a real exception type // TODO: make this a real exception type
throw new Exception("Malformed Inventory connection string '" + connect + "'"); throw new Exception("Malformed Inventory connection string '" + connect + "'");
} }
string dialect = parts[0];
// Establish NHibernate Connection // Establish NHibernate Connection
cfg = new Configuration(); cfg = new Configuration();
@ -74,46 +75,13 @@ namespace OpenSim.Data.NHibernate
cfg.SetProperty(Environment.ConnectionString, parts[2]); cfg.SetProperty(Environment.ConnectionString, parts[2]);
cfg.AddAssembly("OpenSim.Data.NHibernate"); cfg.AddAssembly("OpenSim.Data.NHibernate");
HbmSerializer.Default.Validate = true;
using (MemoryStream stream =
HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()))
cfg.AddInputStream(stream);
// If uncommented this will auto create tables, but it
// does drops of the old tables, so we need a smarter way
// to acturally manage this.
// new SchemaExport(cfg).Create(true, true);
factory = cfg.BuildSessionFactory(); factory = cfg.BuildSessionFactory();
InitDB(); // 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();
private void InitDB()
{
string regex = @"no such table: Inventory";
Regex RE = new Regex(regex, RegexOptions.Multiline);
try
{
using (ISession session = factory.OpenSession())
{
session.Load(typeof(InventoryItemBase), LLUUID.Zero);
}
}
catch (ObjectNotFoundException)
{
// yes, we know it's not there, but that's ok
}
catch (ADOException e)
{
Match m = RE.Match(e.ToString());
if (m.Success)
{
// We don't have this table, so create it.
new SchemaExport(cfg).Create(true, true);
}
}
} }
/***************************************************************** /*****************************************************************

View File

@ -61,6 +61,7 @@ namespace OpenSim.Data.NHibernate
// TODO: make this a real exception type // TODO: make this a real exception type
throw new Exception("Malformed Inventory connection string '" + connect + "'"); throw new Exception("Malformed Inventory connection string '" + connect + "'");
} }
string dialect = parts[0];
// This is stubbing for now, it will become dynamic later and support different db backends // This is stubbing for now, it will become dynamic later and support different db backends
cfg = new Configuration(); cfg = new Configuration();
@ -73,41 +74,12 @@ namespace OpenSim.Data.NHibernate
cfg.SetProperty(Environment.ConnectionString, parts[2]); cfg.SetProperty(Environment.ConnectionString, parts[2]);
cfg.AddAssembly("OpenSim.Data.NHibernate"); cfg.AddAssembly("OpenSim.Data.NHibernate");
HbmSerializer.Default.Validate = true;
using (MemoryStream stream =
HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()))
cfg.AddInputStream(stream);
// new SchemaExport(cfg).Create(true, true);
factory = cfg.BuildSessionFactory(); factory = cfg.BuildSessionFactory();
InitDB();
}
private void InitDB() // This actually does the roll forward assembly stuff
{ Assembly assem = GetType().Assembly;
string regex = @"no such table: UserProfiles"; Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "AssetStore");
Regex RE = new Regex(regex, RegexOptions.Multiline); m.Update();
try
{
using (ISession session = factory.OpenSession())
{
session.Load(typeof(UserProfileData), LLUUID.Zero);
}
}
catch (ObjectNotFoundException)
{
// yes, we know it's not there, but that's ok
}
catch (ADOException e)
{
Match m = RE.Match(e.ToString());
if (m.Success)
{
// We don't have this table, so create it.
new SchemaExport(cfg).Create(true, true);
}
}
} }
private bool ExistsUser(LLUUID uuid) private bool ExistsUser(LLUUID uuid)

View File

@ -4,10 +4,10 @@
<id name="FullID" column="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate"> <id name="FullID" column="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="Type" type="SByte" /> <property name="Type" type="Int16" />
<property name="InvType" type="SByte" /> <property name="InvType" type="Int16" />
<property name="Name" type="String" length="50" /> <property name="Name" type="String" length="64" />
<property name="Description" type="String" length="50" /> <property name="Description" type="String" length="64" />
<property name="Local" type="boolean" /> <property name="Local" type="boolean" />
<property name="Temporary" type="boolean" /> <property name="Temporary" type="boolean" />
<property name="Data" type="binary" /> <property name="Data" type="binary" />

View File

@ -4,8 +4,8 @@
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate"> <id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="Type" type="short" /> <property name="Type" type="Int32" />
<property name="Version" type="UInt16" /> <property name="Version" type="Int32" />
<property name="ParentID" index="folder_parent_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, 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="Owner" index="folder_owner_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Name" type="String" length="64" /> <property name="Name" type="String" length="64" />

View File

@ -4,23 +4,23 @@
<id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate"> <id name="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="InvType" type="int" /> <property name="InvType" type="Int16" />
<property name="AssetType" type="int" /> <property name="AssetType" type="Int16" />
<property name="AssetID" type="OpenSim.Data.NHibernate.LLUUIDUserType, 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="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="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="Creator" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="Name" type="String" length="64" /> <property name="Name" type="String" length="64" />
<property name="Description" type="String" length="64" /> <property name="Description" type="String" length="64" />
<property name="NextPermissions" type="UInt32" /> <property name="NextPermissions" type="Int32" />
<property name="CurrentPermissions" type="UInt32" /> <property name="CurrentPermissions" type="Int32" />
<property name="BasePermissions" type="UInt32" /> <property name="BasePermissions" type="Int32" />
<property name="EveryOnePermissions" type="UInt32" /> <property name="EveryOnePermissions" type="Int32" />
<property name="GroupID" index="item_group_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="GroupID" index="item_group_id" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="GroupOwned" type="boolean" /> <property name="GroupOwned" type="boolean" />
<property name="SalePrice" type="Int32" /> <property name="SalePrice" type="Int32" />
<property name="SaleType" type="Byte" /> <property name="SaleType" type="Int16" />
<property name="Flags" type="UInt32" /> <property name="Flags" type="Int32" />
<property name="CreationDate" type="Int32" /> <property name="CreationDate" type="Int32" />
</class> </class>
</hibernate-mapping> </hibernate-mapping>

View File

@ -5,7 +5,7 @@
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="AgentIP" type="String" length="24" /> <property name="AgentIP" type="String" length="24" />
<property name="AgentPort" type="UInt32" /> <property name="AgentPort" type="Int32" />
<property name="AgentOnline" type="boolean" /> <property name="AgentOnline" type="boolean" />
<property name="SessionID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="SessionID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="SecureSessionID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="SecureSessionID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
@ -13,7 +13,7 @@
<property name="Region" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="Region" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="LoginTime" type="Int32" /> <property name="LoginTime" type="Int32" />
<property name="LogoutTime" type="Int32" /> <property name="LogoutTime" type="Int32" />
<property name="Handle" type="UInt64" /> <property name="Handle" type="Int64" />
<property name="PositionX" type="Single" /> <property name="PositionX" type="Single" />
<property name="PositionY" type="Single" /> <property name="PositionY" type="Single" />
<property name="PositionZ" type="Single" /> <property name="PositionZ" type="Single" />

View File

@ -9,16 +9,16 @@
<property name="PasswordHash" type="String" length="32" /> <property name="PasswordHash" type="String" length="32" />
<property name="PasswordSalt" type="String" length="32" /> <property name="PasswordSalt" type="String" length="32" />
<property name="WebLoginKey" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="WebLoginKey" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="HomeRegionX" type="UInt32" /> <property name="HomeRegionX" type="Int32" />
<property name="HomeRegionY" type="UInt32" /> <property name="HomeRegionY" type="Int32" />
<property name="HomeLocationX" type="Single" /> <property name="HomeLocationX" type="Single" />
<property name="HomeLocationY" type="Single" /> <property name="HomeLocationY" type="Single" />
<property name="HomeLocationZ" type="Single" /> <property name="HomeLocationZ" type="Single" />
<property name="HomeLookAtX" type="Single" /> <property name="HomeLookAtX" type="Single" />
<property name="HomeLookAtY" type="Single" /> <property name="HomeLookAtY" type="Single" />
<property name="HomeLookAtZ" type="Single" /> <property name="HomeLookAtZ" type="Single" />
<property name="Created" type="int" /> <property name="Created" type="Int32" />
<property name="LastLogin" type="int" /> <property name="LastLogin" type="Int32" />
<property name="RootInventoryFolderID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="RootInventoryFolderID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
<property name="UserInventoryURI" type="String" length="255"/> <property name="UserInventoryURI" type="String" length="255"/>
<property name="UserAssetURI" type="String" length="255"/> <property name="UserAssetURI" type="String" length="255"/>