DB4oDataStore.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using OpenSim.Region.Environment.Scenes;
  31. using OpenSim.Region.Environment.LandManagement;
  32. using OpenSim.Region.Environment;
  33. using OpenSim.Region.Interfaces;
  34. using OpenSim.Framework.Console;
  35. using libsecondlife;
  36. using Db4objects.Db4o;
  37. using Db4objects.Db4o.Query;
  38. namespace OpenSim.DataStore.DB4oStorage
  39. {
  40. public class SceneObjectQuery : Predicate
  41. {
  42. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  43. private LLUUID globalIDSearch;
  44. public SceneObjectQuery(LLUUID find)
  45. {
  46. globalIDSearch = find;
  47. }
  48. public bool Match(SceneObjectGroup obj)
  49. {
  50. return obj.UUID == globalIDSearch;
  51. }
  52. }
  53. public class DB4oDataStore : IRegionDataStore
  54. {
  55. private IObjectContainer db;
  56. public void Initialise(string dbfile, string dbname)
  57. {
  58. m_log.Info("[DATASTORE]: DB4O - Opening " + dbfile);
  59. db = Db4oFactory.OpenFile(dbfile);
  60. }
  61. public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID)
  62. {
  63. db.Set(obj);
  64. }
  65. public void RemoveObject(LLUUID obj, LLUUID regionUUID)
  66. {
  67. IObjectSet result = db.Query(new SceneObjectQuery(obj));
  68. if (result.Count > 0)
  69. {
  70. SceneObjectGroup item = (SceneObjectGroup)result.Next();
  71. db.Delete(item);
  72. }
  73. }
  74. public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
  75. {
  76. IObjectSet result = db.Get(typeof(SceneObjectGroup));
  77. List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
  78. m_log.Info("[DATASTORE]: DB4O - LoadObjects found " + result.Count.ToString() + " objects");
  79. foreach (Object obj in result)
  80. {
  81. retvals.Add((SceneObjectGroup)obj);
  82. }
  83. return retvals;
  84. }
  85. public void StoreTerrain(double[,] ter)
  86. {
  87. }
  88. public double[,] LoadTerrain()
  89. {
  90. return null;
  91. }
  92. public void RemoveLandObject(uint id)
  93. {
  94. }
  95. public void StoreParcel(Land parcel)
  96. {
  97. }
  98. public List<Land> LoadLandObjects()
  99. {
  100. return new List<Land>();
  101. }
  102. public void Shutdown()
  103. {
  104. if (db != null)
  105. {
  106. db.Commit();
  107. db.Close();
  108. }
  109. }
  110. }
  111. }