当前位置: 首页>>代码示例>>Java>>正文


Java InclusionRule类代码示例

本文整理汇总了Java中schemacrawler.schemacrawler.InclusionRule的典型用法代码示例。如果您正苦于以下问题:Java InclusionRule类的具体用法?Java InclusionRule怎么用?Java InclusionRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InclusionRule类属于schemacrawler.schemacrawler包,在下文中一共展示了InclusionRule类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateCode

import schemacrawler.schemacrawler.InclusionRule; //导入依赖的package包/类
/**
 * This is a convenience method that combines the whole metadata extraction and code generation process into a single method while still offering
 * most of the customizability.
 * <p>
 * First, this method will use the provided JDBC connection to run SchemaCrawler over the database and extract the metadata. The {@code schemaRule} and
 * {@code tableRule} will be passed on to SchemaCrawler and can be used to specify the tables for which metadata should be extracted.
 * <p>Afterwards the {@link MetadataExtractor} gets called and extracts the relevant data into a list of {@link TableModel}s.
 * <p>The third step generates the code and writes it into the source files at the specified location.
 *
 * @param connection                 The established JDBC connection that will be used as the data source for the analysis
 * @param schemaRule                 The rule used for inclusion/exclusion of database schemas. Use {@code null} or {@link IncludeAll} for no filtering.
 * @param tableRule                  The rule used for inclusion/Exclusion of database tables. Use {@code null} or {@link IncludeAll} for no filtering.
 * @param targetPackage              The java package for the generated code. May not be default package. If {@code null},
 *                                   defaults to {@link TableExtractor#DEFAULT_TARGET_PACKAGE}
 * @param classPrefix                The prefix for the generated java class names
 * @param targetDirectory            The directory to put the generated source files. The package directory structure will be generated automatically
 * @param dataTypeProvider           The data type provider for customization of the SQL type to java type mapping. If {@code null},
 *                                   a {@link com.btc.redg.generator.extractor.datatypeprovider.DefaultDataTypeProvider} will be used.
 * @param nameProvider               The {@link NameProvider} used to determine the names in the generated code
 * @param convenienceSetterProvider  A provider that determines convenience setters
 * @param explicitAttributeDecider   The {@link ExplicitAttributeDecider} that will be used to determine whether a attribute / foreign key should be treated
 *                                   as explicitly required
 * @param enableVisualizationSupport If {@code true}, the RedG visualization features will be enabled for the generated code. This will result in a small
 *                                   performance hit and slightly more memory usage if activated.
 * @param shouldCloseConnection      Indicates whether the JDBC connection should be closed after the database analysis
 */
public static void generateCode(final Connection connection,
                                final InclusionRule schemaRule,
                                final InclusionRule tableRule,
                                String targetPackage,
                                String classPrefix,
                                final Path targetDirectory,
                                final DataTypeProvider dataTypeProvider,
                                final NameProvider nameProvider,
                                final ExplicitAttributeDecider explicitAttributeDecider,
                                final ConvenienceSetterProvider convenienceSetterProvider,
                                final boolean enableVisualizationSupport,
                                final boolean shouldCloseConnection) {
    Objects.requireNonNull(connection, "RedG requires a JDBC connection to a database to perform an analysis");
    targetPackage = targetPackage != null ? targetPackage : TableExtractor.DEFAULT_TARGET_PACKAGE;
    classPrefix = classPrefix != null ? classPrefix : TableExtractor.DEFAULT_CLASS_PREFIX;
    final TableExtractor tableExtractor = new TableExtractor(classPrefix, targetPackage, dataTypeProvider, nameProvider, explicitAttributeDecider,
            convenienceSetterProvider);
    Objects.requireNonNull(targetDirectory, "RedG needs a target directory for the generated source code");

    LOG.info("Starting the RedG all-in-one code generation.");

    Catalog databaseCatalog = crawlDatabase(connection, schemaRule, tableRule, shouldCloseConnection);
    final List<TableModel> tables = extractTableModel(tableExtractor, databaseCatalog);
    Path targetWithPkgFolders = createPackageFolderStructure(targetDirectory, targetPackage);
    new CodeGenerator().generate(tables, targetWithPkgFolders, enableVisualizationSupport);
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:53,代码来源:RedGGenerator.java

示例2: extractTables

import schemacrawler.schemacrawler.InclusionRule; //导入依赖的package包/类
static TableInfo[] extractTables(Connection conn, final String schemaName, Rules rules) throws SchemaCrawlerException, SQLException {
        ArrayList<TableInfo> tableList = new ArrayList<TableInfo>(100);

        final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
        options.setSchemaInfoLevel(SchemaInfoLevel.standard());
        System.out.println("my catalog =" + conn.getCatalog());
        options.setSchemaInclusionRule(new InclusionRule() {
            @Override public boolean test(String anObject) {
                return schemaName.equals(anObject);
            }
        });

        final Catalog catalog = SchemaCrawlerUtility.getCatalog(conn, options);
        System.out.println("schem ! ");


        final Schema schema = catalog.getSchema(schemaName);
        System.out.println("Schema: " + schema);

        for (final Table table : catalog.getTables(schema)) {
            String tableName = table.getName();

            System.out.println(table + " pk " + table.getPrimaryKey() + " fks " + table.getForeignKeys() + " type " + table.getTableType());
            if (rules.skipTable(tableName) || table.getTableType().isView()) {
                System.out.println("SKIPPED");
                continue;
            }
            List<Column> columns = table.getColumns();
            List<String> fields = new ArrayList<>(columns.size());
            for (final Column column : columns) {
//                    System.out.println("     o--> " + column + " pk: "+ column.isPartOfPrimaryKey() + " fk: " + column.isPartOfForeignKey());
                String columnName = column.getName();
                if (column.isPartOfPrimaryKey() && rules.skipPrimaryKey(tableName, columnName)) {
                    // skip, todo strategy
                } else if (column.isPartOfForeignKey()) {
                    // skip, todo strategy
                } else {
                    fields.add(columnName);
                }
            }
            Map<List<String>, String> fks = extractForeignKeys(table);
            tableList.add(TableInfo.add(tableName, extractPrimaryKeys(table, fks), fields, fks));
        }

        return tableList.toArray(new TableInfo[tableList.size()]);
    }
 
开发者ID:jexp,项目名称:neo4j-rdbms-import,代码行数:47,代码来源:MetaDataReader.java


注:本文中的schemacrawler.schemacrawler.InclusionRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。