Deploying Synchronized Systems
Page 3 of 4

Distributing Application Code Within the Database

You can use Cloudsync to distribute application code and code changes to targets. To do this:

  1. Put the target application code into jar files in the source. (See the Cloudscape Developer's Guide for instructions.)
  2. Add the jar files to the publication that the target will subscribe to.
  3. Add the cloudscape.database.classpath property to the publication and set it to include all published jar files.

The target you create with this publication will function just as if the application class files were deployed at the target. Additionally, changes to the published jar files at the source are automatically reproduced at the target when it refreshes, eliminating the need for local administration.

Example of Jar Files in a Database

To illustrate including source and target application code in the database, consider the application described in Chapter 7, "Designing Synchronized Applications". The following example shows how to put that application's work units directly into source and target databases rather than external files. (Note that you could do exactly the same thing for application code other than work units.) This example assumes you have already created the system described in Chapter 7, "Designing Synchronized Applications". (For more information on putting code into the database, see the Cloudscape Developer's Guide.)

  1. Before creating the databases, put the work unit classes into jar files, as follows:

    jar cf TargetLogic.jar TargetLogic.class
    jar cf SourceLogic.jar SourceLogic.class

  2. After creating the source database, but before creating the publication and targets, run the following SQL-J commands to put the jar files and properties into the source database:

    CALL dbclasses.addJar(
        'APP', 'SourceLogic', 'SourceLogic.jar')

    CALL dbclasses.addJar(
        'APP', 'TargetWork', 'TargetLogic.jar')

    CALL PropertyInfo.setDatabaseProperty
            ('cloudscape.database.classpath', 'APP.SourceLogic')

    NOTE: You could also use Cloudview to perform this and the remaining steps. For more information see the Cloudview online help.

  3. Create the publication described in Step 4: Describing the Target Data.
  4. Include the target-side work unit code in the publication, as follows:

    ALTER PUBLICATION toySales
    ADD JAR FILE APP.TargetWork
    ADD TARGET DATABASE PROPERTY
        cloudscape.database.classpath='APP.TargetWork'

  5. Create copy files:

    COPY PUBLICATION toysales (salesRepID = 1)
        TO FILE 'toysalespub1.cpy'

    COPY PUBLICATION toysales (salesRepID = 2)
        TO FILE 'toysalespub2.cpy'

The targets you create with these copy files will be able to call work units and perform refreshes exactly like the application described in Chapter 7, "Designing Synchronized Applications", but without any accompanying code outside the database. If target work unit code stored in the source database is later changed, the changes will automatically be distributed to the targets when they refresh.

See the Cloudscape Developer's Guide for information on using DBClassLoad load a an application from the database.