AppearanceTableMapper.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 libsecondlife;
  29. using OpenSim.Data.Base;
  30. using OpenSim.Framework;
  31. namespace OpenSim.Data.Base
  32. {
  33. public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
  34. {
  35. public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
  36. : base(schema, obj)
  37. {
  38. }
  39. }
  40. public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid>
  41. {
  42. public AppearanceTableMapper(BaseDatabaseConnector database, string tableName)
  43. : base(database, tableName)
  44. {
  45. BaseSchema<AppearanceRowMapper> rowMapperSchema = new BaseSchema<AppearanceRowMapper>(this);
  46. m_schema = rowMapperSchema;
  47. m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("UUID",
  48. delegate(AppearanceRowMapper mapper) { return mapper.Object.Owner.UUID; },
  49. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Owner = new LLUUID(value.ToString()); });
  50. rowMapperSchema.AddMapping<uint>("Serial",
  51. delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.Serial; },
  52. delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.Serial = (int)value; });
  53. rowMapperSchema.AddMapping<Guid>("WearableItem0",
  54. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; },
  55. delegate(AppearanceRowMapper mapper, Guid value)
  56. {
  57. if (mapper.Object.Wearables == null)
  58. {
  59. mapper.Object.Wearables = new AvatarWearable[13];
  60. for (int i = 0; i < 13; i++)
  61. {
  62. mapper.Object.Wearables[i] = new AvatarWearable();
  63. }
  64. }
  65. mapper.Object.Wearables[0].ItemID = new LLUUID(value.ToString());
  66. });
  67. rowMapperSchema.AddMapping<Guid>("WearableAsset0",
  68. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; },
  69. delegate(AppearanceRowMapper mapper, Guid value)
  70. { mapper.Object.Wearables[0].AssetID = new LLUUID(value.ToString()); });
  71. rowMapperSchema.AddMapping<Guid>("WearableItem1",
  72. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; },
  73. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new LLUUID(value.ToString()); });
  74. rowMapperSchema.AddMapping<Guid>("WearableAsset1",
  75. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; },
  76. delegate(AppearanceRowMapper mapper, Guid value)
  77. { mapper.Object.Wearables[1].AssetID = new LLUUID(value.ToString()); });
  78. rowMapperSchema.AddMapping<Guid>("WearableItem2",
  79. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; },
  80. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new LLUUID(value.ToString()); });
  81. rowMapperSchema.AddMapping<Guid>("WearableAsset2",
  82. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; },
  83. delegate(AppearanceRowMapper mapper, Guid value)
  84. { mapper.Object.Wearables[2].AssetID = new LLUUID(value.ToString()); });
  85. rowMapperSchema.AddMapping<Guid>("WearableItem3",
  86. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; },
  87. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new LLUUID(value.ToString()); });
  88. rowMapperSchema.AddMapping<Guid>("WearableAsset3",
  89. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; },
  90. delegate(AppearanceRowMapper mapper, Guid value)
  91. { mapper.Object.Wearables[3].AssetID = new LLUUID(value.ToString()); });
  92. rowMapperSchema.AddMapping<Guid>("WearableItem4",
  93. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; },
  94. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new LLUUID(value.ToString()); });
  95. rowMapperSchema.AddMapping<Guid>("WearableAsset4",
  96. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; },
  97. delegate(AppearanceRowMapper mapper, Guid value)
  98. { mapper.Object.Wearables[4].AssetID = new LLUUID(value.ToString()); });
  99. rowMapperSchema.AddMapping<Guid>("WearableItem5",
  100. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; },
  101. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new LLUUID(value.ToString()); });
  102. rowMapperSchema.AddMapping<Guid>("WearableAsset5",
  103. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; },
  104. delegate(AppearanceRowMapper mapper, Guid value)
  105. { mapper.Object.Wearables[5].AssetID = new LLUUID(value.ToString()); });
  106. rowMapperSchema.AddMapping<Guid>("WearableItem6",
  107. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; },
  108. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new LLUUID(value.ToString()); });
  109. rowMapperSchema.AddMapping<Guid>("WearableAsset6",
  110. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; },
  111. delegate(AppearanceRowMapper mapper, Guid value)
  112. { mapper.Object.Wearables[6].AssetID = new LLUUID(value.ToString()); });
  113. rowMapperSchema.AddMapping<Guid>("WearableItem7",
  114. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; },
  115. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new LLUUID(value.ToString()); });
  116. rowMapperSchema.AddMapping<Guid>("WearableAsset7",
  117. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; },
  118. delegate(AppearanceRowMapper mapper, Guid value)
  119. { mapper.Object.Wearables[7].AssetID = new LLUUID(value.ToString()); });
  120. rowMapperSchema.AddMapping<Guid>("WearableItem8",
  121. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; },
  122. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new LLUUID(value.ToString()); });
  123. rowMapperSchema.AddMapping<Guid>("WearableAsset8",
  124. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; },
  125. delegate(AppearanceRowMapper mapper, Guid value)
  126. { mapper.Object.Wearables[8].AssetID = new LLUUID(value.ToString()); });
  127. rowMapperSchema.AddMapping<Guid>("WearableItem9",
  128. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; },
  129. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new LLUUID(value.ToString()); });
  130. rowMapperSchema.AddMapping<Guid>("WearableAsset9",
  131. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; },
  132. delegate(AppearanceRowMapper mapper, Guid value)
  133. { mapper.Object.Wearables[9].AssetID = new LLUUID(value.ToString()); });
  134. rowMapperSchema.AddMapping<Guid>("WearableItem10",
  135. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; },
  136. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new LLUUID(value.ToString()); });
  137. rowMapperSchema.AddMapping<Guid>("WearableAsset10",
  138. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; },
  139. delegate(AppearanceRowMapper mapper, Guid value)
  140. { mapper.Object.Wearables[10].AssetID = new LLUUID(value.ToString()); });
  141. rowMapperSchema.AddMapping<Guid>("WearableItem11",
  142. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; },
  143. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new LLUUID(value.ToString()); });
  144. rowMapperSchema.AddMapping<Guid>("WearableAsset11",
  145. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; },
  146. delegate(AppearanceRowMapper mapper, Guid value)
  147. { mapper.Object.Wearables[11].AssetID = new LLUUID(value.ToString()); });
  148. rowMapperSchema.AddMapping<Guid>("WearableItem12",
  149. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; },
  150. delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new LLUUID(value.ToString()); });
  151. rowMapperSchema.AddMapping<Guid>("WearableAsset12",
  152. delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; },
  153. delegate(AppearanceRowMapper mapper, Guid value)
  154. { mapper.Object.Wearables[12].AssetID = new LLUUID(value.ToString()); });
  155. }
  156. public bool Add(Guid userID, AvatarAppearance appearance)
  157. {
  158. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  159. return Add(mapper);
  160. }
  161. public bool Update(Guid userID, AvatarAppearance appearance)
  162. {
  163. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  164. return Update(appearance.Owner.UUID, mapper);
  165. }
  166. protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance)
  167. {
  168. return new AppearanceRowMapper(m_schema, appearance);
  169. }
  170. protected AppearanceRowMapper CreateRowMapper()
  171. {
  172. return CreateRowMapper(new AvatarAppearance());
  173. }
  174. protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance)
  175. {
  176. AppearanceRowMapper mapper = CreateRowMapper(appearance);
  177. mapper.FillObject(reader);
  178. return mapper;
  179. }
  180. public override AppearanceRowMapper FromReader(BaseDataReader reader)
  181. {
  182. AppearanceRowMapper mapper = CreateRowMapper();
  183. mapper.FillObject(reader);
  184. return mapper;
  185. }
  186. public bool TryGetValue(Guid presenceID, out AvatarAppearance val)
  187. {
  188. AppearanceRowMapper mapper;
  189. if (TryGetValue(presenceID, out mapper))
  190. {
  191. val = mapper.Object;
  192. return true;
  193. }
  194. else
  195. {
  196. val = null;
  197. return false;
  198. }
  199. }
  200. }
  201. }