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

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

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

Protected Member Functions

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

Package Functions

 PeerDatabaseMapper (TimeServerDatabaseMapper timeServerMapper, LogBase log)
 

Private Attributes

const string InsertSql
 
const string SelectSql
 
readonly TimeServerDatabaseMapper timeServerMapper
 
const string UpdateSql
 

Additional Inherited Members

- Public Member Functions inherited from Ntp.Analyzer.Data.Sql.SqlDatabaseMapper< Peer >
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< Peer >
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 peer.

Definition at line 34 of file PeerDatabaseMapper.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.PeerDatabaseMapper ( TimeServerDatabaseMapper  timeServerMapper,
LogBase  log 
)
inlinepackage

Definition at line 36 of file PeerDatabaseMapper.cs.

37  : base(log)
38  {
40  }
readonly TimeServerDatabaseMapper timeServerMapper

Member Function Documentation

override void Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.Insert ( Peer  item)
inlineprotected

Definition at line 65 of file PeerDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.Peer.Ip, Ntp.Analyzer.Objects.NamedObject.Name, Ntp.Analyzer.Objects.Peer.OrgId, and Ntp.Analyzer.Objects.PersistentObject.SetId().

66  {
67  lock (MapperLocker)
68  {
69  try
70  {
71  Open();
72  Command.CommandText = PrepareInsertSql(InsertSql);
73  Command.Parameters.Add(CreateParameter("@name", item.Name));
74  Command.Parameters.Add(CreateParameter("@ip", item.Ip));
75  Command.Parameters.Add(CreateParameter("@orgId", item.OrgId));
76  Command.Prepare();
77  Log.SqlExecute(Command.CommandText, Command.Parameters);
78  var idObject = Command.ExecuteScalar();
79  item.SetId(Convert.ToInt32(idObject));
80  }
81  catch (Exception e)
82  {
83  Log.InsertError(TableName, e);
84  }
85  finally
86  {
87  Close();
88  }
89  }
90  }
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)
int OrgId
Gets the server identifier as specified on support.ntp.org.
Definition: Peer.cs:48

Here is the call graph for this function:

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

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

Definition at line 93 of file PeerDatabaseMapper.cs.

References e.

94  {
95  try
96  {
97  Open();
98  Command.CommandText = PrepareSql(SelectSql);
99  Log.SqlExecute(Command.CommandText);
100  Reader = Command.ExecuteReader();
101 
102  while (Reader.Read())
103  {
104  int id = Convert.ToInt32(Reader["id"]);
105  string name = Reader["name"].ToString();
106  string ip = Reader["ip"].ToString();
107  var orgId = Reader["orgId"] != DBNull.Value
108  ? Convert.ToInt32(Reader["orgId"])
109  : (int?) null;
110 
111  var server = orgId.HasValue
112  ? timeServerMapper[orgId.Value]
113  : null;
114 
115  var peer = new Peer(id, name, ip, server);
116  AddItem(peer);
117  }
118  }
119  catch (Exception e)
120  {
121  Log.ReadError(TableName, e);
122  }
123  finally
124  {
125  Close();
126  }
127  }
readonly TimeServerDatabaseMapper timeServerMapper
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.Update ( Peer  item)
inlineprotected

Definition at line 130 of file PeerDatabaseMapper.cs.

References e, Ntp.Analyzer.Objects.PersistentObject.Id, Ntp.Analyzer.Objects.Peer.Ip, Ntp.Analyzer.Objects.NamedObject.Name, and Ntp.Analyzer.Objects.Peer.OrgId.

131  {
132  lock (MapperLocker)
133  {
134  try
135  {
136  Open();
137  Command.CommandText = PrepareSql(UpdateSql);
138  Command.Parameters.Add(CreateParameter("@name", item.Name));
139  Command.Parameters.Add(CreateParameter("@ip", item.Ip));
140  Command.Parameters.Add(CreateParameter("@orgId", item.OrgId));
141  Command.Parameters.Add(CreateParameter("@id", item.Id));
142  Command.Prepare();
143  Log.SqlExecute(Command.CommandText, Command.Parameters);
144  Command.ExecuteNonQuery();
145  }
146  catch (Exception e)
147  {
148  Log.UpdateError(TableName, e);
149  }
150  finally
151  {
152  Close();
153  }
154  }
155  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)
int OrgId
Gets the server identifier as specified on support.ntp.org.
Definition: Peer.cs:48

Member Data Documentation

override string Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.CreateSql
protected
Initial value:
=> "CREATE TABLE peer ( " +
" id {0} PRIMARY KEY, " +
" name VARCHAR(255) NOT NULL, " +
" ip VARCHAR(45) NOT NULL, " +
" orgId INT " +
"){1};"

Definition at line 57 of file PeerDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO peer( name, ip, orgId ) VALUES( @name, @ip, @orgId );{0};"

Definition at line 45 of file PeerDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.SelectSql
private
Initial value:
=
"SELECT id, name, ip, orgId FROM peer;"

Definition at line 42 of file PeerDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.TableName => "peer"
protected

Definition at line 55 of file PeerDatabaseMapper.cs.

readonly TimeServerDatabaseMapper Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.timeServerMapper
private

Definition at line 51 of file PeerDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.PeerDatabaseMapper.UpdateSql
private
Initial value:
=
"UPDATE peer SET name = @name, ip = @ip, orgId = @orgId WHERE id = @id"

Definition at line 48 of file PeerDatabaseMapper.cs.

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

Definition at line 53 of file PeerDatabaseMapper.cs.


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