Pending State Pattern

When a create, update, delete, or save operation is called on an entity in a replication-based synchronization application, the requested change becomes pending. To apply the pending change, call submitPending on the entity, or submitPendingOperations on the MBO class:

  Customer e = new Customer();
e.setFname("Fred");
e.setAddress("123 Four St.");
e.create(); // create as pending
e.submitPending(); // submit to server
Customer.submitPendingOperations(); // submit all pending Customer rows to server

submitPendingOperations submits all the pending records for the entity to the Unwired Server. This method internally invokes the submitPending method on each of the pending records.

The call to submitPending causes the operations to be marked for replay by Unwired Server. On the next synchronization, Unwired Server processes the operations and creates log records for each operation with code indicating the status of the operation. The LogRecord interface is defined as follows:

Method Name Java Type Description
component string Name of the MBO for the row for which this log record was written.
entityKey string String representation of the primary key of the row for which this log record was written.
code int One of several possible HTTP error codes:
  • 200 indicates success.
  • 401 indicates that the client request had invalid credentials, or that authentication failed for some other reason.
  • 403 indicates that the client request had valid credentials, but that the user does not have permission to access the requested resource (package, MBO, or operation).
  • 404 indicates that the client tried to access a nonexistent package or MBO.
  • 405 indicates that there is no valid license to check out for the client.
  • 500 to indicate an unexpected (unspecified) server failure.
message String Descriptive message from the server with the reason for the log record.
operation String The operation (create, update, or delete) that caused the log record to be written.
requestId String The id of the replay message sent by the client that caused this log record to be written.
timestamp Date Date and time of the log record.

If a rejection is received, the application can use the entity method getLogRecords to access the log records and get the reason:

  com.sybase.collections.ObjectList logs = e.getLogRecords();
for(int i=0; i<logs.count(); i++)
{
com.sybase.persistence.LogRecord log = 
(com.sybase.persistence.LogRecord)logs.getByIndex(i);
System.out.println("Entity has a log record:");
System.out.println("Code = " + log.getCode());
System.out.println("Component = " + log.getComponent());
System.out.println("EntityKey = " + log.getEntityKey());
System.out.println("Level = " + log.getLevel());
System.out.println("Message = " + log.getMessage());
System.out.println("Operation = " + log.getOperation());
System.out.println("RequestId = " + log.getRequestId());
System.out.println("Timestamp = " + log.getTimestamp());
}

cancelPendingOperations cancels all the pending records for an entity. This method internally invokes the cancelPending method on each of the pending records.