Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Container support

Here are the configurations that currently support DataSource or Resource configuration:

Include Page
Containers with DataSource and Resource support
Containers with DataSource and Resource support

Notes:

  • Datasources on the Jetty container use the c3p0 datasource pool.
  • JOnAS handles transactions for datasources using its jtm service.

DataSource properties

DataSources are added through pipe-delimited configuration properties that starts with cargo.datasource.datasource. Example:

Code Block
cargo.datasource.datasource1=cargo.datasource.url=jdbc:mydriver:userdb\|cargo.datasource.driver=org.database.Driver\|...
cargo.datasource.datasource2=cargo.datasource.url=jdbc:mydriver:referencedb\|cargo.datasource.driver=org.database.Driver\|...

Here are the properties that are valid for this:

  • Note that c.d means cargo.datasource
  • Note that if you specify a property marked do not set you will get a CargoException.

Property

Purpose

Valid Values

DataSource

Transactional DataSource

XA DataSource

c.d.jndi

The path to this datasource in JNDI

Any jndi path, like jdbc/userds

mandatory

mandatory

mandatory

c.d.driver

The implementation class

ex. my.Driver

mandatory: must implement java.sql.Driver

mandatory: must implement java.sql.Driver

mandatory: must implement javax.sql.XADataSource

c.d.properties

Properties to pass to the driver

Semi-colon delimited string

optional

optional

mandatory

c.d.url

URL for the java.sql.Driver

ex. jdbc:host:port/mydb

mandatory

mandatory

optional

c.d.type

Determines the type of the driver

Defaults to java.sql.Driver, only set if you want to use a javax.sql.XADataSource

do not set

do not set

javax.sql.XADataSource

c.d.transactionsupport

Determines transaction support type

LOCAL_TRANSACTION or XA_TRANSACTION

do not set

mandatory

unset defaults to only valid option: XA_TRANSACTION

c.d.id

Identifier used in configuration files to reference this datasource

Must contain no path-like characters

optional

optional

optional

c.d.username

Username to connect to the database

String

optional

optional

optional

c.d.password

Password to connect to the database

String

optional

optional

optional

Resource properties

Resources are added through pipe-delimited configuration properties that starts with cargo.resource.resource. Example:

Code Block
cargo.resource.resource1=cargo.resource.name=resource/apple\|cargo.resource.class=org.mycompany.Apple\|...
cargo.resource.resource2=cargo.resource.name=resource/pear\|cargo.resource.driver=org.mycompany.Pear\|...

Here are the properties that are valid for this:

  • Note that c.r means cargo.resource

Property

Purpose

Valid Values

Mandatory?

c.r.name

The path to this datasource in JNDI

Any jndi path, like resource/apple

mandatory

c.r.type

Interface of the object

Any valid interface

mandatory

c.r.class

The implementation class

Any valid class implementing the interface

mandatory

c.r.parameters

Properties to to populate the class with

Semi-colon delimited string; must correspond to setters

optional

Known issues

The Glassfish container has various known issues with regards to datasource support.

When you try to use Glassfish 3.x or Glassfish 4.x with Derby datasources, you might run into issues where Glassfish doesn't start, and the Glassfish logs show you messages such as the below:

Code Block
java.lang.SecurityException: sealing violation: package org.apache.derby is sealed

This is because Glassfish is already shipped with Derby, and the Glassfish class loaders do not know how to the manage the situation where the same class is duplicated. So, the solution is to simply remove the Derby JAR from dependencies; on the other hand this is not feasible if you are using the same CARGO profile with different containers. Here is how you can work around the issue:

Code Block
languagehtml/xml
<dependencies>
  <dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>${derby.version}</version>
    <scope>test</scope>
  </dependency>
</dependencies>

  ...

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <version>${cargo.version}</version>
      <!--
        This configuration will be used in general.
        -->
      <configuration>
        <container>
          <dependencies>
            <dependency>
              <groupId>org.apache.derby</groupId>
              <artifactId>derby</artifactId>
            </dependency>
          </dependencies>
          <systemProperties>
            <derby.system.home>\${project.build.directory}/derby</derby.system.home>
          </systemProperties>
        </container>
        <configuration>
          <properties>
            <cargo.datasource.datasource.derby>
                cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
                cargo.datasource.url=jdbc:derby:derbyDB;create=true|
                cargo.datasource.jndi=jdbc/CargoDS|
                cargo.datasource.username=APP|
                cargo.datasource.password=nonemptypassword
            </cargo.datasource.datasource.derby>
          </properties>
        </configuration>

          ...

      </configuration>
    </plugin>
  </plugins>
</build>

<profiles>

    ...

  <profile>
    <id>glassfish3x</id>
    <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
              <container>
                <containerId>glassfish3x</containerId>
                <artifactInstaller>
                  <groupId>org.glassfish.main.distributions</groupId>
                  <artifactId>glassfish</artifactId>
                  <version>3.1.2.2</version>
                </artifactInstaller>
                <dependencies>
                  <!--
                    Remove the org.apache.derby dependency since GlassFish 3.x is already
                    shipped with Derby, and adding the dependency twice results in a
                    java.lang.SecurityException: sealing violation: package org.apache.derby.
                    -->
                    <dependency>
                      <groupId>org.apache.derby</groupId>
                      <artifactId>derby</artifactId>
                      <classpath>none</classpath>
                    </dependency>
                </dependencies>
              </container>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </profile>
</profiles>

Examples

Users of the Java API can take a look at the following classes as example:

Users of the Maven2/Maven3 plugin can use the Maven2 Archetype showing datasource support. Please read: Datasource Definition Archetype.