/** * Method declaration * * @param conf */ public static void makeStatAllCumul(StatisticsConfig conf) { Connection con = getConnection(); try { if (conf != null && con != null && conf.isValidConfigFile()) { for (StatType currentType : conf.getAllTypes()) { try { purgeTablesCumul(con, currentType, conf); } catch (SQLException e) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_PURGE_BD", e); } try { makeStatCumul(con, currentType, conf); } catch (SQLException e) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_CUMUL_BD", e); } finally { try { deleteTablesOfTheDay(con, currentType, conf); } catch (SQLException e) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_PURGE_BD", e); } } } } else { if (con == null) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_CONNECTION_BD"); } if (conf == null) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_NO_CONFIG_FILE"); } else if (!conf.isValidConfigFile()) { SilverTrace.error( "silverstatistics", "SilverStatisticsManagerDAO.makeStatAllCumul", "silverstatistics.MSG_CONFIG_FILE"); } } } finally { DBUtil.close(con); } }
@Test public void testPurgeTablesCumul() throws Exception { MockConnection connexion = factory.getMockConnection(); SilverStatisticsManagerDAO.purgeTablesCumul(connexion, typeofStat, config); module.verifyAllStatementsClosed(); Calendar calend = Calendar.getInstance(); calend.add(Calendar.YEAR, -10); String date = SilverStatisticsManagerDAO.getRequestDate( calend.get(Calendar.YEAR), calend.get(Calendar.MONTH) + 1); List<?> statements = module.getPreparedStatements(); assertNotNull(statements); assertThat(statements, hasSize(1)); MockPreparedStatement pstmt = module.getPreparedStatement(0); assertThat(pstmt.getSQL(), is("DELETE FROM SB_Stat_SizeDirCumul WHERE dateStat<" + date)); Map parameters = pstmt.getParameterMap(); assertThat(parameters.size(), is(0)); }