예제 #1
0
        /// <summary>
        /// Get the list of primary key names in the table
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="metadataAccess"></param>
        /// <returns>LIst of primary keys for the specified table</returns>
        private List <string> GetTablePrimaryKeys(string tableName, OleDbMetadataAccess metadataAccess)
        {
            List <string> primaryKeys = new List <string>();
            //get the list of indexes for the table
            DataTable indexList = metadataAccess.GetTableIndexInformation(tableName);

            //check that the table even has an index
            if (indexList != null && indexList.Rows.Count != 0)
            {
                //find the primary key values and add them to the list
                foreach (DataRow index in indexList.Rows)
                {
                    if (Convert.ToBoolean(index["PRIMARY_KEY"]))
                    {
                        primaryKeys.Add(index["COLUMN_NAME"].ToString());
                    }
                }
            }

            return(primaryKeys);
        }
예제 #2
0
        /// <summary>
        /// Retrieve a specific definition for an object including all property definitions
        /// TODO: Add examples for GetObjectProperties, and GetPropertyRelations
        /// </summary>
        /// <param name="objectName">Name of the object to retrieve the definition for</param>
        /// <param name="shouldGetProperties">Defines whether or not to get a list of properties associated with each object</param>
        /// <param name="shouldGetRelations">Defines whether or not to get a list of relations with each object such as foreign keys</param>
        /// <returns>Definition of the requested object</returns>
        public IObjectDefinition RetrieveObjectDefinition(string objectName,
                                                          bool shouldGetProperties = false, bool shouldGetRelations = false)
        {
            IObjectDefinition objectDefinition = null;

            //log the trace for the method execution
            using (new LogMethodExecution(
                       Globals.ConnectorName, "GetObjectDefinition"))
            {
                //retrieve the table's index information
                DataTable tableIndexDefinition =
                    _metadataAccess.GetTableIndexInformation(objectName);
                //retrieve the table's column information
                DataTable columnDefinitions =
                    _metadataAccess.GetColumnDefinitions(objectName);
                //set the object definition
                objectDefinition =
                    SetObjectDefinition(tableIndexDefinition, columnDefinitions);
            }

            return(objectDefinition);
        }
예제 #3
0
        /// <summary>
        /// Get a specific Object's definition, this includes any attributes and
        /// supporting object properties.
        /// In this case retrieve the table definition along with any columns and
        /// the definition of each.
        /// </summary>
        /// <param name="methodInput">Method Input which includes an 'ObjectName'
        /// property to determine the object to retrieve the definition.</param>
        /// <returns>Method Result, which will either include error information or the
        /// Object Definition of the 'ObjectName' specified in the
        /// MethodInput properties.</returns>
        public MethodResult GetObjectDefinition(MethodInput methodInput)
        {
            //Create a new instance of the method result to fill with
            //meta data information
            MethodResult result = null;

            //Create a new instance of the metadata access class and pass the
            //data access instance along with it
            OleDbMetadataAccess metadataAccess = new OleDbMetadataAccess(_dataAccess);

            // 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, "GetObjectDefinition"))
            {
                //Get the name of the object in the input properties.
                string objectName =
                    GetPropertyValueName("ObjectName", methodInput.Input.Properties);

                //Use the metadata access to get the
                //definitions for each of the columns in the table.
                DataTable tableColumnDefinitions =
                    metadataAccess.GetColumnDefinitions(objectName);

                //Using the meta data access get the definition for the
                //table indexes (primary and foreign keys)
                DataTable tableIndexDefinition =
                    metadataAccess.GetTableIndexInformation(objectName);

                //Check that both sets of data have been returned
                //from the meta data access layer
                if ((tableColumnDefinitions != null &&
                     tableColumnDefinitions.Rows.Count != 0) &&
                    (tableIndexDefinition != null &&
                     tableIndexDefinition.Rows.Count != 0))
                {
                    //Create a new replication service object
                    RSObjectDefinition rsObjectDefinition = new RSObjectDefinition()
                    {
                        Name = objectName,
                        RSPropertyDefinitions = new List <RSPropertyDefinition>()
                    };

                    //If this is the change history table set the hidden attribute.
                    //Note: this is how to prevent an object from being replicated.
                    rsObjectDefinition.Hidden = objectName == Globals.ChangeHistoryTableName;

                    List <string> tablePrimaryKeys =
                        GetTablePrimaryKeys(rsObjectDefinition.Name, metadataAccess);

                    //Parse each column returned from the column definitions.
                    //For each column, add a new replication service property definition
                    //to the newly created replication service object definition.
                    foreach (DataRow columnDefinition in tableColumnDefinitions.Rows)
                    {
                        //Process the column definition and set it to the
                        //resplication service property definition.
                        RSPropertyDefinition rsPropertyDefinition =
                            ProcessColumnDefinition(columnDefinition);

                        //Check if this is the default last modified column and
                        //set the object property.
                        if (rsPropertyDefinition.Name == LastModifiedFieldName)
                        {
                            rsObjectDefinition.ModificationDateFullName =
                                rsPropertyDefinition.Name;
                        }

                        //Check if the property is a primary key value.
                        rsPropertyDefinition.InPrimaryKey =
                            tablePrimaryKeys.Contains(rsPropertyDefinition.Name);

                        //Add the property definition to the object definition.
                        rsObjectDefinition.RSPropertyDefinitions.Add(rsPropertyDefinition);
                    }

                    //Convert the replication service object definition to a Data Entity.
                    //Set the result return value to the
                    //replication service object definition.
                    //Set the result Success to true.
                    result = new MethodResult
                    {
                        Success = true, Return = rsObjectDefinition.ToDataEntity()
                    };
                }
                else
                {
                    //Set the proper error information in the method result in the
                    //event of a null table or column definitions.
                    result = SetErrorMethodResult(
                        ErrorCodes.NoObjectsFound.Number,
                        ErrorCodes.NoObjectsFound.Description);
                }
            }

            //Return the method result.
            return(result);
        }