diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateAssetData.cs | 56 |
1 files changed, 29 insertions, 27 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) |