openjpa:sql

Full name:

org.apache.openjpa:openjpa-maven-plugin:3.1.3-SNAPSHOT:sql

Description:

Executes the SQL generation via the OpenJPA MappingTool.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: compile.
  • Since version: 1.0.
  • Binds by default to the lifecycle phase: process-classes.

Required Parameters

Name Type Since Description
<classes> File 1.0 Location where persistence-enabled classes are located.
Default value is: ${project.build.outputDirectory}.
User property is: openjpa.classes.
<forceMojoExecution> boolean 1.0 Setting this parameter to true will force the execution of this mojo, even if it would get skipped usually.
Default value is: false.
User property is: forceOpenJpaExecution.
<workDir> File 1.0 The working directory for putting persistence.xml and other stuff into if we need to.
Default value is: ${project.build.directory}/openjpa-work.
User property is: openjpa.workdir.

Optional Parameters

Name Type Since Description
<action> String 1.0 Argument to specify the action to take on each class. The available actions are: buildSchema, validate
<connectionDriverName> String 1.0

This setting can be used to override any openjpa.ConnectionDriverName set in the persistence.xml. It can also be used if the persistence.xml contains no connection information at all.

Sample:

<connectionDriverName>com.mchange.v2.c3p0.ComboPooledDataSource</connectionDriverName>
This is most times used in conjunction with connectionProperties.
<connectionProperties> String 1.0

Used to define the credentials or any other connection properties.

Sample:
<connectionProperties>
  driverClass=com.mysql.jdbc.Driver,
  jdbcUrl=jdbc:mysql://localhost/mydatabase,
  user=root,
  password=,
  minPoolSize=5,
  acquireRetryAttempts=3,
  maxPoolSize=20
</connectionProperties>
This is most times used in conjunction with connectionDriverName.
<excludes> String 1.0 Comma separated list of excludes to scan searchDir to pass to the jobs. This option may be used to stop OpenJPA tasks from scanning non-JPA classes (which usually leads to warnings such as "Type xxx has no metadata")
<includes> String 1.0 Comma separated list of includes to scan searchDir to pass to the jobs. This may be used to restrict the OpenJPA tasks to e.g. a single package which contains all the entities.
Default value is: **/*.class.
<modifyDatabase> boolean 1.0 Use this option to write the planned schema modifications to the database. If this is set, the sqlFile setting (if any) will be ignored.
Default value is: false.
<persistenceUnitName> String 1.0 An optional PersistenceUnit name. If not specified then OpenJPA will run against 'all anchors'. Means it will use all persistenceunits of all persistence.xml files it finds.
Default value is: ${openjpa.persistenceUnitName}.
<persistenceXmlFile> String 1.0 Used if a non-default file location for the persistence.xml should be used If not specified, the default one in META-INF/persistence.xml will be used. Since openjpa-2.3.0 this can also be a resource location. In prior releases it was only possible to specify a file location.
<skip> boolean 1.0 When true, skip the execution.
Default value is: false.
<sqlAction> String 1.0 The action to take for generating the SQL. Actions can be composed in a comma-separated list of one of the following items:
  • add (see MappingTool#ACTION_ADD)
  • refresh (see MappingTool#ACTION_REFRESH)
  • drop (see MappingTool#ACTION_DROP)
  • dropSchema (see MappingTool#ACTION_DROP_SCHEMA)
  • buildSchema (see MappingTool#ACTION_BUILD_SCHEMA)
  • import (see MappingTool#ACTION_IMPORT)
  • export (see MappingTool#ACTION_EXPORT)
  • validate (see MappingTool#ACTION_VALIDATE)
Technically this is the same like the schemaAction, but we have to split it for the plugin to allow different actions for generating the mapping and generating the SQL files.
Default value is: build.
<sqlFile> File 1.0 Use this option to write the planned schema modifications to a SQL script. Combine this with a schemaAction of "build" to generate a script that recreates the schema for the current mappings, even if the schema already exists.
Default value is: ${project.build.directory}/database.sql.
<toolProperties> Properties 1.0 Additional properties passed to the OpenJPA tools.

Parameter Details

<action>

Argument to specify the action to take on each class. The available actions are: buildSchema, validate
  • Type: java.lang.String
  • Since: 1.0
  • Required: No

<classes>

Location where persistence-enabled classes are located.
  • Type: java.io.File
  • Since: 1.0
  • Required: Yes
  • User Property: openjpa.classes
  • Default: ${project.build.outputDirectory}

<connectionDriverName>

This setting can be used to override any openjpa.ConnectionDriverName set in the persistence.xml. It can also be used if the persistence.xml contains no connection information at all.

Sample:

<connectionDriverName>com.mchange.v2.c3p0.ComboPooledDataSource</connectionDriverName>
This is most times used in conjunction with connectionProperties.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No

<connectionProperties>

Used to define the credentials or any other connection properties.

Sample:
<connectionProperties>
  driverClass=com.mysql.jdbc.Driver,
  jdbcUrl=jdbc:mysql://localhost/mydatabase,
  user=root,
  password=,
  minPoolSize=5,
  acquireRetryAttempts=3,
  maxPoolSize=20
</connectionProperties>
This is most times used in conjunction with connectionDriverName.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No

<excludes>

Comma separated list of excludes to scan searchDir to pass to the jobs. This option may be used to stop OpenJPA tasks from scanning non-JPA classes (which usually leads to warnings such as "Type xxx has no metadata")
  • Type: java.lang.String
  • Since: 1.0
  • Required: No

<forceMojoExecution>

Setting this parameter to true will force the execution of this mojo, even if it would get skipped usually.
  • Type: boolean
  • Since: 1.0
  • Required: Yes
  • User Property: forceOpenJpaExecution
  • Default: false

<includes>

Comma separated list of includes to scan searchDir to pass to the jobs. This may be used to restrict the OpenJPA tasks to e.g. a single package which contains all the entities.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No
  • Default: **/*.class

