/** * Updates the log record of an operation, usually as it ends with a certain status. * * @param logRecord the log record created for the operation by {@link #openLogRecord(String, * Map)} * @param failure the status of the operation if it has failed or <code>null</code> if the * operation succeeded TODO: move this code into the log maintenance service (status update) */ protected void updateLogRecord(SyncLogDTO logRecord, Throwable failure) { String status; if (null == failure) status = SyncLogDTO.OK_STATUS; else { status = failure.toString(); if (null == status || 0 == status.length()) status = "Unknown error"; } logRecord.setStatus(status); try { getDb().findDAO(SyncLogDAO.class).updateStatus(logRecord); } catch (Throwable e) { log().log(Level.WARNING, "Error updating status in the " + logRecord, e); } }
/** * Creates a log record for the operation in the shared database. * * @param operation name of operation to be logged * @param parameters named parameters of the operation or <code>null</code> if the operation takes * no parameters * @return log record for the operation * @throws DBException if there is an error writing the log record to the database TODO: move this * code into the log maintenance service (entry creation) and wrap logRecord into a middle * tier object */ protected SyncLogDTO openLogRecord(String operation, Map<String, String> parameters) throws DBException { SyncLogDAO logDAO = getDb().findDAO(SyncLogDAO.class); SyncLogDTO logRecord = new SyncLogDTO(); logRecord.setFilterId(getEffectiveFilterId()); logRecord.setFilterInverted(getEffectiveFilterSpec().isInverted()); ReplicaDTO replica = getCurrentReplica(); if (null != replica) logRecord.setReplicaId(replica.getId()); logRecord.setOperation(operation); logRecord.setParameters(parameters); logRecord.setStarted(getOperationTimestamp()); logDAO.createRecord(logRecord); return logRecord; }