Dreamine.Database.Oracle 1.0.1
Dreamine.Database.Oracle 데이터베이스 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
OracleDatabaseProvider.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.Database.Abstractions;
2using Dreamine.Database.Core.Mapping;
3using Dreamine.Database.Core.Providers;
4using Oracle.ManagedDataAccess.Client;
5using System.Data;
6
8
17public sealed class OracleDatabaseProvider : DatabaseProviderBase
18{
51 public OracleDatabaseProvider(string connectionString)
52 : base(connectionString)
53 {
54 }
55
64 public override DatabaseProviderKind Kind => DatabaseProviderKind.Oracle;
65
74 protected override string ParameterPrefix => ":";
75
116 public override bool IsTableExists(string tableName)
117 {
118 ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
119
120 const string sql = """
121 SELECT COUNT(1)
122 FROM user_tables
123 WHERE table_name = UPPER(:TableName)
124 """;
125
126 return ExecuteScalar<decimal>(sql, new { TableName = tableName }) > 0;
127 }
128
177 public override async Task<bool> IsTableExistsAsync(
178 string tableName,
179 CancellationToken cancellationToken = default)
180 {
181 ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
182
183 const string sql = """
184 SELECT COUNT(1)
185 FROM user_tables
186 WHERE table_name = UPPER(:TableName)
187 """;
188
189 var count = await ExecuteScalarAsync<decimal>(sql, new { TableName = tableName }, cancellationToken)
190 .ConfigureAwait(false);
191 return count > 0;
192 }
193
210 protected override IDbConnection CreateConnection()
211 {
212 return new OracleConnection(ConnectionString);
213 }
214
255 protected override string QuoteIdentifier(string identifier)
256 {
257 ArgumentException.ThrowIfNullOrWhiteSpace(identifier);
258 return "\"" + identifier.Replace("\"", "\"\"", StringComparison.Ordinal).ToUpperInvariant() + "\"";
259 }
260
285 protected override string BuildCreateTableSql(DatabaseEntityMap map)
286 {
287 var columns = map.Properties.Select(property =>
288 {
289 var sql = $"{QuoteIdentifier(property.ColumnName)} {GetSqlType(property)}";
290 if (property.IsKey)
291 {
292 sql += property.IsGenerated ? " GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY" : " PRIMARY KEY";
293 }
294
295 return sql;
296 });
297
298 return $"CREATE TABLE {QuoteIdentifier(map.TableName)} ({string.Join(", ", columns)})";
299 }
300
325 protected override string GetSqlType(DatabasePropertyMap property)
326 {
327 var type = property.PropertyType;
328
329 if (type == typeof(bool) ||
330 type == typeof(byte) ||
331 type == typeof(short) ||
332 type == typeof(int) ||
333 type == typeof(long))
334 {
335 return "NUMBER";
336 }
337
338 if (type == typeof(float) ||
339 type == typeof(double) ||
340 type == typeof(decimal))
341 {
342 return "NUMBER(18, 4)";
343 }
344
345 if (type == typeof(DateTime) || type == typeof(DateTimeOffset))
346 {
347 return "TIMESTAMP";
348 }
349
350 if (type == typeof(byte[]))
351 {
352 return "BLOB";
353 }
354
355 return "NVARCHAR2(2000)";
356 }
357}
override string BuildCreateTableSql(DatabaseEntityMap map)
override async Task< bool > IsTableExistsAsync(string tableName, CancellationToken cancellationToken=default)
override string GetSqlType(DatabasePropertyMap property)