/// <summary> /// Partial content replacer. /// </summary> string PatternContentAppliesTo_General(PatternContent partialContent) { if (partialContent.ConditionKeyMode == PatternConditionKeyMode.DatabaseProvider) { ConditionItem dbReplacer = null; switch (this._database.Provider) { case DatabaseProvider.Oracle: dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.Oracle); break; case DatabaseProvider.SQLServer: dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLServer); break; case DatabaseProvider.SQLite: dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLite); break; case DatabaseProvider.SqlCe4: dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SqlCe4); break; } if (dbReplacer != null) // Replace the contents return Replacer_ConditionItem_AppliesToGeneral(dbReplacer.ContentText); } else if (partialContent.ConditionKeyMode == PatternConditionKeyMode.General) { var dbReplacer = partialContent.GetFirst(); if (dbReplacer != null) // Replace the contents return Replacer_ConditionItem_AppliesToGeneral(dbReplacer.ContentText); } return ""; }
/// <summary> /// Partial content replacer. /// </summary> string ConditionItem_AppliesToForeignKeyColumns(PatternContent partialContent, DbTable table, DbForeignKey foreignKey) { switch (partialContent.ConditionKeyMode) { case PatternConditionKeyMode.FieldsForeignKeyAll: ConditionItem theReplacer; switch (foreignKey.Multiplicity) { case DbForeignKey.ForeignKeyMultiplicity.OneToMany: theReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldForeignKey.MultiplicityOne); break; case DbForeignKey.ForeignKeyMultiplicity.ManyToOne: theReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldForeignKey.MultiplicityMany); break; default: // not defined Multiplicity return string.Empty; } // Replace the contents return Replacer_ConditionItem_AppliesToForeignKey(theReplacer.ContentText, table, foreignKey); case PatternConditionKeyMode.ForeignKeyUpdateAction: theReplacer = partialContent.GetReplacement(foreignKey.UpdateAction.ToString()); if (theReplacer == null) return string.Empty; return Replacer_ConditionItem_AppliesToForeignKey(theReplacer.ContentText, table, foreignKey); case PatternConditionKeyMode.ForeignKeyDeleteAction: theReplacer = partialContent.GetReplacement(foreignKey.DeleteAction.ToString()); if (theReplacer == null) return string.Empty; return Replacer_ConditionItem_AppliesToForeignKey(theReplacer.ContentText, table, foreignKey); default: // Ignored return string.Empty; } }
/// <summary> /// Partial content replacer. /// </summary> string ConditionItem_AppliesToTable(PatternContent partialContent, DbTable table) { // Find suitable replacement type switch (partialContent.ConditionKeyMode) { //case PatternConditionKeyMode.DatabaseProvider: // ConditionItem dbReplacer = null; // switch (this._database.Provider) // { // case DatabaseProvider.Oracle: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.Oracle); // break; // case DatabaseProvider.SQLServer: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLServer); // break; // case DatabaseProvider.SQLite: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLite); // break; // case DatabaseProvider.SqlCe4: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SqlCe4); // break; // } // if (dbReplacer == null) // return ""; // // Replace the contents // return Replacer_ConditionItem_AppliesToTable(dbReplacer.ContentText, table); case PatternConditionKeyMode.TableForeignKey: var normalKeyReplacer = partialContent.GetFirst(); // Replace the contents return Replacer_ConditionItem_AppliesToForeignKeys(normalKeyReplacer.ContentText, table); case PatternConditionKeyMode.TableIndexConstraint: var indexConstraintReplacer = partialContent.GetFirst(); // Replace the contents return Replacer_ConditionItem_AppliesToIndexConstraints(indexConstraintReplacer.ContentText, table, false); case PatternConditionKeyMode.TableUniqueConstraint: var uniqueConstraintReplacer = partialContent.GetFirst(); // Replace the contents return Replacer_ConditionItem_AppliesToIndexConstraints(uniqueConstraintReplacer.ContentText, table, true); case PatternConditionKeyMode.TablePrimaryKey: ConditionItem primaryReplacer; if (table.ReadOnly) { // Table is marked as read only, like views primaryReplacer = partialContent.GetReplacement( ConditionKeyModeConsts.TablePrimaryKey.ReadOnlyTable); } else if (table.HasPrimaryKey()) { // Table has a primary key primaryReplacer = partialContent.GetReplacement( ConditionKeyModeConsts.TablePrimaryKey.WithPrimaryKey); } else { // There is no primary key, default primaryReplacer = partialContent.GetReplacement( ConditionKeyModeConsts.TablePrimaryKey.NoPrimaryKey); } // Replace the contents return Replacer_ConditionItem_AppliesToTable(primaryReplacer.ContentText, table); case PatternConditionKeyMode.TableAutoIncrement: int autoCount = table.GetAutoIncrementCount(); ConditionItem autoReplacer; if (autoCount == 0) { autoReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.TableAutoIncrement.NoAutoIncrement); } else if (autoCount == 1) { autoReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.TableAutoIncrement.OneAutoIncrement); } else { autoReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.TableAutoIncrement.MoreAutoIncrement); } // Replace the contents return Replacer_ConditionItem_AppliesToTable(autoReplacer.ContentText, table); default: // Ignored return ""; } }
/// <summary> /// Partial content replacer. /// </summary> string ConditionItem_AppliesToColumn(PatternContent partialContent, DbTable table, DbColumn column) { switch (partialContent.ConditionKeyMode) { //case PatternConditionKeyMode.DatabaseProvider: // ConditionItem dbReplacer = null; // switch (this._database.Provider) // { // case DatabaseProvider.Oracle: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider._Oracle); // break; // case DatabaseProvider.SQLServer: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLServer); // break; // case DatabaseProvider.SQLite: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SQLite); // break; // case DatabaseProvider.SqlCe4: // dbReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.DatabaseProvider.SqlCe4); // break; // } // if (dbReplacer == null) // return ""; // // Replace the contents // return Replacer_ConditionItem_AppliesToColumn(dbReplacer.Content, table, column); case PatternConditionKeyMode.FieldsAll: case PatternConditionKeyMode.Field: var replacer = partialContent.GetFirst(); // Replace the contents return Replacer_ConditionItem_AppliesToColumn(replacer.ContentText, table, column); case PatternConditionKeyMode.FieldsCondensedTypeAll: case PatternConditionKeyMode.FieldCondensedType: ConditionItem replacerCondensedType = null; switch (column.DataCondensedType) { case DbColumn.ColumnCondensedType.None: replacerCondensedType = partialContent.GetReplacement(ConditionKeyModeConsts.FieldCondensedType.None); break; case DbColumn.ColumnCondensedType.String: replacerCondensedType = partialContent.GetReplacement(ConditionKeyModeConsts.FieldCondensedType.String); break; case DbColumn.ColumnCondensedType.Decimal: replacerCondensedType = partialContent.GetReplacement(ConditionKeyModeConsts.FieldCondensedType.Decimal); break; case DbColumn.ColumnCondensedType.Integer: replacerCondensedType = partialContent.GetReplacement(ConditionKeyModeConsts.FieldCondensedType.Integer); break; } // Replace the contents if (replacerCondensedType != null) return Replacer_ConditionItem_AppliesToColumn(replacerCondensedType.ContentText, table, column); return string.Empty; case PatternConditionKeyMode.FieldsPrimaryKeyAll: case PatternConditionKeyMode.FieldPrimaryKey: ConditionItem primaryReplacer; if (column.PrimaryKey) primaryReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldPrimaryKey.PrimaryKey); else primaryReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldPrimaryKey.NormalField); // Replace the contents return Replacer_ConditionItem_AppliesToColumn(primaryReplacer.ContentText, table, column); case PatternConditionKeyMode.FieldReferencedKeyType: case PatternConditionKeyMode.FieldKeyType: case PatternConditionKeyMode.FieldsReferencedKeyTypeAll: case PatternConditionKeyMode.FieldsKeyTypeAll: ConditionItem keyTypeReplacer; // this key is not reference type if (_patternProject.SeperateReferenceColumns) { if (column.IsReferenceKey && partialContent.ConditionKeyMode == PatternConditionKeyMode.FieldsKeyTypeAll) return ""; if (!column.IsReferenceKey && partialContent.ConditionKeyMode == PatternConditionKeyMode.FieldsReferencedKeyTypeAll) return ""; } // Key type bool dataTypeNotNullable = !column.DataTypeNullable; if (column.AutoIncrement && column.PrimaryKey) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.AutoInrcementPrimaryKey); } else if (column.AutoIncrement && column.AllowNull && !dataTypeNotNullable) { // AutoIncrement // Nullable column // Nullable object keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.AutoIncNativeNullable); } else if (column.AutoIncrement && column.AllowNull && dataTypeNotNullable) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.AutoIncNullableType); } else if (column.AutoIncrement) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.AutoInrcement); } else if (column.PrimaryKey) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.PrimaryKey); } else if (column.AllowNull && !dataTypeNotNullable) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.NativeNullable); } else if (column.AllowNull && dataTypeNotNullable) { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.NullableType); } else { keyTypeReplacer = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyType.NormalField); } // Replace the contents return Replacer_ConditionItem_AppliesToColumn(keyTypeReplacer.ContentText, table, column); case PatternConditionKeyMode.FieldsKeyReadTypeAll: case PatternConditionKeyMode.FieldKeyReadType: ConditionItem keyRead; bool canConvert = !column.ExplicitCastDataType; // TODO // how to read key type if (!column.AllowNull && canConvert) { keyRead = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyReadType.NormalField_Convert); } else if (!column.AllowNull && !canConvert) { keyRead = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyReadType.NormalField_Cast); } else if (column.AllowNull && canConvert) { keyRead = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyReadType.Nullable_Convert); } else { keyRead = partialContent.GetReplacement(ConditionKeyModeConsts.FieldKeyReadType.Nullable_Cast); } // Replace the contents return Replacer_ConditionItem_AppliesToColumn(keyRead.ContentText, table, column); default: // Ignored return ""; } }