@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); } } }
@Override public void update(Connection connection, T bean) throws PersistenceException { Connection con; if (connection == null) { con = getConnection(); } else { con = connection; } PreparedStatement prepStmt = null; try { String statement = null; for (PropertyDescriptor property : properties) { String type = property.getPropertyType().getName(); SilverTrace.info( "persistence", "SilverpeasBeanDAOImpl.update(SilverpeasBean bean)", "root.MSG_GEN_PARAM_VALUE", "property Name = " + property.getName() + ", type = " + type); if (isTypeValid(type) == true) { if (statement == null) { statement = property.getName() + " = ? "; } else { statement += ", " + property.getName() + " = ? "; } } } String updateStatement = "update " + getTableName(bean.getPK()) + " set " + statement + " where id = ?"; prepStmt = con.prepareStatement(updateStatement); SilverTrace.info( "persistence", "SilverpeasBeanDAOImpl.update(SilverpeasBean bean)", "root.MSG_GEN_PARAM_VALUE", "queryStr = " + updateStatement + ", id= " + bean.getPK().getId()); int count = prepareStatementSetProperties(prepStmt, bean); // for the where clause prepStmt.setInt(count, Integer.parseInt(bean.getPK().getId())); prepStmt.executeUpdate(); } catch (Exception e) { throw new PersistenceException( "SilverpeasBeanDAOImpl.update(SilverpeasBean bean) ", SilverpeasException.ERROR, "persistence.EX_CANT_UPDATE_OBJECT", "", e); } finally { DBUtil.close(prepStmt); if (connection == null) { DBUtil.close(con); } } }
public Group getGroup(String groupId) throws AdminException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.ADMIN_DATASOURCE); Group group = groupDao.getGroup(con, groupId); return group; } catch (Exception e) { throw new AdminException( "GroupManager.getGroup", SilverpeasException.ERROR, "admin.EX_ERR_GET_GROUP", e); } finally { 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); } } }
/** * Method declaration * * @param con * @param questionContainerPK * @return * @throws SQLException * @see */ public static QuestionContainerHeader getQuestionContainerHeader( Connection con, QuestionContainerPK questionContainerPK) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.getQuestionContainerHeader()", "root.MSG_GEN_ENTER_METHOD", "questionContainerPK = " + questionContainerPK); ResultSet rs = null; QuestionContainerHeader questionContainerHeader = null; String selectStatement = "select " + QUESTIONCONTAINERCOLUMNNAMES + " from " + questionContainerPK.getTableName() + " where qcId = ? "; PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(selectStatement); prepStmt.setInt(1, Integer.parseInt(questionContainerPK.getId())); rs = prepStmt.executeQuery(); if (rs.next()) { questionContainerHeader = getQuestionContainerHeaderFromResultSet(rs, questionContainerPK); } } finally { DBUtil.close(rs, prepStmt); } return questionContainerHeader; }
/** * Method declaration * * @param con * @param qcPK * @return * @throws SQLException * @see */ public static Collection<QuestionContainerHeader> getInWaitQuestionContainers( Connection con, QuestionContainerPK qcPK) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.getInWaitQuestionContainers()", "root.MSG_GEN_ENTER_METHOD", "qcPK = " + qcPK); ResultSet rs = null; QuestionContainerHeader header = null; String selectStatement = "select " + QUESTIONCONTAINERCOLUMNNAMES + " from " + qcPK.getTableName() + " where ? < qcBeginDate and instanceId = ?"; PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(selectStatement); prepStmt.setString(1, formatter.format(new java.util.Date())); prepStmt.setString(2, qcPK.getComponentName()); rs = prepStmt.executeQuery(); List<QuestionContainerHeader> list = new ArrayList<QuestionContainerHeader>(); while (rs.next()) { header = getQuestionContainerHeaderFromResultSet(rs, qcPK); list.add(header); } return list; } finally { DBUtil.close(rs, prepStmt); } }
/** * Method declaration * * @param con * @param questionContainerPK * @throws SQLException * @see */ public static void openQuestionContainer(Connection con, QuestionContainerPK questionContainerPK) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.openQuestionContainer()", "root.MSG_GEN_ENTER_METHOD", "questionContainerPK = " + questionContainerPK); String updateStatement = "update " + questionContainerPK.getTableName() + " set qcIsClosed = 0 , instanceId = ?" + " where qcId = ? "; PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(updateStatement); prepStmt.setString(1, questionContainerPK.getComponentName()); prepStmt.setInt(2, Integer.parseInt(questionContainerPK.getId())); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
@Override public void deleteAllThumbnail(String componentId) throws ThumbnailException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.THUMBNAIL_DATASOURCE); dao.deleteAllThumbnails(con, componentId); } catch (SQLException se) { throw new ThumbnailException( "ThumbnailBmImpl.deleteAllThumbnail()", SilverpeasException.ERROR, "thumbnail_MSG_DELETE_ALL_FAILED", se); } finally { DBUtil.close(con); } }
@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<Integer> distinctObjectIds = new HashSet<Integer>(userIds.size()); try { for (String userId : userIds) { List<Integer> objectIds = HistoryObjectDAO.getListObjectAccessByPeriodAndUser( con, primaryKeys, objectType, startDate, endDate, userId); distinctObjectIds.addAll(objectIds); } nb = distinctObjectIds.size(); } catch (Exception e) { throw new StatisticRuntimeException( "StatisticBmEJB().getDistinctCountByPeriod()", SilverpeasRuntimeException.ERROR, "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION", e); } finally { DBUtil.close(con); } } return nb; }
public void updateGroup(Connection c, Group g) throws AdminException { PreparedStatement statement = null; String theQuery = "update " + drvSettings.getGroupTableName() + " set " + drvSettings.getGroupNameColumnName() + " = ?," + drvSettings.getGroupDescriptionColumnName() + " = ?" + " where " + drvSettings.getGroupSpecificIdColumnName() + " = ?"; try { SilverTrace.debug("admin", "SQLGroupTable.updateGroup", "root.MSG_QUERY", theQuery); statement = c.prepareStatement(theQuery); statement.setString(1, drvSettings.trunc(g.getName(), 100)); statement.setString(2, drvSettings.trunc(g.getDescription(), 400)); statement.setInt(3, Integer.parseInt(g.getSpecificId())); statement.executeUpdate(); } catch (Exception e) { throw new AdminException( "SQLGroupTable.updateGroup", SilverpeasException.ERROR, "root.EX_SQL_QUERY_FAILED", "Query = " + theQuery, e); } finally { DBUtil.close(statement); } }
/** * Get saved list type * * @param con * @param componentId * @return * @throws SQLException * @throws VersioningRuntimeException */ public static int getSavedListType(Connection con, String componentId) throws SQLException, VersioningRuntimeException { PreparedStatement prepStmt = null; ResultSet rs = null; int listType = 0; try { prepStmt = con.prepareStatement(GET_SAVED_LIST_TYPE); try { prepStmt.setString(1, componentId); } catch (NumberFormatException e) { throw new VersioningRuntimeException( "WorkListDAO.getSavedListType()", SilverTrace.TRACE_LEVEL_DEBUG, "root.EX_WRONG_PK", componentId, e); } rs = prepStmt.executeQuery(); if (rs.next()) { listType = rs.getInt(1); } } finally { DBUtil.close(rs, prepStmt); } return listType; }
/** * Method declaration * * @param con * @param statsType * @param conf * @throws SQLException * @see */ static void purgeTablesCumul(Connection con, StatType statsType, StatisticsConfig conf) throws SQLException { StringBuilder deleteStatementBuf = new StringBuilder("DELETE FROM " + conf.getTableName(statsType) + "Cumul WHERE dateStat<"); PreparedStatement prepStmt = null; // compute the last date to delete from Calendar dateOfTheDay = Calendar.getInstance(); dateOfTheDay.add(Calendar.MONTH, -(conf.getPurge(statsType))); deleteStatementBuf.append( getRequestDate(dateOfTheDay.get(Calendar.YEAR), dateOfTheDay.get(Calendar.MONTH) + 1)); String deleteStatement = deleteStatementBuf.toString(); SilverTrace.info( "silverstatistics", "SilverStatisticsManagerDAO.purgeTablesCumul", "root.MSG_GEN_PARAM_VALUE", "deleteStatement=" + deleteStatement); try { prepStmt = con.prepareStatement(deleteStatement); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
@Override public void updateThumbnail(ThumbnailDetail thumbDetail) throws ThumbnailException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.THUMBNAIL_DATASOURCE); dao.updateThumbnail(con, thumbDetail); } catch (SQLException se) { throw new ThumbnailException( "ThumbnailBmImpl.updateAttachment()", SilverpeasException.ERROR, "thumbnail.EX_MSG_RECORD_NOT_UPDATE", se); } finally { DBUtil.close(con); } }
@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( "StatisticBmEJB().getCountByPeriodAndUser()", SilverpeasRuntimeException.ERROR, "statistic.CANNOT_GET_HISTORY_STATISTICS_PUBLICATION", e); } finally { DBUtil.close(con); } return nb; }
/** Returns the Group whith the given name. */ public Group getGroupByName(Connection c, String groupName) throws AdminException { ResultSet rs = null; PreparedStatement statement = null; String theQuery = "select " + getColumns() + " from " + drvSettings.getGroupTableName() + " where name = ?"; try { SilverTrace.debug("admin", "SQLGroupTable.getGroupByName", "root.MSG_QUERY", theQuery); statement = c.prepareStatement(theQuery); statement.setString(1, groupName); rs = statement.executeQuery(); if (rs.next()) { return fetchGroup(rs); } else { return null; } } catch (SQLException e) { throw new AdminException( "SQLGroupTable.getGroupByName", SilverpeasException.ERROR, "root.EX_SQL_QUERY_FAILED", "Query = " + theQuery, e); } finally { DBUtil.close(rs, statement); } }
/** * Get the all the sub groups id of a given group * * @param superGroupId * @return * @throws AdminException */ public List<String> getAllSubGroupIdsRecursively(String superGroupId) throws AdminException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.ADMIN_DATASOURCE); return getSubGroupIds(con, superGroupId); } catch (Exception e) { throw new AdminException( "GroupManager.getAllSubGroupIdsRecursively", SilverpeasException.ERROR, "admin.EX_ERR_GET_CHILDREN_GROUP_IDS", "father group Id: '" + superGroupId + "'", e); } finally { DBUtil.close(con); } }
/** Returns the User whith the given id. */ public List<Group> getDirectSubGroups(Connection c, int groupId) throws AdminException { ResultSet rs = null; PreparedStatement statement = null; List<Group> theResult = new ArrayList<Group>(); String theQuery = "select " + getColumns() + " from " + drvSettings.getGroupTableName() + " where " + drvSettings.getGroupParentIdColumnName(); try { if (groupId == -1) theQuery = theQuery + " is null"; else theQuery = theQuery + " = ?"; SilverTrace.debug("admin", "SQLGroupTable.getGroup", "root.MSG_QUERY", theQuery); statement = c.prepareStatement(theQuery); if (groupId != -1) statement.setInt(1, groupId); rs = statement.executeQuery(); while (rs.next()) { theResult.add(fetchGroup(rs)); } return theResult; } catch (SQLException e) { throw new AdminException( "SQLGroupTable.getAllGroups", SilverpeasException.ERROR, "root.EX_SQL_QUERY_FAILED", "Query = " + theQuery, e); } finally { DBUtil.close(rs, statement); } }
public void deleteGroup(Connection c, int groupId) throws AdminException { PreparedStatement statement = null; String theQuery = "delete from " + drvSettings.getGroupTableName() + " where " + drvSettings.getGroupSpecificIdColumnName() + " = ?"; try { SilverTrace.debug("admin", "SQLGroupTable.deleteGroup", "root.MSG_QUERY", theQuery); statement = c.prepareStatement(theQuery); statement.setInt(1, groupId); statement.executeUpdate(); } catch (Exception e) { throw new AdminException( "SQLGroupTable.deleteGroup", SilverpeasException.ERROR, "root.EX_SQL_QUERY_FAILED", "Query = " + theQuery, e); } finally { DBUtil.close(statement); } }
/** * Method declaration * * @param con * @param questionContainerHeader * @throws SQLException * @see */ public static void updateQuestionContainerHeader( Connection con, QuestionContainerHeader questionContainerHeader) throws SQLException { SilverTrace.info( "questionContainer", "QuestionContainerDAO.updateQuestionContainerHeader()", "root.MSG_GEN_ENTER_METHOD", "questionContainerHeader = " + questionContainerHeader); String insertStatement = "update " + questionContainerHeader.getPK().getTableName() + " set qcTitle = ?," + " qcDescription = ?," + " qcComment = ?," + " qcBeginDate = ?," + " qcEndDate = ?," + " qcNbVoters = ?," + " qcNbQuestionsPage = ?," + " qcNbMaxParticipations = ?," + " qcNbTriesBeforeSolution = ?," + " qcMaxTime = ?, " + " instanceId = ?, " + " anonymous = ?" + " where qcId = ?"; PreparedStatement prepStmt = null; try { prepStmt = con.prepareStatement(insertStatement); prepStmt.setString(1, questionContainerHeader.getTitle()); prepStmt.setString(2, questionContainerHeader.getDescription()); prepStmt.setString(3, questionContainerHeader.getComment()); if (questionContainerHeader.getBeginDate() == null) { prepStmt.setString(4, nullBeginDate); } else { prepStmt.setString(4, questionContainerHeader.getBeginDate()); } if (questionContainerHeader.getEndDate() == null) { prepStmt.setString(5, nullEndDate); } else { prepStmt.setString(5, questionContainerHeader.getEndDate()); } prepStmt.setInt(6, questionContainerHeader.getNbVoters()); prepStmt.setInt(7, questionContainerHeader.getNbQuestionsPerPage()); prepStmt.setInt(8, questionContainerHeader.getNbMaxParticipations()); prepStmt.setInt(9, questionContainerHeader.getNbParticipationsBeforeSolution()); prepStmt.setInt(10, questionContainerHeader.getMaxTime()); prepStmt.setString(11, questionContainerHeader.getPK().getComponentName()); if (questionContainerHeader.isAnonymous()) { prepStmt.setInt(12, 1); } else { prepStmt.setInt(12, 0); } prepStmt.setInt(13, Integer.parseInt(questionContainerHeader.getPK().getId())); prepStmt.executeUpdate(); } finally { DBUtil.close(prepStmt); } }
public List<String> getManageableGroupIds(String userId, List<String> groupIds) throws AdminException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.ADMIN_DATASOURCE); return groupDao.getManageableGroupIds(con, userId, groupIds); } catch (Exception e) { throw new AdminException( "GroupManager.getManageableGroupIds", SilverpeasException.ERROR, "admin.EX_ERR_GET_USER_MANAGEABLE_GROUP_IDS", e); } finally { DBUtil.close(con); } }
@Override public void moveThumbnail(ThumbnailDetail thumbDetail, String toInstanceId) throws ThumbnailException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.THUMBNAIL_DATASOURCE); dao.moveThumbnail(con, thumbDetail, toInstanceId); } catch (SQLException se) { throw new ThumbnailException( "ThumbnailBmImpl.moveThumbnail()", SilverpeasException.ERROR, "thumbnail.EX_MSG_CANT_MOVE_THUMBNAIL", se); } finally { DBUtil.close(con); } }
@Override public void deleteThumbnail(ThumbnailDetail thumbDetail) throws ThumbnailException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.THUMBNAIL_DATASOURCE); dao.deleteThumbnail( con, thumbDetail.getObjectId(), thumbDetail.getObjectType(), thumbDetail.getInstanceId()); } catch (SQLException se) { throw new ThumbnailException( "ThumbnailBmImpl.deleteThumbnail()", SilverpeasException.ERROR, "thumbnail.EX_MSG_RECORD_NOT_DELETE", se); } finally { DBUtil.close(con); } }
public List<String> getSuggestions(String fieldName, String templateName, String componentId) { List<String> suggestions = new ArrayList<String>(); Connection connection = null; PreparedStatement statement = null; ResultSet rs = null; try { connection = DBUtil.makeConnection(JNDINames.FORMTEMPLATE_DATASOURCE); statement = connection.prepareStatement(suggestionsQuery); statement.setString(1, fieldName); statement.setString(2, componentId + ":" + templateName); SilverTrace.debug( "formTemplate", "TextFieldImpl.getSuggestions", "root.MSG_GEN_PARAM_VALUE", "fieldName = " + fieldName + ", componentId = " + componentId + ", templateName = " + templateName); rs = statement.executeQuery(); String oneSuggestion = ""; while (rs.next()) { oneSuggestion = rs.getString(1); if (StringUtil.isDefined(oneSuggestion)) suggestions.add(oneSuggestion); } } catch (Exception e) { SilverTrace.error( "formTemplate", "TextFieldImpl.getSuggestions", "root.EX_SQL_QUERY_FAILED", e); } finally { DBUtil.close(rs, statement); try { if (connection != null && !connection.isClosed()) connection.close(); } catch (SQLException e) { SilverTrace.error( "formTemplate", "TextFieldImpl.getSuggestions", "root.EX_CONNECTION_CLOSE_FAILED", e); } } return suggestions; }
@Override public void unsubscribe(Subscription subscription) { SilverTrace.info("subscribe", "SubscribeBmEJB.unsubscribe", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); subscriptionDao.remove(con, subscription); } catch (SQLException e) { DBUtil.rollback(con); throw new SubscribeRuntimeException( "SubscribeBmEJB.removeSubscribe()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_REMOVE_SUBSCRIBE", e); } finally { DBUtil.close(con); } }
/** * Method declaration * * @return * @see */ private Connection getConnection() { try { Connection con = DBUtil.makeConnection(dbName); return con; } catch (Exception e) { throw new FavoritRuntimeException("root.MSG_GEN_CONNECTION_OPEN_FAILED", e); } }
/** * 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); } }
@Override public ThumbnailDetail getCompleteThumbnail(ThumbnailDetail thumbDetail) throws ThumbnailException { Connection con = null; try { con = DBUtil.makeConnection(JNDINames.THUMBNAIL_DATASOURCE); return dao.selectByKey( con, thumbDetail.getInstanceId(), thumbDetail.getObjectId(), thumbDetail.getObjectType()); } catch (SQLException se) { throw new ThumbnailException( "ThumbnailBmImpl.getCompleteThumbnail()", SilverpeasException.ERROR, "thumbnail.EX_MSG_NOT_FOUND", se); } finally { DBUtil.close(con); } }
/** @return the DB connection */ private Connection getConnection() throws WorkflowException { try { Connection con = DBUtil.makeConnection(dbName); return con; } catch (Exception e) { throw new WorkflowException( "ProcessInstanceManagerImpl.getConnection()", "root.EX_CONNECTION_OPEN_FAILED", e); } }
/** * Gets the groups that match the specified criteria. * * @param criteria the criteria in searching of user groups. * @return an array of user groups matching the criteria or an empty array of no ones are found. * @throws AdminException if an error occurs while getting the user groups. */ public Group[] getGroupsMatchingCriteria(final GroupSearchCriteriaForDAO criteria) throws AdminException { Connection connection = null; try { connection = DBUtil.makeConnection(JNDINames.ADMIN_DATASOURCE); List<Group> groups = groupDao.getGroupsByCriteria(connection, (GroupSearchCriteriaForDAO) criteria); String domainIdConstraint = null; List<String> domainIds = criteria.getCriterionOnDomainIds(); for (String domainId : domainIds) { if (!domainId.equals(Domain.MIXED_DOMAIN_ID)) { domainIdConstraint = domainId; break; } } SearchCriteriaDAOFactory factory = SearchCriteriaDAOFactory.getFactory(); for (Group group : groups) { List<String> groupIds = getAllSubGroupIdsRecursively(group.getId()); groupIds.add(group.getId()); UserSearchCriteriaForDAO criteriaOnUsers = factory.getUserSearchCriteriaDAO(); List<UserDetail> users = userDao.getUsersByCriteria( connection, criteriaOnUsers .onDomainId(domainIdConstraint) .and() .onGroupIds(groupIds.toArray(new String[groupIds.size()]))); group.setTotalNbUsers(users.size()); } return groups.toArray(new Group[groups.size()]); } catch (Exception e) { throw new AdminException( "GroupManager.getGroupsMatchingCriteria", SilverpeasException.ERROR, "admin.EX_ERR_GET_USER_GROUPS", e); } finally { DBUtil.close(connection); } }
/** * Method declaration * * @param node * @param path * @see */ @Override public void unsubscribeByPath(NodePK node, String path) { SilverTrace.info( "subscribe", "SubscribeBmEJB.removeSubscriptionsByPath", "root.MSG_GEN_ENTER_METHOD"); Connection con = null; try { con = getConnection(); subscriptionDao.removeByNodePath(con, node.getComponentName(), path); } catch (SQLException e) { DBUtil.rollback(con); throw new SubscribeRuntimeException( "SubscribeBmEJB.removeSubscriptionsByPath()", SilverpeasRuntimeException.ERROR, "subscribe.CANNOT_REMOVE_NODE_SUBSCRIBES", e); } finally { DBUtil.close(con); } }