private static void writeFieldsAndPropertiesForColumn(Column column)
        {
            var columnIsReadOnly = !columns.DataColumns.Contains(column);

            writer.WriteLine(
                "private readonly DataValue<" + column.DataTypeName + "> " + getColumnFieldName(column) + " = new DataValue<" + column.DataTypeName + ">();");
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Gets " + (columnIsReadOnly ? "" : "or sets ") + "the value for the " + column.Name +
                " column. Throws an exception if the value has not been initialized. " + getComment(column));
            var propertyDeclarationBeginning = "public " + column.DataTypeName + " " + EwlStatics.GetCSharpIdentifier(column.PascalCasedNameExceptForOracle) +
                                               " { get { return " + getColumnFieldName(column) + ".Value; } ";

            if (columnIsReadOnly)
            {
                writer.WriteLine(propertyDeclarationBeginning + "}");
            }
            else
            {
                writer.WriteLine(propertyDeclarationBeginning + "set { " + getColumnFieldName(column) + ".Value = value; } }");

                CodeGenerationStatics.AddSummaryDocComment(
                    writer,
                    "Indicates whether or not the value for the " + column.Name +
                    " has been set since object creation or the last call to Execute, whichever was latest.");
                writer.WriteLine(
                    "public bool " + EwlStatics.GetCSharpIdentifier(column.PascalCasedNameExceptForOracle + "HasChanged") + " { get { return " +
                    getColumnFieldName(column) + ".Changed; } }");
            }
        }
        internal static void Generate(DBConnection cn, TextWriter writer, string baseNamespace, Database database, IEnumerable <string> tableNames)
        {
            writer.WriteLine("namespace " + baseNamespace + "." + database.SecondaryDatabaseName + "TableConstants {");
            foreach (var table in tableNames)
            {
                CodeGenerationStatics.AddSummaryDocComment(writer, "This object represents the constants of the " + table + " table.");
                writer.WriteLine("public class " + EwlStatics.GetCSharpIdentifier(table.TableNameToPascal(cn) + "Table") + " {");

                CodeGenerationStatics.AddSummaryDocComment(writer, "The name of this table.");
                writer.WriteLine("public const string Name = \"" + table + "\";");

                foreach (var column in new TableColumns(cn, table, false).AllColumnsExceptRowVersion)
                {
                    CodeGenerationStatics.AddSummaryDocComment(writer, "Contains schema information about this column.");
                    writer.WriteLine("public class " + EwlStatics.GetCSharpIdentifier(column.PascalCasedNameExceptForOracle + "Column") + " {");

                    CodeGenerationStatics.AddSummaryDocComment(writer, "The name of this column.");
                    writer.WriteLine("public const string Name = \"" + column.Name + "\";");

                    CodeGenerationStatics.AddSummaryDocComment(
                        writer,
                        "The size of this column. For varchars, this is the length of the biggest string that can be stored in this column.");
                    writer.WriteLine("public const int Size = " + column.Size + ";");

                    writer.WriteLine("}");
                }

                writer.WriteLine("}");
            }
            writer.WriteLine("}");
        }
        private static void writeCreateForUpdateMethod(DBConnection cn, Table table, bool isRevisionHistoryTable, bool isRevisionHistoryClass, string methodNameSuffix)
        {
            // header
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Creates a modification object in update mode with the specified conditions, which can be used to do a piecemeal update of the " + table.ObjectIdentifier + " table.");
            writer.WriteLine($"public static {table.GetStandardModificationClassReference()} CreateForUpdate{methodNameSuffix}( {getConditionParameterDeclarations( cn, table )} ) {{");


            // body

            writer.WriteLine(
                $"var mod = new {table.GetStandardModificationClassReference()} {{ modType = ModificationType.Update, conditions = getConditionList( requiredCondition, additionalConditions ) }};");

            // Set column values that correspond to modification conditions to the values of those conditions. One reason this is important is so the primary
            // key can be retrieved in a consistent way regardless of whether the modification object is an insert or an update.
            writer.WriteLine("foreach( var condition in mod.conditions ) {");
            var prefix = "if";

            foreach (var column in columns.AllColumnsExceptRowVersion)
            {
                writer.WriteLine($"{prefix}( condition is {table.GetEqualityConditionClassReference( cn, column )} )");
                writer.WriteLine($"mod.{getColumnFieldName( column )}.Value = ( condition as {table.GetEqualityConditionClassReference( cn, column )} ).Value;");
                prefix = "else if";
            }

            writer.WriteLine("}");
            writer.WriteLine(writer.NewLine + "mod.markColumnValuesUnchanged();");

            writer.WriteLine("return mod;");
            writer.WriteLine("}");
        }
        private static void writeCreateForSingleRowUpdateMethod(
            DBConnection cn, string tableName, bool isRevisionHistoryTable, bool isRevisionHistoryClass, string methodNameSuffix)
        {
            // header
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Creates a modification object in single-row update mode with the specified current data. All column values in this object will have HasChanged = false, despite being initialized. This object can then be used to do a piecemeal update of the " +
                tableName + " table.");
            writer.Write(
                "public static " + GetClassName(cn, tableName, isRevisionHistoryTable, isRevisionHistoryClass) + " CreateForSingleRowUpdate" + methodNameSuffix +
                "( ");
            writeColumnParameterDeclarations(columns.AllColumnsExceptRowVersion);
            writer.WriteLine(" ) {");


            // body

            writer.WriteLine(
                "var mod = new " + GetClassName(cn, tableName, isRevisionHistoryTable, isRevisionHistoryClass) + " { modType = ModificationType.Update };");

            // Use the values of key columns as conditions.
            writer.WriteLine("mod.conditions = new List<" + DataAccessStatics.GetTableConditionInterfaceName(cn, database, tableName) + ">();");
            foreach (var column in columns.KeyColumns)
            {
                writer.WriteLine(
                    "mod.conditions.Add( new " + DataAccessStatics.GetEqualityConditionClassName(cn, database, tableName, column) + "( " +
                    EwlStatics.GetCSharpIdentifier(column.CamelCasedName) + " ) );");
            }

            writeColumnValueAssignmentsFromParameters(columns.AllColumnsExceptRowVersion, "mod");
            writer.WriteLine("mod.markColumnValuesUnchanged();");
            writer.WriteLine("return mod;");
            writer.WriteLine("}");
        }
