The Record Store Java Client package is intended to provide a working example of a client that communicates with a Record Store instance and issues record access requests. The sample client program is therefore a template that you can use as a basis for your own client program.

The Record Store API allows users to build client programs that invoke a Record Store instance to programmatically write records to and read records from the Record Store.

The Record Store API consists of two components:

The sample client package includes all the libraries needed to build clients. It also includes an Ant build script (that can compile and run the sample applications) as well as Eclipse .project and .classpath files for the sample client.

See the Oracle Technology Network for the Oracle Commerce CAS API Guide (which documents the Record Store API).

The Ant build.xml file can compile and run the sample writer client program.

The file has the following targets:

To run the sample writer client with the Ant build script:

The sample writer client’s output messages should be similar to this example:

Buildfile: build.xml

init:
  [mkdir] Created dir: C:\Endeca\CAS\<version>\sample\recordstore-java-client\build

compile:
  [javac] Compiling 2 source files to C:\Endeca\CAS\<version>\sample\recordstore-java-client\build

run-sample-writer:
  [java] Setting record store configuration ...
  [java] Starting a new transaction ...
  [java] Writing records ...
  [java] Committing transaction ...
  [java] DONE

BUILD SUCCESSFUL
Total time: 14 seconds

You can use the -c (count) option with the read-baseline task of the Record Store Command-line Utility to determine if the Record Store has any records:

C:\Endeca\CAS\<version>\bin> recordstore-cmd.bat read-baseline -a rs1 -c 
Records read: 1

As the example shows, the Record Store has the one record that was read in by the sample writer client.

This section provides an overview of the more important operations of the sample writer client program. You can modify the files and add other Record Store operations.

The methods for these operations are described in the CAS API Guide, and in the Record Store Javadocs.

Assuming that you have opened the SampleWriter.java source in Eclipse or another editor, you should note the following important operations:

  1. A constant is set for the value of the idPropertyName configuration property that is used for the Record Store instance.

    public static final String PROPERTY_ID = "Endeca.FileSystem.Path";
  2. After a LinkedList of Record objects is instantiated, a record is created and added to the list. The Record.addPropertyValue() method is used to add the property values to the record.

    Collection<Record> records = new LinkedList<Record>();
    Record record = new Record();
    record.addPropertyValue(new PropertyValue(PROPERTY_ID, "id1"));
    record.addPropertyValue(new PropertyValue("property.name",
       "property.value"));
    records.add(record);
    
  3. Using the RecordStoreLocator utility class, create a Web service locator with host name, port number, and Record Store instance name:

    RecordStoreLocator locator = RecordStoreLocator.create("localhost", 8500, recordStoreInstance);
  4. Use the RecordStore.getRecordStore() method to establish a connection to the Record Store instance:

    RecordStore recordStore = locator.getRecordStore();
  5. Using the transaction ID created by the RecordStore.startTransaction() method, the RecordStoreWriter.createWriter() method is used to create a writer.

    tId = recordStore.startTransaction(TransactionType.READ_WRITE);
    
    RecordStoreWriter writer =
       RecordStoreWriter.createWriter(recordStore, tId);
    
  6. The writer first writes a "Delete All" record, then writes the sample record, and finally closes the writer.

    writer.deleteAll();
    writer.write(records);
    writer.close();
    
  7. The RecordStore.commitTransaction() method closes the transaction.

    recordStore.commitTransaction(tId);

This section provides an overview of the more important operations of the sample reader client program. You can modify the files and add other Record Store operations.

The methods for these operations are described in theCAS API Guide and in the Record Store API Reference (Javadoc).

The SampleReader.java source program executes the following important operations:


Copyright © Legal Notices