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

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

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

Public Member Functions

override IEnumerator< PeerReadingGetEnumerator ()
 Read all data from table in a sequential manner. More...
 

Protected Member Functions

override void Insert (PeerReading item)
 
override void ReadContent ()
 
override void Update (PeerReading item)
 
- Protected Member Functions inherited from Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< PeerReading >
 FilteredSqlDatabaseMapper (LogBase log)
 
override string PrepareSql (string sql)
 

Protected Attributes

override string CreateSql
 
override string TableName => "peerReading"
 
override bool UseCache => false
 

Package Functions

 PeerReadingDatabaseMapper (HostDatabaseMapper hostMapper, PeerDatabaseMapper peerMapper, LogBase log)
 

Private Attributes

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

Additional Inherited Members

- Properties inherited from Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< PeerReading >
Host FilterHost [get, set]
 Gets or sets the host More...
 
Peer FilterPeer [get, set]
 Gets or sets the peer to use when extracting data. More...
 
DateTime FilterTime [get, set]
 Gets or sets the time to use when extracting data. Only readings with a timestamp later than FilterTime gets extracted. More...
 

Detailed Description

OR/M mapper for table peerReading.

Definition at line 35 of file PeerReadingDatabaseMapper.cs.

Constructor & Destructor Documentation

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

Definition at line 37 of file PeerReadingDatabaseMapper.cs.

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

Member Function Documentation

override IEnumerator<PeerReading> Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.GetEnumerator ( )
inline

Read all data from table in a sequential manner.

Returns
The enumerator.

Definition at line 83 of file PeerReadingDatabaseMapper.cs.

References e.

84  {
85  lock (MapperLocker)
86  {
87  bool error = false;
88 
89  try
90  {
91  Open();
92  Command.CommandText = PrepareSql(SelectSql);
93  Log.SqlExecute(Command.CommandText);
94  Reader = Command.ExecuteReader();
95  }
96  catch (Exception e)
97  {
98  Log.ReadError(TableName, e);
99  error = true;
100  }
101 
102  if (error)
103  yield break;
104 
105  while (Reader.Read())
106  {
107  int id = Convert.ToInt32(Reader["id"]);
108  var time = Convert.ToDateTime(Reader["time"]);
109  int zone = Convert.ToInt32(Reader["zone"]);
110  int hostId = Convert.ToInt32(Reader["hostId"]);
111  var host = hostMapper[hostId];
112  int peerId = Convert.ToInt32(Reader["peerId"]);
113  var peer = peerMapper[peerId];
114  int last = Convert.ToInt32(Reader["last"]);
115  int reach = Convert.ToInt32(Reader["reach"]);
116  double delay = Convert.ToDouble(Reader["delay"]);
117  double offset = Convert.ToDouble(Reader["offset"]);
118  double jitter = Convert.ToDouble(Reader["jitter"]);
119 
120  var reading = new PeerReading(
121  id, time, zone, host, peer,
122  last, reach, delay, offset, jitter);
123 
124  yield return reading;
125  }
126 
127  Close();
128  }
129  }
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.Insert ( PeerReading  item)
inlineprotected

Definition at line 132 of file PeerReadingDatabaseMapper.cs.

References Ntp.Analyzer.Objects.PeerReading.Delay, e, Ntp.Analyzer.Objects.Reading.Host, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.DispersionReading.Jitter, Ntp.Analyzer.Objects.PeerReading.LastPoll, Ntp.Analyzer.Objects.DispersionReading.Offset, Ntp.Analyzer.Objects.DispersionReading.Peer, Ntp.Analyzer.Objects.PeerReading.Reach, Ntp.Analyzer.Objects.PersistentObject.SetId(), Ntp.Analyzer.Objects.Reading.Time, and Ntp.Analyzer.Objects.Reading.UtcOffset.

133  {
134  lock (MapperLocker)
135  {
136  try
137  {
138  Open();
139  Command.CommandText = PrepareInsertSql(InsertSql);
140  Command.Parameters.Add(CreateParameter("@time", item.Time));
141  Command.Parameters.Add(CreateParameter("@zone", item.UtcOffset));
142  Command.Parameters.Add(CreateParameter("@hostId", item.Host.Id));
143  Command.Parameters.Add(CreateParameter("@peerId", item.Peer.Id));
144  Command.Parameters.Add(CreateParameter("@last", item.LastPoll));
145  Command.Parameters.Add(CreateParameter("@reach", item.Reach));
146  Command.Parameters.Add(CreateParameter("@delay", item.Delay));
147  Command.Parameters.Add(CreateParameter("@offset", item.Offset));
148  Command.Parameters.Add(CreateParameter("@jitter", item.Jitter));
149  Command.Prepare();
150  Log.SqlExecute(Command.CommandText, Command.Parameters);
151  var idObject = Command.ExecuteScalar();
152  item.SetId(Convert.ToInt32(idObject));
153  }
154  catch (Exception e)
155  {
156  Log.InsertError(TableName, e);
157  }
158  finally
159  {
160  Close();
161  }
162  }
163  }
void SetId(int id)
Sets the identifier after the object have been stored in persistent storage.
var e
Definition: bootstrap.min.js:6

Here is the call graph for this function:

override void Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.ReadContent ( )
inlineprotected

Definition at line 165 of file PeerReadingDatabaseMapper.cs.

References Ntp.Analyzer.Data.Log.LogMessages.DatabaseCacheError.

166  {
167  throw new NotSupportedException(LogMessages.DatabaseCacheError);
168  }
override void Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.Update ( PeerReading  item)
inlineprotected

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE peerReading ( " +
" id {0} PRIMARY KEY, " +
" time TIMESTAMP NOT NULL, " +
" zone INT NOT NULL, " +
" hostId INT NOT NULL, " +
" peerId INT NOT NULL, " +
" last INT NOT NULL, " +
" reach INT NOT NULL, " +
" delay DOUBLE PRECISION NOT NULL, " +
" [offset] DOUBLE PRECISION NOT NULL, " +
" jitter DOUBLE PRECISION NOT NULL, " +
" FOREIGN KEY (hostId) REFERENCES host(id), " +
" FOREIGN KEY (peerId) REFERENCES peer(id) " +
"){1};"

Definition at line 63 of file PeerReadingDatabaseMapper.cs.

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

Definition at line 56 of file PeerReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO peerReading ( time, zone, hostId, peerId, last, reach, delay, [offset], jitter ) " +
"VALUES ( @time, @zone, @hostId, @peerId, @last, @reach, @delay, @offset, @jitter );{0};"

Definition at line 52 of file PeerReadingDatabaseMapper.cs.

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

Definition at line 57 of file PeerReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT " +
"id, time, zone, hostId, peerId, last, reach, delay, [offset], jitter " +
"FROM peerReading"

Definition at line 47 of file PeerReadingDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.TableName => "peerReading"
protected

Definition at line 61 of file PeerReadingDatabaseMapper.cs.

override bool Ntp.Analyzer.Data.Sql.PeerReadingDatabaseMapper.UseCache => false
protected

Definition at line 59 of file PeerReadingDatabaseMapper.cs.


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