@Override
 public void remove(Connection connection, WAPrimaryKey pk) throws PersistenceException {
   Connection con;
   if (connection == null) {
     con = getConnection();
   } else {
     con = connection;
   }
   PreparedStatement prepStmt = null;
   try {
     String updateStatement = "delete from " + getTableName(pk) + " where id = ?";
     prepStmt = con.prepareStatement(updateStatement);
     SilverTrace.info(
         "persistence",
         "SilverpeasBeanDAOImpl.remove(WAPrimaryKey pk)",
         "root.MSG_GEN_PARAM_VALUE",
         "queryStr = " + updateStatement + ", id= " + pk.getId());
     prepStmt.setInt(1, Integer.parseInt(pk.getId()));
     prepStmt.executeUpdate();
   } catch (SQLException e) {
     throw new PersistenceException(
         "SilverpeasBeanDAOImpl.remove(WAPrimaryKey pk)",
         SilverpeasException.ERROR,
         "persistence.EX_CANT_REMOVE_OBJECT",
         "",
         e);
   } finally {
     DBUtil.close(prepStmt);
     if (connection == null) {
       DBUtil.close(con);
     }
   }
 }
 /*
  * enregistre la nouvelle réponse de la question courante met en session la question modifiée
  */
 public void saveNewReply() throws QuestionReplyException {
   WAPrimaryKey pk = newReply.getPK();
   pk.setComponentName(getComponentId());
   newReply.setPK(pk);
   getQuestionManager().createReply(newReply, getCurrentQuestion());
   getQuestion(((IdPK) getCurrentQuestion().getPK()).getIdAsLong());
   notifyReply(newReply);
 }
 public void updateCurrentReply(String title, String content) throws QuestionReplyException {
   Reply reply = getCurrentReply();
   reply.setTitle(title);
   reply.setContent(content);
   WAPrimaryKey pk = reply.getPK();
   pk.setComponentName(getComponentId());
   reply.setPK(pk);
   getQuestionManager().updateReply(reply);
   getQuestion(((IdPK) getCurrentQuestion().getPK()).getIdAsLong());
 }
 /*
  * Enregistre une FAQ
  */
 public long saveNewFAQ() throws QuestionReplyException {
   newQuestion.setStatus(2); // close
   newQuestion.setReplyNumber(1);
   newQuestion.setPublicReplyNumber(1);
   newQuestion.setPrivateReplyNumber(0);
   newReply.setPublicReply(1);
   newReply.setPrivateReply(0);
   WAPrimaryKey pk = newReply.getPK();
   pk.setComponentName(getComponentId());
   newReply.setPK(pk);
   return getQuestionManager().createQuestionReply(newQuestion, newReply);
 }
 /*
  * Modifie la réponse courante => supprime la réponse publique => deletePublicReplies() => crée
  * une nouvelle réponse publique et privée met à jour en session la question courante
  */
 public void updateCurrentReplyOLD(String title, String content) throws QuestionReplyException {
   getNewReply();
   setNewReplyContent(title, content, getCurrentReply().getPublicReply(), 1);
   WAPrimaryKey pk = newReply.getPK();
   pk.setComponentName(getComponentId());
   newReply.setPK(pk);
   long replyId = getQuestionManager().createReply(newReply, getCurrentQuestion());
   List<Long> replyIds = new ArrayList<Long>();
   replyIds.add(Long.valueOf(((IdPK) getCurrentReply().getPK()).getIdAsLong()));
   deletePublicReplies(replyIds);
   getReply(replyId);
   getQuestion(((IdPK) getCurrentQuestion().getPK()).getIdAsLong());
   notifyReply(newReply);
 }
 /** getTableName */
 private String getTableName(WAPrimaryKey pk) {
   String result = "";
   if (tableName != null) {
     result = tableName;
   } else {
     result = pk.getTableName();
   }
   return result;
 }
  @Override
  public T findByPrimaryKey(Connection connection, WAPrimaryKey pk) throws PersistenceException {
    PreparedStatement prepStmt = null;
    Connection con;
    if (connection == null) {
      con = getConnection();
    } else {
      con = connection;
    }
    ResultSet rs = null;
    try {
      String selectStatement =
          "select  " + getColumnNames() + " from " + getTableName(pk) + " where id = ?";

      SilverTrace.info(
          "persistence",
          "SilverpeasBeanDAOImpl.findByPrimaryKey(WAPrimaryKey pk)",
          "root.MSG_GEN_PARAM_VALUE",
          "queryStr = " + selectStatement + ", id= " + pk.getId());
      prepStmt = con.prepareStatement(selectStatement);
      prepStmt.setInt(1, Integer.parseInt(pk.getId()));
      rs = prepStmt.executeQuery();
      if (rs.next()) {
        return getSilverpeasBeanFromResultSet(pk, rs);
      }
      return null;
    } catch (Exception e) {
      throw new PersistenceException(
          "SilverpeasBeanDAOImpl.findByPrimaryKey(WAPrimaryKey pk)",
          SilverpeasException.ERROR,
          "persistence.EX_CANT_FIND_OBJECT",
          "",
          e);
    } finally {
      DBUtil.close(rs, prepStmt);
      if (connection == null) {
        DBUtil.close(con);
      }
    }
  }
  @Override
  public Collection<T> findByWhereClause(Connection connection, WAPrimaryKey pk, String whereClause)
      throws PersistenceException {
    PreparedStatement prepStmt = null;
    Connection con;
    if (connection == null) {
      con = getConnection();
    } else {
      con = connection;
    }
    ResultSet rs = null;
    try {
      String selectStatement = "select distinct " + getColumnNames() + " from " + getTableName(pk);
      if (whereClause != null) {
        selectStatement += " where " + whereClause;
      }

      SilverTrace.info(
          "persistence",
          "SilverpeasBeanDAOImpl.findByWhereClause(WAPrimaryKey pk, String whereClause)",
          "root.MSG_GEN_PARAM_VALUE",
          "queryStr = "
              + selectStatement
              + ", id= "
              + pk.getId()
              + ", whereClause= "
              + whereClause);
      prepStmt = con.prepareStatement(selectStatement);

      rs = prepStmt.executeQuery();
      List<T> list = new ArrayList<T>();
      while (rs.next()) {
        T bean = getSilverpeasBeanFromResultSet(pk, rs);
        list.add(bean);
      }
      return list;
    } catch (Exception e) {
      throw new PersistenceException(
          "SilverpeasBeanDAOImpl.findByWhereClause(WAPrimaryKey pk, String whereClause)",
          SilverpeasException.ERROR,
          "persistence.EX_CANT_FIND_OBJECT",
          "",
          e);
    } finally {
      DBUtil.close(rs, prepStmt);
      if (connection == null) {
        DBUtil.close(con);
      }
    }
  }
 private boolean isPublicationReadable(
     WAPrimaryKey pk, String instanceId, Collection<NodePK> autorizedNodes)
     throws RemoteException, CreateException {
   if (pk.getInstanceId().equals(instanceId)) {
     Collection<NodePK> fathers = getPublicationFathers(pk);
     return CollectionUtils.containsAny(autorizedNodes, fathers);
   } else {
     // special case of an alias between two ECM applications
     // check if publication which contains attachment is an alias into this node
     Collection<Alias> aliases = getPublicationAliases(pk);
     for (Alias alias : aliases) {
       NodePK aliasPK = new NodePK(alias.getId(), alias.getInstanceId());
       if (autorizedNodes.contains(aliasPK)) {
         return true;
       }
     }
   }
   return false;
 }
 public void setCurrentReply(Reply reply) {
   WAPrimaryKey pk = reply.getPK();
   pk.setComponentName(getComponentId());
   reply.setPK(pk);
   this.currentReply = reply;
 }
  /** getSilverpeasBeanFromResultSet */
  private T getSilverpeasBeanFromResultSet(WAPrimaryKey pk, ResultSet rs) throws Exception {

    T bean = silverpeasBeanClass.newInstance();
    int count = 1;

    for (PropertyDescriptor property : properties) {
      String type = property.getPropertyType().getName();
      if (isInteger(type)) {
        int value = rs.getInt(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Integer[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isLong(type)) {
        long value = rs.getLong(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Long[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isBoolean(type)) {
        boolean value = rs.getBoolean(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Boolean[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isString(type)) {
        String value = rs.getString(count);
        if (value != null) {
          Object[] parameters = new String[1];
          parameters[0] = value;
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isDate(type)) {
        String value = rs.getString(count);
        if (value != null) {
          Object[] parameters = new Date[1];
          try {
            parameters[0] = DateUtil.parse(value);
          } catch (Exception e) {
            SilverTrace.error(
                "persistence",
                "SilverpeasBeanDAOImpl.getSilverpeasBeanFromResultSet(WAPrimaryKey pk, ResultSet rs)",
                "root.EX_CANT_PARSE_DATE",
                "property Name = " + property.getName() + ", date= " + value);
            throw e;
          }
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if (isFloat(type)) {
        float value = rs.getFloat(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Float[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      } else if ((type.equals("double")) || (type.equals("java.lang.Double"))) {
        double value = rs.getDouble(count);
        if (!rs.wasNull()) {
          Object[] parameters = new Double[] {value};
          property.getWriteMethod().invoke(bean, parameters);
        }
        count++;
      }
    }

    Class<? extends WAPrimaryKey> pkClass = pk.getClass();
    String id = rs.getInt(count) + "";
    Class<?> types[] = new Class[2];
    types[0] = String.class;
    types[1] = WAPrimaryKey.class; // pkClass;
    Constructor<? extends WAPrimaryKey> construct = pkClass.getConstructor(types);
    Object[] parameters = new Object[2];
    parameters[0] = id;
    parameters[1] = pk;
    WAPrimaryKey maPk = construct.newInstance(parameters);
    bean.setPK(maPk);
    return bean;
  }
 protected Collection<Alias> getPublicationAliases(WAPrimaryKey pk)
     throws CreateException, RemoteException {
   return findPublicationBm().getAlias(new PublicationPK(pk.getId(), pk.getInstanceId()));
 }
 protected Collection<NodePK> getPublicationFathers(WAPrimaryKey pk)
     throws CreateException, RemoteException {
   return findPublicationBm().getAllFatherPK(new PublicationPK(pk.getId(), pk.getInstanceId()));
 }