aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateAssetData.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-12-01 07:50:38 +0000
committerAdam Frisby2008-12-01 07:50:38 +0000
commit4ed7ca62b153817a142ded621cc5c5c1b1c055c5 (patch)
treee8cad8abe60b6becd22da1a8d2c2dfefbf6f9784 /OpenSim/Data/NHibernate/NHibernateAssetData.cs
parentMantis #2729 (diff)
downloadopensim-SC_OLD-4ed7ca62b153817a142ded621cc5c5c1b1c055c5.zip
opensim-SC_OLD-4ed7ca62b153817a142ded621cc5c5c1b1c055c5.tar.gz
opensim-SC_OLD-4ed7ca62b153817a142ded621cc5c5c1b1c055c5.tar.bz2
opensim-SC_OLD-4ed7ca62b153817a142ded621cc5c5c1b1c055c5.tar.xz
* From Mantis#2701 - Implements NHibernate data adapter, adds support for MsSql2005 to NHibernate.
* Patch courtesy of Adminotech and realXtend. Thanks!
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateAssetData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateAssetData.cs77
1 files changed, 8 insertions, 69 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
index 6ee527e..90d41e3 100644
--- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
@@ -33,10 +33,7 @@ using System.Text.RegularExpressions;
33using OpenMetaverse; 33using OpenMetaverse;
34using log4net; 34using log4net;
35using NHibernate; 35using NHibernate;
36using NHibernate.Cfg;
37using NHibernate.Expression;
38using NHibernate.Mapping.Attributes; 36using NHibernate.Mapping.Attributes;
39using NHibernate.Tool.hbm2ddl;
40using OpenSim.Framework; 37using OpenSim.Framework;
41using Environment=NHibernate.Cfg.Environment; 38using Environment=NHibernate.Cfg.Environment;
42 39
@@ -49,9 +46,7 @@ namespace OpenSim.Data.NHibernate
49 { 46 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 48
52 private Configuration cfg; 49 private NHibernateManager manager;
53 private ISessionFactory factory;
54 private ISession session;
55 50
56 override public void Dispose() { } 51 override public void Dispose() { }
57 52
@@ -62,79 +57,23 @@ namespace OpenSim.Data.NHibernate
62 57
63 public override void Initialise(string connect) 58 public override void Initialise(string connect)
64 { 59 {
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
87 60
88 61 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateAssetData");
89 HbmSerializer.Default.Validate = true; 62 manager = new NHibernateManager(connect, "AssetStore");
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();
101 63
102 } 64 }
103 65
104 override public AssetBase FetchAsset(UUID uuid) 66 override public AssetBase FetchAsset(UUID uuid)
105 { 67 {
106 try 68 return (AssetBase)manager.Load(typeof(AssetBase), uuid);
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 }
120 } 69 }
121 70
122 private void Save(AssetBase asset) 71 private void Save(AssetBase asset)
123 { 72 {
124 try 73 AssetBase temp = (AssetBase)manager.Load(typeof(AssetBase), asset.FullID);
74 if (temp == null)
125 { 75 {
126 // a is not used anywhere? 76 manager.Save(asset);
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);
138 } 77 }
139 } 78 }
140 79
@@ -147,7 +86,7 @@ namespace OpenSim.Data.NHibernate
147 override public void UpdateAsset(AssetBase asset) 86 override public void UpdateAsset(AssetBase asset)
148 { 87 {
149 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); 88 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
150 Save(asset); 89 manager.Update(asset);
151 } 90 }
152 91
153 // private void LogAssetLoad(AssetBase asset) 92 // private void LogAssetLoad(AssetBase asset)