aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateAssetData.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-12-01 18:42:14 +0000
committerJustin Clarke Casey2008-12-01 18:42:14 +0000
commit80520206fcd4c8c85eb28b4800c42136365b164d (patch)
tree9a5f583028198b44b0dc98b409fa410a4dab6418 /OpenSim/Data/NHibernate/NHibernateAssetData.cs
parent* Temporarily revert nhibernate.dll to the previous one (diff)
downloadopensim-SC_OLD-80520206fcd4c8c85eb28b4800c42136365b164d.zip
opensim-SC_OLD-80520206fcd4c8c85eb28b4800c42136365b164d.tar.gz
opensim-SC_OLD-80520206fcd4c8c85eb28b4800c42136365b164d.tar.bz2
opensim-SC_OLD-80520206fcd4c8c85eb28b4800c42136365b164d.tar.xz
* Unforunately it turns out not to be that simple. Revert the rest of r7560 for now.
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateAssetData.cs77
1 files changed, 69 insertions, 8 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
index 90d41e3..6ee527e 100644
--- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
@@ -33,7 +33,10 @@ using System.Text.RegularExpressions;
33using OpenMetaverse; 33using OpenMetaverse;
34using log4net; 34using log4net;
35using NHibernate; 35using NHibernate;
36using NHibernate.Cfg;
37using NHibernate.Expression;
36using NHibernate.Mapping.Attributes; 38using NHibernate.Mapping.Attributes;
39using NHibernate.Tool.hbm2ddl;
37using OpenSim.Framework; 40using OpenSim.Framework;
38using Environment=NHibernate.Cfg.Environment; 41using Environment=NHibernate.Cfg.Environment;
39 42
@@ -46,7 +49,9 @@ namespace OpenSim.Data.NHibernate
46 { 49 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 51
49 private NHibernateManager manager; 52 private Configuration cfg;
53 private ISessionFactory factory;
54 private ISession session;
50 55
51 override public void Dispose() { } 56 override public void Dispose() { }
52 57
@@ -57,23 +62,79 @@ namespace OpenSim.Data.NHibernate
57 62
58 public override void Initialise(string connect) 63 public override void Initialise(string connect)
59 { 64 {
65 // Split out the dialect, driver, and connect string
66 char[] split = {';'};
67 string[] parts = connect.Split(split, 3);
68 if (parts.Length != 3)
69 {
70 // TODO: make this a real exception type
71 throw new Exception("Malformed Inventory connection string '" + connect + "'");
72 }
73
74 string dialect = parts[0];
75
76 // NHibernate setup
77 cfg = new Configuration();
78 cfg.SetProperty(Environment.ConnectionProvider,
79 "NHibernate.Connection.DriverConnectionProvider");
80 cfg.SetProperty(Environment.Dialect,
81 "NHibernate.Dialect." + dialect);
82 cfg.SetProperty(Environment.ConnectionDriver,
83 "NHibernate.Driver." + parts[1]);
84 cfg.SetProperty(Environment.ConnectionString, parts[2]);
85 cfg.AddAssembly("OpenSim.Data.NHibernate");
86
60 87
61 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateAssetData"); 88
62 manager = new NHibernateManager(connect, "AssetStore"); 89 HbmSerializer.Default.Validate = true;
90 using (MemoryStream stream =
91 HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()))
92 cfg.AddInputStream(stream);
93
94 factory = cfg.BuildSessionFactory();
95 session = factory.OpenSession();
96
97 // This actually does the roll forward assembly stuff
98 Assembly assem = GetType().Assembly;
99 Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "AssetStore");
100 m.Update();
63 101
64 } 102 }
65 103
66 override public AssetBase FetchAsset(UUID uuid) 104 override public AssetBase FetchAsset(UUID uuid)
67 { 105 {
68 return (AssetBase)manager.Load(typeof(AssetBase), uuid); 106 try
107 {
108 return session.Load(typeof(AssetBase), uuid) as AssetBase;
109 }
110 catch (ObjectNotFoundException)
111 {
112 m_log.ErrorFormat("[NHIBERNATE] no such asset {0}", uuid);
113 return null;
114 }
115 catch (Exception e)
116 {
117 m_log.Error("[NHIBERNATE] unexpected exception: ", e);
118 return null;
119 }
69 } 120 }
70 121
71 private void Save(AssetBase asset) 122 private void Save(AssetBase asset)
72 { 123 {
73 AssetBase temp = (AssetBase)manager.Load(typeof(AssetBase), asset.FullID); 124 try
74 if (temp == null)
75 { 125 {
76 manager.Save(asset); 126 // a is not used anywhere?
127 // AssetBase a = session.Load(typeof(AssetBase), asset.FullID) as AssetBase;
128 session.Load(typeof(AssetBase), asset.FullID);
129 }
130 catch (ObjectNotFoundException)
131 {
132 session.Save(asset);
133 session.Flush();
134 }
135 catch (Exception e)
136 {
137 m_log.Error("[NHIBERNATE] issue saving asset", e);
77 } 138 }
78 } 139 }
79 140
@@ -86,7 +147,7 @@ namespace OpenSim.Data.NHibernate
86 override public void UpdateAsset(AssetBase asset) 147 override public void UpdateAsset(AssetBase asset)
87 { 148 {
88 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); 149 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
89 manager.Update(asset); 150 Save(asset);
90 } 151 }
91 152
92 // private void LogAssetLoad(AssetBase asset) 153 // private void LogAssetLoad(AssetBase asset)