Пример #5
0
        private void writeGetInfoMethod(TextWriter writer)
        {
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Creates an info object for this page. Use the Info class constructor instead of this method if you want to reuse the entity setup info object.");
            writer.WriteLine(
                "public static Info GetInfo( " +
                StringTools.ConcatenateWithDelimiter(
                    ", ",
                    entitySetup != null ? WebMetaLogicStatics.GetParameterDeclarations(entitySetup.RequiredParameters) : "",
                    WebMetaLogicStatics.GetParameterDeclarations(requiredParameters),
                    entitySetup != null && entitySetup.OptionalParameters.Count > 0 ? "EntitySetup.OptionalParameterPackage entitySetupOptionalParameterPackage = null" : "",
                    optionalParameters.Count > 0 ? "OptionalParameterPackage optionalParameterPackage = null" : "",
                    "string uriFragmentIdentifier = \"\"") + " ) {");
            var entitySetupArgs = entitySetup != null
                                                      ? "new EntitySetup.Info( " +
                                  StringTools.ConcatenateWithDelimiter(
                ", ",
                InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(entitySetup.RequiredParameters, parameter => parameter.Name),
                entitySetup.OptionalParameters.Count > 0 ? "optionalParameterPackage: entitySetupOptionalParameterPackage" : "") + " )"
                                                      : "";

            writer.WriteLine(
                "return new Info( " +
                StringTools.ConcatenateWithDelimiter(
                    ", ",
                    entitySetupArgs,
                    InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(requiredParameters, parameter => parameter.Name),
                    optionalParameters.Count > 0 ? "optionalParameterPackage: optionalParameterPackage" : "",
                    "uriFragmentIdentifier: uriFragmentIdentifier") + " );");
            writer.WriteLine("}");
        }
 private static void writeDocCommentsForColumnParams(IEnumerable <Column> columns)
 {
     foreach (var column in columns)
     {
         CodeGenerationStatics.AddParamDocComment(writer, column.CamelCasedName, getComment(column));
     }
 }
        internal static void WriteClassIfNecessary(TextWriter writer, IEnumerable <VariableSpecification> parameters)
        {
            if (!parameters.Any())
            {
                return;
            }

            // Class should be public so apps that reference this web app can create Info objects.
            writer.WriteLine("public class OptionalParameterPackage {");

            foreach (var parameter in parameters)
            {
                writer.WriteLine("private readonly InitializationAwareValue<" + parameter.TypeName + "> " + parameter.Name + " = new InitializationAwareValue<" +
                                 parameter.TypeName + ">();");

                var warning  = "";
                var setCheck = "";
                if (parameter.IsString || parameter.IsEnumerable)
                {
                    warning  = " The value cannot be null.";
                    setCheck = "if( value == null ) throw new ApplicationException( \"You cannot specify null for the value of a string or an IEnumerable.\" );";
                }

                // Uninitialized parameters are meaningless since their values will be replaced with current page values or defaults when the Info object is created.
                CodeGenerationStatics.AddSummaryDocComment(writer,
                                                           "Gets or sets the value for the " + parameter.Name +
                                                           " optional parameter. Throws an exception if you try to get the value before it has been set." + warning);

                writer.WriteLine("public " + parameter.TypeName + " " + parameter.PropertyName + " { get { return " + parameter.Name + ".Value; } set { " + setCheck +
                                 parameter.Name + ".Value = value; } }");
                writer.WriteLine("public bool " + GetWasSpecifiedPropertyName(parameter) + " { get { return " + parameter.Name + ".Initialized; } }");
            }
            writer.WriteLine("}");
        }
        private static void writeInsertRowMethod(string tableName, string revisionHistorySuffix, string additionalLogicSuffix, IEnumerable <Column> keyColumns)
        {
            Column returnColumn  = null;
            var    returnComment = "";

            if (keyColumns.Count() == 1 && !columns.DataColumns.Contains(keyColumns.Single()))
            {
                returnColumn  = keyColumns.Single();
                returnComment = " Returns the value of the " + returnColumn.Name + " column.";
            }

            // header
            CodeGenerationStatics.AddSummaryDocComment(writer, "Inserts a row into the " + tableName + " table." + returnComment);
            writeDocCommentsForColumnParams(columns.DataColumns);
            writer.Write("public static ");
            writer.Write(returnColumn != null ? returnColumn.DataTypeName : "void");
            writer.Write(" InsertRow" + revisionHistorySuffix + additionalLogicSuffix + "( ");
            writeColumnParameterDeclarations(columns.DataColumns);
            if (columns.DataColumns.Any())
            {
                writer.Write(", ");
            }
            writer.WriteLine("bool isLongRunning = false ) { ");

            // body
            writer.WriteLine("var mod = CreateForInsert" + revisionHistorySuffix + "();");
            writeColumnValueAssignmentsFromParameters(columns.DataColumns, "mod");
            writer.WriteLine("mod.Execute{0}( isLongRunning: isLongRunning );".FormatWith(additionalLogicSuffix));
            if (returnColumn != null)
            {
                writer.WriteLine("return mod." + returnColumn.Name + ";");
            }
            writer.WriteLine("}");
        }
        private static void writeExecuteMethod(string tableName)
        {
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Executes this " + tableName +
                " modification, persisting all changes. Executes any pre-insert, pre-update, post-insert, or post-update logic that may exist in the class.");
            writer.WriteLine("public void Execute( bool isLongRunning = false ) {");
            writer.WriteLine(DataAccessStatics.GetConnectionExpression(database) + ".ExecuteInTransaction( delegate {");

            // The mod type may change during execute.
            writer.WriteLine("var frozenModType = modType;");

            writer.WriteLine("if( frozenModType == ModificationType.Insert )");
            writer.WriteLine("preInsert();");
            writer.WriteLine("else if( frozenModType == ModificationType.Update )");
            writer.WriteLine("preUpdate();");

            writer.WriteLine("executeInsertOrUpdate( isLongRunning );");

            writer.WriteLine("if( frozenModType == ModificationType.Insert )");
            writer.WriteLine("postInsert();");
            writer.WriteLine("else if( frozenModType == ModificationType.Update )");
            writer.WriteLine("postUpdate();");

            // This must be after the calls to postInsert and postUpdate in case their implementations need to know which column values changed.
            writer.WriteLine("markColumnValuesUnchanged();");

            writer.WriteLine("} );");
            writer.WriteLine("}");
        }
