DB4oManager.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Db4objects.Db4o;
  5. using OpenGrid.Framework.Data;
  6. using libsecondlife;
  7. namespace OpenGrid.Framework.Data.DB4o
  8. {
  9. class DB4oGridManager
  10. {
  11. public Dictionary<LLUUID, SimProfileData> simProfiles = new Dictionary<LLUUID, SimProfileData>();
  12. string dbfl;
  13. public DB4oGridManager(string db4odb)
  14. {
  15. dbfl = db4odb;
  16. IObjectContainer database;
  17. database = Db4oFactory.OpenFile(dbfl);
  18. IObjectSet result = database.Get(typeof(SimProfileData));
  19. foreach(SimProfileData row in result) {
  20. simProfiles.Add(row.UUID, row);
  21. }
  22. database.Close();
  23. }
  24. /// <summary>
  25. /// Adds a new profile to the database (Warning: Probably slow.)
  26. /// </summary>
  27. /// <param name="row">The profile to add</param>
  28. /// <returns>Successful?</returns>
  29. public bool AddRow(SimProfileData row)
  30. {
  31. if (simProfiles.ContainsKey(row.UUID))
  32. {
  33. simProfiles[row.UUID] = row;
  34. }
  35. else
  36. {
  37. simProfiles.Add(row.UUID, row);
  38. }
  39. try
  40. {
  41. IObjectContainer database;
  42. database = Db4oFactory.OpenFile(dbfl);
  43. database.Set(row);
  44. database.Close();
  45. return true;
  46. }
  47. catch (Exception e)
  48. {
  49. return false;
  50. }
  51. }
  52. }
  53. class DB4oUserManager
  54. {
  55. public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>();
  56. string dbfl;
  57. public DB4oUserManager(string db4odb)
  58. {
  59. dbfl = db4odb;
  60. IObjectContainer database;
  61. database = Db4oFactory.OpenFile(dbfl);
  62. IObjectSet result = database.Get(typeof(UserProfileData));
  63. foreach (UserProfileData row in result)
  64. {
  65. userProfiles.Add(row.UUID, row);
  66. }
  67. database.Close();
  68. }
  69. /// <summary>
  70. /// Adds a new profile to the database (Warning: Probably slow.)
  71. /// </summary>
  72. /// <param name="row">The profile to add</param>
  73. /// <returns>Successful?</returns>
  74. public bool AddRow(UserProfileData row)
  75. {
  76. if (userProfiles.ContainsKey(row.UUID))
  77. {
  78. userProfiles[row.UUID] = row;
  79. }
  80. else
  81. {
  82. userProfiles.Add(row.UUID, row);
  83. }
  84. try
  85. {
  86. IObjectContainer database;
  87. database = Db4oFactory.OpenFile(dbfl);
  88. database.Set(row);
  89. database.Close();
  90. return true;
  91. }
  92. catch (Exception e)
  93. {
  94. return false;
  95. }
  96. }
  97. }
  98. }