|
1 | 1 | // -------------------------------------------------------------------------------------------------------------------- |
2 | 2 | // <copyright file="ActualFiniteStateDao.cs" company="RHEA System S.A."> |
3 | | -// Copyright (c) 2015-2020 RHEA System S.A. |
| 3 | +// Copyright (c) 2015-2021 RHEA System S.A. |
4 | 4 | // |
5 | | -// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Kamil Wojnowski, |
6 | | -// Nathanael Smiechowski |
| 5 | +// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski |
7 | 6 | // |
8 | | -// This file is part of CDP4 Web Services Community Edition. |
9 | | -// The CDP4 Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C. |
| 7 | +// This file is part of COMET Web Services Community Edition. |
| 8 | +// The COMET Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C. |
10 | 9 | // This is an auto-generated class. Any manual changes to this file will be overwritten! |
11 | 10 | // |
12 | | -// The CDP4 Web Services Community Edition is free software; you can redistribute it and/or |
| 11 | +// The COMET Web Services Community Edition is free software; you can redistribute it and/or |
13 | 12 | // modify it under the terms of the GNU Affero General Public |
14 | 13 | // License as published by the Free Software Foundation; either |
15 | 14 | // version 3 of the License, or (at your option) any later version. |
16 | 15 | // |
17 | | -// The CDP4 Web Services Community Edition is distributed in the hope that it will be useful, |
| 16 | +// The COMET Web Services Community Edition is distributed in the hope that it will be useful, |
18 | 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | 19 | // Lesser General Public License for more details. |
21 | 20 | // |
22 | 21 | // You should have received a copy of the GNU Affero General Public License |
23 | 22 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
24 | 23 | // </copyright> |
25 | | -// <summary> |
26 | | -// This is an auto-generated Dao class. Any manual changes on this file will be overwritten. |
27 | | -// </summary> |
28 | 24 | // -------------------------------------------------------------------------------------------------------------------- |
29 | 25 |
|
30 | 26 | namespace CDP4Orm.Dao |
@@ -226,6 +222,62 @@ public virtual bool Write(NpgsqlTransaction transaction, string partition, CDP4C |
226 | 222 | return this.AfterWrite(beforeWrite, transaction, partition, actualFiniteState, container); |
227 | 223 | } |
228 | 224 |
|
| 225 | + /// <summary> |
| 226 | + /// Insert a new database record, or updates one if it already exists from the supplied data transfer object. |
| 227 | + /// This is typically used during the import of existing data to the Database. |
| 228 | + /// </summary> |
| 229 | + /// <param name="transaction"> |
| 230 | + /// The current <see cref="NpgsqlTransaction"/> to the database. |
| 231 | + /// </param> |
| 232 | + /// <param name="partition"> |
| 233 | + /// The database partition (schema) where the requested resource will be stored. |
| 234 | + /// </param> |
| 235 | + /// <param name="actualFiniteState"> |
| 236 | + /// The actualFiniteState DTO that is to be persisted. |
| 237 | + /// </param> |
| 238 | + /// <param name="container"> |
| 239 | + /// The container of the DTO to be persisted. |
| 240 | + /// </param> |
| 241 | + /// <returns> |
| 242 | + /// True if the concept was successfully persisted. |
| 243 | + /// </returns> |
| 244 | + public virtual bool Upsert(NpgsqlTransaction transaction, string partition, CDP4Common.DTO.ActualFiniteState actualFiniteState, CDP4Common.DTO.Thing container = null) |
| 245 | + { |
| 246 | + var valueTypeDictionaryAdditions = new Dictionary<string, string>(); |
| 247 | + base.Upsert(transaction, partition, actualFiniteState, container); |
| 248 | + |
| 249 | + var valueTypeDictionaryContents = new Dictionary<string, string> |
| 250 | + { |
| 251 | + { "Kind", !this.IsDerived(actualFiniteState, "Kind") ? actualFiniteState.Kind.ToString() : string.Empty }, |
| 252 | + }.Concat(valueTypeDictionaryAdditions).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); |
| 253 | + |
| 254 | + using (var command = new NpgsqlCommand()) |
| 255 | + { |
| 256 | + var sqlBuilder = new System.Text.StringBuilder(); |
| 257 | + |
| 258 | + sqlBuilder.AppendFormat("INSERT INTO \"{0}\".\"ActualFiniteState\"", partition); |
| 259 | + sqlBuilder.AppendFormat(" (\"Iid\", \"ValueTypeDictionary\", \"Container\")"); |
| 260 | + sqlBuilder.AppendFormat(" VALUES (:iid, :valueTypeDictionary, :container)"); |
| 261 | + |
| 262 | + command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = actualFiniteState.Iid; |
| 263 | + command.Parameters.Add("valueTypeDictionary", NpgsqlDbType.Hstore).Value = valueTypeDictionaryContents; |
| 264 | + command.Parameters.Add("container", NpgsqlDbType.Uuid).Value = container.Iid; |
| 265 | + sqlBuilder.Append(" ON CONFLICT (\"Iid\")"); |
| 266 | + sqlBuilder.Append(" DO UPDATE "); |
| 267 | + sqlBuilder.Append(" SET (\"ValueTypeDictionary\", \"Container\")"); |
| 268 | + sqlBuilder.Append(" = (:valueTypeDictionary, :container);"); |
| 269 | + |
| 270 | + command.CommandText = sqlBuilder.ToString(); |
| 271 | + command.Connection = transaction.Connection; |
| 272 | + command.Transaction = transaction; |
| 273 | + |
| 274 | + this.ExecuteAndLogCommand(command); |
| 275 | + } |
| 276 | + actualFiniteState.PossibleState.ForEach(x => this.UpsertPossibleState(transaction, partition, actualFiniteState.Iid, x)); |
| 277 | + |
| 278 | + return true; |
| 279 | + } |
| 280 | + |
229 | 281 | /// <summary> |
230 | 282 | /// Add the supplied value collection to the association link table indicated by the supplied property name |
231 | 283 | /// </summary> |
@@ -306,6 +358,49 @@ public bool AddPossibleState(NpgsqlTransaction transaction, string partition, Gu |
306 | 358 | } |
307 | 359 | } |
308 | 360 |
|
| 361 | + /// <summary> |
| 362 | + /// Insert a new association record in the link table, or update if it already exists. |
| 363 | + /// This is typically used during the import of existing data to the Database. |
| 364 | + /// </summary> |
| 365 | + /// <param name="transaction"> |
| 366 | + /// The current <see cref="NpgsqlTransaction"/> to the database. |
| 367 | + /// </param> |
| 368 | + /// <param name="partition"> |
| 369 | + /// The database partition (schema) where the requested resource will be stored. |
| 370 | + /// </param> |
| 371 | + /// <param name="iid"> |
| 372 | + /// The <see cref="CDP4Common.DTO.ActualFiniteState"/> id that will be the source for each link table record. |
| 373 | + /// </param> |
| 374 | + /// <param name="possibleState"> |
| 375 | + /// The value for which a link table record wil be created. |
| 376 | + /// </param> |
| 377 | + /// <returns> |
| 378 | + /// True if the value link was successfully created. |
| 379 | + /// </returns> |
| 380 | + public bool UpsertPossibleState(NpgsqlTransaction transaction, string partition, Guid iid, Guid possibleState) |
| 381 | + { |
| 382 | + using (var command = new NpgsqlCommand()) |
| 383 | + { |
| 384 | + var sqlBuilder = new System.Text.StringBuilder(); |
| 385 | + sqlBuilder.AppendFormat("INSERT INTO \"{0}\".\"ActualFiniteState_PossibleState\"", partition); |
| 386 | + sqlBuilder.AppendFormat(" (\"ActualFiniteState\", \"PossibleState\")"); |
| 387 | + sqlBuilder.Append(" VALUES (:actualFiniteState, :possibleState)"); |
| 388 | + sqlBuilder.Append(" ON CONFLICT ON CONSTRAINT \"ActualFiniteState_PossibleState_PK\""); |
| 389 | + sqlBuilder.Append(" DO UPDATE "); |
| 390 | + sqlBuilder.Append(" SET (\"ActualFiniteState\", \"PossibleState\")"); |
| 391 | + sqlBuilder.Append(" = (:actualFiniteState, :possibleState);"); |
| 392 | + |
| 393 | + command.Parameters.Add("actualFiniteState", NpgsqlDbType.Uuid).Value = iid; |
| 394 | + command.Parameters.Add("possibleState", NpgsqlDbType.Uuid).Value = possibleState; |
| 395 | + |
| 396 | + command.CommandText = sqlBuilder.ToString(); |
| 397 | + command.Connection = transaction.Connection; |
| 398 | + command.Transaction = transaction; |
| 399 | + |
| 400 | + return this.ExecuteAndLogCommand(command) > 0; |
| 401 | + } |
| 402 | + } |
| 403 | + |
309 | 404 | /// <summary> |
310 | 405 | /// Update a database record from the supplied data transfer object. |
311 | 406 | /// </summary> |
@@ -388,6 +483,31 @@ public override bool Delete(NpgsqlTransaction transaction, string partition, Gui |
388 | 483 | return this.AfterDelete(beforeDelete, transaction, partition, iid); |
389 | 484 | } |
390 | 485 |
|
| 486 | + /// <summary> |
| 487 | + /// Delete a database record from the supplied data transfer object. |
| 488 | + /// A "Raw" Delete means that the delete is performed without calling BeforeDelete or AfterDelete. |
| 489 | + /// This is typically used during the import of existing data to the Database. |
| 490 | + /// </summary> |
| 491 | + /// <param name="transaction"> |
| 492 | + /// The current <see cref="NpgsqlTransaction"/> to the database. |
| 493 | + /// </param> |
| 494 | + /// <param name="partition"> |
| 495 | + /// The database partition (schema) where the requested resource will be deleted. |
| 496 | + /// </param> |
| 497 | + /// <param name="iid"> |
| 498 | + /// The <see cref="CDP4Common.DTO.ActualFiniteState"/> id that is to be deleted. |
| 499 | + /// </param> |
| 500 | + /// <returns> |
| 501 | + /// True if the concept was successfully deleted. |
| 502 | + /// </returns> |
| 503 | + public override bool RawDelete(NpgsqlTransaction transaction, string partition, Guid iid) |
| 504 | + { |
| 505 | + var result = false; |
| 506 | + |
| 507 | + result = base.Delete(transaction, partition, iid); |
| 508 | + return result; |
| 509 | + } |
| 510 | + |
391 | 511 | /// <summary> |
392 | 512 | /// Delete the supplied value from the association link table indicated by the supplied property name. |
393 | 513 | /// </summary> |
|
0 commit comments