diff options
author | Sean Dague | 2008-04-03 20:59:20 +0000 |
---|---|---|
committer | Sean Dague | 2008-04-03 20:59:20 +0000 |
commit | cd4348738a57fcb85305642bf5e191b292c8d017 (patch) | |
tree | ca1db7f7bc7c6421e05c7156769357362a1cae9d | |
parent | Update svn properties. (diff) | |
download | opensim-SC-cd4348738a57fcb85305642bf5e191b292c8d017.zip opensim-SC-cd4348738a57fcb85305642bf5e191b292c8d017.tar.gz opensim-SC-cd4348738a57fcb85305642bf5e191b292c8d017.tar.bz2 opensim-SC-cd4348738a57fcb85305642bf5e191b292c8d017.tar.xz |
Check in the remaining bits to do Asset store via NHibernate. Still
need to work out auto table creation in a reasonable way. Tommorrow
I'll work on getting the NHibernate bits in place to be able to put this
into the main tree.
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateAssetData.cs | 56 | ||||
-rw-r--r-- | OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml | 15 |
2 files changed, 36 insertions, 35 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index cdb93df..41acd4c 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs | |||
@@ -47,6 +47,7 @@ namespace OpenSim.Data.NHibernate | |||
47 | { | 47 | { |
48 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | private Configuration cfg; | ||
50 | private ISessionFactory factory; | 51 | private ISessionFactory factory; |
51 | 52 | ||
52 | public override void Initialise() | 53 | public override void Initialise() |
@@ -54,7 +55,7 @@ namespace OpenSim.Data.NHibernate | |||
54 | // TODO: hard coding for sqlite based stuff to begin with, just making it easier to test | 55 | // TODO: hard coding for sqlite based stuff to begin with, just making it easier to test |
55 | 56 | ||
56 | // This is stubbing for now, it will become dynamic later and support different db backends | 57 | // This is stubbing for now, it will become dynamic later and support different db backends |
57 | Configuration cfg = new Configuration(); | 58 | cfg = new Configuration(); |
58 | cfg.SetProperty(Environment.ConnectionProvider, | 59 | cfg.SetProperty(Environment.ConnectionProvider, |
59 | "NHibernate.Connection.DriverConnectionProvider"); | 60 | "NHibernate.Connection.DriverConnectionProvider"); |
60 | cfg.SetProperty(Environment.Dialect, | 61 | cfg.SetProperty(Environment.Dialect, |
@@ -65,48 +66,49 @@ namespace OpenSim.Data.NHibernate | |||
65 | "URI=file:Asset.db,version=3"); | 66 | "URI=file:Asset.db,version=3"); |
66 | cfg.AddAssembly("OpenSim.Data.NHibernate"); | 67 | cfg.AddAssembly("OpenSim.Data.NHibernate"); |
67 | 68 | ||
68 | // HbmSerializer.Default.Validate = true; | 69 | HbmSerializer.Default.Validate = true; |
69 | // using ( System.IO.MemoryStream stream = | 70 | // using ( System.IO.MemoryStream stream = |
70 | // HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly())) | 71 | // HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly())) |
71 | // cfg.AddInputStream(stream); | 72 | // cfg.AddInputStream(stream); |
72 | 73 | ||
73 | // new SchemaExport(cfg).Create(true, true); | 74 | // new SchemaExport(cfg).Create(true, true); |
74 | 75 | ||
75 | factory = cfg.BuildSessionFactory(); | 76 | factory = cfg.BuildSessionFactory(); |
76 | |||
77 | } | 77 | } |
78 | 78 | ||
79 | override public AssetBase FetchAsset(LLUUID uuid) | 79 | override public AssetBase FetchAsset(LLUUID uuid) |
80 | { | 80 | { |
81 | return null; | 81 | using(ISession session = factory.OpenSession()) { |
82 | try { | ||
83 | return session.Load(typeof(AssetBase), uuid.ToString()) as AssetBase; | ||
84 | } catch { | ||
85 | return null; | ||
86 | } | ||
87 | } | ||
82 | } | 88 | } |
83 | 89 | ||
84 | override public void CreateAsset(AssetBase asset) | 90 | override public void CreateAsset(AssetBase asset) |
85 | { | 91 | { |
86 | ISession session = null; | 92 | if (!ExistsAsset(asset.FullID)) { |
87 | ITransaction transaction = null; | 93 | using(ISession session = factory.OpenSession()) { |
88 | try { | 94 | using(ITransaction transaction = session.BeginTransaction()) { |
89 | session = factory.OpenSession(); | 95 | session.Save(asset); |
90 | transaction = session.BeginTransaction(); | 96 | transaction.Commit(); |
91 | 97 | } | |
92 | session.SaveOrUpdate(asset); | 98 | } |
93 | // CRUD operations here (with the session) | ||
94 | transaction.Commit(); | ||
95 | } | ||
96 | catch { | ||
97 | if(transaction != null) | ||
98 | transaction.Rollback(); | ||
99 | throw; // Don't trap the exception | ||
100 | } | ||
101 | finally { | ||
102 | if(session != null) | ||
103 | session.Close(); | ||
104 | } | 99 | } |
105 | } | 100 | } |
106 | 101 | ||
107 | override public void UpdateAsset(AssetBase asset) | 102 | override public void UpdateAsset(AssetBase asset) |
108 | { | 103 | { |
109 | 104 | if (ExistsAsset(asset.FullID)) { | |
105 | using(ISession session = factory.OpenSession()) { | ||
106 | using(ITransaction transaction = session.BeginTransaction()) { | ||
107 | session.Update(asset); | ||
108 | transaction.Commit(); | ||
109 | } | ||
110 | } | ||
111 | } | ||
110 | } | 112 | } |
111 | 113 | ||
112 | private void LogAssetLoad(AssetBase asset) | 114 | private void LogAssetLoad(AssetBase asset) |
@@ -124,7 +126,7 @@ namespace OpenSim.Data.NHibernate | |||
124 | 126 | ||
125 | override public bool ExistsAsset(LLUUID uuid) | 127 | override public bool ExistsAsset(LLUUID uuid) |
126 | { | 128 | { |
127 | return false; | 129 | return (FetchAsset(uuid) != null) ? true : false; |
128 | } | 130 | } |
129 | 131 | ||
130 | public void DeleteAsset(LLUUID uuid) | 132 | public void DeleteAsset(LLUUID uuid) |
diff --git a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml index 82c30fe..ec4d168 100644 --- a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml +++ b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml | |||
@@ -1,16 +1,15 @@ | |||
1 | <?xml version="1.0" encoding="utf-8" ?> | 1 | <?xml version="1.0" encoding="utf-8" ?> |
2 | <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> | 2 | <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> |
3 | <class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets"> | 3 | <class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets" lazy="false"> |
4 | <id name="ID" column="UUID" type="String" length="36" > | 4 | <id name="ID" column="UUID" type="String" length="36" > |
5 | <generator class="assigned" /> | 5 | <generator class="assigned" /> |
6 | </id> | 6 | </id> |
7 | <property name="Type" type="integer" /> | 7 | <property name="Type" type="SByte" /> |
8 | <property name="InvType" type="integer" /> | 8 | <property name="InvType" type="SByte" /> |
9 | <property name="Name" type="String" length="50" /> | 9 | <property name="Name" type="String" length="50" /> |
10 | <property name="Description" type="String" length="50" /> | 10 | <property name="Description" type="String" length="50" /> |
11 | <property name="Local" type="boolean" /> | 11 | <property name="Local" type="boolean" /> |
12 | <property name="Temporary" type="boolean" /> | 12 | <property name="Temporary" type="boolean" /> |
13 | <property name="Data" type="binary" /> | 13 | <property name="Data" type="binary" /> |
14 | |||
15 | </class> | 14 | </class> |
16 | </hibernate-mapping> \ No newline at end of file | 15 | </hibernate-mapping> \ No newline at end of file |