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

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

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

Public Member Functions

void Delete (string ip, int hostId)
 
void Delete (int hostId)
 
override IEnumerator< AssociationEntryGetEnumerator ()
 Read all data from table in a sequential manner. More...
 
- Public Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< AssociationEntry >
void CheckTable ()
 
override IEnumerator< T > GetEnumerator ()
 Read all data from table in a sequential manner. More...
 
void Save (T item)
 

Protected Member Functions

override void Insert (AssociationEntry item)
 
override void ReadContent ()
 
override void Update (AssociationEntry item)
 
- Protected Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< AssociationEntry >
 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 => "associationEntry"
 
override bool UseCache => false
 
- Protected Attributes inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< AssociationEntry >
IEnumerable< T > Content
 
readonly object MapperLocker
 
IDataReader Reader
 

Package Functions

 AssociationEntryMapper (LogBase log)
 

Private Attributes

const string DeleteHostSql
 
const string DeleteUniqueSql
 
const string InsertSql
 
const string SelectSql
 

Additional Inherited Members

- Properties inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< AssociationEntry >
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 associationEntry.

Definition at line 35 of file AssociationEntryMapper.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Data.Sql.AssociationEntryMapper.AssociationEntryMapper ( LogBase  log)
inlinepackage

Definition at line 37 of file AssociationEntryMapper.cs.

38  : base(log)
39  {
40  }

Member Function Documentation

void Ntp.Analyzer.Data.Sql.AssociationEntryMapper.Delete ( string  ip,
int  hostId 
)
inline

Definition at line 80 of file AssociationEntryMapper.cs.

References e.

81  {
82  lock (MapperLocker)
83  {
84  try
85  {
86  Open();
87  Command.CommandText = PrepareSql(DeleteUniqueSql);
88  Command.Parameters.Add(CreateParameter("@remote", ip));
89  Command.Parameters.Add(CreateParameter("@hostId", hostId));
90  Command.Prepare();
91  Log.SqlExecute(Command.CommandText, Command.Parameters);
92  Command.ExecuteNonQuery();
93  }
94  catch (Exception e)
95  {
96  Log.DeleteError(TableName, e);
97  }
98  finally
99  {
100  Close();
101  }
102  }
103  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)
void Ntp.Analyzer.Data.Sql.AssociationEntryMapper.Delete ( int  hostId)
inline

Definition at line 106 of file AssociationEntryMapper.cs.

References e.

107  {
108  lock (MapperLocker)
109  {
110  try
111  {
112  Open();
113  Command.CommandText = PrepareSql(DeleteHostSql);
114  Command.Parameters.Add(CreateParameter("@hostId", hostId));
115  Command.Prepare();
116  Log.SqlExecute(Command.CommandText, Command.Parameters);
117  Command.ExecuteNonQuery();
118  }
119  catch (Exception e)
120  {
121  Log.DeleteError(TableName, e);
122  }
123  finally
124  {
125  Close();
126  }
127  }
128  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)
override IEnumerator<AssociationEntry> Ntp.Analyzer.Data.Sql.AssociationEntryMapper.GetEnumerator ( )
inline

Read all data from table in a sequential manner.

Returns
The enumerator.

Definition at line 135 of file AssociationEntryMapper.cs.

References e.

136  {
137  lock (MapperLocker)
138  {
139  bool error = false;
140 
141  try
142  {
143  Open();
144  Command.CommandText = PrepareSql(SelectSql);
145  Log.SqlExecute(Command.CommandText);
146  Reader = Command.ExecuteReader();
147  }
148  catch (Exception e)
149  {
150  Log.ReadError(TableName, e);
151  error = true;
152  }
153 
154  if (error)
155  yield break;
156 
157  while (Reader.Read())
158  {
159  int id = Convert.ToInt32(Reader["id"]);
160  string tallyChar = Convert.ToString(Reader["tallyChar"]);
161  string remote = Convert.ToString(Reader["remote"]);
162  string refid = Convert.ToString(Reader["refid"]);
163  int stratus = Convert.ToInt32(Reader["stratus"]);
164  char type = Convert.ToChar(Reader["type"]);
165  int lastPoll = Convert.ToInt32(Reader["lastPoll"]);
166  int poll = Convert.ToInt32(Reader["poll"]);
167  int reach = Convert.ToInt32(Reader["reach"]);
168  double delay = Convert.ToDouble(Reader["delay"]);
169  double offset = Convert.ToDouble(Reader["offset"]);
170  double jitter = Convert.ToDouble(Reader["jitter"]);
171  int hostId = Convert.ToInt32(Reader["hostId"]);
172 
173  if (tallyChar == string.Empty)
174  tallyChar = " ";
175 
176  var entry = new AssociationEntry(
177  id, hostId, tallyChar[0], remote, refid, stratus, type,
178  lastPoll, poll, reach, delay, offset, jitter);
179 
180  yield return entry;
181  }
182 
183  Close();
184  }
185  }
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.AssociationEntryMapper.Insert ( AssociationEntry  item)
inlineprotected

Definition at line 188 of file AssociationEntryMapper.cs.

