private static void generateDataAccessCodeForDatabase(
            Logger log, IDatabase database, string libraryBasePath, TextWriter writer, string baseNamespace, SystemDevelopmentConfiguration configuration)
        {
            var tableNames = DatabaseOps.GetDatabaseTables(database);

            if (configuration.database == null)
            {
                log.Info($"Configuration is missing the <{nameof( configuration.database )}> element.");
                return;
            }

            ensureTablesExist(tableNames, configuration.database.SmallTables, "small");
            ensureTablesExist(tableNames, configuration.database.TablesUsingRowVersionedDataCaching, "row-versioned data caching");
            ensureTablesExist(tableNames, configuration.database.revisionHistoryTables, "revision history");

            ensureTablesExist(tableNames, configuration.database.WhitelistedTables, "whitelisted");
            tableNames =
                tableNames.Where(
                    table => configuration.database.WhitelistedTables == null || configuration.database.WhitelistedTables.Any(i => i.EqualsIgnoreCase(table)));

            database.ExecuteDbMethod(
                cn => {
                writer.WriteLine();
                ConfigurationRetrievalStatics.Generate(writer, baseNamespace, configuration.database);

                // database logic access - standard
                writer.WriteLine();
                TableConstantStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                // database logic access - custom
                writer.WriteLine();
                RowConstantStatics.Generate(cn, writer, baseNamespace, database, configuration.database);

                // retrieval and modification commands - standard
                writer.WriteLine();
                CommandConditionStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                writer.WriteLine();
                var tableRetrievalNamespaceDeclaration = TableRetrievalStatics.GetNamespaceDeclaration(baseNamespace, database);
                TableRetrievalStatics.Generate(cn, writer, tableRetrievalNamespaceDeclaration, database, tableNames, configuration.database);

                writer.WriteLine();
                var modNamespaceDeclaration = StandardModificationStatics.GetNamespaceDeclaration(baseNamespace, database);
                StandardModificationStatics.Generate(cn, writer, modNamespaceDeclaration, database, tableNames, configuration.database);

                foreach (var tableName in tableNames)
                {
                    TableRetrievalStatics.WritePartialClass(cn, libraryBasePath, tableRetrievalNamespaceDeclaration, database, tableName);
                    StandardModificationStatics.WritePartialClass(
                        cn,
                        libraryBasePath,
                        modNamespaceDeclaration,
                        database,
                        tableName,
                        DataAccessStatics.IsRevisionHistoryTable(tableName, configuration.database));
                }

                // retrieval and modification commands - custom
                writer.WriteLine();
                QueryRetrievalStatics.Generate(cn, writer, baseNamespace, database, configuration.database);
                writer.WriteLine();
                CustomModificationStatics.Generate(cn, writer, baseNamespace, database, configuration.database);

                // other commands
                if (cn.DatabaseInfo is OracleInfo)
                {
                    writer.WriteLine();
                    SequenceStatics.Generate(cn, writer, baseNamespace, database, configuration.database.CommandTimeoutSecondsTyped);
                    writer.WriteLine();
                    ProcedureStatics.Generate(cn, writer, baseNamespace, database);
                }
            });
        }
Пример #2
0
        private void generateDataAccessCodeForDatabase(
            InstallationSupportUtility.DatabaseAbstraction.Database database, string libraryBasePath, TextWriter writer, string baseNamespace,
            Configuration.SystemDevelopment.Database configuration)
        {
            var tableNames = DatabaseOps.GetDatabaseTables(database).ToImmutableArray();

            ensureTablesExist(tableNames, configuration.SmallTables, "small");
            ensureTablesExist(tableNames, configuration.TablesUsingRowVersionedDataCaching, "row-versioned data caching");
            ensureTablesExist(tableNames, configuration.revisionHistoryTables, "revision history");

            ensureTablesExist(tableNames, configuration.WhitelistedTables, "whitelisted");
            tableNames =
                tableNames.Where(table => configuration.WhitelistedTables == null || configuration.WhitelistedTables.Any(i => i.EqualsIgnoreCase(table)))
                .ToImmutableArray();

            database.ExecuteDbMethod(
                delegate(DBConnection cn) {
                // database logic access - standard
                writer.WriteLine();
                TableConstantStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                // database logic access - custom
                writer.WriteLine();
                RowConstantStatics.Generate(cn, writer, baseNamespace, database, configuration);

                // retrieval and modification commands - standard
                writer.WriteLine();
                CommandConditionStatics.Generate(cn, writer, baseNamespace, database, tableNames);

                writer.WriteLine();
                var tableRetrievalNamespaceDeclaration = TableRetrievalStatics.GetNamespaceDeclaration(baseNamespace, database);
                TableRetrievalStatics.Generate(cn, writer, tableRetrievalNamespaceDeclaration, database, tableNames, configuration);

                writer.WriteLine();
                var modNamespaceDeclaration = StandardModificationStatics.GetNamespaceDeclaration(baseNamespace, database);
                StandardModificationStatics.Generate(cn, writer, modNamespaceDeclaration, database, tableNames, configuration);

                foreach (var tableName in tableNames)
                {
                    TableRetrievalStatics.WritePartialClass(cn, libraryBasePath, tableRetrievalNamespaceDeclaration, database, tableName);
                    StandardModificationStatics.WritePartialClass(
                        cn,
                        libraryBasePath,
                        modNamespaceDeclaration,
                        database,
                        tableName,
                        CodeGeneration.DataAccess.DataAccessStatics.IsRevisionHistoryTable(tableName, configuration));
                }

                // retrieval and modification commands - custom
                writer.WriteLine();
                QueryRetrievalStatics.Generate(cn, writer, baseNamespace, database, configuration);
                writer.WriteLine();
                CustomModificationStatics.Generate(cn, writer, baseNamespace, database, configuration);

                // other commands
                if (cn.DatabaseInfo is OracleInfo)
                {
                    writer.WriteLine();
                    SequenceStatics.Generate(cn, writer, baseNamespace, database);
                    writer.WriteLine();
                    ProcedureStatics.Generate(cn, writer, baseNamespace, database);
                }
            });
        }
Пример #3
0
        private void generateDataAccessCodeForDatabase(
            RedStapler.StandardLibrary.InstallationSupportUtility.DatabaseAbstraction.Database database, string libraryBasePath, TextWriter writer, string baseNamespace,
            RedStapler.StandardLibrary.Configuration.SystemDevelopment.Database configuration)
        {
            // Ensure that all tables specified in the configuration file actually exist.
            var tableNames = DatabaseOps.GetDatabaseTables(database);

            ensureTablesExist(tableNames, configuration.SmallTables, "small");
            ensureTablesExist(tableNames, configuration.TablesUsingRowVersionedDataCaching, "row-versioned data caching");
            ensureTablesExist(tableNames, configuration.revisionHistoryTables, "revision history");

            database.ExecuteDbMethod(
                delegate(DBConnection cn) {
                // database logic access - standard
                if (!configuration.EveryTableHasKeySpecified || configuration.EveryTableHasKey)
                {
                    writer.WriteLine();
                    TableConstantStatics.Generate(cn, writer, baseNamespace, database);
                }

                // database logic access - custom
                writer.WriteLine();
                RowConstantStatics.Generate(cn, writer, baseNamespace, database, configuration);

                // retrieval and modification commands - standard
                if (!configuration.EveryTableHasKeySpecified || configuration.EveryTableHasKey)
                {
                    writer.WriteLine();
                    CommandConditionStatics.Generate(cn, writer, baseNamespace, database);

                    writer.WriteLine();
                    var tableRetrievalNamespaceDeclaration = TableRetrievalStatics.GetNamespaceDeclaration(baseNamespace, database);
                    TableRetrievalStatics.Generate(cn, writer, tableRetrievalNamespaceDeclaration, database, configuration);

                    writer.WriteLine();
                    var modNamespaceDeclaration = StandardModificationStatics.GetNamespaceDeclaration(baseNamespace, database);
                    StandardModificationStatics.Generate(cn, writer, modNamespaceDeclaration, database, configuration);

                    foreach (var tableName in DatabaseOps.GetDatabaseTables(database))
                    {
                        TableRetrievalStatics.WritePartialClass(cn, libraryBasePath, tableRetrievalNamespaceDeclaration, database, tableName);
                        StandardModificationStatics.WritePartialClass(
                            cn,
                            libraryBasePath,
                            modNamespaceDeclaration,
                            database,
                            tableName,
                            CodeGeneration.DataAccess.DataAccessStatics.IsRevisionHistoryTable(tableName, configuration));
                    }
                }

                // retrieval and modification commands - custom
                writer.WriteLine();
                QueryRetrievalStatics.Generate(cn, writer, baseNamespace, database, configuration);
                writer.WriteLine();
                CustomModificationStatics.Generate(cn, writer, baseNamespace, database, configuration);

                // other commands
                if (cn.DatabaseInfo is OracleInfo)
                {
                    writer.WriteLine();
                    SequenceStatics.Generate(cn, writer, baseNamespace, database);
                    writer.WriteLine();
                    ProcedureStatics.Generate(cn, writer, baseNamespace, database);
                }
            });
        }
 private static string getPostDeleteCallClassName(DBConnection cn, string tableName)
 {
     return("PostDeleteCall<IEnumerable<" + database.SecondaryDatabaseName + "TableRetrieval." + TableRetrievalStatics.GetClassName(cn, tableName) +
            ".Row>>");
 }
Пример #5
0
 private static string getPostDeleteCallClassName(DBConnection cn, string tableName)
 => "PostDeleteCall<IEnumerable<TableRetrieval." + TableRetrievalStatics.GetClassName(cn, tableName) + ".Row>>";