/*******************************************************************************
 * Copyright 2019 2Fi Business Solutions Ltd.
 *
 *
 *
 * This code is copyrighted. Under no circumstances should any party, people,
 * or organization should redistribute any portions of this code in any form,
 * either verbatim or through electronic media, to any third parties, unless
 * under explicit written permission by 2Fi Business Solutions Ltd.
 ******************************************************************************/
package com.ffii.tbms.log.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.ffii.core.dao.JdbcDao;
import com.ffii.core.utils.MapUtils;
import com.ffii.core.web.AbstractService;

/**
 * @author Patrick
 */
@Service
public class UsageLogService extends AbstractService {

	@Autowired
	private JdbcDao jdbcDao;

	private static final String SQL_INSERT_USAGE_LOG = "INSERT INTO usage_log (`type`, `name`, `userId`, `datetime`, `params`)"
			+ " VALUES (:type, :name, :userId, :datetime, :params)";

	@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = false)
	public int save(String type, String name, int userId, Date datetime, String params) {
		return jdbcDao.executeUpdate(SQL_INSERT_USAGE_LOG,
				MapUtils.toHashMap("type", type, "name", name, "userId", userId,
						"datetime", datetime, "params", params));
	}

}
