diff options
author | mingchen | 2007-12-18 20:31:51 +0000 |
---|---|---|
committer | mingchen | 2007-12-18 20:31:51 +0000 |
commit | 20eecd4155aa2e21a9f57bea0e82ce98c4373970 (patch) | |
tree | 7a574ac406dfaa1ab2cdd4e87e2f8a7c55dcc7f3 | |
parent | Fix typo. AutionID -> AuctionID (diff) | |
download | opensim-SC_OLD-20eecd4155aa2e21a9f57bea0e82ce98c4373970.zip opensim-SC_OLD-20eecd4155aa2e21a9f57bea0e82ce98c4373970.tar.gz opensim-SC_OLD-20eecd4155aa2e21a9f57bea0e82ce98c4373970.tar.bz2 opensim-SC_OLD-20eecd4155aa2e21a9f57bea0e82ce98c4373970.tar.xz |
*Using Mysql as the datastore should now store parcels across multiple sessions
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index cdc8c74..2c08d2a 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | |||
@@ -48,15 +48,21 @@ namespace OpenSim.Framework.Data.MySQL | |||
48 | private const string m_primSelect = "select * from prims"; | 48 | private const string m_primSelect = "select * from prims"; |
49 | private const string m_shapeSelect = "select * from primshapes"; | 49 | private const string m_shapeSelect = "select * from primshapes"; |
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"; | ||
52 | private const string m_landAccessListSelect = "select * from landaccesslist"; | ||
51 | 53 | ||
52 | private DataSet m_dataSet; | 54 | private DataSet m_dataSet; |
53 | private MySqlDataAdapter m_primDataAdapter; | 55 | private MySqlDataAdapter m_primDataAdapter; |
54 | private MySqlDataAdapter m_shapeDataAdapter; | 56 | private MySqlDataAdapter m_shapeDataAdapter; |
55 | private MySqlConnection m_connection; | 57 | private MySqlConnection m_connection; |
56 | private MySqlDataAdapter m_terrainDataAdapter; | 58 | private MySqlDataAdapter m_terrainDataAdapter; |
59 | private MySqlDataAdapter m_landDataAdapter; | ||
60 | private MySqlDataAdapter m_landAccessListDataAdapter; | ||
57 | private DataTable m_primTable; | 61 | private DataTable m_primTable; |
58 | private DataTable m_shapeTable; | 62 | private DataTable m_shapeTable; |
59 | private DataTable m_terrainTable; | 63 | private DataTable m_terrainTable; |
64 | private DataTable m_landTable; | ||
65 | private DataTable m_landAccessListTable; | ||
60 | 66 | ||
61 | /*********************************************************************** | 67 | /*********************************************************************** |
62 | * | 68 | * |
@@ -80,6 +86,12 @@ namespace OpenSim.Framework.Data.MySQL | |||
80 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, m_connection); | 86 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, m_connection); |
81 | m_terrainDataAdapter = new MySqlDataAdapter(terrainSelectCmd); | 87 | m_terrainDataAdapter = new MySqlDataAdapter(terrainSelectCmd); |
82 | 88 | ||
89 | MySqlCommand landSelectCmd = new MySqlCommand(m_landSelect, m_connection); | ||
90 | m_landDataAdapter = new MySqlDataAdapter(landSelectCmd); | ||
91 | |||
92 | MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, m_connection); | ||
93 | m_landAccessListDataAdapter = new MySqlDataAdapter(landAccessListSelectCmd); | ||
94 | |||
83 | TestTables(m_connection); | 95 | TestTables(m_connection); |
84 | 96 | ||
85 | lock (m_dataSet) | 97 | lock (m_dataSet) |
@@ -98,6 +110,16 @@ namespace OpenSim.Framework.Data.MySQL | |||
98 | m_dataSet.Tables.Add(m_terrainTable); | 110 | m_dataSet.Tables.Add(m_terrainTable); |
99 | SetupTerrainCommands(m_terrainDataAdapter, m_connection); | 111 | SetupTerrainCommands(m_terrainDataAdapter, m_connection); |
100 | m_terrainDataAdapter.Fill(m_terrainTable); | 112 | m_terrainDataAdapter.Fill(m_terrainTable); |
113 | |||
114 | m_landTable = createLandTable(); | ||
115 | m_dataSet.Tables.Add(m_landTable); | ||
116 | setupLandCommands(m_landDataAdapter, m_connection); | ||
117 | m_landDataAdapter.Fill(m_landTable); | ||
118 | |||
119 | m_landAccessListTable = createLandAccessListTable(); | ||
120 | m_dataSet.Tables.Add(m_landAccessListTable); | ||
121 | setupLandCommands(m_landAccessListDataAdapter, m_connection); | ||
122 | m_landAccessListDataAdapter.Fill(m_landAccessListTable); | ||
101 | } | 123 | } |
102 | } | 124 | } |
103 | 125 | ||
@@ -438,6 +460,59 @@ namespace OpenSim.Framework.Data.MySQL | |||
438 | return prims; | 460 | return prims; |
439 | } | 461 | } |
440 | 462 | ||
463 | private DataTable createLandTable() | ||
464 | { | ||
465 | DataTable land = new DataTable("land"); | ||
466 | createCol(land, "UUID", typeof(String)); | ||
467 | createCol(land, "RegionUUID", typeof(String)); | ||
468 | createCol(land, "LocalLandID", typeof(UInt32)); | ||
469 | |||
470 | // Bitmap is a byte[512] | ||
471 | createCol(land, "Bitmap", typeof(Byte[])); | ||
472 | |||
473 | createCol(land, "Name", typeof(String)); | ||
474 | createCol(land, "Desc", typeof(String)); | ||
475 | createCol(land, "OwnerUUID", typeof(String)); | ||
476 | createCol(land, "IsGroupOwned", typeof(Boolean)); | ||
477 | createCol(land, "Area", typeof(Int32)); | ||
478 | createCol(land, "AuctionID", typeof(Int32)); //Unemplemented | ||
479 | createCol(land, "Category", typeof(Int32)); //Enum libsecondlife.Parcel.ParcelCategory | ||
480 | createCol(land, "ClaimDate", typeof(Int32)); | ||
481 | createCol(land, "ClaimPrice", typeof(Int32)); | ||
482 | createCol(land, "GroupUUID", typeof(string)); | ||
483 | createCol(land, "SalePrice", typeof(Int32)); | ||
484 | createCol(land, "LandStatus", typeof(Int32)); //Enum. libsecondlife.Parcel.ParcelStatus | ||
485 | createCol(land, "LandFlags", typeof(UInt32)); | ||
486 | createCol(land, "LandingType", typeof(Byte)); | ||
487 | createCol(land, "MediaAutoScale", typeof(Byte)); | ||
488 | createCol(land, "MediaTextureUUID", typeof(String)); | ||
489 | createCol(land, "MediaURL", typeof(String)); | ||
490 | createCol(land, "MusicURL", typeof(String)); | ||
491 | createCol(land, "PassHours", typeof(Double)); | ||
492 | createCol(land, "PassPrice", typeof(UInt32)); | ||
493 | createCol(land, "SnapshotUUID", typeof(String)); | ||
494 | createCol(land, "UserLocationX", typeof(Double)); | ||
495 | createCol(land, "UserLocationY", typeof(Double)); | ||
496 | createCol(land, "UserLocationZ", typeof(Double)); | ||
497 | createCol(land, "UserLookAtX", typeof(Double)); | ||
498 | createCol(land, "UserLookAtY", typeof(Double)); | ||
499 | createCol(land, "UserLookAtZ", typeof(Double)); | ||
500 | |||
501 | land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] }; | ||
502 | |||
503 | return land; | ||
504 | } | ||
505 | |||
506 | private DataTable createLandAccessListTable() | ||
507 | { | ||
508 | DataTable landaccess = new DataTable("landaccesslist"); | ||
509 | createCol(landaccess, "LandUUID", typeof(String)); | ||
510 | createCol(landaccess, "AccessUUID", typeof(String)); | ||
511 | createCol(landaccess, "Flags", typeof(UInt32)); | ||
512 | |||
513 | return landaccess; | ||
514 | } | ||
515 | |||
441 | private DataTable createShapeTable() | 516 | private DataTable createShapeTable() |
442 | { | 517 | { |
443 | DataTable shapes = new DataTable("primshapes"); | 518 | DataTable shapes = new DataTable("primshapes"); |
@@ -547,6 +622,54 @@ namespace OpenSim.Framework.Data.MySQL | |||
547 | return prim; | 622 | return prim; |
548 | } | 623 | } |
549 | 624 | ||
625 | private LandData buildLandData(DataRow row) | ||
626 | { | ||
627 | LandData newData = new LandData(); | ||
628 | |||
629 | newData.globalID = new LLUUID((String)row["UUID"]); | ||
630 | newData.localID = Convert.ToInt32(row["LocalLandID"]); | ||
631 | |||
632 | // Bitmap is a byte[512] | ||
633 | newData.landBitmapByteArray = (Byte[])row["Bitmap"]; | ||
634 | |||
635 | newData.landName = (String)row["Name"]; | ||
636 | newData.landDesc = (String)row["Desc"]; | ||
637 | newData.ownerID = (String)row["OwnerUUID"]; | ||
638 | newData.isGroupOwned = (Boolean)row["IsGroupOwned"]; | ||
639 | newData.area = Convert.ToInt32(row["Area"]); | ||
640 | newData.auctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented | ||
641 | newData.category = (Parcel.ParcelCategory)Convert.ToInt32(row["Category"]); //Enum libsecondlife.Parcel.ParcelCategory | ||
642 | newData.claimDate = Convert.ToInt32(row["ClaimDate"]); | ||
643 | newData.claimPrice = Convert.ToInt32(row["ClaimPrice"]); | ||
644 | newData.groupID = new LLUUID((String)row["GroupUUID"]); | ||
645 | newData.salePrice = Convert.ToInt32(row["SalePrice"]); | ||
646 | newData.landStatus = (Parcel.ParcelStatus)Convert.ToInt32(row["LandStatus"]); //Enum. libsecondlife.Parcel.ParcelStatus | ||
647 | newData.landFlags = Convert.ToUInt32(row["LandFlags"]); | ||
648 | newData.landingType = (Byte)row["LandingType"]; | ||
649 | newData.mediaAutoScale = (Byte)row["MediaAutoScale"]; | ||
650 | newData.mediaID = new LLUUID((String)row["MediaTextureUUID"]); | ||
651 | newData.mediaURL = (String)row["MediaURL"]; | ||
652 | newData.musicURL = (String)row["MusicURL"]; | ||
653 | newData.passHours = Convert.ToSingle(row["PassHours"]); | ||
654 | newData.passPrice = Convert.ToInt32(row["PassPrice"]); | ||
655 | newData.snapshotID = (String)row["SnapshotUUID"]; | ||
656 | |||
657 | newData.userLocation = new LLVector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]), Convert.ToSingle(row["UserLocationZ"])); | ||
658 | newData.userLookAt = new LLVector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]), Convert.ToSingle(row["UserLookAtZ"])); | ||
659 | newData.parcelAccessList = new List<ParcelManager.ParcelAccessEntry>(); | ||
660 | |||
661 | return newData; | ||
662 | } | ||
663 | |||
664 | private ParcelManager.ParcelAccessEntry buildLandAccessData(DataRow row) | ||
665 | { | ||
666 | ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry(); | ||
667 | entry.AgentID = new LLUUID((string)row["AccessUUID"]); | ||
668 | entry.Flags = (ParcelManager.AccessList)row["Flags"]; | ||
669 | entry.Time = new DateTime(); | ||
670 | return entry; | ||
671 | } | ||
672 | |||
550 | private Array serializeTerrain(double[,] val) | 673 | private Array serializeTerrain(double[,] val) |
551 | { | 674 | { |
552 | MemoryStream str = new MemoryStream(65536 * sizeof(double)); | 675 | MemoryStream str = new MemoryStream(65536 * sizeof(double)); |
@@ -607,6 +730,51 @@ namespace OpenSim.Framework.Data.MySQL | |||
607 | row["RotationW"] = prim.RotationOffset.W; | 730 | row["RotationW"] = prim.RotationOffset.W; |
608 | } | 731 | } |
609 | 732 | ||
733 | private void fillLandRow(DataRow row, LandData land, LLUUID regionUUID) | ||
734 | { | ||
735 | row["UUID"] = land.globalID.ToString(); | ||
736 | row["RegionUUID"] = regionUUID.ToString(); | ||
737 | row["LocalLandID"] = land.localID; | ||
738 | |||
739 | // Bitmap is a byte[512] | ||
740 | row["Bitmap"] = land.landBitmapByteArray; | ||
741 | |||
742 | row["Name"] = land.landName; | ||
743 | row["Desc"] = land.landDesc; | ||
744 | row["OwnerUUID"] = land.ownerID.ToString(); | ||
745 | row["IsGroupOwned"] = land.isGroupOwned; | ||
746 | row["Area"] = land.area; | ||
747 | row["AuctionID"] = land.auctionID; //Unemplemented | ||
748 | row["Category"] = land.category; //Enum libsecondlife.Parcel.ParcelCategory | ||
749 | row["ClaimDate"] = land.claimDate; | ||
750 | row["ClaimPrice"] = land.claimPrice; | ||
751 | row["GroupUUID"] = land.groupID.ToString(); | ||
752 | row["SalePrice"] = land.salePrice; | ||
753 | row["LandStatus"] = land.landStatus; //Enum. libsecondlife.Parcel.ParcelStatus | ||
754 | row["LandFlags"] = land.landFlags; | ||
755 | row["LandingType"] = land.landingType; | ||
756 | row["MediaAutoScale"] = land.mediaAutoScale; | ||
757 | row["MediaTextureUUID"] = land.mediaID.ToString(); | ||
758 | row["MediaURL"] = land.mediaURL; | ||
759 | row["MusicURL"] = land.musicURL; | ||
760 | row["PassHours"] = land.passHours; | ||
761 | row["PassPrice"] = land.passPrice; | ||
762 | row["SnapshotUUID"] = land.snapshotID.ToString(); | ||
763 | row["UserLocationX"] = land.userLocation.X; | ||
764 | row["UserLocationY"] = land.userLocation.Y; | ||
765 | row["UserLocationZ"] = land.userLocation.Z; | ||
766 | row["UserLookAtX"] = land.userLookAt.X; | ||
767 | row["UserLookAtY"] = land.userLookAt.Y; | ||
768 | row["UserLookAtZ"] = land.userLookAt.Z; | ||
769 | } | ||
770 | |||
771 | private void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, LLUUID parcelID) | ||
772 | { | ||
773 | row["LandUUID"] = parcelID.ToString(); | ||
774 | row["AccessUUID"] = entry.AgentID.ToString(); | ||
775 | row["Flags"] = entry.Flags; | ||
776 | } | ||
777 | |||
610 | private PrimitiveBaseShape buildShape(DataRow row) | 778 | private PrimitiveBaseShape buildShape(DataRow row) |
611 | { | 779 | { |
612 | PrimitiveBaseShape s = new PrimitiveBaseShape(); | 780 | PrimitiveBaseShape s = new PrimitiveBaseShape(); |
@@ -861,6 +1029,21 @@ namespace OpenSim.Framework.Data.MySQL | |||
861 | da.InsertCommand.Connection = conn; | 1029 | da.InsertCommand.Connection = conn; |
862 | } | 1030 | } |
863 | 1031 | ||
1032 | private void setupLandCommands(MySqlDataAdapter da, MySqlConnection conn) | ||
1033 | { | ||
1034 | da.InsertCommand = createInsertCommand("land", m_dataSet.Tables["land"]); | ||
1035 | da.InsertCommand.Connection = conn; | ||
1036 | |||
1037 | da.UpdateCommand = createUpdateCommand("land", "UUID=?UUID", m_dataSet.Tables["land"]); | ||
1038 | da.UpdateCommand.Connection = conn; | ||
1039 | } | ||
1040 | |||
1041 | private void setupLandAccessCommands(MySqlDataAdapter da, MySqlConnection conn) | ||
1042 | { | ||
1043 | da.InsertCommand = createInsertCommand("landaccesslist", m_dataSet.Tables["landaccesslist"]); | ||
1044 | da.InsertCommand.Connection = conn; | ||
1045 | } | ||
1046 | |||
864 | private void SetupShapeCommands(MySqlDataAdapter da, MySqlConnection conn) | 1047 | private void SetupShapeCommands(MySqlDataAdapter da, MySqlConnection conn) |
865 | { | 1048 | { |
866 | da.InsertCommand = createInsertCommand("primshapes", m_dataSet.Tables["primshapes"]); | 1049 | da.InsertCommand = createInsertCommand("primshapes", m_dataSet.Tables["primshapes"]); |
@@ -880,10 +1063,14 @@ namespace OpenSim.Framework.Data.MySQL | |||
880 | string createPrims = defineTable(createPrimTable()); | 1063 | string createPrims = defineTable(createPrimTable()); |
881 | string createShapes = defineTable(createShapeTable()); | 1064 | string createShapes = defineTable(createShapeTable()); |
882 | string createTerrain = defineTable(createTerrainTable()); | 1065 | string createTerrain = defineTable(createTerrainTable()); |
1066 | string createLand = defineTable(createLandTable()); | ||
1067 | string createLandAccessList = defineTable(createLandTable()); | ||
883 | 1068 | ||
884 | MySqlCommand pcmd = new MySqlCommand(createPrims, conn); | 1069 | MySqlCommand pcmd = new MySqlCommand(createPrims, conn); |
885 | MySqlCommand scmd = new MySqlCommand(createShapes, conn); | 1070 | MySqlCommand scmd = new MySqlCommand(createShapes, conn); |
886 | MySqlCommand tcmd = new MySqlCommand(createTerrain, conn); | 1071 | MySqlCommand tcmd = new MySqlCommand(createTerrain, conn); |
1072 | MySqlCommand lcmd = new MySqlCommand(createLand, conn); | ||
1073 | MySqlCommand lalcmd = new MySqlCommand(createLandAccessList, conn); | ||
887 | 1074 | ||
888 | if (conn.State != ConnectionState.Open) | 1075 | if (conn.State != ConnectionState.Open) |
889 | { | 1076 | { |
@@ -917,6 +1104,23 @@ namespace OpenSim.Framework.Data.MySQL | |||
917 | MainLog.Instance.Warn("MySql", "Terrain Table Already Exists"); | 1104 | MainLog.Instance.Warn("MySql", "Terrain Table Already Exists"); |
918 | } | 1105 | } |
919 | 1106 | ||
1107 | try | ||
1108 | { | ||
1109 | lcmd.ExecuteNonQuery(); | ||
1110 | } | ||
1111 | catch (MySqlException) | ||
1112 | { | ||
1113 | MainLog.Instance.Warn("MySql", "Land Table Already Exists"); | ||
1114 | } | ||
1115 | |||
1116 | try | ||
1117 | { | ||
1118 | lalcmd.ExecuteNonQuery(); | ||
1119 | } | ||
1120 | catch (MySqlException) | ||
1121 | { | ||
1122 | MainLog.Instance.Warn("MySql", "LandAccessList Table Already Exists"); | ||
1123 | } | ||
920 | conn.Close(); | 1124 | conn.Close(); |
921 | } | 1125 | } |
922 | 1126 | ||
@@ -928,6 +1132,10 @@ namespace OpenSim.Framework.Data.MySQL | |||
928 | MySqlDataAdapter sDa = new MySqlDataAdapter(shapeSelectCmd); | 1132 | MySqlDataAdapter sDa = new MySqlDataAdapter(shapeSelectCmd); |
929 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, conn); | 1133 | MySqlCommand terrainSelectCmd = new MySqlCommand(m_terrainSelect, conn); |
930 | MySqlDataAdapter tDa = new MySqlDataAdapter(terrainSelectCmd); | 1134 | MySqlDataAdapter tDa = new MySqlDataAdapter(terrainSelectCmd); |
1135 | MySqlCommand landSelectCmd = new MySqlCommand(m_landSelect, conn); | ||
1136 | MySqlDataAdapter lDa = new MySqlDataAdapter(landSelectCmd); | ||
1137 | MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, conn); | ||
1138 | MySqlDataAdapter lalDa = new MySqlDataAdapter(landAccessListSelectCmd); | ||
931 | 1139 | ||
932 | DataSet tmpDS = new DataSet(); | 1140 | DataSet tmpDS = new DataSet(); |
933 | try | 1141 | try |
@@ -935,6 +1143,8 @@ namespace OpenSim.Framework.Data.MySQL | |||
935 | pDa.Fill(tmpDS, "prims"); | 1143 | pDa.Fill(tmpDS, "prims"); |
936 | sDa.Fill(tmpDS, "primshapes"); | 1144 | sDa.Fill(tmpDS, "primshapes"); |
937 | tDa.Fill(tmpDS, "terrain"); | 1145 | tDa.Fill(tmpDS, "terrain"); |
1146 | lDa.Fill(tmpDS, "land"); | ||
1147 | lalDa.Fill(tmpDS, "landaccesslist"); | ||
938 | } | 1148 | } |
939 | catch (MySqlException) | 1149 | catch (MySqlException) |
940 | { | 1150 | { |
@@ -945,6 +1155,8 @@ namespace OpenSim.Framework.Data.MySQL | |||
945 | pDa.Fill(tmpDS, "prims"); | 1155 | pDa.Fill(tmpDS, "prims"); |
946 | sDa.Fill(tmpDS, "primshapes"); | 1156 | sDa.Fill(tmpDS, "primshapes"); |
947 | tDa.Fill(tmpDS, "terrain"); | 1157 | tDa.Fill(tmpDS, "terrain"); |
1158 | lDa.Fill(tmpDS, "land"); | ||
1159 | lalDa.Fill(tmpDS, "landaccesslist"); | ||
948 | 1160 | ||
949 | foreach (DataColumn col in createPrimTable().Columns) | 1161 | foreach (DataColumn col in createPrimTable().Columns) |
950 | { | 1162 | { |
@@ -970,6 +1182,22 @@ namespace OpenSim.Framework.Data.MySQL | |||
970 | return false; | 1182 | return false; |
971 | } | 1183 | } |
972 | } | 1184 | } |
1185 | foreach (DataColumn col in createLandTable().Columns) | ||
1186 | { | ||
1187 | if (!tmpDS.Tables["land"].Columns.Contains(col.ColumnName)) | ||
1188 | { | ||
1189 | MainLog.Instance.Verbose("DATASTORE", "Missing require column:" + col.ColumnName); | ||
1190 | return false; | ||
1191 | } | ||
1192 | } | ||
1193 | foreach (DataColumn col in createLandAccessListTable().Columns) | ||
1194 | { | ||
1195 | if (!tmpDS.Tables["landaccesslist"].Columns.Contains(col.ColumnName)) | ||
1196 | { | ||
1197 | MainLog.Instance.Verbose("DATASTORE", "Missing require column:" + col.ColumnName); | ||
1198 | return false; | ||
1199 | } | ||
1200 | } | ||
973 | return true; | 1201 | return true; |
974 | } | 1202 | } |
975 | 1203 | ||