com.endeca.itl.recordstore
Class RecordStoreWriter

java.lang.Object
  extended by com.endeca.itl.recordstore.RecordStoreWriter

public class RecordStoreWriter
extends Object

Used to write records to a Record Store. This hides the details of the batching required for communication with the Record Store web service. Here's an example of an incremental write:

 RecordStoreLocator locator = RecordStoreLocator.create(casHost, casPort, "MyRecordStore");
 RecordStore recordStore = locator.getService();
 TransactionId transactionId = recordStore.startTransaction(TransactionType.READ_WRITE);
 RecordStoreWriter writer = RecordStoreWriter.createWriter(recordStore, tId);
 
 Record record1 = new Record();
 record1.addPropertyValue(new PropertyValue("Endeca.Id","id1"));
 record1.addPropertyValue(new PropertyValue("Product.Description","42in Plasma TV"));
 writer.write(record1);
 
 Record record2 = new Record();
 record2.addPropertyValue(new PropertyValue("Endeca.Id","id2"));
 record2.addPropertyValue(new PropertyValue("Product.Description","36in LCD TV"));
 writer.write(record2);
 
 writer.close();
 recordStore.commitTransaction(transactionId);
 

To perform a baseline write call RecordStoreWriter.deleteAll() before writing any records.


Field Summary
static int DEFAULT_RECORDS_PER_TRANSFER
           
 
Method Summary
 void close()
          Flushes the cache after writing operations.
static RecordStoreWriter createWriter(RecordStore recordStore, TransactionId transactionId)
           
static RecordStoreWriter createWriter(RecordStore recordStore, TransactionId transactionId, Integer recordsPerTransfer)
           
 void deleteAll()
          Attempts to delete all Records from the new Generation been written
 void flush()
          Flushes underlying buffer, forcing all Records to be written
 void write(Collection<Record> records)
          Attempts to write a group of records to the Record Store
 void write(Record record)
          Attempts to write a single record to the Record Store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RECORDS_PER_TRANSFER

public static final int DEFAULT_RECORDS_PER_TRANSFER
See Also:
Constant Field Values
Method Detail

createWriter

public static RecordStoreWriter createWriter(RecordStore recordStore,
                                             TransactionId transactionId,
                                             Integer recordsPerTransfer)
Parameters:
recordStore - Record Store to read from
transactionId - Transaction to read on
recordsPerTransfer - Number of records transferred at once
Returns:
A new Writer

createWriter

public static RecordStoreWriter createWriter(RecordStore recordStore,
                                             TransactionId transactionId)
Parameters:
recordStore - Record Store to read from
transactionId - Transaction to read on
Returns:
A new Writer

deleteAll

public void deleteAll()
               throws RecordStoreException,
                      TransactionStateException,
                      TransactionNotFoundException,
                      WriteNotAllowedException,
                      InvalidRecordException
Attempts to delete all Records from the new Generation been written

Throws:
RecordStoreException - If there is an error in the Record Store
TransactionStateException - If the transaction is not in a state that will allow this operation
TransactionNotFoundException - If a valid transaction cannot be found (or the transaction tied to this Reader doesn't exist anymore)
WriteNotAllowedException - If the Transaction has not been set as READ_WRITE
InvalidRecordException - If the Record is invalid

write

public void write(Record record)
           throws RecordStoreException,
                  TransactionStateException,
                  TransactionNotFoundException,
                  WriteNotAllowedException,
                  InvalidRecordException
Attempts to write a single record to the Record Store

Parameters:
record - The record to write
Throws:
RecordStoreException - If there is an error in the Record Store
TransactionStateException - If the transaction is not in a state that will allow this operation
TransactionNotFoundException - If a valid transaction cannot be found (or the transaction tied to this Reader doesn't exist anymore)
WriteNotAllowedException - If the Transaction has not been set as READ_WRITE
InvalidRecordException - If the Record is invalid

write

public void write(Collection<Record> records)
           throws RecordStoreException,
                  TransactionStateException,
                  TransactionNotFoundException,
                  WriteNotAllowedException,
                  InvalidRecordException
Attempts to write a group of records to the Record Store

Parameters:
records - The records to write
Throws:
RecordStoreException - If there is an error in the Record Store
TransactionStateException - If the transaction is not in a state that will allow this operation
TransactionNotFoundException - If a valid transaction cannot be found (or the transaction tied to this Reader doesn't exist anymore)
WriteNotAllowedException - If the Transaction has not been set as READ_WRITE
InvalidRecordException - If one of the Records is invalid

flush

public void flush()
           throws RecordStoreException,
                  TransactionStateException,
                  TransactionNotFoundException,
                  WriteNotAllowedException,
                  InvalidRecordException
Flushes underlying buffer, forcing all Records to be written

Throws:
RecordStoreException - If there is an error in the Record Store
TransactionStateException - If the transaction is not in a state that will allow this operation
TransactionNotFoundException - If a valid transaction cannot be found (or the transaction tied to this Reader doesn't exist anymore)
WriteNotAllowedException - If the Transaction has not been set as READ_WRITE
InvalidRecordException - If one of the Records is invalid

close

public void close()
           throws RecordStoreException,
                  TransactionStateException,
                  TransactionNotFoundException,
                  WriteNotAllowedException,
                  InvalidRecordException
Flushes the cache after writing operations. You should not call any RecordStoreWriter methods after calling close.

Throws:
RecordStoreException - If there is an error in the Record Store
TransactionStateException - If the transaction is not in a state that will allow this operation
TransactionNotFoundException - If a valid transaction cannot be found (or the transaction tied to this Reader doesn't exist anymore)
WriteNotAllowedException - If the Transaction has not been set as READ_WRITE
InvalidRecordException - If one of the Records is invalid


Copyright © 2007, 2012, Oracle and/or its affiliates. All rights reserved.