public DataProviderTableAccessor(TableType tableType) : base() { TableType = tableType; _providerInvariantName = TableType.DataSource.ProviderInvariantName; _connectionString = TableType.DataSource.ConnectionString; }
public TableType GetTableType(String prefix, String[] identifierPart, bool lookupCache) { TableTypeItem tti; string qualifiedName = MakeQualifiedName(identifierPart); string key = String.Format("{0}!{1}", prefix, qualifiedName); lock (_catalogCache) { if (lookupCache && _catalogCache.TryGetValue(key, out tti) && tti.IsActual()) return tti.GetTableType(); DataSourceInfo dsi = ResolveTable(prefix, identifierPart); if (dsi == null) throw new ESQLException(Properties.Resources.UnknownDataSource, qualifiedName); TableType tableType; switch (dsi.TableAccessor) { case AcessorType.DataProvider: tableType = GetDataProviderTableType(dsi, GetProviderTableName(dsi, identifierPart)); break; case AcessorType.XMLFile: { string fullPath = GetFilePath(qualifiedName, "xml"); tableType = new TableType(qualifiedName, fullPath, dsi, null); } break; case AcessorType.DataTable: { string fullPath = GetFilePath(qualifiedName, "xml"); tableType = new TableType(qualifiedName, fullPath, dsi, null); } break; case AcessorType.FlatFile: { string fullPath = GetFilePath(qualifiedName, "txt"); tableType = new TableType(qualifiedName, fullPath, dsi, null); } break; default: throw new NotImplementedException(); } if (tableType == null) throw new ESQLException(Properties.Resources.TableDoesNotExists, qualifiedName); if (dsi.TableAccessor == AcessorType.DataProvider && lookupCache) _catalogCache.Add(key, new TableTypeItem(tableType)); return tableType; } }
public TableTypeItem(TableType tableType) { CachedType = tableType; CreateTimestamp = Stopwatch.GetTimestamp(); }
public DataProviderHelper(TableType tableType) : this(tableType.DataSource.ProviderInvariantName, tableType.DataSource.ConnectionString) { }
public void SetFieldsFromTableType(TableType tableType) { FieldNames.Clear(); foreach (RowType.TypeInfo ti in tableType.TableRowType.Fields) FieldNames.Add(ti.ProviderColumnName); }
public int GetTableEstimate(TableType tableType, int threshold) { TableEstimate tableEstimate; lock (estimate) if (!estimate.TryGetValue(tableType, out tableEstimate)) { tableEstimate = new TableEstimate(); estimate.Add(tableType, tableEstimate); } lock (tableEstimate) { if (tableEstimate.count == tableEstimate.threshold || tableEstimate.threshold < threshold) { DataProviderHelper helper = new DataProviderHelper(tableType); DbConnection connection = DataProviderHelper.CreateDbConnection(tableType.DataSource.ProviderInvariantName); connection.ConnectionString = tableType.DataSource.ConnectionString; connection.Open(); try { DbCommand command = connection.CreateCommand(); command.CommandText = helper.GetEstimateRowCountQuery(tableType.ToString(helper), threshold); tableEstimate.count = Convert.ToInt32(command.ExecuteScalar()); tableEstimate.threshold = threshold; } finally { connection.Close(); } } return tableEstimate.count; } }