diff options
Diffstat (limited to 'OpenSim-Source/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs')
-rw-r--r-- | OpenSim-Source/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/OpenSim-Source/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs b/OpenSim-Source/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs new file mode 100644 index 0000000..5dceb7f --- /dev/null +++ b/OpenSim-Source/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | * Copyright (c) OpenSim project, http://sim.opensecondlife.org/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * Neither the name of the <organization> nor the | ||
12 | * names of its contributors may be used to endorse or promote products | ||
13 | * derived from this software without specific prior written permission. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
18 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | * | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using Db4objects.Db4o; | ||
30 | using Db4objects.Db4o.Query; | ||
31 | using libsecondlife; | ||
32 | using OpenSim.Framework.Interfaces; | ||
33 | using OpenSim.Framework.Types; | ||
34 | using OpenSim.Framework.Terrain; | ||
35 | |||
36 | namespace OpenSim.Storage.LocalStorageDb4o | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// | ||
40 | /// </summary> | ||
41 | public class Db4LocalStorage : ILocalStorage | ||
42 | { | ||
43 | private IObjectContainer db; | ||
44 | private string datastore; | ||
45 | |||
46 | public Db4LocalStorage() | ||
47 | { | ||
48 | |||
49 | } | ||
50 | |||
51 | public void Initialise(string dfile) | ||
52 | { | ||
53 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"Db4LocalStorage Opening " + dfile); | ||
54 | datastore = dfile; | ||
55 | try | ||
56 | { | ||
57 | db = Db4oFactory.OpenFile(datastore); | ||
58 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Db4LocalStorage creation"); | ||
59 | } | ||
60 | catch (Exception e) | ||
61 | { | ||
62 | db.Close(); | ||
63 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"Db4LocalStorage :Constructor - Exception occured"); | ||
64 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,e.ToString()); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | public void StorePrim(PrimData prim) | ||
69 | { | ||
70 | IObjectSet result = db.Query(new UUIDQuery(prim.FullID)); | ||
71 | if(result.Count>0) | ||
72 | { | ||
73 | //prim already in storage | ||
74 | //so update it | ||
75 | PrimData found = (PrimData) result.Next(); | ||
76 | found.PathBegin = prim.PathBegin; | ||
77 | found.PathCurve= prim.PathCurve; | ||
78 | found.PathEnd = prim.PathEnd; | ||
79 | found.PathRadiusOffset = prim.PathRadiusOffset; | ||
80 | found.PathRevolutions = prim.PathRevolutions; | ||
81 | found.PathScaleX= prim.PathScaleX; | ||
82 | found.PathScaleY = prim.PathScaleY; | ||
83 | found.PathShearX = prim.PathShearX; | ||
84 | found.PathShearY = prim.PathShearY; | ||
85 | found.PathSkew = prim.PathSkew; | ||
86 | found.PathTaperX = prim.PathTaperX; | ||
87 | found.PathTaperY = prim.PathTaperY; | ||
88 | found.PathTwist = prim.PathTwist; | ||
89 | found.PathTwistBegin = prim.PathTwistBegin; | ||
90 | found.PCode = prim.PCode; | ||
91 | found.ProfileBegin = prim.ProfileBegin; | ||
92 | found.ProfileCurve = prim.ProfileCurve; | ||
93 | found.ProfileEnd = prim.ProfileEnd; | ||
94 | found.ProfileHollow = prim.ProfileHollow; | ||
95 | found.Position = prim.Position; | ||
96 | found.Rotation = prim.Rotation; | ||
97 | found.Texture = prim.Texture; | ||
98 | db.Set(found); | ||
99 | db.Commit(); | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | //not in storage | ||
104 | db.Set(prim); | ||
105 | db.Commit(); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | public void RemovePrim(LLUUID primID) | ||
110 | { | ||
111 | IObjectSet result = db.Query(new UUIDQuery(primID)); | ||
112 | if(result.Count>0) | ||
113 | { | ||
114 | PrimData found = (PrimData) result.Next(); | ||
115 | db.Delete(found); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | |||
120 | public void LoadPrimitives(ILocalStorageReceiver receiver) | ||
121 | { | ||
122 | IObjectSet result = db.Get(typeof(PrimData)); | ||
123 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Db4LocalStorage.cs: LoadPrimitives() - number of prims in storages is "+result.Count); | ||
124 | foreach (PrimData prim in result) { | ||
125 | receiver.PrimFromStorage(prim); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | public float[] LoadWorld() | ||
130 | { | ||
131 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Loading world...."); | ||
132 | //World blank = new World(); | ||
133 | float[] heightmap = null; | ||
134 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Looking for a heightmap in local DB"); | ||
135 | IObjectSet world_result = db.Get(typeof(MapStorage)); | ||
136 | if (world_result.Count > 0) | ||
137 | { | ||
138 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Found a heightmap in local database, loading"); | ||
139 | MapStorage map = (MapStorage)world_result.Next(); | ||
140 | //blank.LandMap = map.Map; | ||
141 | heightmap = map.Map; | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | /* | ||
146 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LoadWorld() - No heightmap found, generating new one"); | ||
147 | HeightmapGenHills hills = new HeightmapGenHills(); | ||
148 | // blank.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false); | ||
149 | // heightmap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false); | ||
150 | heightmap = new float[256, 256]; | ||
151 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LoadWorld() - Saving heightmap to local database"); | ||
152 | MapStorage map = new MapStorage(); | ||
153 | map.Map = heightmap; //blank.LandMap; | ||
154 | db.Set(map); | ||
155 | db.Commit(); | ||
156 | */ | ||
157 | } | ||
158 | return heightmap; | ||
159 | } | ||
160 | |||
161 | public void SaveMap(float[] heightmap) | ||
162 | { | ||
163 | IObjectSet world_result = db.Get(typeof(MapStorage)); | ||
164 | if (world_result.Count > 0) | ||
165 | { | ||
166 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"SaveWorld() - updating saved copy of heightmap in local database"); | ||
167 | MapStorage map = (MapStorage)world_result.Next(); | ||
168 | db.Delete(map); | ||
169 | } | ||
170 | MapStorage map1 = new MapStorage(); | ||
171 | map1.Map = heightmap; //OpenSim_Main.local_world.LandMap; | ||
172 | db.Set(map1); | ||
173 | db.Commit(); | ||
174 | } | ||
175 | |||
176 | public void ShutDown() | ||
177 | { | ||
178 | db.Commit(); | ||
179 | db.Close(); | ||
180 | } | ||
181 | } | ||
182 | } | ||