<modifyDatabase>

Use this option to write the planned schema modifications to the database. If this is set, the sqlFile setting (if any) will be ignored.
  • Type: boolean
  • Since: 1.0
  • Required: No
  • Default: false

<persistenceUnitName>

An optional PersistenceUnit name. If not specified then OpenJPA will run against 'all anchors'. Means it will use all persistenceunits of all persistence.xml files it finds.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No
  • Default: ${openjpa.persistenceUnitName}

<persistenceXmlFile>

Used if a non-default file location for the persistence.xml should be used If not specified, the default one in META-INF/persistence.xml will be used. Since openjpa-2.3.0 this can also be a resource location. In prior releases it was only possible to specify a file location.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No

<skip>

When true, skip the execution.
  • Type: boolean
  • Since: 1.0
  • Required: No
  • Default: false

<sqlAction>

The action to take for generating the SQL. Actions can be composed in a comma-separated list of one of the following items:
  • add (see MappingTool#ACTION_ADD)
  • refresh (see MappingTool#ACTION_REFRESH)
  • drop (see MappingTool#ACTION_DROP)
  • dropSchema (see MappingTool#ACTION_DROP_SCHEMA)
  • buildSchema (see MappingTool#ACTION_BUILD_SCHEMA)
  • import (see MappingTool#ACTION_IMPORT)
  • export (see MappingTool#ACTION_EXPORT)
  • validate (see MappingTool#ACTION_VALIDATE)
Technically this is the same like the schemaAction, but we have to split it for the plugin to allow different actions for generating the mapping and generating the SQL files.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No
  • Default: build

<sqlFile>

Use this option to write the planned schema modifications to a SQL script. Combine this with a schemaAction of "build" to generate a script that recreates the schema for the current mappings, even if the schema already exists.
  • Type: java.io.File
  • Since: 1.0
  • Required: No
  • Default: ${project.build.directory}/database.sql

<toolProperties>

Additional properties passed to the OpenJPA tools.
  • Type: java.util.Properties
  • Since: 1.0
  • Required: No

<workDir>

The working directory for putting persistence.xml and other stuff into if we need to.
  • Type: java.io.File
  • Since: 1.0
  • Required: Yes
  • User Property: openjpa.workdir
  • Default: ${project.build.directory}/openjpa-work