/// <summary> /// When implemented by a class, fetches data from a data store using the specified query statements. /// </summary> /// <param name="selects">An array of statements to obtain data from the data store.</param> /// <returns> /// Data retrieved from the data store. /// </returns> public SelectedData SelectData(params SelectStatement[] selects) { var appSelects = new List <SelectStatement>(selects.Length); var ssSelects = new List <SelectStatement>(selects.Length); foreach (var stm in selects) { if (isSecondStorageTable(stm.TableName)) { ssSelects.Add(stm); } else { appSelects.Add(stm); } } var resultSet = new List <SelectStatementResult>(); if (appSelects.Count > 0) { resultSet.AddRange(appDataLayer.SelectData(appSelects.ToArray()).ResultSet); } if (ssSelects.Count > 0) { openSecondStorage(); resultSet.AddRange(secondStorageDataLayer.SelectData(ssSelects.ToArray()).ResultSet); } return(new SelectedData(resultSet.ToArray())); }
public SelectedData SelectData(params SelectStatement[] selects) { var isExternals = selects.Select(stmt => IsTempDatabaseTable(stmt.Table.Name)).ToList(); List <SelectStatement> mainSelects = new List <SelectStatement>(selects.Length); List <SelectStatement> externalSelects = new List <SelectStatement>(selects.Length); for (int i = 0; i < isExternals.Count; ++i) { (isExternals[i] ? externalSelects : mainSelects).Add(selects[i]); } var externalResults = (externalSelects.Count == 0 ? Enumerable.Empty <SelectStatementResult>() : tempDataLayer.SelectData(externalSelects.ToArray()).ResultSet).GetEnumerator(); var mainResults = (mainSelects.Count == 0 ? Enumerable.Empty <SelectStatementResult>() : legacyDataLayer.SelectData(mainSelects.ToArray()).ResultSet).GetEnumerator(); SelectStatementResult[] results = new SelectStatementResult[isExternals.Count]; for (int i = 0; i < results.Length; ++i) { var enumerator = isExternals[i] ? externalResults : mainResults; enumerator.MoveNext(); results[i] = enumerator.Current; } return(new SelectedData(results)); }