@Override public List<UserStatisticsVO> listBy(long accountId) { SearchCriteria<UserStatisticsVO> sc = AccountSearch.create(); sc.setParameters("account", accountId); return search(sc, null); }
@Override public List<UserStatisticsVO> listUpdatedStats() { List<UserStatisticsVO> userStats = new ArrayList<UserStatisticsVO>(); TransactionLegacy txn = TransactionLegacy.currentTxn(); try { PreparedStatement pstmt = null; pstmt = txn.prepareAutoCloseStatement(UPDATED_STATS_SEARCH); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { userStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { s_logger.error("error lisitng updated user stats", ex); } return userStats; }
@Override public UserStatisticsVO lock(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) { SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create(); sc.setParameters("account", accountId); sc.setParameters("dc", dcId); sc.setParameters("network", networkId); sc.setParameters("ip", publicIp); sc.setParameters("device", deviceId); sc.setParameters("deviceType", deviceType); return lockOneRandomRow(sc, true); }
@Override public UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) { SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create(); sc.setParameters("account", accountId); sc.setParameters("dc", dcId); sc.setParameters("network", networkId); sc.setParameters("ip", publicIp); sc.setParameters("device", deviceId); sc.setParameters("deviceType", deviceType); return findOneBy(sc); }
public UserStatisticsDaoImpl() { AccountSearch = createSearchBuilder(); AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountSearch.done(); AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("ip", AllFieldsSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("device", AllFieldsSearch.entity().getDeviceId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("deviceType", AllFieldsSearch.entity().getDeviceType(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); }
@Override public List<UserStatisticsVO> listActiveAndRecentlyDeleted(Date minRemovedDate, int startIndex, int limit) { List<UserStatisticsVO> userStats = new ArrayList<UserStatisticsVO>(); if (minRemovedDate == null) return userStats; TransactionLegacy txn = TransactionLegacy.currentTxn(); try { String sql = ACTIVE_AND_RECENTLY_DELETED_SEARCH + " LIMIT " + startIndex + "," + limit; PreparedStatement pstmt = null; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), minRemovedDate)); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { userStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { s_logger.error("error saving user stats to cloud_usage db", ex); } return userStats; }