NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Data.Schema.VersionController Class Reference
Collaboration diagram for Ntp.Data.Schema.VersionController:

Public Member Functions

 VersionController (ISqlFactory factory, LogBase log)
 
int FindCurrentVersion ()
 
void SetCurrentVersion (IVersionChanges version)
 

Private Member Functions

bool CheckTable ()
 
void CreateTable ()
 
void InsertTable ()
 
int SelectVersion ()
 

Private Attributes

const string CreateSql = "CREATE TABLE version (number INT NOT NULL PRIMARY KEY);"
 
readonly ISqlFactory factory
 
const string InsertSql = "INSERT INTO version (number) VALUES (0);"
 
readonly LogBase log
 
const string SelectSql = "SELECT number FROM version;"
 
const string UpdateSql = "UPDATE version SET number=@number;"
 

Detailed Description

Definition at line 30 of file VersionController.cs.

Constructor & Destructor Documentation

Ntp.Data.Schema.VersionController.VersionController ( ISqlFactory  factory,
LogBase  log 
)
inline

Definition at line 32 of file VersionController.cs.

References factory.

33  {
34  this.factory = factory;
35  this.log = log;
36  }

Member Function Documentation

bool Ntp.Data.Schema.VersionController.CheckTable ( )
inlineprivate

Definition at line 91 of file VersionController.cs.

References e.

92  {
93  IDbConnection connection = null;
94 
95  try
96  {
97  connection = factory.CreateConnection();
98  connection.Open();
99  var command = factory.CreateCommand();
100  command.Connection = connection;
101  command.CommandText = factory.PrepareCheckTableSql("version");
102  command.Prepare();
103  log.SqlExecute(command.CommandText);
104  var reader = command.ExecuteReader();
105  return reader.Read();
106  }
107  catch (Exception e)
108  {
109  log.VersionTableCreateError(e);
110  return false;
111  }
112  finally
113  {
114  if (connection != null && connection.State == ConnectionState.Open)
115  connection.Close();
116  }
117  }
abstract void Close()
var e
Definition: bootstrap.min.js:6
string PrepareCheckTableSql(string table)
IDbConnection CreateConnection()
IDbCommand CreateCommand()
void Ntp.Data.Schema.VersionController.CreateTable ( )
inlineprivate

Definition at line 119 of file VersionController.cs.

References e.

120  {
121  IDbConnection connection = null;
122 
123  try
124  {
125  connection = factory.CreateConnection();
126  connection.Open();
127  var command = factory.CreateCommand();
128  command.Connection = connection;
129  command.CommandText = CreateSql;
130  command.Prepare();
131  log.SqlExecute(command.CommandText);
132  command.ExecuteNonQuery();
133  }
134  catch (Exception e)
135  {
136  log.VersionTableCreateError(e);
137  }
138  finally
139  {
140  if (connection != null && connection.State == ConnectionState.Open)
141  connection.Close();
142  }
143 
144  log.VersionTableCreated();
145  }
abstract void Close()
var e
Definition: bootstrap.min.js:6
IDbConnection CreateConnection()
IDbCommand CreateCommand()
int Ntp.Data.Schema.VersionController.FindCurrentVersion ( )
inline

Definition at line 45 of file VersionController.cs.

void Ntp.Data.Schema.VersionController.InsertTable ( )
inlineprivate

Definition at line 147 of file VersionController.cs.

References e.

148  {
149  IDbConnection connection = null;
150 
151  try
152  {
153  connection = factory.CreateConnection();
154  connection.Open();
155  var command = factory.CreateCommand();
156  command.Connection = connection;
157  command.CommandText = InsertSql;
158  command.Prepare();
159  log.SqlExecute(command.CommandText);
160  command.ExecuteNonQuery();
161  }
162  catch (Exception e)
163  {
164  log.VersionTableInsertError(e);
165  }
166  finally
167  {
168  if (connection != null && connection.State == ConnectionState.Open)
169  connection.Close();
170  }
171  }
abstract void Close()
var e
Definition: bootstrap.min.js:6
IDbConnection CreateConnection()
IDbCommand CreateCommand()
int Ntp.Data.Schema.VersionController.SelectVersion ( )
inlineprivate

Definition at line 173 of file VersionController.cs.

References e.

174  {
175  IDbConnection connection = null;
176 
177  try
178  {
179  connection = factory.CreateConnection();
180  connection.Open();
181  var command = factory.CreateCommand();
182  command.Connection = connection;
183  command.CommandText = SelectSql;
184  command.Prepare();
185  log.SqlExecute(command.CommandText);
186  var result = command.ExecuteScalar();
187  return Convert.ToInt32(result);
188  }
189  catch (Exception e)
190  {
191  log.VersionTableFetchError(e);
192  return -1;
193  }
194  finally
195  {
196  if (connection != null && connection.State == ConnectionState.Open)
197  connection.Close();
198  }
199  }
abstract void Close()
var e
Definition: bootstrap.min.js:6
IDbConnection CreateConnection()
IDbCommand CreateCommand()
void Ntp.Data.Schema.VersionController.SetCurrentVersion ( IVersionChanges  version)
inline

Definition at line 55 of file VersionController.cs.

References e, Ntp.Data.Schema.IVersionChanges.VersionNumber, and Ntp.Data.Schema.IVersionChanges.VersionText.

56  {
57  if (version == null)
58  {
59  log.VersionTableParamError();
60  return;
61  }
62 
63  IDbConnection connection = null;
64 
65  try
66  {
67  connection = factory.CreateConnection();
68  connection.Open();
69  var command = factory.CreateCommand();
70  command.Connection = connection;
71  command.CommandText = UpdateSql;
72  command.Parameters.Add(factory.CreateParameter("@number", version.VersionNumber));
73  command.Prepare();
74  log.SqlExecute(command.CommandText, command.Parameters);
75  command.ExecuteNonQuery();
76  }
77  catch (Exception e)
78  {
79  log.VersionTableUpdateError(e);
80  }
81  finally
82  {
83  if (connection != null && connection.State == ConnectionState.Open)
84  connection.Close();
85  }
86 
87  log.SchemaUpdated(version.VersionText);
88  }
abstract void Close()
var e
Definition: bootstrap.min.js:6
IDbConnection CreateConnection()
IDbDataParameter CreateParameter(string name, object value)
var version
Definition: bootstrap.js:13
IDbCommand CreateCommand()

Member Data Documentation

const string Ntp.Data.Schema.VersionController.CreateSql = "CREATE TABLE version (number INT NOT NULL PRIMARY KEY);"
private

Definition at line 38 of file VersionController.cs.

readonly ISqlFactory Ntp.Data.Schema.VersionController.factory
private

Definition at line 42 of file VersionController.cs.

const string Ntp.Data.Schema.VersionController.InsertSql = "INSERT INTO version (number) VALUES (0);"
private

Definition at line 41 of file VersionController.cs.

readonly LogBase Ntp.Data.Schema.VersionController.log
private

Definition at line 43 of file VersionController.cs.

const string Ntp.Data.Schema.VersionController.SelectSql = "SELECT number FROM version;"
private

Definition at line 39 of file VersionController.cs.

const string Ntp.Data.Schema.VersionController.UpdateSql = "UPDATE version SET number=@number;"
private

Definition at line 40 of file VersionController.cs.


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