@Override
 public int getDistinctCountByPeriodUser(
     List<WAPrimaryKey> primaryKeys,
     int action,
     String objectType,
     Date startDate,
     Date endDate,
     List<String> userIds) {
   int nb = 0;
   Connection con = getConnection();
   if (userIds != null && !userIds.isEmpty()) {
     Set<String> distinctObjectIds = new HashSet<>(userIds.size());
     try {
       for (String userId : userIds) {
         List<String> objectIds =
             HistoryObjectDAO.getListObjectAccessByPeriodAndUser(
                 con, primaryKeys, objectType, startDate, endDate, userId);
         distinctObjectIds.addAll(objectIds);
       }
       nb = distinctObjectIds.size();
     } catch (Exception e) {
       throw new StatisticRuntimeException(
           "DefaultStatisticService().getDistinctCountByPeriod()",
           SilverpeasRuntimeException.ERROR,
           "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
           e);
     } finally {
       DBUtil.close(con);
     }
   }
   return nb;
 }
 /*
  * (non-Javadoc)
  * @see
  * FormsOnlineDAO#createInstance(com.silverpeas.formsonline.model
  * .FormInstance)
  */
 public FormInstance createInstance(FormInstance instance) throws FormsOnlineDatabaseException {
   Connection con = getConnection();
   try (PreparedStatement stmt = con.prepareStatement(QUERY_INSERT_FORMINSTANCE)) {
     int id = DBUtil.getNextId(FORMS_INSTANCES_TABLENAME, "id");
     stmt.setInt(1, id);
     stmt.setInt(2, instance.getFormId());
     stmt.setInt(3, instance.getState());
     stmt.setString(4, instance.getCreatorId());
     prepareDateStatement(stmt, 5, instance.getCreationDate());
     stmt.setString(6, instance.getValidatorId());
     prepareDateStatement(stmt, 7, instance.getValidationDate());
     stmt.setString(8, instance.getComments());
     stmt.setString(9, instance.getComponentInstanceId());
     stmt.executeUpdate();
     instance.setId(id);
     return instance;
   } catch (SQLException se) {
     throw new FormsOnlineDatabaseException(
         "FormsOnlineDAOJdbc.createInstance()",
         SilverpeasException.ERROR,
         "formsOnline.INSERTING_FORMINSTANCE_FAILED",
         se);
   } finally {
     freeConnection(con);
   }
 }
예제 #3
0
  /**
   * Method declaration
   *
   * @param con
   * @param pk
   * @param coordinatePoints
   * @throws SQLException
   * @see
   */
  public static void removeCoordinatesByPoints(
      Connection con, CoordinatePK pk, List<String> coordinatePoints) throws SQLException {
    StringBuilder deleteQuery = new StringBuilder("DELETE FROM sb_coordinates_coordinates WHERE ");
    if (coordinatePoints != null) {
      Iterator<String> it = coordinatePoints.iterator();
      deleteQuery.append("(");
      while (it.hasNext()) {
        String pointId = it.next();
        deleteQuery.append(" nodeId = ").append(pointId);
        if (it.hasNext()) {
          deleteQuery.append(" or ");
        }
      }
      deleteQuery.append(" ) ");
    }
    deleteQuery.append(" AND instanceId ='").append(pk.getComponentName()).append("'");
    Statement stmt = null;

    try {
      stmt = con.createStatement();
      stmt.executeUpdate(deleteQuery.toString());
    } finally {
      DBUtil.close(stmt);
    }
  }
 @Override
 public int getCountByPeriodAndUser(
     List<WAPrimaryKey> primaryKeys,
     String objectType,
     Date startDate,
     Date endDate,
     List<String> userIds) {
   int nb = 0;
   Connection con = getConnection();
   try {
     if (!userIds.isEmpty()) {
       for (String userId : userIds) {
         for (WAPrimaryKey primaryKey : primaryKeys) {
           nb +=
               HistoryObjectDAO.getCountByPeriodAndUser(
                   con, primaryKey, objectType, startDate, endDate, userId);
         }
       }
     }
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().getCountByPeriodAndUser()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
         e);
   } finally {
     DBUtil.close(con);
   }
   return nb;
 }
