Search code examples
schemacrawler

schemacrawler returning tables from all available databases


I am using schemacrawler for getting table list from mysql database. The problem is, the result includes table from all the available databases. It is getting tables from outside the given database name(DataSource).

<bean id="schemaCrawlerOptions" class="schemacrawler.schemacrawler.SchemaCrawlerOptions">
    <property name="sequenceInclusionRule">
        <bean class="schemacrawler.schemacrawler.IncludeAll" />
    </property>
    <property name="tableTypes">
        <set>
            <value>TABLE</value>
            <!-- <value>VIEW</value> -->
        </set>
    </property>
    <property name="schemaInfoLevel">
        <bean factory-method="standard"
            class="schemacrawler.schemacrawler.SchemaInfoLevel" />
    </property>
</bean>
<bean id="executableForSchema" class="schemacrawler.tools.text.schema.SchemaTextExecutable"> <!-- This is the final class we need to execute schemacrawler -->
    <constructor-arg value="schema" />
    <property name="schemaCrawlerOptions" ref="schemaCrawlerOptions" />
    <property name="schemaTextOptions">
        <bean class="schemacrawler.tools.text.schema.SchemaTextOptions">
            <property name="showOrdinalNumbers" value="false" />
            <property name="showStandardColumnTypeNames" value="false" />
            <property name="hidePrimaryKeyNames" value="true" />
            <property name="hideIndexNames" value="true" />
            <property name="hideForeignKeyNames" value="true" />
            <property name="hideConstraintNames" value="true" />
            <property name="noInfo" value="false" />
        </bean>
    </property>
    <property name="outputOptions" ref="outputOptions" />
</bean>

Here is my spring-context.


Solution

  • Khader, this behavior really depends on the permissions of your database, and not on the data-source that you are using. If your database user has access to a table, SchemaCrawler will report it, irrespective of what schema it belongs to. So, it is best to use a database user with limited access, rather than a sysadmin account.

    However, you can have SchemaCrawler limit the schemas and tables it will report on. You will need to set the schemaInclusionRule and optionally the tableInclusionRule on schemaCrawlerOptions.

    In other words, please set this appropriately:

    <bean id="schemaCrawlerOptions" class="schemacrawler.schemacrawler.SchemaCrawlerOptions"> <property name="schemaInclusionRule"> ... ... <!-- Set an appropriate value here --> </property> ... ... ... </bean>

    Sualeh.