org.restcomm.connect.dao.mybatis.MybatisUsageDao Maven / Gradle / Ivy
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2014, Telestax Inc and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see
*
*/
package org.restcomm.connect.dao.mybatis;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.restcomm.connect.dao.DaoUtils;
import org.restcomm.connect.dao.UsageDao;
import org.restcomm.connect.commons.dao.Sid;
import org.restcomm.connect.dao.entities.Usage;
import org.restcomm.connect.commons.annotations.concurrency.ThreadSafe;
import java.math.BigDecimal;
import java.net.URI;
import java.sql.Date;
import java.util.Currency;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* @author [email protected] (Alexandre Mendonca)
*/
@ThreadSafe
public final class MybatisUsageDao implements UsageDao {
private static final String namespace = "org.mobicents.servlet.sip.restcomm.dao.UsageDao.";
private final SqlSessionFactory sessions;
public MybatisUsageDao(final SqlSessionFactory sessions) {
super();
this.sessions = sessions;
}
@Override
public List getUsage(final Sid accountSid) {
return getUsageCalls(accountSid, null, null, null, "getAllTimeCalls");
}
@Override
public List getUsageDaily(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getDailyCalls");
}
@Override
public List getUsageMonthly(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getMonthlyCalls");
}
@Override
public List getUsageYearly(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getYearlyCalls");
}
@Override
public List getUsageAllTime(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getAllTimeCalls");
}
/*
@Override
public List getUsageToday(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getTodayCalls");
}
@Override
public List getUsageYesterday(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getYesterdayCalls");
}
@Override
public List getUsageThisMonth(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getThisMonthCalls");
}
@Override
public List getUsageLastMonth(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate) {
return getUsageCalls(accountSid, category, startDate, endDate, "getLastMonthCalls");
}
*/
private List getUsageCalls(final Sid accountSid, Usage.Category category, DateTime startDate, DateTime endDate, final String queryName) {
long startTime = System.currentTimeMillis();
final SqlSession session = sessions.openSession();
Map params = new HashMap();
params.put("sid", accountSid.toString());
params.put("startDate", new Date(startDate.getMillis()));
params.put("endDate", new Date(endDate.getMillis()));
fillParametersByCategory(category, params);
try {
final List © 2015 - 2025 Weber Informatics LLC | Privacy Policy