Пример #10
0
 private static void writePropertyDocComment(TextWriter writer, WebItemParameter parameter)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "Gets or sets the new value for the " + parameter.Name + " parameter." +
         (parameter.IsString || parameter.IsEnumerable ? " The value cannot be null." : ""));
 }
Пример #11
0
        private static void writeQueryMethod(
            TextWriter writer, Database database, EnterpriseWebLibrary.Configuration.SystemDevelopment.Query query,
            EnterpriseWebLibrary.Configuration.SystemDevelopment.QueryPostSelectFromClause postSelectFromClause)
        {
            // header
            CodeGenerationStatics.AddSummaryDocComment(writer, "Queries the database and returns the full results collection immediately.");
            writer.WriteLine(
                "public static IEnumerable<Row> GetRows" + postSelectFromClause.name + "( " +
                DataAccessStatics.GetMethodParamsFromCommandText(info, query.selectFromClause + " " + postSelectFromClause.Value) + " ) {");


            // body

            var namedParamList       = DataAccessStatics.GetNamedParamList(info, query.selectFromClause + " " + postSelectFromClause.Value);
            var getResultSetFirstArg = namedParamList.Any() ? "new[] { " + StringTools.ConcatenateWithDelimiter(", ", namedParamList.ToArray()) + " }, " : "";

            writer.WriteLine("return Cache.Current." + getQueryCacheName(query, postSelectFromClause) + ".GetResultSet( " + getResultSetFirstArg + "() => {");

            writer.WriteLine("var cmd = " + DataAccessStatics.GetConnectionExpression(database) + ".DatabaseInfo.CreateCommand();");
            writer.WriteLine("cmd.CommandText = selectFromClause + @\"" + postSelectFromClause.Value + "\";");
            DataAccessStatics.WriteAddParamBlockFromCommandText(writer, "cmd", info, query.selectFromClause + " " + postSelectFromClause.Value, database);
            writer.WriteLine("var results = new List<Row>();");
            writer.WriteLine(
                DataAccessStatics.GetConnectionExpression(database) +
                ".ExecuteReaderCommand( cmd, r => { while( r.Read() ) results.Add( new Row( new BasicRow( r ) ) ); } );");

            // Update single-row caches.
            writer.WriteLine("foreach( var i in results )");
            writer.WriteLine("updateSingleRowCaches( i );");

            writer.WriteLine("return results;");

            writer.WriteLine("} );");
            writer.WriteLine("}");
        }
