JBatch (Payara 4.1.1.161.1) - Pandrex247/Payara GitHub Wiki

Contents

1. Overview

This page shall cover how to use the additional JBatch functionality in Payara 4.1.1.161.

2. Documentation Conventions

${Product-Root} - This is the root of the Payara server directory, referring to where you have Payara installed.
${Domain} - This refers to the name of your Payara domain.

3. Defining a Schema name

Included in this release of Payara is the ability to define the name of the database schema that will hold the batch tables. This can be set via the Admin Console, in the domain.xml file, or using Asadmin commands.

3.1 Defining a Schema name through the Admin Console

  • Click on the instance or cluster to move to its configuration page.
  • Select the Batch tab, and from there click on the Configuration sub-tab.
  • Enter your desired value in the Database Schema Name field.
  • Save your changes

3.2 Defining a Schema name using Asadmin

This is set using the set-batch-runtime-configuration command.
The command requires you to specify the Executor or Datasource lookup name, which you can do with the -x or -d options respectively.
The command defaults to targeting the Admin Server instance (server), to target a different instance or cluster, use the --target option.
To specify the schema name, use the --schemaName option, or its shortcut -n.
An example can be seen below:

asadmin set-batch-runtime-configuration -d jdbc/__default --target cluster1 -n test

This command expects the Admin Server to be listening on port 4848. If it is not, use the -p option to specify the port, for example:
asadmin -p 5048 set-batch-runtime-configuration -d jdbc/__default --target cluster1 -n test

3.3 Defining a Schema name in the domain.xml file

  • Open up the domain.xml file of the domain in question to edit.
    • It can be found under ${Product_Root}/glassfish/domains/${Domain}/config/
  • Find the <batch-runtime-configuration> tag under the appropriate <config> tag (e.g. <config name="server-config"> for the Admin Server), and enter the schema name like so:
    <batch-runtime-configuration schema-name="testSchemaName"></batch-runtime-configuration>
    • Note - If you're editing the domain.xml of a domain that has not been started at least once, the batch-runtime-configuration tag will not exist and you will have to add it in yourself

3.4 Specifying a Blank Schema Name

If you specify a blank schema name, then the schema name will depend on the type of database being used. MySQL will use test, whereas Derby, Oracle, DB2 and PostgreSQL will use the username of the JDBC connection pool resource associated with the JDBC resource to which JBatch is configured to use. Take note that this only applies if you explicitly specify the schema name as blank; the schema name will still default to APP if not overwritten.

4. Setting a Table Prefix and/or Suffix

This release of Payara allows you to set the prefix and/or the suffix of the batch table name. This can be set via the Admin Console, in the domain.xml file, or using Asadmin commands.
Note - the table prefix and suffix settings may be ignored by non-RDBMS based datastores.

4.1 Setting a Table Prefix and/or Suffix through the Admin Console

  • Click on the instance or cluster to move to its configuration page.
  • Select the Batch tab, and the Configuration sub-tab should load.
  • Enter your desired values in the Table Prefix and Table Suffix fields.
  • Save your changes

4.2 Setting a Table Prefix and/or Suffix using Asadmin

This is set using the set-batch-runtime-configuration command.
The command requires you to specify the Executor or Datasource lookup name, which you can do with the -x or -d options respectively.
The command defaults to targeting the Admin Server instance (server), to target a different instance or cluster, use the --target option.
TO specify the prefix, use the --tablePrefix option.
TO specify the table suffic, use the --tableSuffix option. An example can be seen below:

asadmin set-batch-runtime-configuration -d jdbc/__default --target cluster1 --tablePrefix PRE --tableSuffix SFX

This command expects the Admin Server to be listening on port 4848. If it is not, use the -p option to specify the port, for example:
asadmin -p 5048 set-batch-runtime-configuration -d jdbc/__default --target cluster1 --tablePrefix PRE --tableSuffix SFX

4.3 Setting a Table Prefix and/or Suffix in the domain.xml file

  • Open up the domain.xml file of the domain in question to edit.
    • It can be found under ${Product_Root}/glassfish/domains/${Domain}/config/
  • Find the <batch-runtime-configuration> tag under the appropriate <config> tag (e.g. <config name="server-config"> for the Admin Server), and enter the table prefix and/or suffix like so:
    <batch-runtime-configuration table-prefix="PRE" table-suffix="SFX"></batch-runtime-configuration>
    • Note - If you're editing the domain.xml of a domain that has not been started at least once, the batch-runtime-configuration tag will not exist and you will have to add it in yourself

5. Using MySQL, PostgreSQL, Oracle, or DB2 with JBatch

You configure JBatch to use each of these in the same way that you would configure it to use Derby.

In the Admin Console:

  • Create a Connection Pool:
    • Navigate to Resources > JDBC > JDBC Connection Pools and click on New...
    • Give it a name in the Pool Name field, select the resource type from the Resource Type drop-down, and choose the Database Driver Vendor as either DB2, MySql, Oracle, or Postgresql from the Database Driver Vendor menu.
    • Set any further configuration options on the next page.
    • Click Finish
  • Create a JDBC Resource:
    • Navigate to Resources > JDBC > JDBC Resources and click on New...
    • Give it a name in the JNDI Name field, and select the datasource you just created from the Pool Name drop-down.
    • Add any additional properties and select the targets for it to be enabled on.
    • Click OK.
  • Navigate to the Batch configuration page of the instance or cluster:
    • Click on the instance or cluster to move to its configuration page.
    • Select the Batch tab, and the Configuration sub-tab should load.
  • Select the new datasource from the Data Source Lookup Name drop-down menu.
  • Save the changes.

5.1 Usage Restrictions

JBatch will not create internally more than one set of Jbatch tables per schema. So in your schema if there exists a set of JBatch tables with prefixes and suffixes in the table names and then specify in the Glassfish JBatch configuration for the same schema above that you wish to use JBatch tables under a different name (for example no table prefix and suffix) then during the Jbatch initialisation phase, JBatch will attempt to create these tables since they do not exist. However since the table constraint names already exist for the existing JBatch tables in the same schema, table creation will fail. One can of course run a sql script to create the relevant JBatch schema objects under different names.

5.2 MySQL

For MySQL database use, it is recommended the following additional property be set:

Name Value Description
zeroDateTimeBehavior convertToNull Action for DATETIME values that are composed entirely of zeros (used by MySQL to represent invalid dates)

6. Altered Asadmin Commands

6.1 set-batch-runtime-configuration

Sets the batch runtime configuration settings. This command requires the admin server to be running.

Option Shortcut Description Default Mandatory
--target The instance or cluster to set the JBatch configuration of. server No
--datasourcelookupname -d Sets the name of the datasource to lookup and use. Yes, or specify executorServiceLookupName
--executorservicelookupname -x Sets the name of the executor service to lookup and use. Yes, or specify datasourceLookupName
--schemaName -n Sets the name of the database schema that holds the batch tables. APP No
--tablePrefix Sets the prefix to apply to the batch table name. No
--tableSuffix Sets the suffix to apply to the batch table name. No
⚠️ **GitHub.com Fallback** ⚠️