PrimitiveBaseShapeTableMapper.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 OpenSim.Framework;
  29. using OpenSim.Framework.Data.Base;
  30. using libsecondlife;
  31. namespace OpenSim.Framework.Data
  32. {
  33. public class PrimitiveBaseShapeRowMapper : BaseRowMapper<PrimitiveBaseShape>
  34. {
  35. public Guid SceneObjectPartId;
  36. public PrimitiveBaseShapeRowMapper(BaseSchema schema, PrimitiveBaseShape obj) : base(schema, obj)
  37. {
  38. }
  39. }
  40. public class PrimitiveBaseShapeTableMapper : OpenSimTableMapper<PrimitiveBaseShapeRowMapper, Guid>
  41. {
  42. public PrimitiveBaseShapeTableMapper(BaseDatabaseConnector connection, string tableName)
  43. : base(connection, tableName)
  44. {
  45. BaseSchema<PrimitiveBaseShapeRowMapper> rowMapperSchema = new BaseSchema<PrimitiveBaseShapeRowMapper>(this);
  46. m_schema = rowMapperSchema;
  47. m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("SceneObjectPartId",
  48. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.SceneObjectPartId; },
  49. delegate(PrimitiveBaseShapeRowMapper shape, Guid value) { shape.SceneObjectPartId = value; });
  50. rowMapperSchema.AddMapping<byte>("PCode",
  51. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PCode; },
  52. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PCode = value; });
  53. rowMapperSchema.AddMapping<ushort>("PathBegin",
  54. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathBegin; },
  55. delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathBegin = value; });
  56. rowMapperSchema.AddMapping<ushort>("PathEnd",
  57. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathEnd; },
  58. delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathEnd = value; });
  59. rowMapperSchema.AddMapping<byte>("PathScaleX",
  60. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleX; },
  61. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleX = value; });
  62. rowMapperSchema.AddMapping<byte>("PathScaleY",
  63. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleY; },
  64. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleY = value; });
  65. rowMapperSchema.AddMapping<byte>("PathShearX",
  66. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearX; },
  67. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearX = value; });
  68. rowMapperSchema.AddMapping<byte>("PathShearY",
  69. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearY; },
  70. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearY = value; });
  71. rowMapperSchema.AddMapping<ushort>("ProfileBegin",
  72. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileBegin; },
  73. delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileBegin = value; });
  74. rowMapperSchema.AddMapping<ushort>("ProfileEnd",
  75. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileEnd; },
  76. delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileEnd = value; });
  77. rowMapperSchema.AddMapping<LLVector3>("Scale",
  78. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.Scale; },
  79. delegate(PrimitiveBaseShapeRowMapper shape, LLVector3 value) { shape.Object.Scale = value; });
  80. rowMapperSchema.AddMapping<sbyte>("PathTaperX",
  81. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperX; },
  82. delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperX = value; });
  83. rowMapperSchema.AddMapping<sbyte>("PathTaperY",
  84. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperY; },
  85. delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperY = value; });
  86. rowMapperSchema.AddMapping<sbyte>("PathTwist",
  87. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwist; },
  88. delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwist = value; });
  89. rowMapperSchema.AddMapping<sbyte>("PathRadiusOffset",
  90. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRadiusOffset; },
  91. delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathRadiusOffset = value; });
  92. rowMapperSchema.AddMapping<byte>("PathRevolutions",
  93. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRevolutions; },
  94. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathRevolutions = value; });
  95. rowMapperSchema.AddMapping<sbyte>("PathTwistBegin",
  96. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwistBegin; },
  97. delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwistBegin = value; });
  98. rowMapperSchema.AddMapping<byte>("PathCurve",
  99. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathCurve; },
  100. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathCurve = value; });
  101. rowMapperSchema.AddMapping<byte>("ProfileCurve",
  102. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileCurve; },
  103. delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.ProfileCurve = value; });
  104. rowMapperSchema.AddMapping<ushort>("ProfileHollow",
  105. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileHollow; },
  106. delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileHollow = value; });
  107. rowMapperSchema.AddMapping<byte[]>("TextureEntry",
  108. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.TextureEntry; },
  109. delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.TextureEntry = value; });
  110. rowMapperSchema.AddMapping<byte[]>("ExtraParams",
  111. delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ExtraParams; },
  112. delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.ExtraParams = value; });
  113. }
  114. public override PrimitiveBaseShapeRowMapper FromReader(BaseDataReader reader)
  115. {
  116. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  117. PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper(m_schema, shape);
  118. mapper.FillObject( reader );
  119. return mapper;
  120. }
  121. public bool Update(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
  122. {
  123. PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape);
  124. return Update(sceneObjectPartId, mapper);
  125. }
  126. public bool Add(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
  127. {
  128. PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape);
  129. return Add(mapper);
  130. }
  131. private PrimitiveBaseShapeRowMapper CreateRowMapper(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape)
  132. {
  133. PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper( m_schema, primitiveBaseShape );
  134. mapper.SceneObjectPartId = sceneObjectPartId;
  135. return mapper;
  136. }
  137. }
  138. }