Пример #12
0
        private static void writeInequalityConditionClasses(DBConnection cn, TextWriter writer, Table table)
        {
            // NOTE: This kind of sucks. It seems like we could use generics to not have to write N of these methods into ISU.cs.
            writer.WriteLine("public static class " + Utility.GetCSharpIdentifier(table.Name.TableNameToPascal(cn) + "TableInequalityConditions") + " {");
            foreach (var column in new TableColumns(cn, table.ObjectIdentifier, false).AllColumnsExceptRowVersion)
            {
                CodeGenerationStatics.AddSummaryDocComment(writer, "A condition that narrows the scope of a command.");
                writer.WriteLine($"public class {GetConditionClassName( column )}: {table.GetTableConditionInterfaceReference()} {{");
                writer.WriteLine("private readonly InequalityCondition.Operator op; ");
                writer.WriteLine("private readonly " + column.DataTypeName + " value;");

                CodeGenerationStatics.AddSummaryDocComment(
                    writer,
                    "Creates a condition to narrow the scope of a command. Expression will read 'valueInDatabase op yourValue'. So new InequalityCondition( Operator.GreaterThan, value ) will turn into 'columnName > @value'.");
                writer.WriteLine("public " + GetConditionClassName(column) + "( InequalityCondition.Operator op, " + column.DataTypeName + " value ) {");
                writer.WriteLine("this.op = op;");
                writer.WriteLine("this.value = value;");
                writer.WriteLine("}");

                var colVal = column.GetCommandColumnValueExpression("value");
                writer.WriteLine("InlineDbCommandCondition TableCondition.CommandCondition { get { return new InequalityCondition( op, " + colVal + " ); } }");
                writer.WriteLine("}");
            }

            writer.WriteLine("}");               // class
        }
Пример #13
0
        private static void writeDeleteRowsMethod( DBConnection cn, string tableName, string methodNameSuffix, bool executeAdditionalLogic )
        {
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "<para>Deletes the rows that match the specified conditions and returns the number of rows deleted.</para>" +
                "<para>WARNING: After calling this method, delete referenced rows in other tables that are no longer needed.</para>" );
            writer.WriteLine( "public static int DeleteRows" + methodNameSuffix + "( " + getConditionParameterDeclarations( cn, tableName ) + " ) {" );
            if( executeAdditionalLogic )
                writer.WriteLine( "return " + DataAccessStatics.GetConnectionExpression( database ) + ".ExecuteInTransaction( () => {" );

            writer.WriteLine( "var conditions = getConditionList( requiredCondition, additionalConditions );" );

            if( executeAdditionalLogic ) {
                writer.WriteLine( getPostDeleteCallClassName( cn, tableName ) + " postDeleteCall = null;" );
                writer.WriteLine( "preDelete( conditions, ref postDeleteCall );" );
            }

            writer.WriteLine( "var rowsDeleted = deleteRows( conditions );" );

            if( executeAdditionalLogic ) {
                writer.WriteLine( "if( postDeleteCall != null )" );
                writer.WriteLine( "postDeleteCall.Execute();" );
            }

            writer.WriteLine( "return rowsDeleted;" );

            if( executeAdditionalLogic )
                writer.WriteLine( "} );" ); // cn.ExecuteInTransaction
            writer.WriteLine( "}" );
        }
		private static void writeGetNameFromValueMethod( TextWriter writer, string valueTypeName ) {
			CodeGenerationStatics.AddSummaryDocComment( writer, "Returns the name of the constant given the constant's value." );
			const string parameterName = "constantValue";
			writer.WriteLine( "public static string GetNameFromValue( " + valueTypeName + " " + parameterName + " ) {" );
			writer.WriteLine( "return " + dictionaryName + ".GetRightFromLeft( " + parameterName + " );" );
			writer.WriteLine( "}" ); // method
		}
