LogRecord stores two types of logs.
This code executes an update operation and examines the log records for the Customer MBO:
int id = 101;
Customer result = Customer.findById(id);
result.setFname("newFname");
result.save();
result.submitPending();
SUP101DB.synchronize();
result = Customer.findById(id);
ObjectList logs = result.getLogRecords();
for (int i = 0; i < logs.count(); i )
{
com.sybase.persistence.LogRecord logRecord =
(com.sybase.persistence.LogRecord)logs.elementAt(i);
// working with logRecord
}
The code in the log record is an HTTP status code. See Developer Guide: BlackBerry Object API Applications >Client Object API Usage >Exceptions > Handling Exceptions > HTTP Error Codes.
There is no logRecord generated for a successful operation replay. The Unwired Server only creates a logRecord when an operation fails.
This sample code shows how to find the corresponding MBO with the LogRecord and to delete the log record when a record is processed.
private void processLogRecords()
{
Query query = new Query();
ObjectList logRecords = SUP101DB.getLogRecords(query);
boolean callSync = false;
for(int i = 0; i < logRecords.size(); ++i)
{
LogRecord log = (LogRecord)logRecords.elementAt(i);
// log warning message
Log.warning("log " + log.getComponent() + ":" + log.getEntityKey()
+ " code:" + log.getCode()
+ " msg:" + log.getMessage());
if (log.getComponent().equals("Customer"))
{
long surrogateKey = Long.parseLong(log.getEntityKey());
Customer c = Customer.find(surrogateKey);
if (c.isPending())
{
c.cancelPending();
}
log.delete();
log.submitPending();
callSync = true;
}
}
if (callSync)
{
SUP101DB.beginSynchronize(null, null);
}
}