예제 #5
0
  public static List<String> getHolidayDates(
      Connection con, String userId, Date beginDate, Date endDate) throws SQLException {
    List<String> holidayDates = new ArrayList<String>();
    StringBuilder query = new StringBuilder(128);
    query.append("select * ");
    query.append("from ").append(AGENDA_HOLIDAYS_TABLENAME);
    query.append(" where userId = ? ");
    query.append(" and ? <= holidayDate ");
    query.append(" and holidayDate <= ? ");
    query.append("order by holidayDate ASC");

    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      stmt = con.prepareStatement(query.toString());
      stmt.setInt(1, Integer.parseInt(userId));
      stmt.setString(2, DateUtil.date2SQLDate(beginDate));
      stmt.setString(3, DateUtil.date2SQLDate(endDate));
      rs = stmt.executeQuery();
      while (rs.next()) {
        holidayDates.add(rs.getString("holidayDate"));
      }
    } finally {
      DBUtil.close(rs, stmt);
    }
    return holidayDates;
  }
  public FormDetail createForm(FormDetail formDetail) throws FormsOnlineDatabaseException {
    Connection con = getConnection();
    try (PreparedStatement stmt = con.prepareStatement(QUERY_INSERT_FORM)) {
      int id = DBUtil.getNextId(FORMS_TABLENAME, "id");
      stmt.setInt(1, id);
      stmt.setString(2, formDetail.getXmlFormName());
      stmt.setString(3, formDetail.getName());
      stmt.setString(4, formDetail.getDescription());
      stmt.setString(5, formDetail.getTitle());
      stmt.setString(6, formDetail.getCreatorId());
      prepareDateStatement(stmt, 7, formDetail.getCreationDate());
      stmt.setInt(8, formDetail.getState());
      stmt.setInt(9, (formDetail.isAlreadyUsed()) ? 1 : 0);
      stmt.setString(10, formDetail.getInstanceId());

      stmt.executeUpdate();
      formDetail.setId(id);

      return formDetail;
    } catch (SQLException se) {
      throw new FormsOnlineDatabaseException(
          "FormsOnlineDAOJdbc.createForm()",
          SilverpeasException.ERROR,
          "formsOnline.INSERTING_FORM_FAILED",
          se);
    } finally {
      freeConnection(con);
    }
  }
 private Connection getConnection() {
   try {
     return DBUtil.openConnection();
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().getConnection()",
         SilverpeasRuntimeException.ERROR,
         "root.EX_CONNECTION_OPEN_FAILED",
         e);
   }
 }
