Ejemplo n.º 1
0
 public DataProviderTableAccessor(TableType tableType)
     : base()
 {
     TableType = tableType;
     _providerInvariantName = TableType.DataSource.ProviderInvariantName;
     _connectionString = TableType.DataSource.ConnectionString;
 }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
 public TableTypeItem(TableType tableType)
 {
     CachedType = tableType;
     CreateTimestamp = Stopwatch.GetTimestamp();
 }
Ejemplo n.º 4
0
 public DataProviderHelper(TableType tableType)
     : this(tableType.DataSource.ProviderInvariantName, tableType.DataSource.ConnectionString)
 {
 }
Ejemplo n.º 5
0
 public void SetFieldsFromTableType(TableType tableType)
 {
     FieldNames.Clear();
     foreach (RowType.TypeInfo ti in tableType.TableRowType.Fields)
         FieldNames.Add(ti.ProviderColumnName);
 }
Ejemplo n.º 6
0
 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;
     }
 }