Пример #15
0
        private void writeGetInfoMethod(TextWriter writer)
        {
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Creates an object for this page. Use the constructor instead of this method if you want to reuse the entity setup object.");
            writer.WriteLine(
                "public static {0} GetInfo( ".FormatWith(generalData.ClassName) + StringTools.ConcatenateWithDelimiter(
                    ", ",
                    entitySetup != null ? WebFrameworkStatics.GetParameterDeclarations(entitySetup.RequiredParameters) : "",
                    WebFrameworkStatics.GetParameterDeclarations(requiredParameters),
                    entitySetup != null && entitySetup.OptionalParameters.Count > 0
                                                ? "Action<EntitySetup.OptionalParameterSpecifier, EntitySetup.Parameters> entitySetupOptionalParameterSetter = null"
                                                : "",
                    optionalParameters.Count > 0
                                                ? "Action<{0}> optionalParameterSetter = null".FormatWith(
                        StringTools.ConcatenateWithDelimiter(", ", "OptionalParameterSpecifier", entitySetup != null ? "EntitySetup" : "", "Parameters"))
                                                : "",
                    "string uriFragmentIdentifier = \"\"") + " ) {");
            var entitySetupArgs = entitySetup != null
                                                      ? "new EntitySetup( " + StringTools.ConcatenateWithDelimiter(
                ", ",
                InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(entitySetup.RequiredParameters, parameter => parameter.Name),
                entitySetup.OptionalParameters.Count > 0 ? "optionalParameterSetter: entitySetupOptionalParameterSetter" : "") + " )"
                                                      : "";

            writer.WriteLine(
                "return new {0}( ".FormatWith(generalData.ClassName) + StringTools.ConcatenateWithDelimiter(
                    ", ",
                    entitySetupArgs,
                    InfoStatics.GetInfoConstructorArgumentsForRequiredParameters(requiredParameters, parameter => parameter.Name),
                    optionalParameters.Count > 0 ? "optionalParameterSetter: optionalParameterSetter" : "",
                    "uriFragmentIdentifier: uriFragmentIdentifier") + " );");
            writer.WriteLine("}");
        }
        private static void writeUpdateRowsMethod(
            DBConnection cn, string tableName, string revisionHistorySuffix, string additionalLogicSuffix, bool includeIsLongRunningParameter)
        {
            // header
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Updates rows in the " + tableName + " table that match the specified conditions with the specified data.");
            writeDocCommentsForColumnParams(columns.DataColumns);
            CodeGenerationStatics.AddParamDocComment(writer, "requiredCondition", "A condition.");               // This prevents Resharper warnings.
            CodeGenerationStatics.AddParamDocComment(writer, "additionalConditions", "Additional conditions.");  // This prevents Resharper warnings.
            writer.Write("public static void UpdateRows" + revisionHistorySuffix + additionalLogicSuffix + "( ");
            writeColumnParameterDeclarations(columns.DataColumns);
            if (columns.DataColumns.Any())
            {
                writer.Write(", ");
            }
            writer.WriteLine(
                "{0} ) {{".FormatWith(
                    StringTools.ConcatenateWithDelimiter(
                        ", ",
                        includeIsLongRunningParameter ? "bool isLongRunning" : "",
                        getConditionParameterDeclarations(cn, tableName))));

            // body
            writer.WriteLine("var mod = CreateForUpdate" + revisionHistorySuffix + "( requiredCondition, additionalConditions );");
            writeColumnValueAssignmentsFromParameters(columns.DataColumns, "mod");
            writer.WriteLine(
                "mod.Execute{0}( isLongRunning: {1} );".FormatWith(additionalLogicSuffix, includeIsLongRunningParameter ? "isLongRunning" : "false"));
            writer.WriteLine("}");
        }
        private static void writeGetRowsMethod(
            DBConnection cn, TextWriter writer, IDatabase database, string table, TableColumns tableColumns, bool isSmallTable, bool tableUsesRowVersionedCaching,
            bool isRevisionHistoryTable, bool excludePreviousRevisions, int?commandTimeoutSeconds)
        {
            // header
            var methodName = "GetRows" + (isSmallTable ? "MatchingConditions" : "") +
                             (isRevisionHistoryTable && !excludePreviousRevisions ? "IncludingPreviousRevisions" : "");

            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Retrieves the rows from the table that match the specified conditions, ordered in a stable way." +
                (isSmallTable ? " Since the table is specified as small, you should only use this method if you cannot filter the rows in code." : ""));
            writer.WriteLine(
                "public static IEnumerable<Row> " + methodName + "( params " + DataAccessStatics.GetTableConditionInterfaceName(cn, database, table) + "[] conditions ) {");


            // body

            // If it's a primary key query, use RowsByPk if possible.
            foreach (var i in tableColumns.KeyColumns)
            {
                var equalityConditionClassName = DataAccessStatics.GetEqualityConditionClassName(cn, database, table, i);
                writer.WriteLine("var {0}Condition = conditions.OfType<{1}>().FirstOrDefault();".FormatWith(i.CamelCasedName, equalityConditionClassName));
            }
            writer.WriteLine("var cache = Cache.Current;");
            var pkConditionVariableNames = tableColumns.KeyColumns.Select(i => i.CamelCasedName + "Condition");

            writer.WriteLine(
                "var isPkQuery = " + StringTools.ConcatenateWithDelimiter(" && ", pkConditionVariableNames.Select(i => i + " != null").ToArray()) +
                " && conditions.Count() == " + tableColumns.KeyColumns.Count() + ";");
            writer.WriteLine("if( isPkQuery ) {");
            writer.WriteLine("Row row;");
            writer.WriteLine(
                "if( cache." + (excludePreviousRevisions ? "LatestRevision" : "") + $"RowsByPk.TryGetValue( {TypeNames.Tuple}.Create( " +
                StringTools.ConcatenateWithDelimiter(", ", pkConditionVariableNames.Select(i => i + ".Value").ToArray()) + " ), out row ) )");
            writer.WriteLine("return new [] {row};");
            writer.WriteLine("}");

            var commandConditionsExpression = "conditions.Select( i => i.CommandCondition )";

            if (excludePreviousRevisions)
            {
                commandConditionsExpression += ".Concat( new [] {getLatestRevisionsCondition()} )";
            }
            writer.WriteLine("return cache.Queries.GetResultSet( " + commandConditionsExpression + ", commandConditions => {");
            writeResultSetCreatorBody(
                cn,
                writer,
                database,
                table,
                tableColumns,
                tableUsesRowVersionedCaching,
                excludePreviousRevisions,
                "!isPkQuery",
                commandTimeoutSeconds);
            writer.WriteLine("} );");

            writer.WriteLine("}");
        }
		private static void writeGetValuesToNamesMethod( TextWriter writer, string valueTypeName ) {
			CodeGenerationStatics.AddSummaryDocComment(
				writer,
				"Returns a list of key value pairs where the key is the value of the row constant and the value is the name of the row constant." );
			writer.WriteLine( "public static ICollection<KeyValuePair<" + valueTypeName + ", string>> GetValuesToNames() {" );
			writer.WriteLine( "return valuesAndNames.GetAllPairs();" );
			writer.WriteLine( "}" ); // method
		}