예제 #8
0
  private static List<String> selectCoordinateIdsByNodeIds(
      Connection con, List<String> fatherPaths, CoordinatePK pk) throws SQLException {
    ResultSet rs = null;

    String fatherPath = "";
    String whereClause = "";
    String fatherId = "";
    String rootFatherId = "";
    int axisToMatch = fatherPaths.size();
    if (fatherPaths != null) {
      Iterator<String> it = fatherPaths.iterator();
      while (it.hasNext()) {
        fatherPath = it.next();
        // enleve le premier /0/
        fatherPath = fatherPath.substring(1);
        fatherPath = fatherPath.substring(fatherPath.indexOf('/') + 1, fatherPath.length());
        // extrait l'id
        fatherId = fatherPath.substring(fatherPath.lastIndexOf('/') + 1, fatherPath.length());
        // extrait l'id de la racine
        rootFatherId = fatherPath.substring(0, fatherPath.indexOf('/'));
        whereClause += " nodeId = " + fatherId;
        whereClause += " or (nodeId = " + rootFatherId + " and coordinatesLeaf = '1') ";
        if (it.hasNext()) {
          whereClause += " Or ";
        }
      }
    }

    String selectStatement = "select coordinatesId, count(*) " + "from " + pk.getTableName() + " ";
    if (fatherPaths != null && fatherPaths.size() > 0) {
      selectStatement += "where " + whereClause;
    }
    selectStatement += " And instanceId = '" + pk.getComponentName() + "' ";
    selectStatement += " GROUP BY coordinatesId";

    PreparedStatement prepStmt = null;
    try {
      prepStmt = con.prepareStatement(selectStatement);
      rs = prepStmt.executeQuery();
      List<String> list = new ArrayList<String>();
      int coordinateId = 0;
      int nbMatches = 0;
      while (rs.next()) {
        coordinateId = rs.getInt(1);
        nbMatches = rs.getInt(2);
        if (nbMatches == axisToMatch) {
          list.add(new Integer(coordinateId).toString());
        }
      }
      return list;
    } finally {
      DBUtil.close(rs, prepStmt);
    }
  }
예제 #9
0
  protected final synchronized void createConnection() throws UtilException {

    try {
      if (this.connection != null) {
        DBUtil.close(this.connection);
      }
      this.connection = DBUtil.openConnection();
      if (!this.connection.getAutoCommit()) {
        managed = true;
      } else {
        managed = false;
        this.connection.setAutoCommit(false);
      }
      isLocalConnection = true;

    } catch (SQLException e) {
      throw new UtilException(
          "Schema.createConnection", SilverpeasException.ERROR, "root.EX_DATASOURCE_INVALID", e);
    }
  }
 /**
  * Get a new connection.
  *
  * @return the initialized connection.
  * @throws FormsOnlineDatabaseException if a database error occured while getting connection
  */
 protected Connection getConnection() throws FormsOnlineDatabaseException {
   try {
     return DBUtil.openConnection();
   } catch (SQLException e) {
     throw new FormsOnlineDatabaseException(
         "FormsOnlineDAOJdbc.getConnection()",
         SilverpeasException.FATAL,
         "root.EX_CONNECTION_OPEN_FAILED",
         e);
   }
 }
예제 #11
0
  public synchronized void close() {

    /*
     * for (Object o : statementsMap.values()) { DBUtil.close((Statement) o); }
     * statementsMap.clear();
     */
    try {
      DBUtil.close(this.connection);
    } finally {
      connection = null;
    }
  }
 /**
  * Deletes the resources belonging to the specified component instance. This method is invoked by
  * Silverpeas when a component instance is being deleted.
  *
  * @param componentInstanceId the unique identifier of a component instance.
  */
 @Override
 @Transactional
 public void delete(final String componentInstanceId) {
   Connection con = getConnection();
   try {
     HistoryObjectDAO.deleteStatsOfComponent(con, componentInstanceId);
   } catch (Exception e) {
     throw new RuntimeException(
         "A failure occurred when deleting the statistics relative to the component instance "
             + componentInstanceId,
         e);
   } finally {
     DBUtil.close(con);
   }
 }
 @Override
 public int getCount(List<ForeignPK> foreignPKs, int action, String objectType) {
   Connection con = getConnection();
   try {
     return HistoryObjectDAO.getCount(con, foreignPKs, objectType);
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().getCount()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
         e);
   } finally {
     DBUtil.close(con);
   }
 }
예제 #14
0
 /**
  * Method declaration
  *
  * @param con
  * @param pk
  * @return
  * @throws SQLException
  * @see
  */
 static Collection<String> getCoordinateIds(Connection con, CoordinatePK pk) throws SQLException {
   List<String> coordinateIds = new ArrayList<String>();
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = con.prepareStatement(SELECT_BY_COMPONENT);
     pstmt.setString(1, pk.getComponentName());
     rs = pstmt.executeQuery();
     while (rs.next()) {
       coordinateIds.add(rs.getString("coordinatesid"));
     }
   } finally {
     DBUtil.close(rs, pstmt);
   }
   return coordinateIds;
 }
