/Aurora/Framework/DatabaseInterfaces/IGenericsConnector.cs
C# | 135 lines | 34 code | 12 blank | 89 comment | 2 complexity | 3ee27fe87f4679e354e4c156169c1c55 MD5 | raw file
1/* 2 * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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 28using Aurora.Framework.Modules; 29using Aurora.Framework.Services; 30using OpenMetaverse; 31using OpenMetaverse.StructuredData; 32using System.Collections.Generic; 33 34namespace Aurora.Framework.DatabaseInterfaces 35{ 36 /// <summary> 37 /// Some background to this class 38 /// This class saves any class that implements the IDataTransferable interface. 39 /// When implementing the IDataTransferable interface, it is heavily recommending to implement ToOSD and FromOSD first, then use the Utility methods to convert OSDMaps into Dictionarys, as shown in the LandData class. 40 /// This method of saving uses 4 columns in the database, OwnerID, Type, Key, and Value 41 /// - OwnerID : This is a way to be able to save Agent or Region or anything with a UUID into the database and have it be set to that UUID only. 42 /// - Type : What made this data? This just tells what module created the given row in the database. 43 /// - Key : Another identifying setting so that you can store more than one row under an OwnerID and Type 44 /// - Value : The value of the row 45 /// This class deals with the Getting/Setting/Removing of these generic interfaces. 46 /// </summary> 47 public interface IGenericsConnector : IAuroraDataPlugin 48 { 49 /// <summary> 50 /// Gets a Generic type as set by the ownerID, Type, and Key 51 /// </summary> 52 /// <typeparam name="T">return value of type IDataTransferable</typeparam> 53 /// <param name="OwnerID"></param> 54 /// <param name="Type"></param> 55 /// <param name="Key"></param> 56 /// <returns></returns> 57 T GetGeneric<T>(UUID OwnerID, string Type, string Key) where T : IDataTransferable; 58 59 /// <summary> 60 /// Gets a list of generic T's from the database 61 /// </summary> 62 /// <typeparam name="T"></typeparam> 63 /// <param name="OwnerID"></param> 64 /// <param name="Type"></param> 65 /// <returns></returns> 66 List<T> GetGenerics<T>(UUID OwnerID, string Type) where T : IDataTransferable; 67 68 /// <summary> 69 /// Adds a generic IDataTransferable into the database 70 /// </summary> 71 /// <param name="OwnerID"></param> 72 /// <param name="Type"></param> 73 /// <param name="Key"></param> 74 /// <param name="Value"></param> 75 void AddGeneric(UUID OwnerID, string Type, string Key, OSDMap Value); 76 77 /// <summary> 78 /// Removes a generic IDataTransferable from the database 79 /// </summary> 80 /// <param name="OwnerID"></param> 81 /// <param name="Type"></param> 82 /// <param name="Key"></param> 83 void RemoveGeneric(UUID OwnerID, string Type, string Key); 84 85 /// <summary> 86 /// Removes a generic IDataTransferable from the database 87 /// </summary> 88 /// <param name="OwnerID"></param> 89 /// <param name="Type"></param> 90 void RemoveGeneric(UUID OwnerID, string Type); 91 92 /// <summary> 93 /// Returns a list of UUIDs of the specified type that have the specified key 94 /// </summary> 95 /// <param name="Type"></param> 96 /// <param name="Key"></param> 97 /// <returns></returns> 98 List<UUID> GetOwnersByGeneric(string Type, string Key); 99 100 /// <summary> 101 /// Returns a list of UUIDs of the specified type that have the specified key and value 102 /// </summary> 103 /// <param name="Type"></param> 104 /// <param name="Key"></param> 105 /// <param name="Value"></param> 106 /// <returns></returns> 107 List<UUID> GetOwnersByGeneric(string Type, string Key, OSDMap Value); 108 109 /// <summary> 110 /// Gets the number of list of generic T's from the database 111 /// </summary> 112 /// <param name="OwnerID"></param> 113 /// <param name="Type"></param> 114 /// <returns></returns> 115 int GetGenericCount(UUID OwnerID, string Type); 116 } 117 118 public class OSDWrapper : IDataTransferable 119 { 120 public OSD Info; 121 122 public override void FromOSD(OSDMap map) 123 { 124 if (map != null) 125 Info = map["Info"]; 126 } 127 128 public override OSDMap ToOSD() 129 { 130 OSDMap map = new OSDMap(); 131 map["Info"] = Info; 132 return map; 133 } 134 } 135}