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);
for(com.sybase.persistence.LogRecord logRecord : result.getLogRecords())
{
//Working with logRecord
}
The code in the log record is an HTTP status code. See Developer Guide: Android 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 processLogs()
{
Query query = new Query();
GenericList<LogRecord> logRecords = SUP101DB.getLogRecords(query);
boolean callSync = false;
for(LogRecord log : logRecords)
{
// 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();
}
// delete the LogRecord after it is processed
log.delete();
log.submitPending();
callSync = true;
}
}