res-write-xom-db

The res-write-xom-db Ant task adds XOM, JAR, ZIP, or Java™ resources, or libraries or both, to the database persistence layer of Rule Execution Server. This task does not notify any other Rule Execution Server component or execution unit (XU) instance.

When you deploy a set of JAR or ZIP files with the jarMajorVersion increment policy set to true, each new JAR file is deployed with an incremented major version number to the Rule Execution Server instance (that is, with the same name but a different SHA-1 checksum). If you set the jarMajorVersion increment policy to false, the minor version number is incremented. The resources that already exist in the Rule Execution Server (that is, with the same name and same SHA-1 checksum) are not deployed again.

If you specify a library name by using the libName attribute, the res-deploy-xom-db Ant task creates a library name and passes the set of JAR files to that library. If you set the libMajorVersion increment policy to true, the library that already exists in the Rule Execution Server is deployed with an incremented major version number. If you set the libMajorVersion increment policy to false, the minor version number is incremented.

res-write-xom-db nested elements

The res-write-xom-db Ant task supports the following nested elements:

xompath

The xompath nested element specifies a Path-like structure External link opens a new window or tab. All the files included in this path are placed in the internal layer of the Rule Execution Server console as a JAR resource, in the same order as listed in the path. The xompath element supports the nested fileset element (see FileSet External link opens a new window or tab).

classpath

This class path must contain the JDBC driver classes. Whenever you must specify path-like External link opens a new window or tab values, you can use a nested element.

res-write-xom-db element attributes

The following table describes the res-write-xom-db element attributes and specifies whether they are mandatory or optional.

Table 1. res-write-xom-db element attributes
Element attribute Description Mandatory/optional
credentialsfile A file that contains the userid and password values, encrypted the first time the attribute is used. If you set this attribute, do not use the userid and password attributes.

A credentials file is a text file that sets two properties: username and password.

Optional
driver The JDBC driver class name for the database. Mandatory
failonerror If you set this attribute to false, a warning message is logged when an error occurs, but the build is not stopped.

Optional

The default is set to true.

jarMajorVersion The server uses the version policy to process the XOM, JAR, ZIP, or Java resources. If you set this attribute to true, the major version number is incremented, if applicable. Otherwise, the minor version number is incremented.

Optional

The default value is false.

libMajorVersion The server uses the version policy to process the library. If you set this attribute to true, the major version is incremented, if applicable. Otherwise, the minor version is incremented.

Optional

The default value is false.

libMergingPolicy

The server uses the merging policy to process the library.

This attribute can take the following values:
  • INCREMENT_MERGING_POLICY to increment the version during the deployment process
  • REPLACE_LATEST_MERGING_POLICY to replace the last version during the deployment process
Optional
libName The server uses this name to create a library. If you do not set this attribute, no library is created and the other library attributes, libMajorVersion and libMergingPolicy, are ignored. Optional
password The password of the user who is allowed to connect to the database. If you set this attribute, do not use the credentialsfile attribute. Optional
url The JDBC URL for the database. Mandatory
userid The user name to connect in the database. If you set this attribute, do not use the credentialsfile attribute. The user must be assigned the resDeployer role or above. Optional

Example: Writing Java XOM resources to a database

The following code sample shows how to deploy XOM, JAR, ZIP, or Java resources in a database by using the res-write-xom-db task:
<res-write-xom-db driver="com.ibm.db2.jcc.DB2Driver"
                  url="jdbc:oracle:thin:@127.0.0.1:1521:XE"
                  userid="res"
                  password="mypassword" jarMajorVersion="true">
  <xompath>
    <fileset dir="./javaxoms">
      <include name="**/*.jar"/>
    </fileset>
  </xompath>
</res-write-xom-db>

Example: Encrypting deployment to a database

You can also run an encrypted res-write-xom-db Ant task by using the credentialsfile attribute. Replace the userid and password attributes with the credentialsfile attribute, as follows:

Instead of
userid="res" password="mypassword"
Write
credentialsfile="credentials.properties"
The credentials file is a text file that sets the following values:
username=res
password=mypassword

Credentials file must comply with the Java format for property files. For more information, see the Java documentation External link opens a new window or tab).

After the first execution of the res-write-xom-db Ant task, the contents are encrypted. For example:
username={AES}6ee3l4NrmD3p8QTViSszow\=\=
password={AES}6ee3l4NrmD3p8QTViSszow\=\=

By using encryption, you ensure that the user name and password are never displayed in plain text in traces while JAR files are deployed.

Example: Using the xompath and classpath nested elements

This example declares the class path and the mapping between the res-write-xom-db Ant task and an equivalent Java class, then writes the Java XOM to a database.
<taskdef name="res-write-xom-db" classname="com.ibm.rules.res.tools.ant.xom.WriteXOMDbTask" onerror="ignore">
  <classpath refid="jrules-res-tools.classpath"/>
</taskdef>

<res-write-xom-db 
    driver="com.ibm.db2.jcc.DB2Driver"
    url="jdbc:db2://winmvsga.hursley.ibm.com:49100/DSN910GP:currentSchema=IL2CELL1;" 
    userid="myuserid" 
    password="xxxxxxxx">
  <xompath>
    <fileset dir="${dist.dir.ds.zrules.samples}/ruleApps/${ruleappname}"> 
      <include name="${ruleappname}-xom.jar"/>
    </fileset>
  </xompath>
  <classpath>
    <pathelement location="classes12.jar"/>
  </classpath>
</res-write-xom-db>
where
  • The connection string and the schema name are the value of the url attribute: winmvsga.hursley.ibm.com:49100/DSN910GP:currentSchema=IL2CELL1
  • Write the credentials to make the connection to the database as follows:
    userid="myuserid" 
        password="xxxxxxxx">
  • The JAR files are written to the table, for example IL2CELL1?.XOM_RESOURCES.
  • You must replace ${ruleappname} with the actual RuleApp name.
  • You must replace ${dist.dir.ds.zrules.samples} with the RuleApps directory path.