Skip to content

Commit 72b15af

Browse files
committed
Use generic type for storage IDs in repos
1 parent 564b754 commit 72b15af

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

IntegrationEngine.Core/Storage/DatabaseRepository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public IEnumerable<TItem> SelectAll<TItem>() where TItem : class, IHasLongId
2929
return db.Set<TItem>().ToList<TItem>();
3030
}
3131

32-
public TItem SelectById<TItem>(object id) where TItem : class, IHasLongId
32+
public TItem SelectById<TItem>(long id) where TItem : class, IHasLongId
3333
{
3434
return db.Set<TItem>().Find(id);
3535

@@ -47,7 +47,7 @@ public TItem Update<TItem>(TItem item) where TItem : class, IHasLongId
4747
return db.Entry(item).Entity;
4848
}
4949

50-
public void Delete<TItem>(object id) where TItem : class
50+
public void Delete<TItem>(long id) where TItem : class
5151
{
5252
TItem existing = db.Set<TItem>().Find(id);
5353
db.Set<TItem>().Remove(existing);
@@ -58,7 +58,7 @@ public void Save()
5858
db.SaveChanges();
5959
}
6060

61-
public bool Exists<TItem>(object id) where TItem : class
61+
public bool Exists<TItem>(long id) where TItem : class
6262
{
6363
return db.Set<TItem>().Find(id) != null;
6464
}

IntegrationEngine.Core/Storage/ElasticsearchRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public IEnumerable<TItem> Search<TItem, TKey>(string query,
7171
return documents.AsEnumerable();
7272
}
7373

74-
public TItem SelectById<TItem>(object id) where TItem : class, IHasStringId
74+
public TItem SelectById<TItem>(string id) where TItem : class, IHasStringId
7575
{
7676
var response = ElasticClient.Get<TItem>(x => x.Id(id.ToString()));
7777
if (response.Source == null)
@@ -95,15 +95,15 @@ public TItem Update<TItem>(TItem item) where TItem : class, IHasStringId
9595
);
9696
return SelectById<TItem>(updateResponse.Id);
9797
}
98-
99-
public void Delete<TItem>(object id) where TItem : class
98+
99+
public void Delete<TItem>(string id) where TItem : class
100100
{
101101
ElasticClient.Delete<TItem>(x => x.Id(id.ToString()));
102102
}
103103

104-
public bool Exists<TItem>(object id) where TItem : class
104+
public bool Exists<TItem>(string id) where TItem : class
105105
{
106-
return ElasticClient.DocumentExists<TItem>(x => x.Id(id.ToString())).Exists;
106+
return ElasticClient.DocumentExists<TItem>(x => x.Id(id)).Exists;
107107
}
108108

109109
public bool IsServerAvailable()

IntegrationEngine.Core/Storage/IDatabaseRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace IntegrationEngine.Core.Storage
66
{
7-
public interface IDatabaseRepository : IRepository<IHasLongId>, IDisposable
7+
public interface IDatabaseRepository : IRepository<IHasLongId, long>, IDisposable
88
{
99
void Save();
1010
void SetState<TItem>(TItem item, EntityState entityState) where TItem : class;

IntegrationEngine.Core/Storage/IElasticsearchRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace IntegrationEngine.Core.Storage
88
{
9-
public interface IElasticsearchRepository : IRepository<IHasStringId>
9+
public interface IElasticsearchRepository : IRepository<IHasStringId, string>
1010
{
1111
IEnumerable<TItem> SelectAll<TItem, TKey>(Expression<Func<TItem, TKey>> orderBy, bool ascending = true, int pageIndex = 0, int rowCount = 10) where TItem : class, IHasStringId;
1212
IEnumerable<TItem> Search<TItem, TKey>(string query, Expression<Func<TItem, TKey>> orderBy, bool ascending = true, int pageIndex = 0, int rowCount = 10) where TItem : class, IHasStringId;

IntegrationEngine.Core/Storage/IRepository.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
namespace IntegrationEngine.Core.Storage
99
{
10-
public interface IRepository<TId>
10+
public interface IRepository<THasId, TId>
1111
{
12-
IEnumerable<TItem> SelectAll<TItem>() where TItem : class, TId;
13-
TItem SelectById<TItem>(object id) where TItem : class, TId;
14-
TItem Insert<TItem>(TItem item) where TItem : class, TId;
15-
TItem Update<TItem>(TItem item) where TItem : class, TId;
16-
void Delete<TItem>(object id) where TItem : class;
17-
bool Exists<TItem>(object id) where TItem : class;
12+
IEnumerable<TItem> SelectAll<TItem>() where TItem : class, THasId;
13+
TItem SelectById<TItem>(TId id) where TItem : class, THasId;
14+
TItem Insert<TItem>(TItem item) where TItem : class, THasId;
15+
TItem Update<TItem>(TItem item) where TItem : class, THasId;
16+
void Delete<TItem>(TId id) where TItem : class;
17+
bool Exists<TItem>(TId id) where TItem : class;
1818
bool IsServerAvailable();
1919
}
2020
}

0 commit comments

Comments
 (0)