aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs')
-rw-r--r--OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs301
1 files changed, 195 insertions, 106 deletions
diff --git a/OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs b/OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs
index a50795a..93f55d6 100644
--- a/OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs
+++ b/OpenSim/OpenSim.Storage/LocalStorageDb4o/Db4LocalStorage.cs
@@ -1,5 +1,6 @@
1/* 1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
3* 4*
4* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
@@ -8,14 +9,14 @@
8* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the 12* * Neither the name of the OpenSim Project nor the
12* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
14* 15*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (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* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -28,133 +29,120 @@ using System;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using Db4objects.Db4o; 30using Db4objects.Db4o;
30using Db4objects.Db4o.Query; 31using Db4objects.Db4o.Query;
32
31using libsecondlife; 33using libsecondlife;
32using OpenSim.Framework.Interfaces; 34using OpenSim.Framework.Interfaces;
33using OpenSim.Framework.Types; 35using OpenSim.Framework.Types;
36using OpenSim.Framework.Console;
34 37
35 38
36namespace OpenSim.Storage.LocalStorageDb4o 39namespace OpenSim.Storage.LocalStorageDb4o
37{ 40{
38 /// <summary> 41 /// <summary>
39 /// 42 ///
40 /// </summary> 43 /// </summary>
41 public class Db4LocalStorage : ILocalStorage 44 public class Db4LocalStorage : ILocalStorage
42 { 45 {
43 private IObjectContainer db; 46 private IObjectContainer db;
44 private string datastore; 47 private string datastore;
45 48
46 public Db4LocalStorage() 49 public Db4LocalStorage()
47 { 50 {
48 51
49 } 52 }
50 53
51 public void Initialise(string dfile) 54 public void Initialise(string dfile)
52 { 55 {
53 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"Db4LocalStorage Opening " + dfile); 56 OpenSim.Framework.Console.MainConsole.Instance.Warn("Db4LocalStorage Opening " + dfile);
54 datastore = dfile; 57 datastore = dfile;
55 try 58 try
56 { 59 {
57 db = Db4oFactory.OpenFile(datastore); 60 db = Db4oFactory.OpenFile(datastore);
58 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Db4LocalStorage creation"); 61 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Db4LocalStorage creation");
59 } 62 }
60 catch (Exception e) 63 catch (Exception e)
61 { 64 {
62 db.Close(); 65 db.Close();
63 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"Db4LocalStorage :Constructor - Exception occured"); 66 OpenSim.Framework.Console.MainConsole.Instance.Warn("Db4LocalStorage :Constructor - Exception occured");
64 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,e.ToString()); 67 OpenSim.Framework.Console.MainConsole.Instance.Warn(e.ToString());
65 } 68 }
66 } 69 }
67 70
68 public void StorePrim(PrimData prim) 71 public void StorePrim(PrimData prim)
69 { 72 {
70 IObjectSet result = db.Query(new UUIDQuery(prim.FullID)); 73 IObjectSet result = db.Query(new UUIDPrimQuery(prim.FullID));
71 if(result.Count>0) 74 if (result.Count > 0)
72 { 75 {
73 //prim already in storage 76 //prim already in storage
74 //so update it 77 //so update it
75 PrimData found = (PrimData) result.Next(); 78 PrimData found = (PrimData)result.Next();
76 found.PathBegin = prim.PathBegin; 79 found.PathBegin = prim.PathBegin;
77 found.PathCurve= prim.PathCurve; 80 found.PathCurve = prim.PathCurve;
78 found.PathEnd = prim.PathEnd; 81 found.PathEnd = prim.PathEnd;
79 found.PathRadiusOffset = prim.PathRadiusOffset; 82 found.PathRadiusOffset = prim.PathRadiusOffset;
80 found.PathRevolutions = prim.PathRevolutions; 83 found.PathRevolutions = prim.PathRevolutions;
81 found.PathScaleX= prim.PathScaleX; 84 found.PathScaleX = prim.PathScaleX;
82 found.PathScaleY = prim.PathScaleY; 85 found.PathScaleY = prim.PathScaleY;
83 found.PathShearX = prim.PathShearX; 86 found.PathShearX = prim.PathShearX;
84 found.PathShearY = prim.PathShearY; 87 found.PathShearY = prim.PathShearY;
85 found.PathSkew = prim.PathSkew; 88 found.PathSkew = prim.PathSkew;
86 found.PathTaperX = prim.PathTaperX; 89 found.PathTaperX = prim.PathTaperX;
87 found.PathTaperY = prim.PathTaperY; 90 found.PathTaperY = prim.PathTaperY;
88 found.PathTwist = prim.PathTwist; 91 found.PathTwist = prim.PathTwist;
89 found.PathTwistBegin = prim.PathTwistBegin; 92 found.PathTwistBegin = prim.PathTwistBegin;
90 found.PCode = prim.PCode; 93 found.PCode = prim.PCode;
91 found.ProfileBegin = prim.ProfileBegin; 94 found.ProfileBegin = prim.ProfileBegin;
92 found.ProfileCurve = prim.ProfileCurve; 95 found.ProfileCurve = prim.ProfileCurve;
93 found.ProfileEnd = prim.ProfileEnd; 96 found.ProfileEnd = prim.ProfileEnd;
94 found.ProfileHollow = prim.ProfileHollow; 97 found.ProfileHollow = prim.ProfileHollow;
95 found.Position = prim.Position; 98 found.Position = prim.Position;
96 found.Rotation = prim.Rotation; 99 found.Rotation = prim.Rotation;
97 found.Texture = prim.Texture; 100 found.Texture = prim.Texture;
98 db.Set(found); 101 db.Set(found);
99 db.Commit(); 102 db.Commit();
100 } 103 }
101 else 104 else
102 { 105 {
103 //not in storage 106 //not in storage
104 db.Set(prim); 107 db.Set(prim);
105 db.Commit(); 108 db.Commit();
106 } 109 }
107 } 110 }
108 111
109 public void RemovePrim(LLUUID primID) 112 public void RemovePrim(LLUUID primID)
110 { 113 {
111 IObjectSet result = db.Query(new UUIDQuery(primID)); 114 IObjectSet result = db.Query(new UUIDPrimQuery(primID));
112 if(result.Count>0) 115 if (result.Count > 0)
113 { 116 {
114 PrimData found = (PrimData) result.Next(); 117 PrimData found = (PrimData)result.Next();
115 db.Delete(found); 118 db.Delete(found);
116 } 119 }
117 } 120 }
118 121
119 122
120 public void LoadPrimitives(ILocalStorageReceiver receiver) 123 public void LoadPrimitives(ILocalStorageReceiver receiver)
121 { 124 {
122 IObjectSet result = db.Get(typeof(PrimData)); 125 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); 126 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Db4LocalStorage.cs: LoadPrimitives() - number of prims in storages is " + result.Count);
124 foreach (PrimData prim in result) { 127 foreach (PrimData prim in result)
125 receiver.PrimFromStorage(prim); 128 {
126 } 129 receiver.PrimFromStorage(prim);
127 } 130 }
131 }
128 132
129 public float[] LoadWorld() 133 public float[] LoadWorld()
130 { 134 {
131 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Loading world...."); 135 OpenSim.Framework.Console.MainConsole.Instance.Verbose("LoadWorld() - Loading world....");
132 //World blank = new World();
133 float[] heightmap = null; 136 float[] heightmap = null;
134 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Looking for a heightmap in local DB"); 137 OpenSim.Framework.Console.MainConsole.Instance.Verbose("LoadWorld() - Looking for a heightmap in local DB");
135 IObjectSet world_result = db.Get(typeof(MapStorage)); 138 IObjectSet world_result = db.Get(typeof(MapStorage));
136 if (world_result.Count > 0) 139 if (world_result.Count > 0)
137 { 140 {
138 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"LoadWorld() - Found a heightmap in local database, loading"); 141 OpenSim.Framework.Console.MainConsole.Instance.Verbose("LoadWorld() - Found a heightmap in local database, loading");
139 MapStorage map = (MapStorage)world_result.Next(); 142 MapStorage map = (MapStorage)world_result.Next();
140 //blank.LandMap = map.Map; 143 //blank.LandMap = map.Map;
141 heightmap = map.Map; 144 heightmap = map.Map;
142 } 145 }
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; 146 return heightmap;
159 } 147 }
160 148
@@ -163,7 +151,7 @@ namespace OpenSim.Storage.LocalStorageDb4o
163 IObjectSet world_result = db.Get(typeof(MapStorage)); 151 IObjectSet world_result = db.Get(typeof(MapStorage));
164 if (world_result.Count > 0) 152 if (world_result.Count > 0)
165 { 153 {
166 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"SaveWorld() - updating saved copy of heightmap in local database"); 154 OpenSim.Framework.Console.MainConsole.Instance.Verbose("SaveWorld() - updating saved copy of heightmap in local database");
167 MapStorage map = (MapStorage)world_result.Next(); 155 MapStorage map = (MapStorage)world_result.Next();
168 db.Delete(map); 156 db.Delete(map);
169 } 157 }
@@ -173,10 +161,111 @@ namespace OpenSim.Storage.LocalStorageDb4o
173 db.Commit(); 161 db.Commit();
174 } 162 }
175 163
176 public void ShutDown() 164 public void SaveParcel(ParcelData parcel)
177 { 165 {
178 db.Commit(); 166 IObjectSet result = db.Query(new UUIDParcelQuery(parcel.globalID));
179 db.Close(); 167 if (result.Count > 0)
180 } 168 {
181 } 169 //Old Parcel
182} 170 ParcelData updateParcel = (ParcelData)result.Next();
171 updateParcel.AABBMax = parcel.AABBMax;
172 updateParcel.AABBMin = parcel.AABBMin;
173 updateParcel.area = parcel.area;
174 updateParcel.auctionID = parcel.auctionID;
175 updateParcel.authBuyerID = parcel.authBuyerID;
176 updateParcel.category = parcel.category;
177 updateParcel.claimDate = parcel.claimDate;
178 updateParcel.claimPrice = parcel.claimPrice;
179 updateParcel.groupID = parcel.groupID;
180 updateParcel.groupPrims = parcel.groupPrims;
181 updateParcel.isGroupOwned = parcel.isGroupOwned;
182 updateParcel.landingType = parcel.landingType;
183 updateParcel.mediaAutoScale = parcel.mediaAutoScale;
184 updateParcel.mediaID = parcel.mediaID;
185 updateParcel.mediaURL = parcel.mediaURL;
186 updateParcel.musicURL = parcel.musicURL;
187 updateParcel.localID = parcel.localID;
188 updateParcel.ownerID = parcel.ownerID;
189 updateParcel.passHours = parcel.passHours;
190 updateParcel.passPrice = parcel.passPrice;
191 updateParcel.parcelBitmapByteArray = (byte[])parcel.parcelBitmapByteArray.Clone();
192 updateParcel.parcelDesc = parcel.parcelDesc;
193 updateParcel.parcelFlags = parcel.parcelFlags;
194 updateParcel.parcelName = parcel.parcelName;
195 updateParcel.parcelStatus = parcel.parcelStatus;
196 updateParcel.salePrice = parcel.salePrice;
197 updateParcel.snapshotID = parcel.snapshotID;
198 updateParcel.userLocation = parcel.userLocation;
199 updateParcel.userLookAt = parcel.userLookAt;
200
201 db.Set(updateParcel);
202 }
203 else
204 {
205 db.Set(parcel);
206 }
207 db.Commit();
208 }
209
210 public void SaveParcels(ParcelData[] parcel_data)
211 {
212 MainConsole.Instance.Notice("Parcel Backup: Saving Parcels...");
213 int i;
214 for (i = 0; i < parcel_data.GetLength(0); i++)
215 {
216
217 SaveParcel(parcel_data[i]);
218
219 }
220 MainConsole.Instance.Notice("Parcel Backup: Parcel Save Complete");
221 }
222
223 public void RemoveParcel(ParcelData parcel)
224 {
225 IObjectSet result = db.Query(new UUIDParcelQuery(parcel.globalID));
226 if (result.Count > 0)
227 {
228 db.Delete(result[0]);
229 }
230 db.Commit();
231 }
232 public void RemoveAllParcels()
233 {
234 MainConsole.Instance.Notice("Parcel Backup: Removing all parcels...");
235 IObjectSet result = db.Get(typeof(ParcelData));
236 if (result.Count > 0)
237 {
238 foreach (ParcelData parcelData in result)
239 {
240 RemoveParcel(parcelData);
241 }
242 }
243 }
244
245 public void LoadParcels(ILocalStorageParcelReceiver recv)
246 {
247 MainConsole.Instance.Notice("Parcel Backup: Loading Parcels...");
248 IObjectSet result = db.Get(typeof(ParcelData));
249 if (result.Count > 0)
250 {
251 MainConsole.Instance.Notice("Parcel Backup: Parcels exist in database.");
252 foreach (ParcelData parcelData in result)
253 {
254
255 recv.ParcelFromStorage(parcelData);
256 }
257 }
258 else
259 {
260 MainConsole.Instance.Notice("Parcel Backup: No parcels exist. Creating basic parcel.");
261 recv.NoParcelDataFromStorage();
262 }
263 MainConsole.Instance.Notice("Parcel Backup: Parcels Restored");
264 }
265 public void ShutDown()
266 {
267 db.Commit();
268 db.Close();
269 }
270 }
271} \ No newline at end of file