Пример #1
0
        /**
         * IntelliText constructor. It receives:
         *
         * @param Initial setting configuration
         */
        public PreferenceIntelliText(TextSettings settings)
        {
            // we have all the information in the settings
            Settings = settings;

            // create the template catalog constructor
            TemplateConstructor = new PreferenceTemplateConstructor(Settings);

            // store the object data provider
            Data = IntelliText.DataProviders.PreferenceDataProviderFactory.getDataProvider(settings.DataProvider, settings.PathDataProvider);

            // create the render
            Render = IntelliText.Render.PreferenceRenderFactory.getRender(settings.Render);
        }
Пример #2
0
        /// <summary>
        /// Loads the tables from the database.
        /// </summary>
        /// <param name="dataProvider">The data provider.</param>
        /// <returns>
        /// The loaded collections.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">dataProvider;dataProvider cannot be null</exception>
        public static Collection<Table> LoadFromDatabase(IObjectDataProvider dataProvider)
        {
            Collection<Table> result = new Collection<Table>();

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader reader = dataProvider.LoadTableData())
            {
                while (reader.Read())
                {
                    // Read the result data
                    string tableCatalog = reader.GetString(0);
                    string tableSchema = reader.GetString(1);
                    string tableName = reader.GetString(2);

                    // Build the new table
                    Table table = new Table(tableCatalog, tableSchema, tableName);

                    result.Add(table);
                }
            }

            // Populate additional schema objects
            foreach (Table table in result)
            {
                Column.PopulateColumns(table, dataProvider);
                Constraint.PopulateUniqueConstraints(table, dataProvider);
            }

            Constraint.PopulateReferentialConstraints(result, dataProvider);

            return result;
        }