예제 #15
0
 /**
  * Method declaration
  *
  * @param con
  * @param pk
  * @return
  * @throws SQLException
  * @see
  */
 private static int getMaxDisplayOrder(Connection con, CoordinatePK pk) throws SQLException {
   int maxFromTable = 0;
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = con.prepareStatement(SELECT_MAX_ORDER);
     pstmt.setString(1, pk.getComponentName());
     rs = pstmt.executeQuery();
     if (rs.next()) {
       maxFromTable = rs.getInt(1);
     }
   } finally {
     DBUtil.close(rs, pstmt);
   }
   return maxFromTable;
 }
  @Override
  public void deleteStats(ForeignPK foreignPK, String objectType) {

    Connection con = getConnection();
    try {
      HistoryObjectDAO.deleteHistoryByObject(con, foreignPK, objectType);
    } catch (Exception e) {
      throw new StatisticRuntimeException(
          "DefaultStatisticService().deleteHistoryByAction",
          SilverpeasRuntimeException.ERROR,
          "statistic.CANNOT_DELETE_HISTORY_STATISTICS_PUBLICATION",
          e);
    } finally {
      DBUtil.close(con);
    }
  }
  @Override
  public void addStat(String userId, ForeignPK foreignPK, int actionType, String objectType) {

    Connection con = getConnection();
    try {
      HistoryObjectDAO.add(con, userId, foreignPK, actionType, objectType);
    } catch (Exception e) {
      throw new StatisticRuntimeException(
          "DefaultStatisticService().addStat()",
          SilverpeasRuntimeException.ERROR,
          "statistic.CANNOT_ADD_VISITE_NODE",
          e);
    } finally {
      DBUtil.close(con);
    }
  }
 public boolean isRead(SilverpeasContent content, String userId) {
   Connection con = getConnection();
   try {
     int numberOfReading =
         HistoryObjectDAO.getCountByPeriodAndUser(
             con, getForeignPK(content), content.getContributionType(), null, null, userId);
     return numberOfReading > 0;
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().isRead()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
         e);
   } finally {
     DBUtil.close(con);
   }
 }
 @Override
 public void moveStat(ForeignPK toForeignPK, int actionType, String objectType) {
   SilverTrace.info(
       "statistic", "DefaultStatisticService.deleteHistoryByAction", "root.MSG_GEN_ENTER_METHOD");
   Connection con = getConnection();
   try {
     HistoryObjectDAO.move(con, toForeignPK, actionType, objectType);
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().addObjectToHistory()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_ADD_VISITE_NODE",
         e);
   } finally {
     DBUtil.close(con);
   }
 }
예제 #20
0
  public static void removeHolidayDate(Connection con, HolidayDetail holiday) throws SQLException {
    StringBuilder deleteStatement = new StringBuilder(128);
    deleteStatement.append("delete from ").append(AGENDA_HOLIDAYS_TABLENAME);
    deleteStatement.append(" where holidayDate = ? ");
    deleteStatement.append(" and userId = ? ");
    PreparedStatement prepStmt = null;

    try {
      prepStmt = con.prepareStatement(deleteStatement.toString());

      prepStmt.setString(1, DateUtil.date2SQLDate(holiday.getDate()));
      prepStmt.setInt(2, Integer.parseInt(holiday.getUserId()));

      prepStmt.executeUpdate();
    } finally {
      DBUtil.close(prepStmt);
    }
  }
