diff options
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteAssetData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteAssetData.cs | 67 |
1 files changed, 46 insertions, 21 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 61e7aaf..f0dda64 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs | |||
@@ -46,7 +46,7 @@ namespace OpenSim.Data.SQLite | |||
46 | /// </summary> | 46 | /// </summary> |
47 | public class SQLiteAssetData : AssetDataBase | 47 | public class SQLiteAssetData : AssetDataBase |
48 | { | 48 | { |
49 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 50 | ||
51 | private const string SelectAssetSQL = "select * from assets where UUID=:UUID"; | 51 | private const string SelectAssetSQL = "select * from assets where UUID=:UUID"; |
52 | private const string SelectAssetMetadataSQL = "select Name, Description, Type, Temporary, asset_flags, UUID, CreatorID from assets limit :start, :count"; | 52 | private const string SelectAssetMetadataSQL = "select Name, Description, Type, Temporary, asset_flags, UUID, CreatorID from assets limit :start, :count"; |
@@ -133,8 +133,26 @@ namespace OpenSim.Data.SQLite | |||
133 | /// <param name="asset">Asset Base</param> | 133 | /// <param name="asset">Asset Base</param> |
134 | override public void StoreAsset(AssetBase asset) | 134 | override public void StoreAsset(AssetBase asset) |
135 | { | 135 | { |
136 | string assetName = asset.Name; | ||
137 | if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) | ||
138 | { | ||
139 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); | ||
140 | m_log.WarnFormat( | ||
141 | "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
142 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
143 | } | ||
144 | |||
145 | string assetDescription = asset.Description; | ||
146 | if (asset.Description.Length > AssetBase.MAX_ASSET_DESC) | ||
147 | { | ||
148 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); | ||
149 | m_log.WarnFormat( | ||
150 | "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
151 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
152 | } | ||
153 | |||
136 | //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); | 154 | //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); |
137 | if (ExistsAsset(asset.FullID)) | 155 | if (AssetsExist(new[] { asset.FullID })[0]) |
138 | { | 156 | { |
139 | //LogAssetLoad(asset); | 157 | //LogAssetLoad(asset); |
140 | 158 | ||
@@ -143,8 +161,8 @@ namespace OpenSim.Data.SQLite | |||
143 | using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) | 161 | using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) |
144 | { | 162 | { |
145 | cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); | 163 | cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); |
146 | cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); | 164 | cmd.Parameters.Add(new SqliteParameter(":Name", assetName)); |
147 | cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description)); | 165 | cmd.Parameters.Add(new SqliteParameter(":Description", assetDescription)); |
148 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); | 166 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); |
149 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); | 167 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); |
150 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); | 168 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); |
@@ -163,8 +181,8 @@ namespace OpenSim.Data.SQLite | |||
163 | using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) | 181 | using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) |
164 | { | 182 | { |
165 | cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); | 183 | cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); |
166 | cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); | 184 | cmd.Parameters.Add(new SqliteParameter(":Name", assetName)); |
167 | cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description)); | 185 | cmd.Parameters.Add(new SqliteParameter(":Description", assetDescription)); |
168 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); | 186 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); |
169 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); | 187 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); |
170 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); | 188 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); |
@@ -196,32 +214,39 @@ namespace OpenSim.Data.SQLite | |||
196 | // } | 214 | // } |
197 | 215 | ||
198 | /// <summary> | 216 | /// <summary> |
199 | /// Check if an asset exist in database | 217 | /// Check if the assets exist in the database. |
200 | /// </summary> | 218 | /// </summary> |
201 | /// <param name="uuid">The asset UUID</param> | 219 | /// <param name="uuids">The assets' IDs</param> |
202 | /// <returns>True if exist, or false.</returns> | 220 | /// <returns>For each asset: true if it exists, false otherwise</returns> |
203 | override public bool ExistsAsset(UUID uuid) | 221 | public override bool[] AssetsExist(UUID[] uuids) |
204 | { | 222 | { |
205 | lock (this) | 223 | if (uuids.Length == 0) |
224 | return new bool[0]; | ||
225 | |||
226 | HashSet<UUID> exist = new HashSet<UUID>(); | ||
227 | |||
228 | string ids = "'" + string.Join("','", uuids) + "'"; | ||
229 | string sql = string.Format("select UUID from assets where UUID in ({0})", ids); | ||
230 | |||
231 | lock (this) | ||
206 | { | 232 | { |
207 | using (SqliteCommand cmd = new SqliteCommand(SelectAssetSQL, m_conn)) | 233 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) |
208 | { | 234 | { |
209 | cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); | ||
210 | using (IDataReader reader = cmd.ExecuteReader()) | 235 | using (IDataReader reader = cmd.ExecuteReader()) |
211 | { | 236 | { |
212 | if (reader.Read()) | 237 | while (reader.Read()) |
213 | { | ||
214 | reader.Close(); | ||
215 | return true; | ||
216 | } | ||
217 | else | ||
218 | { | 238 | { |
219 | reader.Close(); | 239 | UUID id = new UUID((string)reader["UUID"]); |
220 | return false; | 240 | exist.Add(id); |
221 | } | 241 | } |
222 | } | 242 | } |
223 | } | 243 | } |
224 | } | 244 | } |
245 | |||
246 | bool[] results = new bool[uuids.Length]; | ||
247 | for (int i = 0; i < uuids.Length; i++) | ||
248 | results[i] = exist.Contains(uuids[i]); | ||
249 | return results; | ||
225 | } | 250 | } |
226 | 251 | ||
227 | /// <summary> | 252 | /// <summary> |