Пример #3
0
        /// <summary>
        /// Loads the columns from the database for a specific table.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="dataProvider">The data provider.</param>
        /// <exception cref="System.ArgumentNullException">
        /// table;table cannot be null
        /// or
        /// dataProvider;dataProvider cannot be null
        /// </exception>
        public static void PopulateColumns(Table table, IObjectDataProvider dataProvider)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table", "table cannot be null");
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader result = dataProvider.LoadColumnDataForTable(table))
            {
                while (result.Read())
                {
                    // Read the result data
                    string name = (string)result["COLUMN_NAME"];
                    int ordinalPosition = (int)result["ORDINAL_POSITION"];
                    string columnDefault = result.GetNullableString("COLUMN_DEFAULT");
                    bool isNullable = ((string)result["IS_NULLABLE"]).Equals("NO") ? false : true;

                    // Read the result data for the routine's return type
                    string dataType = (string)result["DATA_TYPE"];
                    int? characterMaximumLength = result.GetNullable<int>("CHARACTER_MAXIMUM_LENGTH");
                    int? numericPrecision = result.GetNullable<int>("NUMERIC_PRECISION");
                    int? numericPrecisionRadix = result.GetNullable<int>("NUMERIC_PRECISION_RADIX");
                    int? numericScale = result.GetNullable<int>("NUMERIC_SCALE");
                    int? dateTimePrecision = result.GetNullable<int>("DATETIME_PRECISION");
                    string characterSetName = result.GetNullableString("CHARACTER_SET_NAME");
                    string collationName = result.GetNullableString("COLLATION_NAME");

                    // Build the proper data structure for return type
                    SqlType type = new SqlType(dataType, characterMaximumLength, characterSetName, collationName, numericPrecision, numericPrecisionRadix, numericScale, dateTimePrecision);

                    // Build the new column
                    table.Columns.Add(new Column(name, type, ordinalPosition, columnDefault, isNullable));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Loads the routines from the database.
        /// </summary>
        /// <param name="dataProvider">The data provider.</param>
        /// <returns>
        /// The loaded routines.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">dataProvider;dataProvider cannot be null</exception>
        public static Collection<Routine> LoadFromDatabase(IObjectDataProvider dataProvider)
        {
            Collection<Routine> result = new Collection<Routine>();

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader reader = dataProvider.LoadRoutineData())
            {
                while (reader.Read())
                {
                    // Read the result data for the routine
                    string catalog = (string)reader["SPECIFIC_CATALOG"];
                    string schema = (string)reader["SPECIFIC_SCHEMA"];
                    string name = (string)reader["SPECIFIC_NAME"];
                    string routineTypeAsText = (string)reader["ROUTINE_TYPE"];
                    string definition = (string)reader["ROUTINE_DEFINITION"];
                    DateTime created = (DateTime)reader["CREATED"];
                    DateTime lastAltered = (DateTime)reader["LAST_ALTERED"];

                    // Build the proper data structure for routine type
                    RoutineType routineType = (RoutineType)Enum.Parse(typeof(RoutineType), routineTypeAsText, true);

                    // Build the proper data structure for return type
                    SqlType returnType = null;
                    if (!reader.IsDBNull("DATA_TYPE"))
                    {
                        // Read the result data for the routine's return type
                        string dataType = (string)reader["DATA_TYPE"];
                        int? characterMaximumLength = reader.GetNullable<int>("CHARACTER_MAXIMUM_LENGTH");
                        int? numericPrecision = reader.GetNullable<int>("NUMERIC_PRECISION");
                        int? numericPrecisionRadix = reader.GetNullable<int>("NUMERIC_PRECISION_RADIX");
                        int? numericScale = reader.GetNullable<int>("NUMERIC_SCALE");
                        int? dateTimePrecision = reader.GetNullable<int>("DATETIME_PRECISION");
                        string characterSetName = reader.GetNullableString("CHARACTER_SET_NAME");
                        string collationName = reader.GetNullableString("COLLATION_NAME");

                        returnType = new SqlType(dataType, characterMaximumLength, characterSetName, collationName, numericPrecision, numericPrecisionRadix, numericScale, dateTimePrecision);
                    }

                    // Build the new routine
                    Routine routine = new Routine(catalog, schema, name, routineType, returnType, definition, created, lastAltered);

                    result.Add(routine);
                }
            }

            // Populate parameters
            foreach (Routine routine in result)
            {
                RoutineParameter.PopulateParameters(routine, dataProvider);
            }

            return result;
        }
Пример #5
0
        /// <summary>
        /// Loads unique and primary key constraints from the database.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="dataProvider">The data provider.</param>
        /// <exception cref="System.ArgumentNullException">
        /// table;table cannot be null
        /// or
        /// dataProvider;dataProvider cannot be null
        /// </exception>
        public static void PopulateUniqueConstraints(Table table, IObjectDataProvider dataProvider)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table", "table cannot be null");
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            using (IDataReader result = dataProvider.LoadUniqueConstraintDataForTable(table))
            {
                while (result.Read())
                {
                    // Read the result data
                    string name = (string)result["ConstraintName"];
                    string typeAsText = (string)result["Type"];
                    string columnName = (string)result["ColumnName"];
                    bool isDeferrable = ((string)result["IsDeferrable"]).Equals("NO") ? false : true;
                    bool initiallyDeferred = ((string)result["InitiallyDeferred"]).Equals("NO") ? false : true;

                    // Convert the constraint type
                    ConstraintType type = (ConstraintType)Enum.Parse(typeof(ConstraintType), typeAsText.Replace(" ", string.Empty), true);

                    // If the constraint has already been read, then this is just an additional column
                    // Otherwise it is a new constraint
                    if (table.Constraints.Any(constraint => constraint.Name == name))
                    {
                        // Add the column to the constraint
                        table.Constraints.Single(constraint => constraint.Name == name).AddColumn(table.GetColumn(columnName));
                    }
                    else
                    {
                        // Build the new constraint
                        Constraint newConstraint = new Constraint(name, type, isDeferrable, initiallyDeferred);
                        newConstraint.AddColumn(table.GetColumn(columnName));

                        table.Constraints.Add(newConstraint);
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Loads foreign key constraints from the database.
        /// </summary>
        /// <param name="tables">The tables.</param>
        /// <param name="dataProvider">The data provider.</param>
        /// <exception cref="System.ArgumentNullException">
        /// tables;tables cannot be null
        /// or
        /// dataProvider;dataProvider cannot be null
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// The foreign key refers to a table which doesn't exist in the collection
        /// or
        /// The foreign key refers to a column which hasn't been populated for the given table
        /// </exception>
        public static void PopulateReferentialConstraints(IEnumerable<Table> tables, IObjectDataProvider dataProvider)
        {
            if (tables == null)
            {
                throw new ArgumentNullException("tables", "tables cannot be null");
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            foreach (Table table in tables)
            {
                using (IDataReader result = dataProvider.LoadReferentialConstraintsDataForTable(table))
                {
                    while (result.Read())
                    {
                        // Read the result data
                        string name = (string)result["ConstraintName"];
                        string columnName = (string)result["ColumnName"];
                        bool isDeferrable = ((string)result["IsDeferrable"]).Equals("NO") ? false : true;
                        bool initiallyDeferred = ((string)result["InitiallyDeferred"]).Equals("NO") ? false : true;
                        string referencedCatalog = (string)result["ReferencedCatalog"];
                        string referencedSchema = (string)result["ReferencedSchema"];
                        string referencedTableName = (string)result["ReferencedTable"];
                        string referencedColumnName = (string)result["ReferencedColumn"];

                        // Create the constraint
                        Constraint constraint = new Constraint(name, ConstraintType.ForeignKey, isDeferrable, initiallyDeferred);
                        constraint.AddColumn(table.GetColumn(columnName));

                        // Find the table the foreign key refers to
                        Table referencedTable = tables.SingleOrDefault(t =>
                            t.Catalog == referencedCatalog
                            && t.Schema == referencedSchema
                            && t.Name == referencedTableName);

                        // Check it exists
                        if (referencedTable == null)
                        {
                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The foreign key refers to a table which doesn't exist in the collection ({0}.{1}.{2})", referencedCatalog, referencedSchema, referencedTableName));
                        }

                        // Find the column on the table
                        Column referencedColumn = referencedTable.Columns.SingleOrDefault(c => c.Name == referencedColumnName);

                        // Check it exists
                        if (referencedColumn == null)
                        {
                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The foreign key refers to a column which hasn't been populated for the given table ({0}.{1})", referencedTable, referencedColumnName));
                        }

                        // Assign the referenced column to the constraint
                        constraint.ReferencedColumn = referencedColumn;

                        table.Constraints.Add(constraint);
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Loads check constraints from the database.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="dataProvider">The data provider.</param>
        /// <exception cref="System.ArgumentNullException">table;table cannot be null
        /// or
        /// dataProvider;dataProvider cannot be null</exception>
        public static void PopulateCheckConstraints(Table table, IObjectDataProvider dataProvider)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table", "table cannot be null");
            }

            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }
        }
Пример #8
0
        /// <summary>
        /// Loads the objects from the database.
        /// </summary>
        /// <param name="dataProvider">The data provider.</param>
        /// <returns>
        /// The model.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">dataProvider;dataProvider cannot be null</exception>
        private static Model LoadFromDatabase(IObjectDataProvider dataProvider)
        {
            if (dataProvider == null)
            {
                throw new ArgumentNullException("dataProvider", "dataProvider cannot be null");
            }

            return new Model(Table.LoadFromDatabase(dataProvider), Routine.LoadFromDatabase(dataProvider));
        }