예제 #21
0
 /**
  * Method declaration
  *
  * @param con
  * @param pk
  * @param nodeId
  * @return
  * @throws SQLException
  * @see
  */
 public static Collection<String> getCoordinateIdsByNodeId(
     Connection con, CoordinatePK pk, String nodeId) throws SQLException {
   List<String> coordinateIds = new ArrayList<String>();
   PreparedStatement prepStmt = null;
   ResultSet rs = null;
   try {
     prepStmt = con.prepareStatement(SELECT_BY_NODEID);
     prepStmt.setInt(1, new Integer(nodeId).intValue());
     prepStmt.setString(2, pk.getComponentName());
     rs = prepStmt.executeQuery();
     while (rs.next()) {
       coordinateIds.add(rs.getString("id"));
     }
   } finally {
     DBUtil.close(rs, prepStmt);
   }
   return coordinateIds;
 }
  @Override
  public Collection<HistoryObjectDetail> getLastHistoryOfObjectsForUser(
      String userId, int actionType, String objectType, int nbObjects) {

    Connection con = getConnection();
    try {
      return HistoryObjectDAO.getLastHistoryDetailOfObjectsForUser(
          con, userId, actionType, objectType, nbObjects);
    } catch (Exception e) {
      throw new StatisticRuntimeException(
          "DefaultStatisticService().getLastHistoryOfObjectsForUser()",
          SilverpeasRuntimeException.ERROR,
          "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
          e);
    } finally {
      DBUtil.close(con);
    }
  }
예제 #23
0
 /**
  * Method declaration
  *
  * @param con
  * @param pk
  * @param point
  * @param coordinateId
  * @throws SQLException
  * @see
  */
 private static void addCoordinatePoint(
     Connection con, CoordinatePK pk, CoordinatePoint point, int coordinateId)
     throws SQLException {
   PreparedStatement prepStmt = null;
   try {
     prepStmt = con.prepareStatement(INSERT_COORDINATE);
     prepStmt.setInt(1, coordinateId);
     prepStmt.setInt(2, point.getNodeId());
     if (point.isLeaf()) {
       prepStmt.setString(3, "1");
     } else {
       prepStmt.setString(3, "0");
     }
     prepStmt.setInt(4, point.getOrder());
     prepStmt.setString(5, pk.getComponentName());
     prepStmt.executeUpdate();
   } finally {
     DBUtil.close(prepStmt);
   }
 }
예제 #24
0
 /**
  * Method declaration
  *
  * @param con
  * @param pk
  * @return
  * @throws SQLException
  * @see
  */
 private static Coordinate selectCoordinateByCoordinatePK(Connection con, CoordinatePK pk)
     throws SQLException {
   List<CoordinatePoint> list = new ArrayList<CoordinatePoint>();
   int id = Integer.parseInt(pk.getId());
   PreparedStatement prepStmt = null;
   ResultSet rs = null;
   try {
     prepStmt = con.prepareStatement(SELECT_BY_PK);
     prepStmt.setInt(1, id);
     prepStmt.setString(2, "1");
     prepStmt.setString(3, pk.getComponentName());
     rs = prepStmt.executeQuery();
     while (rs.next()) {
       list.add(getCoordinatePointFromResultSet(rs));
     }
   } finally {
     DBUtil.close(rs, prepStmt);
   }
   return new Coordinate(id, list);
 }
 @Override
 public Collection<HistoryObjectDetail> getHistoryByObjectAndUser(
     ForeignPK foreignPK, int action, String objectType, String userId) {
   SilverTrace.info(
       "statistic",
       "DefaultStatisticService.getHistoryByObjectAndUser",
       "root.MSG_GEN_ENTER_METHOD");
   Connection con = getConnection();
   try {
     return HistoryObjectDAO.getHistoryDetailByObjectAndUser(con, foreignPK, objectType, userId);
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().getHistoryByObjectAndUser()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
         e);
   } finally {
     DBUtil.close(con);
   }
 }
