コード例 #1
0
 /**
  * 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);
   }
 }
コード例 #2
0
 @Test
 public void testMakeStatCumulWithoutExistingData() throws Exception {
   MockConnection connexion = factory.getMockConnection();
   StatementResultSetHandler statementHandler = connexion.getStatementResultSetHandler();
   statementHandler.setExactMatch(true);
   MockResultSet result = statementHandler.createResultSet();
   result.addColumn("dateStat", new Object[] {"2011-04-17"});
   result.addColumn("fileDir", new Object[] {"/var/data/silverpeas/kmelia36"});
   result.addColumn("sizeDir", new Object[] {543L});
   statementHandler.prepareResultSet("SELECT * FROM SB_Stat_SizeDir", result);
   MockResultSet cumulResult = statementHandler.createResultSet();
   statementHandler.prepareResultSet(
       "SELECT dateStat,fileDir,sizeDir FROM SB_Stat_SizeDirCumul "
           + "WHERE dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'",
       cumulResult);
   SilverStatisticsManagerDAO.makeStatCumul(connexion, typeofStat, config);
   module.verifyAllStatementsClosed();
   List<?> statements = module.getExecutedSQLStatements();
   assertNotNull(statements);
   assertThat(statements.size(), is(3));
   List<?> preparedStatements = module.getPreparedStatements();
   assertNotNull(preparedStatements);
   assertThat(preparedStatements, hasSize(2));
   MockPreparedStatement pstmt = module.getPreparedStatement(0);
   assertThat(
       pstmt.getSQL(),
       is(
           "UPDATE SB_Stat_SizeDirCumul SET sizeDir=?  WHERE "
               + "dateStat='2011-04-01' AND fileDir='/var/data/silverpeas/kmelia36'"));
   Map parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(0));
   pstmt = module.getPreparedStatement(1);
   assertThat(
       pstmt.getSQL(),
       is("INSERT INTO SB_Stat_SizeDirCumul(dateStat,fileDir,sizeDir) " + "VALUES(?,?,?)"));
   parameters = pstmt.getParameterMap();
   assertThat(parameters.size(), is(3));
   assertThat((String) parameters.get(1), is("2011-04-01"));
   assertThat((String) parameters.get(2), is("/var/data/silverpeas/kmelia36"));
   assertThat((Long) parameters.get(3), is(543L));
 }