🥳 fix: Oracle分表判断是否存在及示例

This commit is contained in:
宋家乐 2023-04-27 16:40:23 +08:00
parent 04237772bf
commit 3bf980a759
2 changed files with 39 additions and 0 deletions

View File

@ -12,6 +12,7 @@ namespace ShardingCore.TableExists
private readonly SqliteTableEnsureManager _tem_sqlite; private readonly SqliteTableEnsureManager _tem_sqlite;
private readonly PostgreSqlTableEnsureManager _tem_pgsql; private readonly PostgreSqlTableEnsureManager _tem_pgsql;
private readonly SqlServerTableEnsureManager _tem_mssql; private readonly SqlServerTableEnsureManager _tem_mssql;
private readonly OracleTableEnsureManager _tem_oracle;
public GuessTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory) public GuessTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory)
{ {
@ -19,6 +20,7 @@ namespace ShardingCore.TableExists
_tem_sqlite = new SqliteTableEnsureManager(routeTailFactory); _tem_sqlite = new SqliteTableEnsureManager(routeTailFactory);
_tem_pgsql = new PostgreSqlTableEnsureManager(routeTailFactory); _tem_pgsql = new PostgreSqlTableEnsureManager(routeTailFactory);
_tem_mssql = new SqlServerTableEnsureManager(routeTailFactory); _tem_mssql = new SqlServerTableEnsureManager(routeTailFactory);
_tem_oracle = new OracleTableEnsureManager(routeTailFactory);
} }
public override ISet<string> DoGetExistTables(DbConnection connection, string dataSourceName) public override ISet<string> DoGetExistTables(DbConnection connection, string dataSourceName)
@ -46,6 +48,10 @@ namespace ShardingCore.TableExists
result = _tem_mssql.DoGetExistTables(connection, dataSourceName); result = _tem_mssql.DoGetExistTables(connection, dataSourceName);
break; break;
case "Oracle.ManagedDataAccess.Client.OracleConnection":
result = _tem_oracle.DoGetExistTables(connection, dataSourceName);
break;
default: default:
break; break;
} }

View File

@ -0,0 +1,33 @@
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.TableExists.Abstractions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace ShardingCore.TableExists
{
public class OracleTableEnsureManager : AbstractTableEnsureManager
{
private const string Tables = "Tables";
private const string TABLE_NAME = "TABLE_NAME";
public OracleTableEnsureManager(IRouteTailFactory routeTailFactory) : base(routeTailFactory)
{
}
public override ISet<string> DoGetExistTables(DbConnection connection, string dataSourceName)
{
ISet<string> result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
using (DataTable dataTable = connection.GetSchema(Tables))
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
string schema = dataTable.Rows[i][TABLE_NAME]?.ToString();
result.Add(schema);
}
}
return result;
}
}
}