NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper Class Reference

OR/M mapper for table peerActivity. More...

Inheritance diagram for Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper:
Collaboration diagram for Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper:

Protected Member Functions

override void Insert (PeerActivity item)
 
override void ReadContent ()
 
override void Update (PeerActivity item)
 
- Protected Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< PeerActivity >
 SqlDatabaseMapper (LogBase log)
 
void AddItem (T item)
 
void Close ()
 
IDbDataParameter CreateParameter (string name, object value)
 
virtual T FetchExternal (int id)
 
abstract void Insert (T item)
 
void Open ()
 
string PrepareInsertSql (string sql)
 
virtual string PrepareSql (string sql)
 
void RemoveItem (T item)
 
abstract void Update (T item)
 

Protected Attributes

override string CreateSql
 
override string TableName => "peerActivity"
 
override bool UseCache => true
 
- Protected Attributes inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< PeerActivity >
IEnumerable< T > Content
 
readonly object MapperLocker
 
IDataReader Reader
 

Package Functions

 PeerActivityDatabaseMapper (HostDatabaseMapper hostMapper, PeerDatabaseMapper peerMapper, LogBase log)
 

Private Attributes

readonly HostDatabaseMapper hostMapper
 
const string InsertSql
 
readonly PeerDatabaseMapper peerMapper
 
const string SelectSql
 
const string UpdateSql
 

Additional Inherited Members

- Public Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< PeerActivity >
void CheckTable ()
 
override IEnumerator< T > GetEnumerator ()
 Read all data from table in a sequential manner. More...
 
void Save (T item)
 
- Properties inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< PeerActivity >
IDbCommand Command [get, private set]
 
abstract string CreateSql [get]
 
abstract string TableName [get]
 
this[int id] [get]
 
abstract bool UseCache [get]
 

Detailed Description

OR/M mapper for table peerActivity.

Definition at line 34 of file PeerActivityDatabaseMapper.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.PeerActivityDatabaseMapper ( HostDatabaseMapper  hostMapper,
PeerDatabaseMapper  peerMapper,
LogBase  log 
)
inlinepackage

Definition at line 36 of file PeerActivityDatabaseMapper.cs.

40  : base(log)
41  {
42  this.hostMapper = hostMapper;
43  this.peerMapper = peerMapper;
44  }

Member Function Documentation

override void Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.Insert ( PeerActivity  item)
inlineprotected

Definition at line 76 of file PeerActivityDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.PeerActivity.Hide, Ntp.Analyzer.Objects.PeerActivity.Host, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.PeerActivity.LastActive, Ntp.Analyzer.Objects.PeerActivity.Peer, Ntp.Analyzer.Objects.PersistentObject.SetId(), and Ntp.Analyzer.Objects.PeerActivity.UtcOffset.

77  {
78  lock (MapperLocker)
79  {
80  try
81  {
82  Open();
83  Command.CommandText = PrepareInsertSql(InsertSql);
84  Command.Parameters.Add(CreateParameter("@lastActive", item.LastActive));
85  Command.Parameters.Add(CreateParameter("@zone", item.UtcOffset));
86  Command.Parameters.Add(CreateParameter("@hide", item.Hide));
87  Command.Parameters.Add(CreateParameter("@hostId", item.Host.Id));
88  Command.Parameters.Add(CreateParameter("@peerId", item.Peer.Id));
89  Command.Prepare();
90  Log.SqlExecute(Command.CommandText, Command.Parameters);
91  var idObject = Command.ExecuteScalar();
92  item.SetId(Convert.ToInt32(idObject));
93  }
94  catch (Exception e)
95  {
96  Log.InsertError(TableName, e);
97  }
98  finally
99  {
100  Close();
101  }
102  }
103  }
void SetId(int id)
Sets the identifier after the object have been stored in persistent storage.
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)

Here is the call graph for this function:

override void Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.ReadContent ( )
inlineprotectedvirtual

Implements Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< PeerActivity >.

Definition at line 106 of file PeerActivityDatabaseMapper.cs.

References e.

107  {
108  try
109  {
110  Open();
111  Command.CommandText = PrepareSql(SelectSql);
112  Log.SqlExecute(Command.CommandText);
113  Reader = Command.ExecuteReader();
114 
115  while (Reader.Read())
116  {
117  int id = Convert.ToInt32(Reader["id"]);
118  var time = Convert.ToDateTime(Reader["lastActive"]);
119  int zone = Convert.ToInt32(Reader["zone"]);
120  bool hide = Convert.ToBoolean(Reader["hide"]);
121  int hostId = Convert.ToInt32(Reader["hostId"]);
122  var host = hostMapper[hostId];
123  int peerId = Convert.ToInt32(Reader["peerId"]);
124  var peer = peerMapper[peerId];
125  var item = new PeerActivity(id, peer, host, time, zone, hide);
126  AddItem(item);
127  }
128  }
129  catch (Exception e)
130  {
131  Log.UpdateError(TableName, e);
132  }
133  finally
134  {
135  Close();
136  }
137  }
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.Update ( PeerActivity  item)
inlineprotected

Definition at line 140 of file PeerActivityDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.PeerActivity.LastActive, and Ntp.Analyzer.Objects.PeerActivity.UtcOffset.

141  {
142  lock (MapperLocker)
143  {
144  try
145  {
146  Open();
147  Command.CommandText = PrepareSql(UpdateSql);
148  Command.Parameters.Add(CreateParameter("@lastActive", item.LastActive));
149  Command.Parameters.Add(CreateParameter("@zone", item.UtcOffset));
150  Command.Parameters.Add(CreateParameter("@id", item.Id));
151  Command.Prepare();
152  Log.SqlExecute(Command.CommandText, Command.Parameters);
153  Command.ExecuteNonQuery();
154  }
155  catch (Exception e)
156  {
157  Log.UpdateError(TableName, e);
158  }
159  finally
160  {
161  Close();
162  }
163  }
164  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE peerActivity ( " +
" id {0} PRIMARY KEY, " +
" lastActive TIMESTAMP NOT NULL, " +
" zone INT NOT NULL, " +
" hide BIT(1) NOT NULL, " +
" hostId INT NOT NULL, " +
" peerId INT NOT NULL, " +
" UNIQUE KEY (hostId, peerId), " +
" FOREIGN KEY (hostId) REFERENCES host(id), " +
" FOREIGN KEY (peerId) REFERENCES peer(id) " +
"){1};"

Definition at line 63 of file PeerActivityDatabaseMapper.cs.

readonly HostDatabaseMapper Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.hostMapper
private

Definition at line 56 of file PeerActivityDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO peerActivity( lastActive, zone, hide, hostId, peerId ) " +
"VALUES( @lastActive, @zone, @hide, @hostId, @peerId );{0};"

Definition at line 49 of file PeerActivityDatabaseMapper.cs.

readonly PeerDatabaseMapper Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.peerMapper
private

Definition at line 57 of file PeerActivityDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT id, lastActive, zone, hide, hostId, peerId FROM peerActivity"

Definition at line 46 of file PeerActivityDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.TableName => "peerActivity"
protected

Definition at line 61 of file PeerActivityDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.UpdateSql
private
Initial value:
=
"UPDATE peerActivity SET lastActive = @lastActive, zone = @zone WHERE id = @id"

Definition at line 53 of file PeerActivityDatabaseMapper.cs.

override bool Ntp.Analyzer.Data.Sql.PeerActivityDatabaseMapper.UseCache => true
protected

Definition at line 59 of file PeerActivityDatabaseMapper.cs.


The documentation for this class was generated from the following file: