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

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

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

Protected Member Functions

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

Package Functions

 HostDatabaseMapper (LogBase log)
 

Private Attributes

const string InsertSql
 
const string SelectSql
 
const string UpdateSql
 

Additional Inherited Members

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

Definition at line 34 of file HostDatabaseMapper.cs.

Constructor & Destructor Documentation

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

Definition at line 36 of file HostDatabaseMapper.cs.

37  : base(log)
38  {
39  }

Member Function Documentation

override void Ntp.Analyzer.Data.Sql.HostDatabaseMapper.Insert ( Host  item)
inlineprotected

Definition at line 62 of file HostDatabaseMapper.cs.

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

63  {
64  lock (MapperLocker)
65  {
66  try
67  {
68  Open();
69  Command.CommandText = PrepareInsertSql(InsertSql);
70  Command.Parameters.Add(CreateParameter("@id", item.Id));
71  Command.Parameters.Add(CreateParameter("@name", item.Name));
72  Command.Parameters.Add(CreateParameter("@ip", item.Ip));
73  Command.Parameters.Add(CreateParameter("@orgId", item.OrgId));
74  Command.Prepare();
75  Log.SqlExecute(Command.CommandText, Command.Parameters);
76  Command.ExecuteNonQuery();
77  }
78  catch (Exception e)
79  {
80  Log.InsertError(TableName, e);
81  }
82  finally
83  {
84  Close();
85  }
86  }
87  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)
override void Ntp.Analyzer.Data.Sql.HostDatabaseMapper.ReadContent ( )
inlineprotectedvirtual

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

Definition at line 90 of file HostDatabaseMapper.cs.

References e.

91  {
92  try
93  {
94  Open();
95  Command.CommandText = PrepareSql(SelectSql);
96  Log.SqlExecute(Command.CommandText);
97  Reader = Command.ExecuteReader();
98 
99  while (Reader.Read())
100  {
101  int id = Convert.ToInt32(Reader["id"]);
102  string name = Reader["name"].ToString();
103  string ip = Reader["ip"].ToString();
104  var orgId = Reader["orgId"] != DBNull.Value
105  ? Convert.ToInt32(Reader["orgId"])
106  : (int?) null;
107  var host = new Host(id, name, ip, orgId, false);
108  AddItem(host);
109  }
110  }
111  catch (Exception e)
112  {
113  Log.ReadError(TableName, e);
114  }
115  finally
116  {
117  Close();
118  }
119  }
var e
Definition: bootstrap.min.js:6
override void Ntp.Analyzer.Data.Sql.HostDatabaseMapper.Update ( Host  item)
inlineprotected

Definition at line 122 of file HostDatabaseMapper.cs.

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

123  {
124  lock (MapperLocker)
125  {
126  try
127  {
128  Open();
129  Command.CommandText = PrepareSql(UpdateSql);
130  Command.Parameters.Add(CreateParameter("@name", item.Name));
131  Command.Parameters.Add(CreateParameter("@ip", item.Ip));
132  Command.Parameters.Add(CreateParameter("@orgId", item.OrgId));
133  Command.Parameters.Add(CreateParameter("@id", item.Id));
134  Command.Prepare();
135  Log.SqlExecute(Command.CommandText, Command.Parameters);
136  Command.ExecuteScalar();
137  }
138  catch (Exception e)
139  {
140  Log.UpdateError(TableName, e);
141  }
142  finally
143  {
144  Close();
145  }
146  }
147  }
var e
Definition: bootstrap.min.js:6
IDbDataParameter CreateParameter(string name, object value)

Member Data Documentation

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

Definition at line 54 of file HostDatabaseMapper.cs.

const string Ntp.Analyzer.Data.Sql.HostDatabaseMapper.InsertSql
private
Initial value:
=
"INSERT INTO host( id, name, ip, orgId ) VALUES( @id, @name, @ip, @orgId );"

Definition at line 44 of file HostDatabaseMapper.cs.

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

Definition at line 41 of file HostDatabaseMapper.cs.

override string Ntp.Analyzer.Data.Sql.HostDatabaseMapper.TableName => "host"
protected

Definition at line 52 of file HostDatabaseMapper.cs.

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

Definition at line 47 of file HostDatabaseMapper.cs.

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

Definition at line 50 of file HostDatabaseMapper.cs.


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