Пример #19
0
 private static void writeColumnProperty(TextWriter writer, Column column)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "This object will " + (column.AllowsNull && !column.NullValueExpression.Any() ? "sometimes" : "never") + " be null.");
     writer.WriteLine(
         "public " + column.DataTypeName + " " + EwlStatics.GetCSharpIdentifier(column.PascalCasedNameExceptForOracle) + " { get { return __basicRow." +
         EwlStatics.GetCSharpIdentifier(column.PascalCasedName) + "; } }");
 }
        private static void writeGetAllRowsMethod(TextWriter writer, bool isRevisionHistoryTable, bool excludePreviousRevisions)
        {
            var revisionHistorySuffix = isRevisionHistoryTable && !excludePreviousRevisions ? "IncludingPreviousRevisions" : "";

            CodeGenerationStatics.AddSummaryDocComment(writer, "Retrieves the rows from the table, ordered in a stable way.");
            writer.WriteLine("public static IEnumerable<Row> GetAllRows" + revisionHistorySuffix + "() {");
            writer.WriteLine("return GetRowsMatchingConditions" + revisionHistorySuffix + "();");
            writer.WriteLine("}");
        }
Пример #21
0
 internal static void WriteParameterMembers(TextWriter writer, List <VariableSpecification> requiredParameters, List <VariableSpecification> optionalParameters)
 {
     writeMembersForParameterList(writer, requiredParameters, false);
     writeMembersForParameterList(writer, optionalParameters, true);
     if (optionalParameters.Any())
     {
         CodeGenerationStatics.AddGeneratedCodeUseOnlyComment(writer);
         writer.WriteLine("internal OptionalParameterPackage " + DefaultOptionalParameterPackageName + " = new OptionalParameterPackage();");
     }
 }
Пример #22
0
 internal static void WriteParameterMembers(TextWriter writer, List <WebItemParameter> requiredParameters, List <WebItemParameter> optionalParameters)
 {
     writeMembersForParameterList(writer, requiredParameters);
     writeMembersForParameterList(writer, optionalParameters);
     if (optionalParameters.Any())
     {
         CodeGenerationStatics.AddGeneratedCodeUseOnlyComment(writer);
         writer.WriteLine(
             "internal OptionalParameterSpecifier {0} = new OptionalParameterSpecifier();".FormatWith(WebItemGeneralData.ParameterDefaultsFieldName));
     }
 }
 private static void writeExecuteWithoutAdditionalLogicMethod(string tableName)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "Executes this " + tableName +
         " modification, persisting all changes. Does not execute pre-insert, pre-update, post-insert, or post-update logic that may exist in the class.");
     writer.WriteLine("public void ExecuteWithoutAdditionalLogic( bool isLongRunning = false ) {");
     writer.WriteLine("executeInsertOrUpdate( isLongRunning );");
     writer.WriteLine("markColumnValuesUnchanged();");
     writer.WriteLine("}");
 }
        private static void writeCreateForInsertMethod(DBConnection cn, Table table, bool isRevisionHistoryTable, bool isRevisionHistoryClass, string methodNameSuffix)
        {
            CodeGenerationStatics.AddSummaryDocComment(
                writer,
                "Creates a modification object in insert mode, which can be used to do a piecemeal insert of a new row in the " + table + " table.");
            var className = table.GetStandardModificationClassReference();

            writer.WriteLine($"public static {className} CreateForInsert{methodNameSuffix}() {{");
            writer.WriteLine($"return new {className} {{ modType = ModificationType.Insert }};");
            writer.WriteLine("}");
        }
 private static void writeCreateForInsertMethod(
     DBConnection cn, string tableName, bool isRevisionHistoryTable, bool isRevisionHistoryClass, string methodNameSuffix)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "Creates a modification object in insert mode, which can be used to do a piecemeal insert of a new row in the " + tableName + " table.");
     writer.WriteLine(
         "public static " + GetClassName(cn, tableName, isRevisionHistoryTable, isRevisionHistoryClass) + " CreateForInsert" + methodNameSuffix + "() {");
     writer.WriteLine("return new " + GetClassName(cn, tableName, isRevisionHistoryTable, isRevisionHistoryClass) + " { modType = ModificationType.Insert };");
     writer.WriteLine("}");
 }
Пример #26
0
 private static void writeConstructorDocComments(TextWriter writer, List <VariableSpecification> requiredParameters)
 {
     foreach (var parameter in requiredParameters)
     {
         var warning = "";
         if (parameter.IsString || parameter.IsEnumerable)
         {
             warning = " Do not pass null.";
         }
         CodeGenerationStatics.AddParamDocComment(writer, parameter.Name, parameter.Comment + warning);
     }
 }
