aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLAssetData.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLAssetData.cs198
1 files changed, 0 insertions, 198 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
deleted file mode 100644
index 79994ae..0000000
--- a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs
+++ /dev/null
@@ -1,198 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using libsecondlife;
32using MySql.Data.MySqlClient;
33using OpenSim.Framework.Console;
34
35namespace OpenSim.Framework.Data.MySQL
36{
37 internal class MySQLAssetData : AssetDataBase, IPlugin
38 {
39 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
40
41 private MySQLManager _dbConnection;
42
43 #region IAssetProvider Members
44
45 private void UpgradeAssetsTable(string oldVersion)
46 {
47 // null as the version, indicates that the table didn't exist
48 if (oldVersion == null)
49 {
50 m_log.Info("[ASSETS]: Creating new database tables");
51 _dbConnection.ExecuteResourceSql("CreateAssetsTable.sql");
52 return;
53 }
54 }
55
56 /// <summary>
57 /// Ensure that the assets related tables exists and are at the latest version
58 /// </summary>
59 private void TestTables()
60 {
61 Dictionary<string, string> tableList = new Dictionary<string, string>();
62
63 tableList["assets"] = null;
64 _dbConnection.GetTableVersion(tableList);
65
66 UpgradeAssetsTable(tableList["assets"]);
67 }
68
69 override public AssetBase FetchAsset(LLUUID assetID)
70 {
71 AssetBase asset = null;
72 lock (_dbConnection)
73 {
74 MySqlCommand cmd =
75 new MySqlCommand(
76 "SELECT name, description, assetType, invType, local, temporary, data FROM assets WHERE id=?id",
77 _dbConnection.Connection);
78 MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
79 p.Value = assetID.GetBytes();
80
81 try
82 {
83 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
84 {
85 if (dbReader.Read())
86 {
87 asset = new AssetBase();
88 asset.Data = (byte[]) dbReader["data"];
89 asset.Description = (string) dbReader["description"];
90 asset.FullID = assetID;
91 asset.InvType = (sbyte) dbReader["invType"];
92 asset.Local = ((sbyte) dbReader["local"]) != 0 ? true : false;
93 asset.Name = (string) dbReader["name"];
94 asset.Type = (sbyte) dbReader["assetType"];
95 }
96 dbReader.Close();
97 cmd.Dispose();
98 }
99 }
100 catch (Exception e)
101 {
102 m_log.ErrorFormat(
103 "[ASSETS]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString()
104 + Environment.NewLine + "Attempting reconnection", assetID);
105 _dbConnection.Reconnect();
106 }
107 }
108 return asset;
109 }
110
111 override public void CreateAsset(AssetBase asset)
112 {
113 lock (_dbConnection)
114 {
115 MySqlCommand cmd =
116 new MySqlCommand(
117 "REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" +
118 "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)",
119 _dbConnection.Connection);
120
121 // need to ensure we dispose
122 try
123 {
124 using (cmd)
125 {
126 MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16);
127 p.Value = asset.FullID.GetBytes();
128 cmd.Parameters.AddWithValue("?name", asset.Name);
129 cmd.Parameters.AddWithValue("?description", asset.Description);
130 cmd.Parameters.AddWithValue("?assetType", asset.Type);
131 cmd.Parameters.AddWithValue("?invType", asset.InvType);
132 cmd.Parameters.AddWithValue("?local", asset.Local);
133 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
134 cmd.Parameters.AddWithValue("?data", asset.Data);
135 cmd.ExecuteNonQuery();
136 cmd.Dispose();
137 }
138 }
139 catch (Exception e)
140 {
141 m_log.ErrorFormat(
142 "[ASSETS]: " +
143 "MySql failure creating asset {0} with name {1}" + Environment.NewLine + e.ToString()
144 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
145 _dbConnection.Reconnect();
146 }
147 }
148 }
149
150 override public void UpdateAsset(AssetBase asset)
151 {
152 CreateAsset(asset);
153 }
154
155 override public bool ExistsAsset(LLUUID uuid)
156 {
157 throw new Exception("The method or operation is not implemented.");
158 }
159
160 /// <summary>
161 /// All writes are immediately commited to the database, so this is a no-op
162 /// </summary>
163 override public void CommitAssets()
164 {
165 }
166
167 #endregion
168
169 #region IPlugin Members
170
171 override public void Initialise()
172 {
173 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
174 string hostname = GridDataMySqlFile.ParseFileReadValue("hostname");
175 string database = GridDataMySqlFile.ParseFileReadValue("database");
176 string username = GridDataMySqlFile.ParseFileReadValue("username");
177 string password = GridDataMySqlFile.ParseFileReadValue("password");
178 string pooling = GridDataMySqlFile.ParseFileReadValue("pooling");
179 string port = GridDataMySqlFile.ParseFileReadValue("port");
180
181 _dbConnection = new MySQLManager(hostname, database, username, password, pooling, port);
182
183 TestTables();
184 }
185
186 override public string Version
187 {
188 get { return _dbConnection.getVersion(); }
189 }
190
191 override public string Name
192 {
193 get { return "MySQL Asset storage engine"; }
194 }
195
196 #endregion
197 }
198}