aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorTeravus Ovares2008-04-30 20:08:15 +0000
committerTeravus Ovares2008-04-30 20:08:15 +0000
commitb3f44fbb94287d58c635cad7d75e5223ef35aedf (patch)
tree246dac84c3d914907f028fdb93cf030bd13f9dc9 /OpenSim
parent* Refactor: Rename InventoryFolderImpl.HasSubFolder() to GetDescendentFolder() (diff)
downloadopensim-SC_OLD-b3f44fbb94287d58c635cad7d75e5223ef35aedf.zip
opensim-SC_OLD-b3f44fbb94287d58c635cad7d75e5223ef35aedf.tar.gz
opensim-SC_OLD-b3f44fbb94287d58c635cad7d75e5223ef35aedf.tar.bz2
opensim-SC_OLD-b3f44fbb94287d58c635cad7d75e5223ef35aedf.tar.xz
* Refactored the land table to be versionable in mySQL.
* Added AuthbuyerID so that if someone sets a land for sale to someone and then restarts the simulator, when the simulator comes back up, the setting persists.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/MySQL/MySQLDataStore.cs139
-rw-r--r--OpenSim/Data/MySQL/Resources/CreateLandTable.sql39
-rw-r--r--OpenSim/Data/MySQL/Resources/UpgradeLandTableToVersion2.sql3
3 files changed, 170 insertions, 11 deletions
diff --git a/OpenSim/Data/MySQL/MySQLDataStore.cs b/OpenSim/Data/MySQL/MySQLDataStore.cs
index 7714fdc..d438064 100644
--- a/OpenSim/Data/MySQL/MySQLDataStore.cs
+++ b/OpenSim/Data/MySQL/MySQLDataStore.cs
@@ -50,6 +50,12 @@ namespace OpenSim.Data.MySQL
50 private const string m_terrainSelect = "select * from terrain limit 1"; 50 private const string m_terrainSelect = "select * from terrain limit 1";
51 private const string m_landSelect = "select * from land"; 51 private const string m_landSelect = "select * from land";
52 private const string m_landAccessListSelect = "select * from landaccesslist"; 52 private const string m_landAccessListSelect = "select * from landaccesslist";
53
54
55 /// <summary>
56 /// We're only using this to version the table!
57 /// </summary>
58
53 59
54 private DataSet m_dataSet; 60 private DataSet m_dataSet;
55 private MySqlDataAdapter m_primDataAdapter; 61 private MySqlDataAdapter m_primDataAdapter;
@@ -85,6 +91,8 @@ namespace OpenSim.Data.MySQL
85 m_log.Info("[DATASTORE]: MySql - connecting: " + connectionstring); 91 m_log.Info("[DATASTORE]: MySql - connecting: " + connectionstring);
86 m_connection = new MySqlConnection(connectionstring); 92 m_connection = new MySqlConnection(connectionstring);
87 93
94 TestTablesVersionable(m_connection);
95
88 MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, m_connection); 96 MySqlCommand primSelectCmd = new MySqlCommand(m_primSelect, m_connection);
89 m_primDataAdapter = new MySqlDataAdapter(primSelectCmd); 97 m_primDataAdapter = new MySqlDataAdapter(primSelectCmd);
90 98
@@ -103,6 +111,7 @@ namespace OpenSim.Data.MySQL
103 MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, m_connection); 111 MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, m_connection);
104 m_landAccessListDataAdapter = new MySqlDataAdapter(landAccessListSelectCmd); 112 m_landAccessListDataAdapter = new MySqlDataAdapter(landAccessListSelectCmd);
105 113
114
106 TestTables(m_connection); 115 TestTables(m_connection);
107 116
108 lock (m_dataSet) 117 lock (m_dataSet)
@@ -141,7 +150,104 @@ namespace OpenSim.Data.MySQL
141 m_landAccessListDataAdapter.Fill(m_landAccessListTable); 150 m_landAccessListDataAdapter.Fill(m_landAccessListTable);
142 } 151 }
143 } 152 }
153 /// <summary>
154 /// Given a list of tables, return the version of the tables, as seen in the database
155 /// </summary>
156 /// <param name="tableList"></param>
157 public void GetTableVersion(Dictionary<string, string> tableList, MySqlConnection dbcon)
158 {
159 lock (dbcon)
160 {
161 MySqlCommand tablesCmd =
162 new MySqlCommand(
163 "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname",
164 dbcon);
165 tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
166 using (MySqlDataReader tables = tablesCmd.ExecuteReader())
167 {
168 while (tables.Read())
169 {
170 try
171 {
172 string tableName = (string)tables["TABLE_NAME"];
173 string comment = (string)tables["TABLE_COMMENT"];
174 if (tableList.ContainsKey(tableName))
175 {
176 tableList[tableName] = comment;
177 }
178 }
179 catch (Exception e)
180 {
181 m_log.Error(e.ToString());
182 }
183 }
184 tables.Close();
185 }
186 }
187 }
188 private void TestTablesVersionable(MySqlConnection dbconn)
189 {
190 Dictionary<string, string> tableList = new Dictionary<string, string>();
191
192 tableList["land"] = null;
193 dbconn.Open();
194 GetTableVersion(tableList,dbconn);
195
196 UpgradeLandTable(tableList["land"], dbconn);
197 //database.Close();
198
199 }
200
201 /// <summary>
202 /// Execute a SQL statement stored in a resource, as a string
203 /// </summary>
204 /// <param name="name"></param>
205 public void ExecuteResourceSql(string name, MySqlConnection dbcon)
206 {
207 MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon);
208 cmd.ExecuteNonQuery();
209 }
210
211 /// <summary>
212 /// Extract a named string resource from the embedded resources
213 /// </summary>
214 /// <param name="name">name of embedded resource</param>
215 /// <returns>string contained within the embedded resource</returns>
216 private string getResourceString(string name)
217 {
218 Assembly assem = GetType().Assembly;
219 string[] names = assem.GetManifestResourceNames();
220
221 foreach (string s in names)
222 {
223 if (s.EndsWith(name))
224 {
225 using (Stream resource = assem.GetManifestResourceStream(s))
226 {
227 using (StreamReader resourceReader = new StreamReader(resource))
228 {
229 string resourceString = resourceReader.ReadToEnd();
230 return resourceString;
231 }
232 }
233 }
234 }
235 throw new Exception(string.Format("Resource '{0}' was not found", name));
236 }
144 237
238 private void UpgradeLandTable(string oldVersion, MySqlConnection dbconn)
239 {
240 // null as the version, indicates that the table didn't exist
241 if (oldVersion == null)
242 {
243 ExecuteResourceSql("CreateLandTable.sql",dbconn);
244 oldVersion = "Rev. 2; InnoDB free: 0 kB";
245 }
246 if (!oldVersion.Contains("Rev."))
247 {
248 ExecuteResourceSql("UpgradeLandTableToVersion2.sql", dbconn);
249 }
250 }
145 public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID) 251 public void StoreObject(SceneObjectGroup obj, LLUUID regionUUID)
146 { 252 {
147 lock (m_dataSet) 253 lock (m_dataSet)
@@ -673,6 +779,7 @@ namespace OpenSim.Data.MySQL
673 createCol(land, "UserLookAtX", typeof (Double)); 779 createCol(land, "UserLookAtX", typeof (Double));
674 createCol(land, "UserLookAtY", typeof (Double)); 780 createCol(land, "UserLookAtY", typeof (Double));
675 createCol(land, "UserLookAtZ", typeof (Double)); 781 createCol(land, "UserLookAtZ", typeof (Double));
782 createCol(land, "AuthBuyerID", typeof (String));
676 783
677 land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]}; 784 land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]};
678 785
@@ -925,7 +1032,14 @@ namespace OpenSim.Data.MySQL
925 newData.musicURL = (String) row["MusicURL"]; 1032 newData.musicURL = (String) row["MusicURL"];
926 newData.passHours = Convert.ToSingle(row["PassHours"]); 1033 newData.passHours = Convert.ToSingle(row["PassHours"]);
927 newData.passPrice = Convert.ToInt32(row["PassPrice"]); 1034 newData.passPrice = Convert.ToInt32(row["PassPrice"]);
928 newData.snapshotID = (String) row["SnapshotUUID"]; 1035 LLUUID authedbuyer = LLUUID.Zero;
1036 LLUUID snapshotID = LLUUID.Zero;
1037
1038 Helpers.TryParse((string)row["AuthBuyerID"], out authedbuyer);
1039 Helpers.TryParse((string)row["SnapshotUUID"], out snapshotID);
1040
1041 newData.authBuyerID = authedbuyer;
1042 newData.snapshotID = snapshotID;
929 1043
930 newData.userLocation = 1044 newData.userLocation =
931 new LLVector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]), 1045 new LLVector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
@@ -1096,6 +1210,7 @@ namespace OpenSim.Data.MySQL
1096 row["UserLookAtX"] = land.userLookAt.X; 1210 row["UserLookAtX"] = land.userLookAt.X;
1097 row["UserLookAtY"] = land.userLookAt.Y; 1211 row["UserLookAtY"] = land.userLookAt.Y;
1098 row["UserLookAtZ"] = land.userLookAt.Z; 1212 row["UserLookAtZ"] = land.userLookAt.Z;
1213 row["AuthBuyerID"] = land.authBuyerID;
1099 } 1214 }
1100 1215
1101 private void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, LLUUID parcelID) 1216 private void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, LLUUID parcelID)
@@ -1479,14 +1594,16 @@ namespace OpenSim.Data.MySQL
1479 string createShapes = defineTable(createShapeTable()); 1594 string createShapes = defineTable(createShapeTable());
1480 string createItems = defineTable(createItemsTable()); 1595 string createItems = defineTable(createItemsTable());
1481 string createTerrain = defineTable(createTerrainTable()); 1596 string createTerrain = defineTable(createTerrainTable());
1482 string createLand = defineTable(createLandTable()); 1597
1598 // Land table is created from the Versionable Test Table routine now.
1599 //string createLand = defineTable(createLandTable());
1483 string createLandAccessList = defineTable(createLandAccessListTable()); 1600 string createLandAccessList = defineTable(createLandAccessListTable());
1484 1601
1485 MySqlCommand pcmd = new MySqlCommand(createPrims, conn); 1602 MySqlCommand pcmd = new MySqlCommand(createPrims, conn);
1486 MySqlCommand scmd = new MySqlCommand(createShapes, conn); 1603 MySqlCommand scmd = new MySqlCommand(createShapes, conn);
1487 MySqlCommand icmd = new MySqlCommand(createItems, conn); 1604 MySqlCommand icmd = new MySqlCommand(createItems, conn);
1488 MySqlCommand tcmd = new MySqlCommand(createTerrain, conn); 1605 MySqlCommand tcmd = new MySqlCommand(createTerrain, conn);
1489 MySqlCommand lcmd = new MySqlCommand(createLand, conn); 1606 //MySqlCommand lcmd = new MySqlCommand(createLand, conn);
1490 MySqlCommand lalcmd = new MySqlCommand(createLandAccessList, conn); 1607 MySqlCommand lalcmd = new MySqlCommand(createLandAccessList, conn);
1491 1608
1492 if (conn.State != ConnectionState.Open) 1609 if (conn.State != ConnectionState.Open)
@@ -1539,14 +1656,14 @@ namespace OpenSim.Data.MySQL
1539 m_log.WarnFormat("[MySql]: Terrain Table Already Exists: {0}", e); 1656 m_log.WarnFormat("[MySql]: Terrain Table Already Exists: {0}", e);
1540 } 1657 }
1541 1658
1542 try 1659 //try
1543 { 1660 //{
1544 lcmd.ExecuteNonQuery(); 1661 //lcmd.ExecuteNonQuery();
1545 } 1662 //}
1546 catch (MySqlException e) 1663 //catch (MySqlException e)
1547 { 1664 //{
1548 m_log.WarnFormat("[MySql]: Land Table Already Exists: {0}", e); 1665 //m_log.WarnFormat("[MySql]: Land Table Already Exists: {0}", e);
1549 } 1666 //}
1550 1667
1551 try 1668 try
1552 { 1669 {
diff --git a/OpenSim/Data/MySQL/Resources/CreateLandTable.sql b/OpenSim/Data/MySQL/Resources/CreateLandTable.sql
new file mode 100644
index 0000000..8a1b626
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/CreateLandTable.sql
@@ -0,0 +1,39 @@
1CREATE TABLE `land`
2 (
3 `UUID` varchar (255) NOT NULL,
4 `RegionUUID` varchar (255) DEFAULT NULL ,
5 `LocalLandID` int (11) DEFAULT NULL ,
6 `Bitmap` longblob,
7 `Name` varchar (255) DEFAULT NULL ,
8 `Description` varchar (255) DEFAULT NULL ,
9 `OwnerUUID` varchar (255) DEFAULT NULL ,
10 `IsGroupOwned` int (11) DEFAULT NULL ,
11 `Area` int (11) DEFAULT NULL ,
12 `AuctionID` int (11) DEFAULT NULL ,
13 `Category` int (11) DEFAULT NULL ,
14 `ClaimDate` int (11) DEFAULT NULL ,
15 `ClaimPrice` int (11) DEFAULT NULL ,
16 `GroupUUID` varchar (255) DEFAULT NULL ,
17 `SalePrice` int (11) DEFAULT NULL ,
18 `LandStatus` int (11) DEFAULT NULL ,
19 `LandFlags` int (11) DEFAULT NULL ,
20 `LandingType` int (11) DEFAULT NULL ,
21 `MediaAutoScale` int (11) DEFAULT NULL ,
22 `MediaTextureUUID` varchar (255) DEFAULT NULL ,
23 `MediaURL` varchar (255) DEFAULT NULL ,
24 `MusicURL` varchar (255) DEFAULT NULL ,
25 `PassHours` float DEFAULT NULL ,
26 `PassPrice` int (11) DEFAULT NULL ,
27 `SnapshotUUID` varchar (255) DEFAULT NULL ,
28 `UserLocationX` float DEFAULT NULL ,
29 `UserLocationY` float DEFAULT NULL ,
30 `UserLocationZ` float DEFAULT NULL ,
31 `UserLookAtX` float DEFAULT NULL ,
32 `UserLookAtY` float DEFAULT NULL ,
33 `UserLookAtZ` float DEFAULT NULL ,
34 `AuthbuyerID` varchar(36) default '00000000-0000-0000-0000-000000000000' not null,
35
36 PRIMARY KEY (`UUID`)
37 )
38 ENGINE=INNODB
39 DEFAULT CHARSET=utf8 COMMENT='Rev. 2'; \ No newline at end of file
diff --git a/OpenSim/Data/MySQL/Resources/UpgradeLandTableToVersion2.sql b/OpenSim/Data/MySQL/Resources/UpgradeLandTableToVersion2.sql
new file mode 100644
index 0000000..eb024be
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/UpgradeLandTableToVersion2.sql
@@ -0,0 +1,3 @@
1ALTER TABLE `land`
2 ADD COLUMN `AuthbuyerID` varchar(36) default '00000000-0000-0000-0000-000000000000' not null,
3COMMENT='Rev. 2'; \ No newline at end of file