예제 #26
0
  /**
   * Method declaration
   *
   * @param con the Connection to database
   * @param fatherIds an ArrayList of nodeId
   * @param pk a CoordinatePK
   * @return an ArrayList which contains CoordinatePoint corresponding to fatherIds
   * @throws SQLException
   * @see
   */
  private static List<CoordinatePoint> selectCoordinatePointsByNodeIds(
      Connection con, List<Integer> fatherIds, CoordinatePK pk) throws SQLException {
    List<CoordinatePoint> list = new ArrayList<CoordinatePoint>();
    StringBuilder whereClause = new StringBuilder(20 * fatherIds.size() + 200);
    if (fatherIds != null) {
      Iterator<Integer> it = fatherIds.iterator();
      whereClause.append("(");
      while (it.hasNext()) {
        whereClause.append(" nodeId = ").append(it.next());
        if (it.hasNext()) {
          whereClause.append(" OR ");
        } else {
          whereClause.append(" ) ");
        }
      }
    }
    String selectQuery =
        "SELECT coordinatesId, nodeId, coordinatesLeaf, coordinatesDisplayOrder, "
            + "instanceId FROM sb_coordinates_coordinates WHERE "
            + whereClause
            + " AND instanceId = '"
            + pk.getComponentName()
            + "' "
            + " ORDER BY coordinatesId, nodeId ASC";

    Statement stmt = null;
    ResultSet rs = null;

    try {
      stmt = con.createStatement();
      rs = stmt.executeQuery(selectQuery);
      while (rs.next()) {
        CoordinatePoint coordinatePoint = getCoordinatePointFromResultSet(rs);
        list.add(coordinatePoint);
      }
    } finally {
      DBUtil.close(rs, stmt);
    }

    return list;
  }
예제 #27
0
  public static void addHolidayDate(Connection con, HolidayDetail holiday)
      throws SQLException, UtilException {

    if (!isHolidayDate(con, holiday)) {
      StringBuilder insertStatement = new StringBuilder(128);
      insertStatement.append("insert into ").append(AGENDA_HOLIDAYS_TABLENAME);
      insertStatement.append(" values ( ? , ? )");
      PreparedStatement prepStmt = null;

      try {
        prepStmt = con.prepareStatement(insertStatement.toString());

        prepStmt.setInt(1, Integer.parseInt(holiday.getUserId()));
        prepStmt.setString(2, DateUtil.date2SQLDate(holiday.getDate()));

        prepStmt.executeUpdate();
      } finally {
        DBUtil.close(prepStmt);
      }
    }
  }
 @Override
 public int getDistinctCountByPeriod(
     List<WAPrimaryKey> primaryKeys, int action, String objectType, Date startDate, Date endDate) {
   int nb = 0;
   Connection con = getConnection();
   try {
     List<String> objectIds =
         HistoryObjectDAO.getListObjectAccessByPeriod(
             con, primaryKeys, objectType, startDate, endDate);
     Set<String> distinctObjectIds = new HashSet<String>(objectIds);
     nb = distinctObjectIds.size();
   } catch (Exception e) {
     throw new StatisticRuntimeException(
         "DefaultStatisticService().getDistinctCountByPeriod()",
         SilverpeasRuntimeException.ERROR,
         "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION",
         e);
   } finally {
     DBUtil.close(con);
   }
   return nb;
 }
예제 #29
0
  public static boolean isHolidayDate(Connection con, HolidayDetail holiday) throws SQLException {
    StringBuilder query = new StringBuilder(128);
    query.append("select * ");
    query.append("from ").append(AGENDA_HOLIDAYS_TABLENAME);
    query.append(" where holidayDate = ? ");
    query.append(" and userId = ? ");

    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      stmt = con.prepareStatement(query.toString());

      stmt.setString(1, DateUtil.date2SQLDate(holiday.getDate()));
      stmt.setInt(2, Integer.parseInt(holiday.getUserId()));

      rs = stmt.executeQuery();

      return rs.next();
    } finally {
      DBUtil.close(rs, stmt);
    }
  }