public static Session getSession(boolean cache) { Session session = null; try { session = MailServiceUtil.getSession(); } catch (SystemException se) { if (_log.isWarnEnabled()) { _log.warn(se, se); } session = InfrastructureUtil.getMailSession(); } if (_log.isDebugEnabled()) { session.setDebug(true); session.getProperties().list(System.out); } return session; }
/** * Performs an SQL query. * * @param sql the sql query */ protected void runSQL(String sql) throws SystemException { try { DataSource dataSource = InfrastructureUtil.getDataSource(); SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql, new int[0]); sqlUpdate.update(); } catch (Exception e) { throw new SystemException(e); } }
/** * Retorna os usuários por UF * * @param companyId * TODO * @param pais * * @return */ @Transactional(readOnly = true) public Map<String, Integer> getUsuariosPorUf(long companyId, Country pais) { long contactClassId = ClassNameLocalServiceUtil.getClassNameId(Contact.class.getName()); long classId = pais.getCountryId(); DataSource dataSource = InfrastructureUtil.getDataSource(); String sql = "select reg.regionCode, count(*) from User_ u join Contact_ c on u.contactId = c.contactId " + "left outer join " + "Address ad on (c.contactId = ad.classPK and ad.classNameId = ? and ad.countryId = ? and ad.primary_ <> 0) " + "left outer join Region reg on (ad.regionId = reg.regionId) where u.companyId = ? " + "group by reg.regionCode order by reg.regionCode"; MappingSqlQuery<UsuarioPorEstado> query = MappingSqlQueryFactoryUtil.getMappingSqlQuery(dataSource, sql, new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT }, new RowMapper<UsuarioPorEstado>() { @Override public UsuarioPorEstado mapRow(ResultSet rs, int rowNumber) throws SQLException { String uf = rs.getString(1); if (uf == null) uf = "N/D"; return new UsuarioPorEstado(uf, rs.getInt(2)); } }); Map<String, Integer> retorno = new LinkedHashMap<String, Integer>(); for (UsuarioPorEstado entrada : query.execute(contactClassId, classId, companyId)) { retorno.put(entrada.getUf(), entrada.getNumero()); } return retorno; }
private Map<String, Integer> buscaQuantidadePorData(long companyId, TimeZone tz, Date inicio, Date fim, String sql) { DataSource dataSource = InfrastructureUtil.getDataSource(); // Corrige as datas de início e fim Calendar cal = Calendar.getInstance(tz); cal.setTime(inicio); inicio = CalendarUtil.getGTDate(cal); cal.setTime(fim); fim = CalendarUtil.getLTDate(cal); Map<String, Integer> retorno = new LinkedHashMap<String, Integer>(); MappingSqlQuery<Date> mensagens = MappingSqlQueryFactoryUtil.getMappingSqlQuery(dataSource, sql, new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.BIGINT }, new RowMapper<Date>() { @Override public Date mapRow(ResultSet rs, int rowNumber) throws SQLException { return rs.getTimestamp(1); } }); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setTimeZone(tz); for (Date data : mensagens.execute(inicio, fim, companyId)) { String dia = sdf.format(data); if (!retorno.containsKey(dia)) retorno.put(dia, 1); else retorno.put(dia, retorno.get(dia) + 1); } return retorno; }
/** * Performs an SQL query. * * @param sql the sql query to perform */ protected void runSQL(String sql) throws SystemException { try { DataSource dataSource = InfrastructureUtil.getDataSource(); SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql, new int[0]); sqlUpdate.update(); } catch (Exception e) { throw new SystemException(e); } }
private QueryRunner createRunner(){ final DataSource dataSource = InfrastructureUtil.getDataSource(); return new QueryRunner(dataSource); }