All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mobi.cangol.mobile.stat.traffic.TrafficDbService Maven / Gradle / Ivy

There is a newer version: 1.2.7
Show newest version
/**
 * Copyright (c) 2013 Cangol
 * 

* Licensed under the Apache License, Version 2.0 (the "License") * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package mobi.cangol.mobile.stat.traffic; import android.content.Context; import android.database.SQLException; import java.util.List; import mobi.cangol.mobile.db.Dao; import mobi.cangol.mobile.db.QueryBuilder; import mobi.cangol.mobile.logging.Log; /** * Created by weixuewu on 16/1/23. */ class TrafficDbService { private Dao dateTrafficDao; private Dao appTrafficDao; public TrafficDbService(Context context) { try { final StatDatabaseHelper dbHelper = StatDatabaseHelper .createDataBaseHelper(context.getApplicationContext()); dateTrafficDao = dbHelper.getDao(DateTraffic.class); appTrafficDao = dbHelper.getDao(AppTraffic.class); } catch (SQLException e) { Log.e("TrafficDbService init fail!" + e.getMessage()); } } public int saveAppTraffic(AppTraffic obj) { int result = -1; try { if (obj.id > 0 && obj.id != -1) { result = appTrafficDao.update(obj); if (result > 0) { result = obj.id; } } else { result = appTrafficDao.create(obj); } } catch (SQLException e) { Log.e("TrafficDbService saveAppTraffic fail! " + e.getMessage()); } return result; } public int saveDateTraffic(DateTraffic obj) { int result = -1; try { if (obj.id > 0 && obj.id != -1) { result = dateTrafficDao.update(obj); if (result > 0) { result = obj.id; } } else { result = dateTrafficDao.create(obj); } } catch (SQLException e) { Log.e("TrafficDbService saveDateTraffic fail! " + e.getMessage()); } return result; } public DateTraffic getDateTrafficByDate(int uid, String date) { final QueryBuilder queryBuilder = new QueryBuilder(DateTraffic.class); queryBuilder.addQuery("uid", uid, "="); queryBuilder.addQuery("date", date, "="); final List list = dateTrafficDao.query(queryBuilder); if (!list.isEmpty()) { return list.get(0); } else { return null; } } public AppTraffic getAppTraffic(int uid) { final QueryBuilder queryBuilder = new QueryBuilder(AppTraffic.class); queryBuilder.addQuery("uid", uid, "="); final List list = appTrafficDao.query(queryBuilder); if (!list.isEmpty()) { return list.get(0); } else { return null; } } public List getAppTrafficList() { return appTrafficDao.queryForAll(); } public List getDateTrafficByStatus(int uid, String date, int status) { final QueryBuilder queryBuilder = new QueryBuilder(DateTraffic.class); queryBuilder.addQuery("uid", uid, "="); queryBuilder.addQuery("date", date, "<"); queryBuilder.addQuery("status", status, "="); queryBuilder.orderBy("date asc"); return dateTrafficDao.query(queryBuilder); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy