Schemacrawler : Getting Check constraint values from Table columns using Java APIs

孤街浪徒 提交于 2021-01-29 17:23:52

问题


I'm struggling for the past few days, to get the check constraints and their values, from tables in MySQL database using latest 16.3.2 version of schemacrawler. I have been able to get the table, columns, primary keys etc, using the same, but getting the check constraints is becoming a challenge. I've gone through the website from Sualeh, but not getting the exact steps to get this information. If somebody can share the code snippets, it would be helpful.

Following is POM entry

    <dependency>
        <groupId>us.fatehi</groupId>
        <artifactId>schemacrawler</artifactId>
        <version>16.3.2</version>

And following is the catalog extraction code that I'm using. @Override public Catalog getTargetDBObjects(ProjectDatabase projectDB) throws AppException { Catalog theCatalog = null; Connection theConn = DBUtils.getTargetDBConnection(projectDB);

    // Create the options
    final SchemaCrawlerOptionsBuilder optionsBuilder =
      SchemaCrawlerOptionsBuilder.builder()
        // Set what details are required in the schema - this affects the time taken to crawl the schema
        .withSchemaInfoLevel(SchemaInfoLevelBuilder.detailed())
        .includeSchemas(new RegularExpressionInclusionRule("appuser"))
        //.includeAllRoutines()
        .includeAllSequences();


    final SchemaCrawlerOptions options = optionsBuilder.toOptions();


    logger.info("Constraint Definition Processing "+options.getSchemaInfoLevel().isRetrieveTableConstraintDefinitions());
    logger.info("Constraint Information Processing "+options.getSchemaInfoLevel().isRetrieveTableConstraintInformation());

    logger.info("Schema crawling at work........");
    try {
        theCatalog = SchemaCrawlerUtility.getCatalog(theConn, options);
    } catch (SchemaCrawlerException e) {
        e.printStackTrace();
    }
    logger.info("Schema crawled successfully.");
    return theCatalog;
}

        Collection<TableConstraint> allConstraints = theTable.getTableConstraints();
        logger.info("-------@#$> Constraint length "+ allConstraints.size());

Here the length of allConstraints.size is always ZERO whereas the table does have check constraints defined on some columns. Also the log file of Schemacrawler shows that not table constraints was fetched.

INFO: Total time taken for <crawlTables> - 00:00:02.580 hours
-  1.7% - 00:00:00.045 - <retrieveTables>
- 12.1% - 00:00:00.312 - <retrieveColumns>
- 72.2% - 00:00:01.863 - <retrieveForeignKeys>
-  3.3% - 00:00:00.085 - <filterAndSortTables>
- 10.6% - 00:00:00.273 - <retrieveIndexes>
-  0.0% - 00:00:00.000 - <retrieveTableConstraintInformation>
-  0.0% - 00:00:00.000 - <isRetrieveTableConstraintDefinitions>
-  0.0% - 00:00:00.001 - <retrieveTriggerInformation>
-  0.0% - 00:00:00.000 - <retrieveViewInformation>
-  0.0% - 00:00:00.000 - <retrieveTableDefinitions>
-  0.0% - 00:00:00.000 - <retrieveIndexInformation>
-  0.0% - 00:00:00.000 - <retrieveAdditionalTableAttributes>
-  0.0% - 00:00:00.000 - <retrieveTablePrivileges>
-  0.0% - 00:00:00.000 - <retrieveAdditionalColumnAttributes>
-  0.0% - 00:00:00.001 - <retrieveTableColumnPrivileges>

Thanks

来源:https://stackoverflow.com/questions/59853341/schemacrawler-getting-check-constraint-values-from-table-columns-using-java-ap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!