« prev index next »

5. Database Schema extraction

Principle

The database schema extraction is performed by the extract-metadata goal of the dbmetadata-maven-plugin, a Maven plugin provided by Jaxio.

This plugin connects to a relational database using JDBC, retrieves the database schema metadata and write it into an XML file named metadata.xml.

Note

The metadata file produced by the dbmetadata plugin is not meant to be edited manually. If you need to change some settings, you should either change your database schema or use Celerio’s configuration file.

While pretty straightforward the schema extraction may take several minutes on large database schemas (e.g. more than 200 tables). To prevent useless extraction , the simplest approach is to declare a Maven profile dedicated to database extraction and activate it only when needed (i.e. each time you modify the database schema).

The metadata.xml file produced by this plugin is used by Celerio’s generate goal.

Details of dbmetadata-maven-plugin

Full name

Attributes

skip

jdbcDriver

jdbcUrl

jdbcUser

jdbcPassword

jdbcCatalog

jdbcOracleRetrieveRemarks

jdbcOracleRetrieveSynonyms

jdbc.reverseIndexes

jdbc.reverseOnlyUniqueIndexes

jdbcReverseViews

jdbcSchema

targetFilename

jdbcTableNamePatterns

Simple Usage

In your pom.xml, declare as properties the necessary expressions that the plugin needs to connect to your database and reverse it. Then create a dedicated profile to execute the plugin.

<properties>
  <jdbc.groupId>com.h2database</jdbc.groupId>
  <jdbc.artifactId>h2</jdbc.artifactId>
  <jdbc.version>1.3.167</jdbc.version>
  <jdbc.driver>org.h2.Driver</jdbc.driver>
  <jdbc.url>jdbc:h2:~/.h2/mydbname;MVCC=TRUE</jdbc.url>
  <jdbc.user>admin</jdbc.user>
  <jdbc.password></jdbc.password>
</properties>

<!-- skip -->
	
<profile>
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <!-- Extract the database metadata -->
  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  <id>metadata</id>
  <build>
    <defaultGoal>generate-sources</defaultGoal>
    <plugins>
      <plugin>
        <groupId>com.jaxio.celerio</groupId>
        <artifactId>dbmetadata-maven-plugin</artifactId>
        <version>${celerio-maven-plugin.version}</version>
        <executions>
          <execution>
            <id>Extract the database schema.</id>
            <goals>
              <goal>extract-metadata</goal>
          	</goals>
            <configuration>
              <jdbcTableNamePatterns><!-- pre-filtering, configurable since 4.0.7, optional, will be % by default -->
                <param>%</param> <!-- "%" means match any substring of 0 or more characters, and "_" means match any one character -->
              </jdbcTableNamePatterns>
            </configuration>						
          </executions>
          <dependencies>
            <dependency>
              <groupId>${jdbc.groupId}</groupId>
              <artifactId>${jdbc.artifactId}</artifactId>
              <version>${jdbc.version}</version>
            </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</profile>

© 2005-2015 Jaxio | @jaxiosoft | Legal