diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | 201 |
1 files changed, 57 insertions, 144 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs index bcd1900..fccf50d 100644 --- a/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs +++ b/OpenSim/Grid/AssetInventoryServer/Plugins/OpenSim/OpenSimAssetStoragePlugin.cs | |||
@@ -30,7 +30,6 @@ | |||
30 | using System; | 30 | using System; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Data; | 32 | using System.Data; |
33 | using MySql.Data.MySqlClient; | ||
34 | using OpenMetaverse; | 33 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
36 | using OpenSim.Data; | 35 | using OpenSim.Data; |
@@ -54,46 +53,18 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
54 | 53 | ||
55 | #region IAssetStorageProvider implementation | 54 | #region IAssetStorageProvider implementation |
56 | 55 | ||
57 | public BackendResponse TryFetchMetadata(UUID assetID, out Metadata metadata) | 56 | public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata) |
58 | { | 57 | { |
59 | metadata = null; | 58 | metadata = null; |
60 | BackendResponse ret; | 59 | BackendResponse ret; |
61 | 60 | ||
62 | using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) | 61 | AssetBase asset = m_assetProvider.FetchAsset(assetID); |
63 | { | ||
64 | IDataReader reader; | ||
65 | 62 | ||
66 | try | 63 | if (asset == null) ret = BackendResponse.NotFound; |
67 | { | 64 | else |
68 | dbConnection.Open(); | 65 | { |
69 | 66 | metadata = asset.Metadata; | |
70 | IDbCommand command = dbConnection.CreateCommand(); | 67 | ret = BackendResponse.Success; |
71 | command.CommandText = String.Format("SELECT name,description,assetType,temporary FROM assets WHERE id='{0}'", assetID.ToString()); | ||
72 | reader = command.ExecuteReader(); | ||
73 | |||
74 | if (reader.Read()) | ||
75 | { | ||
76 | metadata = new Metadata(); | ||
77 | metadata.CreationDate = OpenMetaverse.Utils.Epoch; | ||
78 | metadata.SHA1 = null; | ||
79 | metadata.ID = assetID; | ||
80 | metadata.Name = reader.GetString(0); | ||
81 | metadata.Description = reader.GetString(1); | ||
82 | metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); | ||
83 | metadata.Temporary = reader.GetBoolean(3); | ||
84 | |||
85 | ret = BackendResponse.Success; | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | ret = BackendResponse.NotFound; | ||
90 | } | ||
91 | } | ||
92 | catch (MySqlException ex) | ||
93 | { | ||
94 | m_log.Error("Connection to MySQL backend failed: " + ex.Message); | ||
95 | ret = BackendResponse.Failure; | ||
96 | } | ||
97 | } | 68 | } |
98 | 69 | ||
99 | m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); | 70 | m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now); |
@@ -105,33 +76,13 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
105 | assetData = null; | 76 | assetData = null; |
106 | BackendResponse ret; | 77 | BackendResponse ret; |
107 | 78 | ||
108 | using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) | 79 | AssetBase asset = m_assetProvider.FetchAsset(assetID); |
109 | { | ||
110 | IDataReader reader; | ||
111 | 80 | ||
112 | try | 81 | if (asset == null) ret = BackendResponse.NotFound; |
113 | { | 82 | else |
114 | dbConnection.Open(); | 83 | { |
115 | 84 | assetData = asset.Data; | |
116 | IDbCommand command = dbConnection.CreateCommand(); | 85 | ret = BackendResponse.Success; |
117 | command.CommandText = String.Format("SELECT data FROM assets WHERE id='{0}'", assetID.ToString()); | ||
118 | reader = command.ExecuteReader(); | ||
119 | |||
120 | if (reader.Read()) | ||
121 | { | ||
122 | assetData = (byte[])reader.GetValue(0); | ||
123 | ret = BackendResponse.Success; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | ret = BackendResponse.NotFound; | ||
128 | } | ||
129 | } | ||
130 | catch (MySqlException ex) | ||
131 | { | ||
132 | m_log.Error("Connection to MySQL backend failed: " + ex.Message); | ||
133 | ret = BackendResponse.Failure; | ||
134 | } | ||
135 | } | 86 | } |
136 | 87 | ||
137 | m_server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); | 88 | m_server.MetricsProvider.LogAssetDataFetch(EXTENSION_NAME, ret, assetID, (assetData != null ? assetData.Length : 0), DateTime.Now); |
@@ -147,101 +98,63 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim | |||
147 | return BackendResponse.Success; | 98 | return BackendResponse.Success; |
148 | } | 99 | } |
149 | 100 | ||
150 | public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData, out UUID assetID) | 101 | public BackendResponse TryCreateAsset(AssetBase asset, out UUID assetID) |
151 | { | 102 | { |
152 | assetID = metadata.ID = UUID.Random(); | 103 | assetID = asset.FullID = UUID.Random(); |
153 | return TryCreateAsset(metadata, assetData); | 104 | return TryCreateAsset(asset); |
154 | } | 105 | } |
155 | 106 | ||
156 | public BackendResponse TryCreateAsset(Metadata metadata, byte[] assetData) | 107 | public BackendResponse TryCreateAsset(AssetBase asset) |
157 | { | 108 | { |
158 | BackendResponse ret; | 109 | BackendResponse ret; |
159 | 110 | ||
160 | using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) | 111 | m_assetProvider.CreateAsset(asset); |
161 | { | 112 | ret = BackendResponse.Success; |
162 | try | ||
163 | { | ||
164 | dbConnection.Open(); | ||
165 | |||
166 | MySqlCommand command = new MySqlCommand( | ||
167 | "REPLACE INTO assets (name,description,assetType,local,temporary,data,id) VALUES " + | ||
168 | "(?name,?description,?assetType,?local,?temporary,?data,?id)", dbConnection); | ||
169 | |||
170 | command.Parameters.AddWithValue("?name", metadata.Name); | ||
171 | command.Parameters.AddWithValue("?description", metadata.Description); | ||
172 | command.Parameters.AddWithValue("?assetType", Utils.ContentTypeToSLAssetType(metadata.ContentType)); | ||
173 | command.Parameters.AddWithValue("?local", 0); | ||
174 | command.Parameters.AddWithValue("?temporary", metadata.Temporary); | ||
175 | command.Parameters.AddWithValue("?data", assetData); | ||
176 | command.Parameters.AddWithValue("?id", metadata.ID.ToString()); | ||
177 | |||
178 | int rowsAffected = command.ExecuteNonQuery(); | ||
179 | if (rowsAffected == 1) | ||
180 | { | ||
181 | ret = BackendResponse.Success; | ||
182 | } | ||
183 | else if (rowsAffected == 2) | ||
184 | { | ||
185 | m_log.Info("Replaced asset " + metadata.ID.ToString()); | ||
186 | ret = BackendResponse.Success; | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | m_log.ErrorFormat("MySQL REPLACE query affected {0} rows", rowsAffected); | ||
191 | ret = BackendResponse.Failure; | ||
192 | } | ||
193 | } | ||
194 | catch (MySqlException ex) | ||
195 | { | ||
196 | m_log.Error("Connection to MySQL backend failed: " + ex.Message); | ||
197 | ret = BackendResponse.Failure; | ||
198 | } | ||
199 | } | ||
200 | 113 | ||
201 | m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, metadata.ID, assetData.Length, DateTime.Now); | 114 | m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); |
202 | return ret; | 115 | return ret; |
203 | } | 116 | } |
204 | 117 | ||
205 | public int ForEach(Action<Metadata> action, int start, int count) | 118 | public int ForEach(Action<AssetMetadata> action, int start, int count) |
206 | { | 119 | { |
207 | int rowCount = 0; | 120 | int rowCount = 0; |
208 | 121 | ||
209 | using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) | 122 | //using (MySqlConnection dbConnection = new MySqlConnection(m_openSimConfig.GetString("asset_database_connect"))) |
210 | { | 123 | //{ |
211 | MySqlDataReader reader; | 124 | // MySqlDataReader reader; |
212 | 125 | ||
213 | try | 126 | // try |
214 | { | 127 | // { |
215 | dbConnection.Open(); | 128 | // dbConnection.Open(); |
216 | 129 | ||
217 | MySqlCommand command = dbConnection.CreateCommand(); | 130 | // MySqlCommand command = dbConnection.CreateCommand(); |
218 | command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", | 131 | // command.CommandText = String.Format("SELECT name,description,assetType,temporary,data,id FROM assets LIMIT {0}, {1}", |
219 | start, count); | 132 | // start, count); |
220 | reader = command.ExecuteReader(); | 133 | // reader = command.ExecuteReader(); |
221 | } | 134 | // } |
222 | catch (MySqlException ex) | 135 | // catch (MySqlException ex) |
223 | { | 136 | // { |
224 | m_log.Error("Connection to MySQL backend failed: " + ex.Message); | 137 | // m_log.Error("Connection to MySQL backend failed: " + ex.Message); |
225 | return 0; | 138 | // return 0; |
226 | } | 139 | // } |
227 | 140 | ||
228 | while (reader.Read()) | 141 | // while (reader.Read()) |
229 | { | 142 | // { |
230 | Metadata metadata = new Metadata(); | 143 | // Metadata metadata = new Metadata(); |
231 | metadata.CreationDate = OpenMetaverse.Utils.Epoch; | 144 | // metadata.CreationDate = OpenMetaverse.Utils.Epoch; |
232 | metadata.Description = reader.GetString(1); | 145 | // metadata.Description = reader.GetString(1); |
233 | metadata.ID = UUID.Parse(reader.GetString(5)); | 146 | // metadata.ID = UUID.Parse(reader.GetString(5)); |
234 | metadata.Name = reader.GetString(0); | 147 | // metadata.Name = reader.GetString(0); |
235 | metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); | 148 | // metadata.SHA1 = OpenMetaverse.Utils.SHA1((byte[])reader.GetValue(4)); |
236 | metadata.Temporary = reader.GetBoolean(3); | 149 | // metadata.Temporary = reader.GetBoolean(3); |
237 | metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); | 150 | // metadata.ContentType = Utils.SLAssetTypeToContentType(reader.GetInt32(2)); |
238 | 151 | ||
239 | action(metadata); | 152 | // action(metadata); |
240 | ++rowCount; | 153 | // ++rowCount; |
241 | } | 154 | // } |
242 | 155 | ||
243 | reader.Close(); | 156 | // reader.Close(); |
244 | } | 157 | //} |
245 | 158 | ||
246 | return rowCount; | 159 | return rowCount; |
247 | } | 160 | } |