/// <summary> /// Retrieves a list of column definitions for the specified table name. /// </summary> /// <param name="tableName">Name of the table to retrieve the properties for</param> /// <returns></returns> private List <IPropertyDefinition> GetTableProperties(string tableName) { List <IPropertyDefinition> properties = new List <IPropertyDefinition>(); //retrieve the table's index information DataTable tableIndexDefinition = _metadataAccess.GetTableIndexInformation(tableName); //retrieve the table's column information DataTable columnDefinitions = _metadataAccess.GetColumnDefinitions(tableName); //parse through each of the table indexes and set the primary key value List <string> primaryKeys = (from DataRow tableIndex in tableIndexDefinition.Rows where Convert.ToBoolean(tableIndex["PRIMARY_KEY"]) select tableIndex["COLUMN_NAME"].ToString()).ToList(); //parse through the column information and set each property definition foreach (DataRow columnDefinition in columnDefinitions.Rows) { //get the property defintion using the column information var propertyDefinition = SetPropertyDefinition(columnDefinition, tableIndexDefinition, primaryKeys.Contains( columnDefinition["COLUMN_NAME"].ToString())); properties.Add(propertyDefinition); } return(properties); }
/// <summary> /// The Connector will perform the query and pass the results back in an /// enumerable set of ResultEntities. Each of which could be a set of objects /// </summary> /// <param name="query"></param> /// <returns></returns> public IEnumerable <DataEntity> ExecuteQuery(Query query) { // Use LogMethodExecution to add entry and exit tracing to a method. // When wrapped in a using statement, the exit point // is written during garbage collection. using (new LogMethodExecution(Globals.ConnectorName, "ExecuteQuery")) { //set the enumerated list of data entities to null IEnumerable <DataEntity> dataEntities = null; try { //Verify that a root entity is decalred and that return data is requested in the property list. if (string.IsNullOrWhiteSpace(query.RootEntity.ObjectDefinitionFullName)) { //this message can be anything that is meaningfull to the user string message = string.Format(ErrorCodes.InvalidQueryObject.Description, query.RootEntity.PropertyList.Count); //Log that no query has been filled out Logger.Write(Logger.Severity.Error, "Execute Query Failed", message); throw new ArgumentException(message); } //retrieve the name of the root entity string tableName = query.RootEntity.ObjectDefinitionFullName; //retrieve the list of column definitions for proper data type convertion DataTable columnDefinitions = _metadataAccess.GetColumnDefinitions(tableName); columnDefinitions.TableName = tableName; //Create a new instance of the query builder and send the query information along SqlQueryBuilder queryBuilder = new SqlQueryBuilder(query, columnDefinitions); //Convert the query builder to a string value string queryString = queryBuilder.ToString(); //Execute the query and retrieve the enumerated results dataEntities = _dataAccess.Execute(query.RootEntity.ObjectDefinitionFullName, queryString, queryBuilder.RelatedForeignKeys); if (dataEntities != null) { //Since the dataEntities is an enumerated list it will need to be forced to fire the execute method foreach (var entity in dataEntities) { break; } } } catch (FatalErrorException) { throw; } catch (Exception exception) { //this message may be anything that is meaningful to the user string message = string.Format("{0} {1}", ErrorCodes.GenericConnectorError, exception.Message); //Log the exception Logger.Write(Logger.Severity.Error, message, exception.StackTrace); //All exeptions that occur in the query execution must be returned as an InvalidQueryException throw new InvalidExecuteQueryException(message); } return(dataEntities); } }