AppearanceTableMapper.cs 14 KB

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