Пример #27
0
 private static void writeMembersForParameterList(TextWriter writer, List <WebItemParameter> parameters)
 {
     foreach (var parameter in parameters)
     {
         CodeGenerationStatics.AddGeneratedCodeUseOnlyComment(writer);
         writer.WriteLine(
             "private " + parameter.TypeName + " " + parameter.FieldName +
             (parameter.IsString ? " = \"\"" : parameter.IsEnumerable ? " = " + parameter.EnumerableInitExpression : "") + ";");
         CodeGenerationStatics.AddSummaryDocComment(writer, parameter.Comment);
         writer.WriteLine("public " + parameter.TypeName + " " + parameter.PropertyName + " { get { return " + parameter.FieldName + "; } }");
     }
 }
Пример #28
0
 internal static void WriteSpecifyParameterDefaultsMethod(TextWriter writer, bool includeEsParameter)
 {
     CodeGenerationStatics.AddSummaryDocComment(
         writer,
         "Specifies optional parameter default values. This method is always called during construction of an object.");
     writer.WriteLine(
         "static partial void specifyParameterDefaults( {0} );".FormatWith(
             StringTools.ConcatenateWithDelimiter(
                 ", ",
                 "OptionalParameterSpecifier specifier",
                 includeEsParameter ? "EntitySetup entitySetup" : "",
                 "Parameters parameters")));
 }
        private static void writeSetAllDataMethod()
        {
            // header
            CodeGenerationStatics.AddSummaryDocComment(writer, "Sets all column values. This is useful for enforcing the number of arguments when deferred execution is needed.");
            writeDocCommentsForColumnParams(columns.DataColumns);
            writer.Write("public void SetAllData( ");
            writeColumnParameterDeclarations(columns.DataColumns);
            writer.WriteLine(" ) {");

            // body
            writeColumnValueAssignmentsFromParameters(columns.DataColumns, "this");
            writer.WriteLine("}");
        }
Пример #30
0
        internal static void WriteConstructorAndHelperMethods(
            TextWriter writer, List <VariableSpecification> requiredParameters, List <VariableSpecification> optionalParameters, bool includeEsInfoParameter, bool isEsInfo)
        {
            // It's important to force the cache to be enabled in the constructor since info objects are often created in post-back-action getters.

            writeConstructorDocComments(writer, requiredParameters);
            var constructorAndInitialParameterArguments = "( " +
                                                          StringTools.ConcatenateWithDelimiter(
                ", ",
                includeEsInfoParameter ? "EntitySetup.Info esInfo" : "",
                WebMetaLogicStatics.GetParameterDeclarations(requiredParameters),
                optionalParameters.Count > 0 ? "OptionalParameterPackage optionalParameterPackage = null" : "",
                !isEsInfo ? "string uriFragmentIdentifier = \"\"" : "") + " ) {";

            writer.WriteLine("internal Info" + constructorAndInitialParameterArguments);
            writer.WriteLine("DataAccessState.Current.ExecuteWithCache( () => {");

            // Initialize required parameter fields. We want to create and call this method even if there are no parameters so that non-generated Info constructors can still
            // call it and remain resistant to changes.
            writer.WriteLine(
                "initializeParameters( " +
                StringTools.ConcatenateWithDelimiter(
                    ", ",
                    includeEsInfoParameter ? "esInfo" : "",
                    GetInfoConstructorArgumentsForRequiredParameters(requiredParameters, p => p.Name),
                    optionalParameters.Count > 0 ? "optionalParameterPackage: optionalParameterPackage" : "",
                    !isEsInfo ? "uriFragmentIdentifier: uriFragmentIdentifier" : "") + " );");

            // Call init.
            writer.WriteLine("init();");

            writer.WriteLine("} );");
            writer.WriteLine("}");

            // Declare partial helper methods that will be called by the constructor.
            writeInitParametersMethod(writer, requiredParameters, optionalParameters, includeEsInfoParameter, isEsInfo, constructorAndInitialParameterArguments);
            if (optionalParameters.Any())
            {
                CodeGenerationStatics.AddSummaryDocComment(
                    writer,
                    "Initializes an optional parameter package with request time default values. This method is always called during construction of the object.");
                writer.WriteLine("partial void initDefaultOptionalParameterPackage( OptionalParameterPackage package );");
                CodeGenerationStatics.AddSummaryDocComment(
                    writer,
                    "Initializes an optional parameter package with non request time default values. This method is called during construction of the object unless the object is being created from the URL to directly handle the current request.");
                writer.WriteLine("partial void initUserDefaultOptionalParameterPackage( OptionalParameterPackage package );");
            }
        }