Пример #1
0
 public static TableLink LoadTableLink(IDataLayer dbConnection, IPrimaryKeyCreator primaryKeyCreator,
   FieldBlank[] fields, IndexBlank[] indicies,
   string database, string select, string conditionWithoutWhere, params DbParameter[] conditionParameters)
 {
   return LoadTableLink(dbConnection, primaryKeyCreator, fields, indicies, new LinkConstraint[0],
     database, select, conditionWithoutWhere, conditionParameters);
 }
Пример #2
0
 public static TableLink Load(IDataLayer dbConnection, FieldBlank[] fields, IndexBlank[] indices,
   string database, string select, string conditionWithoutWhere, params DbParameter[] conditionParameters)
 {
   return new TableLink(
     new ReadonlyTableProvider(
       dbConnection.GetTable(database,
         StringHlp.IsEmpty(conditionWithoutWhere) ? select : string.Format("{0} Where {1}", select, conditionWithoutWhere),
         conditionParameters
       )
     ), null, fields, indices
   );
 }
Пример #3
0
    public static TableLink LoadTableLink(IDataLayer dbConnection, IPrimaryKeyCreator primaryKeyCreator,
      FieldBlank[] fields, IndexBlank[] indicies, LinkConstraint[] constraints,
      string database, string select, string conditionWithoutWhere, params DbParameter[] conditionParameters)
    {
      TableLink link = new TableLink(
        new DatabaseTableProvider(dbConnection, database, select, conditionWithoutWhere, conditionParameters),
        primaryKeyCreator, fields, indicies, constraints);

      if (primaryKeyCreator != null)
        link.Table.PrimaryKey = new DataColumn[] { link.Table.Columns[0] };

      return link;
    }
Пример #4
0
    public TableLink(ITableProvider tableProvider, IPrimaryKeyCreator primaryKeyCreator,
      FieldBlank[] fields, IndexBlank[] indicies, params LinkConstraint[] constraints)
    {
      this.tableProvider = tableProvider;

      if (tableProvider.Table.Columns.Count != fields.Length)
        throw new Exception("Ошибка создания TableLink: число колонок таблицы не равно числу полей");

      this.primaryKeyCreator = primaryKeyCreator;
      this.indicies = indicies;
      this.constraints = constraints;

      Dictionary<string, bool> isIndicesPartByName = new Dictionary<string, bool>();
      foreach (IndexBlank index in indicies)
      {
        if (index.IsMultiIndex)
          multiIndicesByName[index.IndexName] = new Dictionary<UniversalKey, List<RowLink>>();
        else
          singleIndicesByName[index.IndexName] = new Dictionary<UniversalKey, RowLink>();

        foreach (string fieldName in index.IndexColumns)
          isIndicesPartByName[fieldName] = true;
          //fieldsByName[fieldName].IsIndicesPart = true;
      }

      int columnIndex = 0;
      foreach (FieldBlank fieldBlank in fields)
      {
        fieldsByName[fieldBlank.FieldName] = new FieldLink(fieldBlank, columnIndex, 
          DictionaryHlp.GetValueOrDefault(isIndicesPartByName, fieldBlank.FieldName));
        columnIndex++;
      }

      foreach (DataRow dataRow in tableProvider.Table.Rows)
      {
        if (dataRow.RowState != DataRowState.Deleted)
          CreateIndexForRow(new RowLink(this, dataRow));
      }
    }
Пример #5
0
    //public SourceTableProvider(TableLink sourceTableLink, RowLink[] sourceRows)
    //{
    //  this.sourceTableLink = sourceTableLink;

    //  this.table = sourceTableLink.Table.Clone();

    //  foreach (RowLink sourceRow in sourceRows)
    //  {
    //    DataRow newRow = table.NewRow();
    //    for (int i = 0; i < table.Columns.Count; ++i)
    //    {
    //      newRow[i] = sourceRow.DataRow[i];
    //    }
    //    table.Rows.Add(newRow);
    //  }

    //  table.AcceptChanges();
    //}

    public SourceTableProvider(TableLink sourceTableLink, IndexBlank index, params object[] keyParts) :
      this(sourceTableLink, sourceTableLink.FindRows(index, keyParts))
    {
    }
Пример #6
0
 public TableLink(DataTable table, FieldBlank[] fields, IndexBlank[] indices) :
   this(new ReadonlyTableProvider(table), null, fields, indices)
 {
 }
Пример #7
0
    public RowLink[] FindRows(IndexBlank index, params object[] keyParts)
    {
      if (index.IsMultiIndex)
        return FindRows((MultiIndexBlank)index, keyParts);

      RowLink row = FindRow((SingleIndexBlank)index, keyParts);
      return row != null ? new RowLink[] { row } : new RowLink[0];
    }
Пример #8
0
 public ICollection<UniversalKey> KeysForIndex(IndexBlank index)
 {
   if (index.IsMultiIndex)
     return multiIndicesByName[index.IndexName].Keys;
   else
     return singleIndicesByName[index.IndexName].Keys;
 }
Пример #9
0
 public TableLink(IDataLayer dbConnection, string database, DataTable table, string updateQuery, 
   IPrimaryKeyCreator primaryKeyCreator, FieldBlank[] fields, IndexBlank[] indicies, params LinkConstraint[] constraints) :
   this(new DatabaseTableProvider(dbConnection, database, updateQuery, table),
     primaryKeyCreator, fields, indicies, constraints)
 {
 }