aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateAssetData.cs
diff options
context:
space:
mode:
authorSean Dague2008-04-03 12:29:25 +0000
committerSean Dague2008-04-03 12:29:25 +0000
commitfe14d65f07b453b079aee1fe5ae17cfe7d6cb855 (patch)
treeee8a561b95bf7bd20fc6c77208bc832d2e35f12e /OpenSim/Data/NHibernate/NHibernateAssetData.cs
parent* ODEPlugin: put a limit on the minimum size a prim can be ( scale <=0 ). (diff)
downloadopensim-SC_OLD-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.zip
opensim-SC_OLD-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.gz
opensim-SC_OLD-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.bz2
opensim-SC_OLD-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.xz
point in time update of NHibernate Asset Mapping code
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateAssetData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateAssetData.cs154
1 files changed, 154 insertions, 0 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
new file mode 100644
index 0000000..cdb93df
--- /dev/null
+++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs
@@ -0,0 +1,154 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Data;
30using System.Reflection;
31using libsecondlife;
32using NHibernate;
33using NHibernate.Cfg;
34using NHibernate.Tool.hbm2ddl;
35using NHibernate.Mapping.Attributes;
36using OpenSim.Data;
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39using Environment = NHibernate.Cfg.Environment;
40
41namespace OpenSim.Data.NHibernate
42{
43 /// <summary>
44 /// A User storage interface for the DB4o database system
45 /// </summary>
46 public class NHibernateAssetData : AssetDataBase, IDisposable
47 {
48 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
49
50 private ISessionFactory factory;
51
52 public override void Initialise()
53 {
54 // TODO: hard coding for sqlite based stuff to begin with, just making it easier to test
55
56 // This is stubbing for now, it will become dynamic later and support different db backends
57 Configuration cfg = new Configuration();
58 cfg.SetProperty(Environment.ConnectionProvider,
59 "NHibernate.Connection.DriverConnectionProvider");
60 cfg.SetProperty(Environment.Dialect,
61 "NHibernate.Dialect.SQLiteDialect");
62 cfg.SetProperty(Environment.ConnectionDriver,
63 "NHibernate.Driver.SqliteClientDriver");
64 cfg.SetProperty(Environment.ConnectionString,
65 "URI=file:Asset.db,version=3");
66 cfg.AddAssembly("OpenSim.Data.NHibernate");
67
68 // HbmSerializer.Default.Validate = true;
69// using ( System.IO.MemoryStream stream =
70// HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly()))
71// cfg.AddInputStream(stream);
72
73// new SchemaExport(cfg).Create(true, true);
74
75 factory = cfg.BuildSessionFactory();
76
77 }
78
79 override public AssetBase FetchAsset(LLUUID uuid)
80 {
81 return null;
82 }
83
84 override public void CreateAsset(AssetBase asset)
85 {
86 ISession session = null;
87 ITransaction transaction = null;
88 try {
89 session = factory.OpenSession();
90 transaction = session.BeginTransaction();
91
92 session.SaveOrUpdate(asset);
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 }
105 }
106
107 override public void UpdateAsset(AssetBase asset)
108 {
109
110 }
111
112 private void LogAssetLoad(AssetBase asset)
113 {
114 string temporary = asset.Temporary ? "Temporary" : "Stored";
115 string local = asset.Local ? "Local" : "Remote";
116
117 int assetLength = (asset.Data != null) ? asset.Data.Length : 0;
118
119 m_log.Info("[SQLITE]: " +
120 string.Format("Loaded {6} {5} Asset: [{0}][{3}/{4}] \"{1}\":{2} ({7} bytes)",
121 asset.FullID, asset.Name, asset.Description, asset.Type,
122 asset.InvType, temporary, local, assetLength));
123 }
124
125 override public bool ExistsAsset(LLUUID uuid)
126 {
127 return false;
128 }
129
130 public void DeleteAsset(LLUUID uuid)
131 {
132
133 }
134
135 override public void CommitAssets() // force a sync to the database
136 {
137 m_log.Info("[SQLITE]: Attempting commit");
138 }
139
140
141 public override string Name {
142 get { return "NHibernate"; }
143 }
144
145 public override string Version {
146 get { return "0.1"; }
147 }
148
149 public void Dispose()
150 {
151
152 }
153 }
154}