Skip to content

Commit

Permalink
[Remove] unused methods
Browse files Browse the repository at this point in the history
[Update] formatting

[Remove] redundant using statements

[Remove] redundant string interpolation

[Replace] string.format with string interpolation
  • Loading branch information
samatstarion committed Oct 12, 2024
1 parent 4acdd58 commit ee86164
Show file tree
Hide file tree
Showing 109 changed files with 475 additions and 963 deletions.
4 changes: 2 additions & 2 deletions CDP4Orm.Tests/UtilsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public void VerifyOrderedListDeserialization()

var expected = (IEnumerable)new List<OrderedItem>
{
new OrderedItem { K = 0, V = "item0" },
new OrderedItem { K = 1, V = "item1" }
new() { K = 0, V = "item0" },
new() { K = 1, V = "item1" }
};

Assert.That(Utils.ParseOrderedList<string>(orderdListSource), Is.EquivalentTo(expected));
Expand Down
8 changes: 4 additions & 4 deletions CDP4Orm/AutoGenDao/DataModelUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class DataModelUtils : IDataModelUtils
/// <summary>
/// The derived properties per class.
/// </summary>
private readonly HashSet<string> derivedProperties = new HashSet<string>
{
private readonly HashSet<string> derivedProperties = new()
{
{ "ActualFiniteState.Name" },
{ "ActualFiniteState.Owner" },
{ "ActualFiniteState.ShortName" },
Expand Down Expand Up @@ -124,8 +124,8 @@ public class DataModelUtils : IDataModelUtils
/// <summary>
/// The type source partition mapping for each concrete class.
/// </summary>
private readonly Dictionary<string, IEnumerable<string>> typePartitionMap = new Dictionary<string, IEnumerable<string>>
{
private readonly Dictionary<string, IEnumerable<string>> typePartitionMap = new()
{

{
"EngineeringModel",
Expand Down
6 changes: 3 additions & 3 deletions CDP4Orm/Dao/Authentication/AuthenticationPersonDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ private static AuthenticationPerson MapToDto(NpgsqlDataReader reader)

var dto = new AuthenticationPerson(iid, revisionNumber)
{
Role = reader["Role"] is DBNull ? (Guid?)null : Guid.Parse(reader["Role"].ToString()),
DefaultDomain = reader["DefaultDomain"] is DBNull? (Guid?)null : Guid.Parse(reader["DefaultDomain"].ToString()),
Organization = reader["Organization"] is DBNull ? (Guid?)null : Guid.Parse(reader["Organization"].ToString())
Role = reader["Role"] is DBNull ? null : Guid.Parse(reader["Role"].ToString()),
DefaultDomain = reader["DefaultDomain"] is DBNull? null : Guid.Parse(reader["DefaultDomain"].ToString()),
Organization = reader["Organization"] is DBNull ? null : Guid.Parse(reader["Organization"].ToString())
};

if (valueDict.TryGetValue("IsActive", out var tempIsActive))
Expand Down
5 changes: 2 additions & 3 deletions CDP4Orm/Dao/BaseDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ private DateTime GetTransactionDateTime(NpgsqlTransaction transaction)
{
this.currentTransactionDataTimeTransaction = transaction;

using var command = new NpgsqlCommand(
$"SELECT * FROM \"SiteDirectory\".\"get_transaction_time\"();",
using var command = new NpgsqlCommand("SELECT * FROM \"SiteDirectory\".\"get_transaction_time\"();",
transaction.Connection,
transaction);
this.currentTransactionDatetime = (DateTime)command.ExecuteScalar();
Expand All @@ -322,7 +321,7 @@ protected Thing MapJsonbToDto(NpgsqlDataReader reader)
{
var jsonObject = JObject.Parse(reader.GetValue(0).ToString());

Thing thing = null;
Thing thing;

try
{
Expand Down
29 changes: 9 additions & 20 deletions CDP4Orm/Dao/Cache/CacheDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ public class CacheDao : ICacheDao
/// </summary>
public IFileDao FileDao { get; set; }

/// <summary>
/// Gets or sets the folder dao.
/// </summary>
public IFolderDao FolderDao { get; set; }

/// <summary>
/// Gets or sets the fileRevision dao.
/// </summary>
public IFileRevisionDao FileRevisionDao { get; set; }

/// <summary>
/// Gets or sets the injected <see cref="ILogger{T}" />
/// </summary>
Expand All @@ -100,19 +90,18 @@ public void Write(NpgsqlTransaction transaction, string partition, Thing thing)
{
var table = GetThingCacheTableName(thing);

var columns = string.Format("(\"{0}\", \"{1}\", \"{2}\")", IidKey, RevisionColumnName, JsonColumnName);
var columns = $"(\"{IidKey}\", \"{RevisionColumnName}\", \"{JsonColumnName}\")";
var values = "(:iid, :revisionnumber, :jsonb)";
var sqlQuery = string.Format("INSERT INTO \"{0}\".\"{1}\" {2} VALUES {3} ON CONFLICT (\"{4}\") DO UPDATE SET \"{5}\"=:revisionnumber, \"{6}\"=:jsonb;", partition, table, columns, values, IidKey, RevisionColumnName, JsonColumnName);
var sqlQuery = $"INSERT INTO \"{partition}\".\"{table}\" {columns} VALUES {values} ON CONFLICT (\"{IidKey}\") DO UPDATE SET \"{RevisionColumnName}\"=:revisionnumber, \"{JsonColumnName}\"=:jsonb;";

using (var command = new NpgsqlCommand(sqlQuery, transaction.Connection, transaction))
{
command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = thing.Iid;
command.Parameters.Add("revisionnumber", NpgsqlDbType.Integer).Value = thing.RevisionNumber;
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonObject().ToString(Formatting.None);
using var command = new NpgsqlCommand(sqlQuery, transaction.Connection, transaction);

// log the sql command
command.ExecuteNonQuery();
}
command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = thing.Iid;
command.Parameters.Add("revisionnumber", NpgsqlDbType.Integer).Value = thing.RevisionNumber;
command.Parameters.Add("jsonb", NpgsqlDbType.Jsonb).Value = thing.ToJsonObject().ToString(Formatting.None);

// log the sql command
command.ExecuteNonQuery();
}

/// <summary>
Expand Down
38 changes: 17 additions & 21 deletions CDP4Orm/Dao/Resolve/ContainerDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,15 @@ private IEnumerable<Tuple<Guid, ContainerInfo>> ReadInternalFromSiteDirectory(Np

var sql = sqlBuilder.ToString();

using (var command = new NpgsqlCommand(sql, transaction.Connection, transaction))
using var command = new NpgsqlCommand(sql, transaction.Connection, transaction);

command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using var reader = command.ExecuteReader();

while (reader.Read())
{
command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
yield return MapToSiteDirectoryContainmentInfo(reader, connectedPartition);
}
}
yield return MapToSiteDirectoryContainmentInfo(reader, connectedPartition);
}
}

Expand Down Expand Up @@ -197,7 +195,7 @@ private static Tuple<Guid, ContainerInfo> MapToSiteDirectoryContainmentInfo(Npgs
/// </returns>
private IEnumerable<Tuple<Guid, ContainerInfo>> ReadInternalFromEngineeringModel(NpgsqlTransaction transaction, string partition, string typeName, IEnumerable<Guid> ids)
{
var sqlBuilder = new System.Text.StringBuilder();
var sqlBuilder = new StringBuilder();

var connectedPartition = partition;
var otherPartition = partition.Replace(Utils.EngineeringModelPartition, Utils.IterationSubPartition);
Expand Down Expand Up @@ -225,17 +223,15 @@ private IEnumerable<Tuple<Guid, ContainerInfo>> ReadInternalFromEngineeringModel

var sql = sqlBuilder.ToString();

using (var command = new NpgsqlCommand(sql, transaction.Connection, transaction))
{
command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();
using var command = new NpgsqlCommand(sql, transaction.Connection, transaction);

using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
yield return MapToEngineeringModelContainmentInfo(reader, connectedPartition, otherPartition);
}
}
command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using var reader = command.ExecuteReader();

while (reader.Read())
{
yield return MapToEngineeringModelContainmentInfo(reader, connectedPartition, otherPartition);
}
}

Expand Down
36 changes: 16 additions & 20 deletions CDP4Orm/Dao/Resolve/ResolveDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,15 @@ private static IEnumerable<ResolveInfo> ReadSiteDirectoryThing(NpgsqlTransaction

var sql = sqlBuilder.ToString();

using (var command = new NpgsqlCommand(sql, transaction.Connection, transaction))
using var command = new NpgsqlCommand(sql, transaction.Connection, transaction);

command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using var reader = command.ExecuteReader();

while (reader.Read())
{
command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
yield return MapToSiteDirectoryDto(reader);
}
}
yield return MapToSiteDirectoryDto(reader);
}
}

Expand Down Expand Up @@ -145,17 +143,15 @@ private static IEnumerable<ResolveInfo> ReadEngineeringModelInternal(NpgsqlTrans
connectedPartition,
subPartition);

using (var command = new NpgsqlCommand(sql, transaction.Connection, transaction))
using var command = new NpgsqlCommand(sql, transaction.Connection, transaction);

command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using var reader = command.ExecuteReader();

while (reader.Read())
{
command.Parameters.Add("ids", NpgsqlDbType.Array | NpgsqlDbType.Uuid).Value = ids.ToList();

using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
yield return MapToEngineeringModelDto(reader, connectedPartition, subPartition);
}
}
yield return MapToEngineeringModelDto(reader, connectedPartition, subPartition);
}
}

Expand Down
4 changes: 2 additions & 2 deletions CDP4Orm/Dao/Revision/RevisionDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private static ReadOnlyCollection<RevisionInfo> ReadSiteDirectoryRevisions(Npgsq
{
var result = new List<RevisionInfo>();

var sqlBuilder = new System.Text.StringBuilder();
var sqlBuilder = new StringBuilder();

// get all Thing 'concepts' whose revisions are as per the supplied revision comparator
sqlBuilder.Append(
Expand Down Expand Up @@ -557,7 +557,7 @@ private static ReadOnlyCollection<RevisionInfo> ReadEngineeringModelRevisions(Np
{
var result = new List<RevisionInfo>();

var sqlBuilder = new System.Text.StringBuilder();
var sqlBuilder = new StringBuilder();

var connectedPartition = partition;
var subPartition = partition.Replace(Utils.EngineeringModelPartition, Utils.IterationSubPartition);
Expand Down
20 changes: 0 additions & 20 deletions CDP4Orm/Dao/Supplemental/IIterationSetupDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,5 @@ public partial interface IIterationSetupDao
/// List of instances of <see cref="IterationSetup"/>.
/// </returns>
IEnumerable<IterationSetup> ReadByIteration(NpgsqlTransaction transaction, string partition, Guid iterationId, DateTime? instant = null);

/// <summary>
/// Read the data from the database based on <see cref="EngineeringModelSetup.Iid"/>.
/// </summary>
/// <param name="transaction">
/// The current transaction to the database.
/// </param>
/// <param name="partition">
/// The database partition (schema) where the requested resource is stored.
/// </param>
/// <param name="engineeringModelSetupId">
/// The <see cref="EngineeringModelSetup"/> Id.
/// </param>
/// <param name="instant">
/// The instant as a <see cref="DateTime"/>
/// </param>
/// <returns>
/// List of instances of <see cref="IterationSetup"/>.
/// </returns>
IEnumerable<IterationSetup> ReadByEngineeringModelSetup(NpgsqlTransaction transaction, string partition, Guid engineeringModelSetupId, DateTime? instant = null);
}
}
16 changes: 0 additions & 16 deletions CDP4Orm/Dao/Supplemental/IPersonDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace CDP4Orm.Dao
{
using System;

using Npgsql;

/// <summary>
Expand All @@ -38,20 +36,6 @@ public partial interface IPersonDao
/// </summary>
string PasswordChangeToken { get; }

/// <summary>
/// Gets the given name of a person.
/// </summary>
/// <param name="transaction">
/// The transaction.
/// </param>
/// <param name="personIid">
/// The person id.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
string GivenName(NpgsqlTransaction transaction, Guid personIid);

/// <summary>
/// Update user credentials after migration
/// </summary>
Expand Down
48 changes: 0 additions & 48 deletions CDP4Orm/Dao/Supplemental/IterationSetupDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,54 +91,6 @@ public virtual IEnumerable<IterationSetup> ReadByIteration(NpgsqlTransaction tra
}
}

/// <summary>
/// Read the data from the database based on <see cref="EngineeringModelSetup.Iid"/>.
/// </summary>
/// <param name="transaction">
/// The current transaction to the database.
/// </param>
/// <param name="partition">
/// The database partition (schema) where the requested resource is stored.
/// </param>
/// <param name="engineeringModelSetupId">
/// The <see cref="EngineeringModelSetup"/> Id.
/// </param>
/// <param name="instant">
/// The instant as a nullable <see cref="DateTime"/>
/// </param>
/// <returns>
/// List of instances of <see cref="CDP4Common.DTO.IterationSetup"/>.
/// </returns>
public IEnumerable<IterationSetup> ReadByEngineeringModelSetup(NpgsqlTransaction transaction, string partition, Guid engineeringModelSetupId, DateTime? instant = null)
{
using var command = new NpgsqlCommand();

var sqlBuilder = new StringBuilder();

sqlBuilder.Append($"SELECT * FROM {this.BuildReadQuery(partition, instant)}");
sqlBuilder.Append($" WHERE \"Iid\"::text = ANY(SELECT unnest(\"IterationSetup\") FROM ({this.EngineeringModelSetupDao.BuildReadQuery(partition, instant)}) EngineeringModelSetup WHERE \"Iid\"::text = :engineeringModelSetupId)");

command.Parameters.Add("engineeringModelSetupId", NpgsqlDbType.Text).Value = engineeringModelSetupId.ToString();

if (instant.HasValue && instant.Value != DateTime.MaxValue)
{
command.Parameters.Add("instant", NpgsqlDbType.Timestamp).Value = instant;
}

sqlBuilder.Append(';');

command.Connection = transaction.Connection;
command.Transaction = transaction;
command.CommandText = sqlBuilder.ToString();

using var reader = command.ExecuteReader();

while (reader.Read())
{
yield return this.MapToDto(reader);
}
}

/// <summary>
/// Execute additional logic before each delete function call.
/// </summary>
Expand Down
Loading

0 comments on commit ee86164

Please sign in to comment.