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

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

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

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Package Functions

 DriftReadingDatabaseMapper (HostDatabaseMapper hostMapper, LogBase log)
 

Private Attributes

readonly HostDatabaseMapper hostMapper
 
const string InsertSql
 
const string SelectSql
 

Additional Inherited Members

- Properties inherited from Ntp.Analyzer.Data.Sql.FilteredSqlDatabaseMapper< DriftReading >
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 driftReading.

Definition at line 35 of file DriftReadingDatabaseMapper.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.DriftReadingDatabaseMapper ( HostDatabaseMapper  hostMapper,
LogBase  log 
)
inlinepackage

Definition at line 37 of file DriftReadingDatabaseMapper.cs.

38  : base(log)
39  {
40  this.hostMapper = hostMapper;
41  }

Member Function Documentation

override IEnumerator<DriftReading> Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.GetEnumerator ( )
inline

Read all data from table in a sequential manner.

Returns
The enumerator.

Definition at line 72 of file DriftReadingDatabaseMapper.cs.

References e.

73  {
74  lock (MapperLocker)
75  {
76  bool error = false;
77  string sql = PrepareSql(SelectSql);
78 
79  try
80  {
81  Open();
82  Command.CommandText = sql;
83  Log.SqlExecute(Command.CommandText);
84  Reader = Command.ExecuteReader();
85  }
86  catch (Exception e)
87  {
88  Log.ReadError(TableName, e);
89  error = true;
90  }
91 
92  if (error)
93  yield break;
94 
95  while (Reader.Read())
96  {
97  int id = Convert.ToInt32(Reader["id"]);
98  var time = Convert.ToDateTime(Reader["time"]);
99  int zone = Convert.ToInt32(Reader["zone"]);
100  int hostId = Convert.ToInt32(Reader["hostId"]);
101  var host = hostMapper[hostId];
102  double drift = Convert.ToDouble(Reader["drift"]);
103  yield return new DriftReading(id, time, zone, host, drift);
104  }
105 
106  Close();
107  }
108  }
var e
Definition: bootstrap.min.js:6
Value from NTP drift file.
Definition: DriftReading.cs:29
override void Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.Insert ( DriftReading  item)
inlineprotected

Definition at line 111 of file DriftReadingDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.Reading.Host, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.PersistentObject.SetId(), Ntp.Analyzer.Objects.Reading.Time, Ntp.Analyzer.Objects.Reading.UtcOffset, and Ntp.Analyzer.Objects.DriftReading.Value.

112  {
113  lock (MapperLocker)
114  {
115  try
116  {
117  Open();
118  Command.CommandText = PrepareInsertSql(InsertSql);
119  Command.Parameters.Add(CreateParameter("@time", item.Time));
120  Command.Parameters.Add(CreateParameter("@zone", item.UtcOffset));
121  Command.Parameters.Add(CreateParameter("@hostId", item.Host.Id));
122  Command.Parameters.Add(CreateParameter("@drift", item.Value));
123  Command.Prepare();
124  Log.SqlExecute(Command.CommandText, Command.Parameters);
125  var idObject = Command.ExecuteScalar();
126  item.SetId(Convert.ToInt32(idObject));
127  }
128  catch (Exception e)
129  {
130  Log.InsertError(TableName, e);
131  }
132  finally
133  {
134  Close();
135  }
136  }
137  }
void SetId(int id)
Sets the identifier after the object have been stored in persistent storage.
var e
Definition: bootstrap.min.js:6
double Value
Gets the drift value.
Definition: DriftReading.cs:47

Here is the call graph for this function:

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

Definition at line 139 of file DriftReadingDatabaseMapper.cs.

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

140  {
141  throw new NotSupportedException(LogMessages.DatabaseCacheError);
142  }
override void Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.Update ( DriftReading  item)
inlineprotected

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE driftReading ( " +
" id {0} PRIMARY KEY, " +
" time TIMESTAMP NOT NULL, " +
" zone INT NOT NULL, " +
" hostId INT NOT NULL, " +
" drift DOUBLE PRECISION NOT NULL, " +
" FOREIGN KEY (hostId) REFERENCES host(id) " +
"){1};"

Definition at line 58 of file DriftReadingDatabaseMapper.cs.

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

Definition at line 52 of file DriftReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO driftReading ( time, zone, hostId, drift ) " +
"VALUES ( @time, @zone, @hostId, @drift );{0};"

Definition at line 48 of file DriftReadingDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT " +
"id, time, zone, hostId, drift " +
"FROM driftReading"

Definition at line 43 of file DriftReadingDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.DriftReadingDatabaseMapper.TableName => "driftReading"
protected

Definition at line 56 of file DriftReadingDatabaseMapper.cs.

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

Definition at line 54 of file DriftReadingDatabaseMapper.cs.


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