References Ntp.Analyzer.Objects.AssociationEntry.Delay, e, Ntp.Analyzer.Objects.AssociationEntry.HostId, Ntp.Analyzer.Objects.AssociationEntry.Jitter, Ntp.Analyzer.Objects.AssociationEntry.LastPoll, Ntp.Analyzer.Objects.AssociationEntry.Offset, Ntp.Analyzer.Objects.AssociationEntry.PeerType, Ntp.Analyzer.Objects.AssociationEntry.Poll, Ntp.Analyzer.Objects.AssociationEntry.Reach, Ntp.Analyzer.Objects.AssociationEntry.Refid, Ntp.Analyzer.Objects.AssociationEntry.Remote, Ntp.Analyzer.Objects.PersistentObject.SetId(), Ntp.Analyzer.Objects.AssociationEntry.Stratus, and Ntp.Analyzer.Objects.AssociationEntry.TallyChar.

189  {
190  lock (MapperLocker)
191  {
192  try
193  {
194  Open();
195  Command.CommandText = PrepareInsertSql(InsertSql);
196  Command.Parameters.Add(CreateParameter("@tallyChar", item.TallyChar));
197  Command.Parameters.Add(CreateParameter("@remote", item.Remote));
198  Command.Parameters.Add(CreateParameter("@refid", item.Refid));
199  Command.Parameters.Add(CreateParameter("@stratus", item.Stratus));
200  Command.Parameters.Add(CreateParameter("@type", item.PeerType));
201  Command.Parameters.Add(CreateParameter("@lastPoll", item.LastPoll));
202  Command.Parameters.Add(CreateParameter("@poll", item.Poll));
203  Command.Parameters.Add(CreateParameter("@reach", item.Reach));
204  Command.Parameters.Add(CreateParameter("@delay", item.Delay));
205  Command.Parameters.Add(CreateParameter("@offset", item.Offset));
206  Command.Parameters.Add(CreateParameter("@jitter", item.Jitter));
207  Command.Parameters.Add(CreateParameter("@hostId", item.HostId));
208  Command.Prepare();
209  Log.SqlExecute(Command.CommandText, Command.Parameters);
210  var idObject = Command.ExecuteScalar();
211  item.SetId(Convert.ToInt32(idObject));
212  }
213  catch (Exception e)
214  {
215  Log.InsertError(TableName, e);
216  }
217  finally
218  {
219  Close();
220  }
221  }
222  }
string Refid
Gets the reference ID (0.0.0.0 if this is unknown)
double Jitter
Gets the dispersion of the peer in milliseconds.
int Poll
Gets the the polling interval in seconds.
int Stratus
Gets the stratum of the remote peer.
char PeerType
Gets the type of the peer (local, unicast, multicast or broadcast)
double Offset
Gets the offset of the peer in milliseconds.
void SetId(int id)
Sets the identifier after the object have been stored in persistent storage.
var e
Definition: bootstrap.min.js:6
string Remote
Gets the address of the remote peer.
char TallyChar
Gets the tally char.
int HostId
Gets the host ID of this association entry.
IDbDataParameter CreateParameter(string name, object value)
double Delay
Gets the current estimated delay.
int LastPoll
Gets when the last packet was received, the polling interval, in seconds.
int Reach
Gets the reachability register in octal.

Here is the call graph for this function:

override void Ntp.Analyzer.Data.Sql.AssociationEntryMapper.ReadContent ( )
inlineprotectedvirtual
override void Ntp.Analyzer.Data.Sql.AssociationEntryMapper.Update ( AssociationEntry  item)
inlineprotected

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE associationEntry ( " +
" id {0} PRIMARY KEY, " +
" tallyChar CHAR(1) NOT NULL, " +
" remote VARCHAR(45) NOT NULL, " +
" refid VARCHAR(45) NOT NULL, " +
" stratus INT NOT NULL, " +
" type CHAR(1) NOT NULL, " +
" lastPoll INT NOT NULL, " +
" poll INT NOT NULL, " +
" reach INT NOT NULL, " +
" delay DOUBLE PRECISION NOT NULL, " +
" [offset] DOUBLE PRECISION NOT NULL, " +
" jitter DOUBLE PRECISION NOT NULL, " +
" hostId INT NOT NULL, " +
" UNIQUE KEY (hostId, remote), " +
" FOREIGN KEY (hostId) REFERENCES host(id) " +
"){1};"

Definition at line 61 of file AssociationEntryMapper.cs.

const string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.DeleteHostSql
private
Initial value:
=
"DELETE FROM associationEntry WHERE hostId = @hostId"

Definition at line 54 of file AssociationEntryMapper.cs.

const string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.DeleteUniqueSql
private
Initial value:
=
"DELETE FROM associationEntry WHERE remote = @remote AND hostId = @hostId"

Definition at line 51 of file AssociationEntryMapper.cs.

const string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.InsertSql
private
Initial value:
=
"INSERT INTO associationEntry ( tallyChar, hostId, remote, refid, stratus, type, lastPoll, poll, reach, delay, [offset], jitter ) " +
"VALUES ( @tallyChar, @hostId, @remote, @refid, @stratus, @type, @lastPoll, @poll, @reach, @delay, @offset, @jitter );{0};"

Definition at line 47 of file AssociationEntryMapper.cs.

const string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.SelectSql
private
Initial value:
=
"SELECT " +
"id, tallyChar, remote, refid, stratus, type, lastPoll, poll, reach, delay, [offset], jitter, hostId " +
"FROM associationEntry"

Definition at line 42 of file AssociationEntryMapper.cs.

override string Ntp.Analyzer.Data.Sql.AssociationEntryMapper.TableName => "associationEntry"
protected

Definition at line 59 of file AssociationEntryMapper.cs.

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

Definition at line 57 of file AssociationEntryMapper.cs.


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