diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs new file mode 100644 index 0000000..70e04b6 --- /dev/null +++ b/OpenSim/Framework/Data.MySQL/MySQLAssetData.cs | |||
@@ -0,0 +1,112 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using MySql.Data.MySqlClient; | ||
4 | |||
5 | using libsecondlife; | ||
6 | using OpenSim.Framework.Console; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Framework.Data.MySQL | ||
11 | { | ||
12 | class MySQLAssetData : IAssetProvider | ||
13 | { | ||
14 | MySQLManager _dbConnection; | ||
15 | #region IAssetProvider Members | ||
16 | |||
17 | private void UpgradeAssetsTable(string oldVersion) | ||
18 | { | ||
19 | // null as the version, indicates that the table didn't exist | ||
20 | if (oldVersion == null) | ||
21 | { | ||
22 | MainLog.Instance.Notice("ASSETS", "Creating new database tables"); | ||
23 | _dbConnection.ExecuteResourceSql("CreateAssetsTable.sql"); | ||
24 | return; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Ensure that the assets related tables exists and are at the latest version | ||
30 | /// </summary> | ||
31 | private void TestTables() | ||
32 | { | ||
33 | |||
34 | Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||
35 | |||
36 | tableList["assets"] = null; | ||
37 | _dbConnection.GetTableVersion(tableList); | ||
38 | |||
39 | UpgradeAssetsTable(tableList["assets"]); | ||
40 | |||
41 | } | ||
42 | |||
43 | public AssetBase FetchAsset(LLUUID uuid) | ||
44 | { | ||
45 | throw new Exception("The method or operation is not implemented."); | ||
46 | } | ||
47 | |||
48 | public void CreateAsset(AssetBase asset) | ||
49 | { | ||
50 | MySqlCommand cmd = new MySqlCommand("REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" + | ||
51 | "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)", _dbConnection.Connection); | ||
52 | MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); | ||
53 | p.Value = asset.FullID.GetBytes(); | ||
54 | cmd.Parameters.AddWithValue("?name", asset.Name); | ||
55 | cmd.Parameters.AddWithValue("?description", asset.Description); | ||
56 | cmd.Parameters.AddWithValue("?assetType", asset.Type); | ||
57 | cmd.Parameters.AddWithValue("?invType", asset.InvType); | ||
58 | cmd.Parameters.AddWithValue("?local", asset.Local); | ||
59 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | ||
60 | cmd.Parameters.AddWithValue("?data", asset.Data); | ||
61 | cmd.ExecuteNonQuery(); | ||
62 | } | ||
63 | |||
64 | public void UpdateAsset(AssetBase asset) | ||
65 | { | ||
66 | CreateAsset(asset); | ||
67 | } | ||
68 | |||
69 | public bool ExistsAsset(LLUUID uuid) | ||
70 | { | ||
71 | throw new Exception("The method or operation is not implemented."); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// All writes are immediately commited to the database, so this is a no-op | ||
76 | /// </summary> | ||
77 | public void CommitAssets() | ||
78 | { | ||
79 | } | ||
80 | |||
81 | #endregion | ||
82 | |||
83 | #region IPlugin Members | ||
84 | |||
85 | public void Initialise() | ||
86 | { | ||
87 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
88 | string hostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
89 | string database = GridDataMySqlFile.ParseFileReadValue("database"); | ||
90 | string username = GridDataMySqlFile.ParseFileReadValue("username"); | ||
91 | string password = GridDataMySqlFile.ParseFileReadValue("password"); | ||
92 | string pooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
93 | string port = GridDataMySqlFile.ParseFileReadValue("port"); | ||
94 | |||
95 | _dbConnection = new MySQLManager(hostname, database, username, password, pooling, port); | ||
96 | |||
97 | TestTables(); | ||
98 | } | ||
99 | |||
100 | public string Version | ||
101 | { | ||
102 | get { return _dbConnection.getVersion(); } | ||
103 | } | ||
104 | |||
105 | public string Name | ||
106 | { | ||
107 | get { return "MySQL Asset storage engine"; } | ||
108 | } | ||
109 | |||
110 | #endregion | ||
111 | } | ||
112 | } | ||