aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie2011-10-11 21:30:42 +0100
committerMelanie2011-10-11 21:30:42 +0100
commit673886d2311ad9873f386ca794f5e1adf41755be (patch)
treea55c40204c3a351db5d2d86e6c3369ac71c40385 /OpenSim
parentMerge commit '90466515839eb34d7fd9984c92f1970ab5d6f3ad' into bigmerge (diff)
parentReattaching a region was failing if the estate name had not changed (issue 50... (diff)
downloadopensim-SC_OLD-673886d2311ad9873f386ca794f5e1adf41755be.zip
opensim-SC_OLD-673886d2311ad9873f386ca794f5e1adf41755be.tar.gz
opensim-SC_OLD-673886d2311ad9873f386ca794f5e1adf41755be.tar.bz2
opensim-SC_OLD-673886d2311ad9873f386ca794f5e1adf41755be.tar.xz
Merge commit '1458fab82c4dab9901d81419e6b515f47ea7320f' into bigmerge
Diffstat (limited to '')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs17
-rw-r--r--OpenSim/Data/MSSQL/MSSQLEstateData.cs117
-rw-r--r--OpenSim/Data/MySQL/MySQLEstateData.cs123
-rwxr-xr-xOpenSim/Data/Null/NullEstateData.cs5
-rw-r--r--OpenSim/Data/SQLite/SQLiteEstateData.cs126
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEstateDataService.cs10
-rw-r--r--OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs8
-rw-r--r--OpenSim/Services/Connectors/Simulation/EstateDataService.cs7
8 files changed, 267 insertions, 146 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
index 86c0ac8..b190a3d 100644
--- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -844,21 +844,30 @@ namespace OpenSim.ApplicationPlugins.RemoteController
844 } 844 }
845 845
846 // Create a new estate with the name provided 846 // Create a new estate with the name provided
847 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, true); 847 region.EstateSettings = m_application.EstateDataService.CreateNewEstate();
848 848
849 region.EstateSettings.EstateName = (string) requestData["estate_name"]; 849 region.EstateSettings.EstateName = (string) requestData["estate_name"];
850 region.EstateSettings.EstateOwner = userID; 850 region.EstateSettings.EstateOwner = userID;
851 // Persistence does not seem to effect the need to save a new estate 851 // Persistence does not seem to effect the need to save a new estate
852 region.EstateSettings.Save(); 852 region.EstateSettings.Save();
853
854 if (!m_application.EstateDataService.LinkRegion(region.RegionID, (int) region.EstateSettings.EstateID))
855 throw new Exception("Failed to join estate.");
853 } 856 }
854 else 857 else
855 { 858 {
856 int estateID = estateIDs[0]; 859 int estateID = estateIDs[0];
857 860
858 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID); 861 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(region.RegionID, false);
859 862
860 if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID)) 863 if (region.EstateSettings.EstateID != estateID)
861 throw new Exception("Failed to join estate."); 864 {
865 // The region is already part of an estate, but not the one we want.
866 region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID);
867
868 if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID))
869 throw new Exception("Failed to join estate.");
870 }
862 } 871 }
863 872
864 // Create the region and perform any initial initialization 873 // Create the region and perform any initial initialization
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
index 9c54e77..1faa249 100644
--- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
@@ -148,56 +148,29 @@ namespace OpenSim.Data.MSSQL
148 } 148 }
149 } 149 }
150 150
151
152 if (insertEstate && create) 151 if (insertEstate && create)
153 { 152 {
154 List<string> names = new List<string>(FieldList); 153 DoCreate(es);
155 154 LinkRegion(regionID, (int)es.EstateID);
156 names.Remove("EstateID"); 155 }
157
158 sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
159
160 //_Log.Debug("[DB ESTATE]: SQL: " + sql);
161 using (SqlConnection conn = new SqlConnection(m_connectionString))
162 using (SqlCommand insertCommand = new SqlCommand(sql, conn))
163 {
164 insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()";
165 156
166 foreach (string name in names) 157 LoadBanList(es);
167 {
168 insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es)));
169 }
170 SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int);
171 idParameter.Direction = ParameterDirection.Output;
172 insertCommand.Parameters.Add(idParameter);
173 conn.Open();
174 insertCommand.ExecuteNonQuery();
175 158
176 es.EstateID = Convert.ToUInt32(idParameter.Value); 159 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
177 } 160 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
161 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
178 162
179 sql = "INSERT INTO [estate_map] ([RegionID] ,[EstateID]) VALUES (@RegionID, @EstateID)"; 163 //Set event
180 using (SqlConnection conn = new SqlConnection(m_connectionString)) 164 es.OnSave += StoreEstateSettings;
181 using (SqlCommand cmd = new SqlCommand(sql, conn)) 165 return es;
182 { 166 }
183 167
184 cmd.Parameters.Add(_Database.CreateParameter("@RegionID", regionID)); 168 public EstateSettings CreateNewEstate()
185 cmd.Parameters.Add(_Database.CreateParameter("@EstateID", es.EstateID)); 169 {
186 // This will throw on dupe key 170 EstateSettings es = new EstateSettings();
187 try 171 es.OnSave += StoreEstateSettings;
188 {
189 conn.Open();
190 cmd.ExecuteNonQuery();
191 }
192 catch (Exception e)
193 {
194 m_log.DebugFormat("[ESTATE DB]: Error inserting regionID and EstateID in estate_map: {0}", e);
195 }
196 }
197 172
198 //TODO check if this is needed?? 173 DoCreate(es);
199 es.Save();
200 }
201 174
202 LoadBanList(es); 175 LoadBanList(es);
203 176
@@ -205,11 +178,40 @@ namespace OpenSim.Data.MSSQL
205 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); 178 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
206 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); 179 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
207 180
208 //Set event
209 es.OnSave += StoreEstateSettings;
210 return es; 181 return es;
211 } 182 }
212 183
184 private void DoCreate(EstateSettings es)
185 {
186 List<string> names = new List<string>(FieldList);
187
188 names.Remove("EstateID");
189
190 string sql = string.Format("insert into estate_settings ({0}) values ( @{1})", String.Join(",", names.ToArray()), String.Join(", @", names.ToArray()));
191
192 //_Log.Debug("[DB ESTATE]: SQL: " + sql);
193 using (SqlConnection conn = new SqlConnection(m_connectionString))
194 using (SqlCommand insertCommand = new SqlCommand(sql, conn))
195 {
196 insertCommand.CommandText = sql + " SET @ID = SCOPE_IDENTITY()";
197
198 foreach (string name in names)
199 {
200 insertCommand.Parameters.Add(_Database.CreateParameter("@" + name, _FieldMap[name].GetValue(es)));
201 }
202 SqlParameter idParameter = new SqlParameter("@ID", SqlDbType.Int);
203 idParameter.Direction = ParameterDirection.Output;
204 insertCommand.Parameters.Add(idParameter);
205 conn.Open();
206 insertCommand.ExecuteNonQuery();
207
208 es.EstateID = Convert.ToUInt32(idParameter.Value);
209 }
210
211 //TODO check if this is needed??
212 es.Save();
213 }
214
213 /// <summary> 215 /// <summary>
214 /// Stores the estate settings. 216 /// Stores the estate settings.
215 /// </summary> 217 /// </summary>
@@ -498,24 +500,43 @@ namespace OpenSim.Data.MSSQL
498 500
499 public bool LinkRegion(UUID regionID, int estateID) 501 public bool LinkRegion(UUID regionID, int estateID)
500 { 502 {
501 string sql = "insert into estate_map values (@RegionID, @EstateID)"; 503 string deleteSQL = "delete from estate_map where RegionID = @RegionID";
504 string insertSQL = "insert into estate_map values (@RegionID, @EstateID)";
502 using (SqlConnection conn = new SqlConnection(m_connectionString)) 505 using (SqlConnection conn = new SqlConnection(m_connectionString))
503 { 506 {
504 conn.Open(); 507 conn.Open();
508 SqlTransaction transaction = conn.BeginTransaction();
509
505 try 510 try
506 { 511 {
507 using (SqlCommand cmd = new SqlCommand(sql, conn)) 512 using (SqlCommand cmd = new SqlCommand(deleteSQL, conn))
508 { 513 {
509 cmd.Parameters.AddWithValue("@RegionID", regionID); 514 cmd.Transaction = transaction;
515 cmd.Parameters.AddWithValue("@RegionID", regionID.Guid);
516
517 cmd.ExecuteNonQuery();
518 }
519
520 using (SqlCommand cmd = new SqlCommand(insertSQL, conn))
521 {
522 cmd.Transaction = transaction;
523 cmd.Parameters.AddWithValue("@RegionID", regionID.Guid);
510 cmd.Parameters.AddWithValue("@EstateID", estateID); 524 cmd.Parameters.AddWithValue("@EstateID", estateID);
511 525
512 int ret = cmd.ExecuteNonQuery(); 526 int ret = cmd.ExecuteNonQuery();
527
528 if (ret != 0)
529 transaction.Commit();
530 else
531 transaction.Rollback();
532
513 return (ret != 0); 533 return (ret != 0);
514 } 534 }
515 } 535 }
516 catch (Exception ex) 536 catch (Exception ex)
517 { 537 {
518 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); 538 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message);
539 transaction.Rollback();
519 } 540 }
520 } 541 }
521 return false; 542 return false;
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs
index 9dcf5e2..3d647ca 100644
--- a/OpenSim/Data/MySQL/MySQLEstateData.cs
+++ b/OpenSim/Data/MySQL/MySQLEstateData.cs
@@ -149,6 +149,22 @@ namespace OpenSim.Data.MySQL
149 } 149 }
150 } 150 }
151 151
152 public EstateSettings CreateNewEstate()
153 {
154 EstateSettings es = new EstateSettings();
155 es.OnSave += StoreEstateSettings;
156
157 DoCreate(es);
158
159 LoadBanList(es);
160
161 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
162 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
163 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
164
165 return es;
166 }
167
152 private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create) 168 private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create)
153 { 169 {
154 EstateSettings es = new EstateSettings(); 170 EstateSettings es = new EstateSettings();
@@ -188,63 +204,65 @@ namespace OpenSim.Data.MySQL
188 204
189 if (!found && create) 205 if (!found && create)
190 { 206 {
191 // Migration case 207 DoCreate(es);
192 List<string> names = new List<string>(FieldList); 208 LinkRegion(regionID, (int)es.EstateID);
209 }
210 }
193 211
194 names.Remove("EstateID"); 212 LoadBanList(es);
195 213
196 string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; 214 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
215 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
216 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
217 return es;
218 }
197 219
198 using (MySqlCommand cmd2 = dbcon.CreateCommand()) 220 private void DoCreate(EstateSettings es)
199 { 221 {
200 cmd2.CommandText = sql; 222 // Migration case
201 cmd2.Parameters.Clear(); 223 List<string> names = new List<string>(FieldList);
202 224
203 foreach (string name in FieldList) 225 names.Remove("EstateID");
204 {
205 if (m_FieldMap[name].GetValue(es) is bool)
206 {
207 if ((bool)m_FieldMap[name].GetValue(es))
208 cmd2.Parameters.AddWithValue("?" + name, "1");
209 else
210 cmd2.Parameters.AddWithValue("?" + name, "0");
211 }
212 else
213 {
214 cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
215 }
216 }
217 226
218 cmd2.ExecuteNonQuery(); 227 string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")";
219 228
220 cmd2.CommandText = "select LAST_INSERT_ID() as id"; 229 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
221 cmd2.Parameters.Clear(); 230 {
231 dbcon.Open();
232 using (MySqlCommand cmd2 = dbcon.CreateCommand())
233 {
234 cmd2.CommandText = sql;
235 cmd2.Parameters.Clear();
222 236
223 using (IDataReader r = cmd2.ExecuteReader()) 237 foreach (string name in FieldList)
238 {
239 if (m_FieldMap[name].GetValue(es) is bool)
240 {
241 if ((bool)m_FieldMap[name].GetValue(es))
242 cmd2.Parameters.AddWithValue("?" + name, "1");
243 else
244 cmd2.Parameters.AddWithValue("?" + name, "0");
245 }
246 else
224 { 247 {
225 r.Read(); 248 cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString());
226 es.EstateID = Convert.ToUInt32(r["id"]);
227 } 249 }
250 }
228 251
229 cmd2.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; 252 cmd2.ExecuteNonQuery();
230 cmd2.Parameters.AddWithValue("?RegionID", regionID.ToString());
231 cmd2.Parameters.AddWithValue("?EstateID", es.EstateID.ToString());
232 253
233 // This will throw on dupe key 254 cmd2.CommandText = "select LAST_INSERT_ID() as id";
234 try { cmd2.ExecuteNonQuery(); } 255 cmd2.Parameters.Clear();
235 catch (Exception) { }
236 256
237 es.Save(); 257 using (IDataReader r = cmd2.ExecuteReader())
258 {
259 r.Read();
260 es.EstateID = Convert.ToUInt32(r["id"]);
238 } 261 }
262
263 es.Save();
239 } 264 }
240 } 265 }
241
242 LoadBanList(es);
243
244 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
245 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
246 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
247 return es;
248 } 266 }
249 267
250 public void StoreEstateSettings(EstateSettings es) 268 public void StoreEstateSettings(EstateSettings es)
@@ -477,7 +495,6 @@ namespace OpenSim.Data.MySQL
477 } 495 }
478 } 496 }
479 497
480
481 dbcon.Close(); 498 dbcon.Close();
482 } 499 }
483 500
@@ -507,7 +524,6 @@ namespace OpenSim.Data.MySQL
507 } 524 }
508 } 525 }
509 526
510
511 dbcon.Close(); 527 dbcon.Close();
512 } 528 }
513 529
@@ -519,16 +535,34 @@ namespace OpenSim.Data.MySQL
519 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 535 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
520 { 536 {
521 dbcon.Open(); 537 dbcon.Open();
538 MySqlTransaction transaction = dbcon.BeginTransaction();
522 539
523 try 540 try
524 { 541 {
542 // Delete any existing association of this region with an estate.
543 using (MySqlCommand cmd = dbcon.CreateCommand())
544 {
545 cmd.Transaction = transaction;
546 cmd.CommandText = "delete from estate_map where RegionID = ?RegionID";
547 cmd.Parameters.AddWithValue("?RegionID", regionID);
548
549 cmd.ExecuteNonQuery();
550 }
551
525 using (MySqlCommand cmd = dbcon.CreateCommand()) 552 using (MySqlCommand cmd = dbcon.CreateCommand())
526 { 553 {
554 cmd.Transaction = transaction;
527 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; 555 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
528 cmd.Parameters.AddWithValue("?RegionID", regionID); 556 cmd.Parameters.AddWithValue("?RegionID", regionID);
529 cmd.Parameters.AddWithValue("?EstateID", estateID); 557 cmd.Parameters.AddWithValue("?EstateID", estateID);
530 558
531 int ret = cmd.ExecuteNonQuery(); 559 int ret = cmd.ExecuteNonQuery();
560
561 if (ret != 0)
562 transaction.Commit();
563 else
564 transaction.Rollback();
565
532 dbcon.Close(); 566 dbcon.Close();
533 567
534 return (ret != 0); 568 return (ret != 0);
@@ -537,6 +571,7 @@ namespace OpenSim.Data.MySQL
537 catch (MySqlException ex) 571 catch (MySqlException ex)
538 { 572 {
539 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); 573 m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message);
574 transaction.Rollback();
540 } 575 }
541 576
542 dbcon.Close(); 577 dbcon.Close();
diff --git a/OpenSim/Data/Null/NullEstateData.cs b/OpenSim/Data/Null/NullEstateData.cs
index 8db8064..d64136d 100755
--- a/OpenSim/Data/Null/NullEstateData.cs
+++ b/OpenSim/Data/Null/NullEstateData.cs
@@ -84,6 +84,11 @@ namespace OpenSim.Data.Null
84 { 84 {
85 return new EstateSettings(); 85 return new EstateSettings();
86 } 86 }
87
88 public EstateSettings CreateNewEstate()
89 {
90 return new EstateSettings();
91 }
87 92
88 public List<EstateSettings> LoadEstateSettingsAll() 93 public List<EstateSettings> LoadEstateSettingsAll()
89 { 94 {
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs
index 65719a6..8db9262 100644
--- a/OpenSim/Data/SQLite/SQLiteEstateData.cs
+++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs
@@ -151,67 +151,77 @@ namespace OpenSim.Data.SQLite
151 } 151 }
152 else if (create) 152 else if (create)
153 { 153 {
154 r.Close(); 154 DoCreate(es);
155 LinkRegion(regionID, (int)es.EstateID);
156 }
155 157
156 List<string> names = new List<string>(FieldList); 158 LoadBanList(es);
157 159
158 names.Remove("EstateID"); 160 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
161 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
162 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
163 return es;
164 }
159 165
160 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; 166 public EstateSettings CreateNewEstate()
167 {
168 EstateSettings es = new EstateSettings();
169 es.OnSave += StoreEstateSettings;
161 170
162 cmd.CommandText = sql; 171 DoCreate(es);
163 cmd.Parameters.Clear();
164 172
165 foreach (string name in FieldList) 173 LoadBanList(es);
166 {
167 if (m_FieldMap[name].GetValue(es) is bool)
168 {
169 if ((bool)m_FieldMap[name].GetValue(es))
170 cmd.Parameters.AddWithValue(":"+name, "1");
171 else
172 cmd.Parameters.AddWithValue(":"+name, "0");
173 }
174 else
175 {
176 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
177 }
178 }
179 174
180 cmd.ExecuteNonQuery(); 175 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
176 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
177 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
181 178
182 cmd.CommandText = "select LAST_INSERT_ROWID() as id"; 179 return es;
183 cmd.Parameters.Clear(); 180 }
184 181
185 r = cmd.ExecuteReader(); 182 private void DoCreate(EstateSettings es)
183 {
184 List<string> names = new List<string>(FieldList);
186 185
187 r.Read(); 186 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
187 IDataReader r = null;
188 188
189 es.EstateID = Convert.ToUInt32(r["id"]); 189 names.Remove("EstateID");
190 190
191 r.Close(); 191 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
192 192
193 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; 193 cmd.CommandText = sql;
194 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); 194 cmd.Parameters.Clear();
195 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
196 195
197 // This will throw on dupe key 196 foreach (string name in FieldList)
198 try 197 {
198 if (m_FieldMap[name].GetValue(es) is bool)
199 { 199 {
200 cmd.ExecuteNonQuery(); 200 if ((bool)m_FieldMap[name].GetValue(es))
201 cmd.Parameters.AddWithValue(":"+name, "1");
202 else
203 cmd.Parameters.AddWithValue(":"+name, "0");
201 } 204 }
202 catch (Exception) 205 else
203 { 206 {
207 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
204 } 208 }
205
206 es.Save();
207 } 209 }
208 210
209 LoadBanList(es); 211 cmd.ExecuteNonQuery();
210 212
211 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); 213 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
212 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); 214 cmd.Parameters.Clear();
213 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); 215
214 return es; 216 r = cmd.ExecuteReader();
217
218 r.Read();
219
220 es.EstateID = Convert.ToUInt32(r["id"]);
221
222 r.Close();
223
224 es.Save();
215 } 225 }
216 226
217 public void StoreEstateSettings(EstateSettings es) 227 public void StoreEstateSettings(EstateSettings es)
@@ -440,16 +450,36 @@ namespace OpenSim.Data.SQLite
440 450
441 public bool LinkRegion(UUID regionID, int estateID) 451 public bool LinkRegion(UUID regionID, int estateID)
442 { 452 {
443 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 453 SqliteTransaction transaction = m_connection.BeginTransaction();
444 454
445 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; 455 // Delete any existing estate mapping for this region.
446 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); 456 using(SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
447 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); 457 {
458 cmd.CommandText = "delete from estate_map where RegionID = :RegionID";
459 cmd.Transaction = transaction;
460 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
448 461
449 if (cmd.ExecuteNonQuery() == 0) 462 cmd.ExecuteNonQuery();
450 return false; 463 }
451 464
452 return true; 465 using(SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
466 {
467 cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)";
468 cmd.Transaction = transaction;
469 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
470 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString());
471
472 if (cmd.ExecuteNonQuery() == 0)
473 {
474 transaction.Rollback();
475 return false;
476 }
477 else
478 {
479 transaction.Commit();
480 return true;
481 }
482 }
453 } 483 }
454 484
455 public List<UUID> GetRegions(int estateID) 485 public List<UUID> GetRegions(int estateID)
diff --git a/OpenSim/Region/Framework/Interfaces/IEstateDataService.cs b/OpenSim/Region/Framework/Interfaces/IEstateDataService.cs
index 7066cf2..35cc220 100644
--- a/OpenSim/Region/Framework/Interfaces/IEstateDataService.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEstateDataService.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -48,6 +48,14 @@ namespace OpenSim.Region.Framework.Interfaces
48 /// <param name="estateID"></param> 48 /// <param name="estateID"></param>
49 /// <returns></returns> 49 /// <returns></returns>
50 EstateSettings LoadEstateSettings(int estateID); 50 EstateSettings LoadEstateSettings(int estateID);
51
52 /// <summary>
53 /// Create a new estate.
54 /// </summary>
55 /// <returns>
56 /// A <see cref="EstateSettings"/>
57 /// </returns>
58 EstateSettings CreateNewEstate();
51 59
52 /// <summary> 60 /// <summary>
53 /// Load/Get all estate settings. 61 /// Load/Get all estate settings.
diff --git a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
index d790a30..8febb13 100644
--- a/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEstateDataStore.cs
@@ -55,6 +55,14 @@ namespace OpenSim.Region.Framework.Interfaces
55 EstateSettings LoadEstateSettings(int estateID); 55 EstateSettings LoadEstateSettings(int estateID);
56 56
57 /// <summary> 57 /// <summary>
58 /// Create a new estate.
59 /// </summary>
60 /// <returns>
61 /// A <see cref="EstateSettings"/>
62 /// </returns>
63 EstateSettings CreateNewEstate();
64
65 /// <summary>
58 /// Load/Get all estate settings. 66 /// Load/Get all estate settings.
59 /// </summary> 67 /// </summary>
60 /// <returns>An empty list if no estates were found.</returns> 68 /// <returns>An empty list if no estates were found.</returns>
diff --git a/OpenSim/Services/Connectors/Simulation/EstateDataService.cs b/OpenSim/Services/Connectors/Simulation/EstateDataService.cs
index 7184ba1..cdcdecf 100644
--- a/OpenSim/Services/Connectors/Simulation/EstateDataService.cs
+++ b/OpenSim/Services/Connectors/Simulation/EstateDataService.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -90,6 +90,11 @@ namespace OpenSim.Services.Connectors
90 { 90 {
91 return m_database.LoadEstateSettings(estateID); 91 return m_database.LoadEstateSettings(estateID);
92 } 92 }
93
94 public EstateSettings CreateNewEstate()
95 {
96 return m_database.CreateNewEstate();
97 }
93 98
94 public List<EstateSettings> LoadEstateSettingsAll() 99 public List<EstateSettings> LoadEstateSettingsAll()
95 { 100 {