NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Data.Provider.PostgreSqlFactory Class Reference
Inheritance diagram for Ntp.Data.Provider.PostgreSqlFactory:
Collaboration diagram for Ntp.Data.Provider.PostgreSqlFactory:

Public Member Functions

override IDbCommand CreateCommand ()
 
override IDbConnection CreateConnection ()
 
override void CreateDatabase ()
 
override IDbConnection CreateGenericConnection ()
 
override IDbDataParameter CreateParameter (string name, object value)
 
override string DateAddMinutes (string dateColumn, string minuteColumn)
 
override string PrepareCheckTableSql (string table)
 
override string PrepareCreateTableSql (string sql)
 
override string PrepareInsertSql (string sql)
 
override string PrepareSql (string sql)
 

Package Functions

 PostgreSqlFactory ()
 

Static Private Member Functions

static string BuildConnectionString (bool includeName=true)
 

Private Attributes

const string CheckTableSql
 
const string CreateDatabaseSql1
 
const string CreateDatabaseSql2
 

Additional Inherited Members

- Static Public Member Functions inherited from Ntp.Data.Provider.SqlDatabaseFactory
static void Initialize (IDatabaseConfiguration factoryConfiguration)
 
- Static Protected Attributes inherited from Ntp.Data.Provider.SqlDatabaseFactory
static IDatabaseConfiguration Config
 
- Properties inherited from Ntp.Data.Provider.SqlDatabaseFactory
static SqlDatabaseFactory Instance [get]
 

Detailed Description

Definition at line 50 of file PostgreSqlFactory.cs.

Constructor & Destructor Documentation

Ntp.Data.Provider.PostgreSqlFactory.PostgreSqlFactory ( )
inlinepackage

Definition at line 52 of file PostgreSqlFactory.cs.

53  {
54  }

Member Function Documentation

static string Ntp.Data.Provider.PostgreSqlFactory.BuildConnectionString ( bool  includeName = true)
inlinestaticprivate

Definition at line 139 of file PostgreSqlFactory.cs.

References b.

140  {
141  if (Config.ConnectionString != null)
142  return Config.ConnectionString;
143 
144  var b = new StringBuilder();
145  b.Append($"Server={Config.Host};");
146 
147  if (Config.Port != null)
148  b.Append($"Port={Config.Port};");
149 
150  b.Append(includeName ? $"Database={Config.Name};" : @"Database=postgres;");
151 
152  b.Append($"User Id={Config.User};");
153  b.Append($"Password={Config.Pass};");
154 
155  if (Config.ConnectionTimeout.HasValue)
156  b.Append($"Timeout={Config.ConnectionTimeout.Value};");
157 
158  b.Append(Config.EnableSsl ? @"SslMode=Require;" : @"SslMode=Disable;");
159 
160  if (Config.Protocol.HasValue)
161  b.Append($"Protocol={Config.Protocol.Value};");
162 
163  return b.ToString();
164  }
static IDatabaseConfiguration Config
var b
Definition: bootstrap.min.js:6
override IDbCommand Ntp.Data.Provider.PostgreSqlFactory.CreateCommand ( )
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 68 of file PostgreSqlFactory.cs.

69  {
70  return new NpgsqlCommand();
71  }
override IDbConnection Ntp.Data.Provider.PostgreSqlFactory.CreateConnection ( )
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 73 of file PostgreSqlFactory.cs.

74  {
75  return new NpgsqlConnection(BuildConnectionString());
76  }
static string BuildConnectionString(bool includeName=true)
override void Ntp.Data.Provider.PostgreSqlFactory.CreateDatabase ( )
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 79 of file PostgreSqlFactory.cs.

80  {
81  var connection = CreateGenericConnection();
82  connection.Open();
83 
84  var command = Instance.CreateCommand();
85  command.Connection = connection;
86  command.CommandText = string.Format(CreateDatabaseSql1, Config.Name);
87  command.Prepare();
88  int count = Convert.ToInt32(command.ExecuteScalar());
89 
90  if (count == 0)
91  {
92  command.CommandText = string.Format(CreateDatabaseSql2, Config.Name);
93  command.Prepare();
94  command.ExecuteNonQuery();
95  }
96 
97  connection.Close();
98  }
abstract IDbCommand CreateCommand()
static SqlDatabaseFactory Instance
static IDatabaseConfiguration Config
override IDbConnection CreateGenericConnection()
override IDbConnection Ntp.Data.Provider.PostgreSqlFactory.CreateGenericConnection ( )
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 100 of file PostgreSqlFactory.cs.

101  {
102  return new NpgsqlConnection(BuildConnectionString(false));
103  }
static string BuildConnectionString(bool includeName=true)
override IDbDataParameter Ntp.Data.Provider.PostgreSqlFactory.CreateParameter ( string  name,
object  value 
)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 105 of file PostgreSqlFactory.cs.

106  {
107  return new NpgsqlParameter(name, value);
108  }
override string Ntp.Data.Provider.PostgreSqlFactory.DateAddMinutes ( string  dateColumn,
string  minuteColumn 
)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 110 of file PostgreSqlFactory.cs.

111  {
112  return $"{dateColumn} - {minuteColumn} * INTERVAL '1 minute'";
113  }
override string Ntp.Data.Provider.PostgreSqlFactory.PrepareCheckTableSql ( string  table)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 115 of file PostgreSqlFactory.cs.

116  {
117  return PrepareSql(string.Format(CheckTableSql, Config.Name, table));
118  }
override string PrepareSql(string sql)
static IDatabaseConfiguration Config
override string Ntp.Data.Provider.PostgreSqlFactory.PrepareCreateTableSql ( string  sql)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 120 of file PostgreSqlFactory.cs.

121  {
122  string sql2 = sql.
123  Replace("UNIQUE KEY", "UNIQUE").
124  Replace("BIT(1)", "BOOL");
125 
126  return PrepareSql(string.Format(sql2, "SERIAL", string.Empty));
127  }
override string PrepareSql(string sql)
override string Ntp.Data.Provider.PostgreSqlFactory.PrepareInsertSql ( string  sql)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 129 of file PostgreSqlFactory.cs.

130  {
131  return PrepareSql(string.Format(sql, "SELECT LASTVAL();"));
132  }
override string PrepareSql(string sql)
override string Ntp.Data.Provider.PostgreSqlFactory.PrepareSql ( string  sql)
inlinevirtual

Implements Ntp.Data.Provider.SqlDatabaseFactory.

Definition at line 134 of file PostgreSqlFactory.cs.

135  {
136  return sql.Replace('[', '\"').Replace(']', '\"');
137  }

Member Data Documentation

const string Ntp.Data.Provider.PostgreSqlFactory.CheckTableSql
private
Initial value:
=
"SELECT * " +
"FROM information_schema.tables " +
"WHERE table_catalog = lower('{0}') " +
"AND table_name = lower('{1}');"

Definition at line 62 of file PostgreSqlFactory.cs.

const string Ntp.Data.Provider.PostgreSqlFactory.CreateDatabaseSql1
private
Initial value:
=
"SELECT COUNT(*) FROM pg_database WHERE datname = lower('{0}');"

Definition at line 56 of file PostgreSqlFactory.cs.

const string Ntp.Data.Provider.PostgreSqlFactory.CreateDatabaseSql2
private
Initial value:
=
"CREATE DATABASE {0};"

Definition at line 59 of file PostgreSqlFactory.cs.


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