String maxConnectionToLog = engineSettingService.getEngineSettingDefaultValueByCode(EngineSettingService.ENGINE_SETTING_MAX_CUSTOMER_CONNECTION_LOG);
final Long customerId = customerConnectionLog.getCustomerId();
final String appCode = customerConnectionLog.getAppCode();
List<CustomerConnectionLog> customerConnectionLogs = customerConnectionLogDao.findCustomerConnectionLogsByCustomerIdAndAppCode(customerId, appCode);
if(customerConnectionLogs.size() >= new Integer(maxConnectionToLog)){
CustomerConnectionLog customerConnectionLogToUpdate = customerConnectionLogs.get(0);
customerConnectionLogToUpdate.setAddress(customerConnectionLog.getAddress());
customerConnectionLogToUpdate.setHost(customerConnectionLog.getHost());
customerConnectionLogToUpdate.setLoginDate(customerConnectionLog.getLoginDate());
customerConnectionLogDao.saveOrUpdateCustomerConnectionLog(customerConnectionLogToUpdate);
} else {
customerConnectionLogDao.saveOrUpdateCustomerConnectionLog(customerConnectionLog);
}
}