This example shows how to create a factory, session and map instance. This map instance is used to store, retrieve and remove a String instance using application identity.
The example is contained in file Example1.java .
package org.job.examples; import org.job.*; /** * This class shows how to create a factory, a session and a map instance. The map * instance is used to store, retrieve and remove a String instance * using application identity. */ public class Example1 { /** * This method is invoked with an argument array containing an URL. * @param args the command line arguments containing an URL. */ public static void main(String[] args) { // create a factory JobFactory jobFactory = org.job.impl.JobFactory.newInstance(); try { // create a session using a built in user JobSession session = jobFactory.getSession(args[0], "rio", "dejaneiro"); try { // start a transaction session.begin(); // create a JOB map JobMap jobMap = session.newMap("myJobMap"); // store a key/value pair of type String jobMap.put("key", "value"); // retrieve the stored value Object value = jobMap.get("key"); // check the retrieved value if (!"value".equals(value)) throw new RuntimeException("Retrieved: \"" + value + "\", expected: \"value\""); // remove the stored key/value pair Object removedValue = jobMap.remove("key"); // check the removed value if (!value.equals(removedValue)) throw new RuntimeException("Removed: \"" + removedValue + "\", expected: \"value\""); // commit the transaction session.end(); } finally { // close the session session.close(); } } finally { // close the factory jobFactory.close(); } } }