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

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

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

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Package Functions

 HostReadingDatabaseMapper (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< HostReading >
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 hostReading.

Definition at line 35 of file HostReadingDatabaseMapper.cs.

Constructor & Destructor Documentation

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

Definition at line 37 of file HostReadingDatabaseMapper.cs.

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

Member Function Documentation

override IEnumerator<HostReading> Ntp.Analyzer.Data.Sql.HostReadingDatabaseMapper.GetEnumerator ( )
inline

Read all data from table in a sequential manner.

Returns
The enumerator.

Definition at line 82 of file HostReadingDatabaseMapper.cs.

References e.

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

Definition at line 130 of file HostReadingDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.HostReading.Frequency, Ntp.Analyzer.Objects.Reading.Host, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.DispersionReading.Jitter, Ntp.Analyzer.Objects.DispersionReading.Offset, Ntp.Analyzer.Objects.DispersionReading.Peer, Ntp.Analyzer.Objects.PersistentObject.SetId(), Ntp.Analyzer.Objects.HostReading.Stability, Ntp.Analyzer.Objects.Reading.Time, and Ntp.Analyzer.Objects.Reading.UtcOffset.

131  {
132  lock (MapperLocker)
133  {
134  try
135  {
136  Open();
137  Command.CommandText = PrepareInsertSql(InsertSql);
138  Command.Parameters.Add(CreateParameter("@time", item.Time));
139  Command.Parameters.Add(CreateParameter("@zone", item.UtcOffset));
140  Command.Parameters.Add(CreateParameter("@hostId", item.Host.Id));
141  Command.Parameters.Add(CreateParameter("@peerId", item.Peer.Id));
142  Command.Parameters.Add(CreateParameter("@offset", item.Offset));
143  Command.Parameters.Add(CreateParameter("@jitter", item.Jitter));
144  Command.Parameters.Add(CreateParameter("@frequency", item.Frequency));
145  Command.Parameters.Add(CreateParameter("@stability", item.Stability));
146  Command.Prepare();
147  Log.SqlExecute(Command.CommandText, Command.Parameters);
148  var idObject = Command.ExecuteScalar();
149  item.SetId(Convert.ToInt32(idObject));
150  }
151  catch (Exception e)
152  {
153  Log.InsertError(TableName, e);
154  }
155  finally
156  {
157  Close();
158  }
159  }
160  }
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.HostReadingDatabaseMapper.ReadContent ( )
inlineprotected

Definition at line 162 of file HostReadingDatabaseMapper.cs.

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

163  {
164  throw new NotSupportedException(LogMessages.DatabaseCacheError);
165  }
override void Ntp.Analyzer.Data.Sql.HostReadingDatabaseMapper.Update ( HostReading  item)
inlineprotected

Member Data Documentation

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

Definition at line 63 of file HostReadingDatabaseMapper.cs.

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

Definition at line 56 of file HostReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.HostReadingDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO hostReading ( time, zone, hostId, peerId, [offset], jitter, frequency, stability ) " +
"VALUES ( @time, @zone, @hostId, @peerId, @offset, @jitter, @frequency, @stability );{0};"

Definition at line 52 of file HostReadingDatabaseMapper.cs.

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

Definition at line 57 of file HostReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.HostReadingDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT " +
"id, time, zone, hostId, peerId, [offset], jitter, frequency, stability " +
"FROM hostReading"

Definition at line 47 of file HostReadingDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.HostReadingDatabaseMapper.TableName => "hostReading"
protected

Definition at line 61 of file HostReadingDatabaseMapper.cs.

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

Definition at line 59 of file HostReadingDatabaseMapper.cs.


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