How to repeat a particular execution multiple times

Posted by Joshua on Stack Overflow See other posts from Stack Overflow or by Joshua
Published on 2009-09-07T06:43:30Z Indexed on 2010/05/17 15:20 UTC
Read the original article Hit count: 316

Filed under:
|

The following snippet generates create / drop sql for a particular database, whenever there is a modification to JPA entity classes.

How do I perform something equivalent of a 'for' operation where-in the following code can be used to generate sql for all supported databases (e.g. H2, MySQL, Postgres)

Currently I have to modify db.groupId, db.artifactId, db.driver.version everytime to generate the sql files

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>${hibernate3-maven-plugin.version}</version>

                <executions>
                    <execution>
                        <id>create schema</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                        <configuration>
                            <componentProperties>
                                <persistenceunit>${app.module}</persistenceunit>
                                <drop>false</drop>
                                <create>true</create>
                                <outputfilename>${app.sql}-create.sql</outputfilename>
                            </componentProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>drop schema</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                        <configuration>
                            <componentProperties>
                                <persistenceunit>${app.module}</persistenceunit>
                                <drop>true</drop>
                                <create>false</create>
                                <outputfilename>${app.sql}-drop.sql</outputfilename>
                            </componentProperties>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-core</artifactId>
                        <version>${hibernate-core.version}</version>
                    </dependency>

                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>${slf4j-api.version}</version>
                    </dependency>

                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-nop</artifactId>
                        <version>${slf4j-nop.version}</version>
                    </dependency>

                    <dependency>
                        <groupId>${db.groupId}</groupId>
                        <artifactId>${db.artifactId}</artifactId>
                        <version>${db.driver.version}</version>
                    </dependency>
                </dependencies>

                <configuration>
                    <components>
                        <component>
                            <name>hbm2cfgxml</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2dao</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>jpaconfiguration</implementation>
                            <outputDirectory>src/main/sql</outputDirectory>
                        </component>
                        <component>
                            <name>hbm2doc</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2hbmxml</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2java</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                        <component>
                            <name>hbm2template</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                    </components>
                </configuration>
            </plugin>

© Stack Overflow or respective owner

Related posts about maven-2

Related posts about hibernate