diff options
author | Sean Dague | 2008-04-03 12:29:25 +0000 |
---|---|---|
committer | Sean Dague | 2008-04-03 12:29:25 +0000 |
commit | fe14d65f07b453b079aee1fe5ae17cfe7d6cb855 (patch) | |
tree | ee8a561b95bf7bd20fc6c77208bc832d2e35f12e /OpenSim/Data/NHibernate | |
parent | * ODEPlugin: put a limit on the minimum size a prim can be ( scale <=0 ). (diff) | |
download | opensim-SC-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.zip opensim-SC-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.gz opensim-SC-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.bz2 opensim-SC-fe14d65f07b453b079aee1fe5ae17cfe7d6cb855.tar.xz |
point in time update of NHibernate Asset Mapping code
Diffstat (limited to 'OpenSim/Data/NHibernate')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateAssetData.cs | 154 | ||||
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateManager.cs | 20 | ||||
-rw-r--r-- | OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml | 16 |
3 files changed, 180 insertions, 10 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 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.Reflection; | ||
31 | using libsecondlife; | ||
32 | using NHibernate; | ||
33 | using NHibernate.Cfg; | ||
34 | using NHibernate.Tool.hbm2ddl; | ||
35 | using NHibernate.Mapping.Attributes; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using Environment = NHibernate.Cfg.Environment; | ||
40 | |||
41 | namespace 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 | } | ||
diff --git a/OpenSim/Data/NHibernate/NHibernateManager.cs b/OpenSim/Data/NHibernate/NHibernateManager.cs index f9405b4..edef8ad 100644 --- a/OpenSim/Data/NHibernate/NHibernateManager.cs +++ b/OpenSim/Data/NHibernate/NHibernateManager.cs | |||
@@ -45,17 +45,17 @@ namespace OpenSim.Data.NHibernate | |||
45 | public NHibernateManager() | 45 | public NHibernateManager() |
46 | { | 46 | { |
47 | // This is stubbing for now, it will become dynamic later and support different db backends | 47 | // This is stubbing for now, it will become dynamic later and support different db backends |
48 | NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); | 48 | // NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration(); |
49 | cfg.Properties[NHibernate.Cfg.Environment.ConnectionProvider] = | 49 | // cfg.Properties[NHibernate.Cfg.Environment.ConnectionProvider] = |
50 | "NHibernate.Connection.DriverConnectionProvider"; | 50 | // "NHibernate.Connection.DriverConnectionProvider"; |
51 | cfg.Properties[NHibernate.Cfg.Environment.Dialect] = | 51 | // cfg.Properties[NHibernate.Cfg.Environment.Dialect] = |
52 | "NHibernate.Dialect.SQLite"; | 52 | // "NHibernate.Dialect.SQLite"; |
53 | cfg.Properties[NHibernate.Cfg.Environment.ConnectionDriver] = | 53 | // cfg.Properties[NHibernate.Cfg.Environment.ConnectionDriver] = |
54 | "NHibernate.Driver.SqliteClientDriver"; | 54 | // "NHibernate.Driver.SqliteClientDriver"; |
55 | cfg.Properties[NHibernate.Cfg.Environment.ConnectionString] = | 55 | // cfg.Properties[NHibernate.Cfg.Environment.ConnectionString] = |
56 | "URI=file:opensim-nh.db,version=3"; | 56 | // "URI=file:opensim-nh.db,version=3"; |
57 | 57 | ||
58 | factory = cfg.BuildSessionFactory(); | 58 | // factory = cfg.BuildSessionFactory(); |
59 | } | 59 | } |
60 | 60 | ||
61 | } | 61 | } |
diff --git a/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml new file mode 100644 index 0000000..82c30fe --- /dev/null +++ b/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml | |||
@@ -0,0 +1,16 @@ | |||
1 | <?xml version="1.0" encoding="utf-8" ?> | ||
2 | <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> | ||
3 | <class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets"> | ||
4 | <id name="ID" column="UUID" type="String" length="36" > | ||
5 | <generator class="assigned" /> | ||
6 | </id> | ||
7 | <property name="Type" type="integer" /> | ||
8 | <property name="InvType" type="integer" /> | ||
9 | <property name="Name" type="String" length="50" /> | ||
10 | <property name="Description" type="String" length="50" /> | ||
11 | <property name="Local" type="boolean" /> | ||
12 | <property name="Temporary" type="boolean" /> | ||
13 | <property name="Data" type="binary" /> | ||
14 | |||
15 | </class> | ||
16 | </hibernate-mapping> \ No newline at end of file | ||