dao.setDistinct(distinct); dao.setCountValues(select); String focusField = dao.getJumpToField(); String focusValue = dao.getJumpToValue(); String orderField = dao.getOrderField(); int limit = dao.getLimit(); int offset = dao.getOffset(); dao.setJumpToField(null); dao.setJumpToValue(null); dao.setOrderField(null); dao.setLimit(-1); dao.setOffset(-1); int count = dao.doCountQuery(); dao.setJumpToField(focusField); dao.setJumpToValue(focusValue); dao.setOrderField(orderField); dao.setLimit(limit); dao.setOffset(offset); dao.setCountValues(null);
/** * Convert the value into an offset into the table for this browse * * @param value value * @return the focus value to use * @throws BrowseException if browse error */ private int getOffsetForDistinctValue(String value) throws BrowseException { if (!browseIndex.isMetadataIndex()) { throw new IllegalArgumentException("getOffsetForDistinctValue called when not a metadata index"); } // now get the DAO to do the query for us, returning the highest // string value in the given column in the given table for the // item (I think) return dao.doDistinctOffsetQuery("sort_value", value, scope.isAscending()); }
dao.setTable(browseIndex.getDistinctTableName()); dao.setStartsWith(StringUtils.lowerCase(scope.getStartsWith())); dao.setDistinct(true); dao.setAscending(scope.isAscending()); dao.setEnableBrowseFrequencies(browseIndex.isDisplayFrequencies()); dao.setFilterMappingTables(null, browseIndex.getMapTableName()); dao.setFilterMappingTables(null, browseIndex.getMapTableName()); dao.setContainerTable("collection2item"); dao.setContainerIDField("collection_id"); dao.setContainerID(col.getID()); } else if (scope.inCommunity()) { Community com = (Community) scope.getBrowseContainer(); dao.setContainerTable("communities2item"); dao.setContainerIDField("community_id"); dao.setContainerID(com.getID()); dao.setOrderField("sort_value"); dao.setJumpToField("sort_value"); int offset = scope.getOffset(); String rawFocusValue = null;
dao.setTable(browseIndex.getTableName()); dao.setAscending(scope.isAscending()); dao.setAuthorityValue(scope.getAuthorityValue()); dao.setFilterValueField("value"); dao.setFilterValue(rawValue); } else { dao.setFilterValueField("sort_value"); dao.setFilterValue(value); dao.setFilterValuePartial(scope.getFilterValuePartial()); dao.setFilterMappingTables(browseIndex.getDistinctTableName(), browseIndex.getMapTableName()); if (scope.inCollection()) { Collection col = (Collection) scope.getBrowseContainer(); dao.setContainerTable("collection2item"); dao.setContainerIDField("collection_id"); dao.setContainerID(col.getID()); } else if (scope.inCommunity()) { Community com = (Community) scope.getBrowseContainer(); dao.setContainerTable("communities2item"); dao.setContainerIDField("community_id"); dao.setContainerID(com.getID()); dao.setOrderField(orderBy);
dao.setTable(browseIndex.getTableName()); dao.setAscending(scope.isAscending()); if (scope.inCollection()) { Collection col = (Collection) scope.getBrowseContainer(); dao.setContainerTable("collection2item"); dao.setContainerIDField("collection_id"); dao.setContainerID(col.getID()); } else if (scope.inCommunity()) { Community com = (Community) scope.getBrowseContainer(); dao.setContainerTable("communities2item"); dao.setContainerIDField("community_id"); dao.setContainerID(com.getID()); dao.setOffset(scope.getOffset()); dao.setLimit(scope.getResultsPerPage()); orderBy = "sort_" + Integer.toString(scope.getSortBy()); dao.setOrderField(orderBy); List<Item> results = dao.doQuery();
/** * Convert the value into an offset into the table for this browse * * @param value value * @return the focus value to use * @throws BrowseException if browse error */ private int getOffsetForValue(String value) throws BrowseException { // we need to make sure that we select from the correct column. If the sort option // is the 0th option then we use sort_value, but if it is one of the others we have // to select from that column instead. Otherwise, we end up missing the focus value // to do comparisons in other columns. The use of the focus value needs to be consistent // across the browse SortOption so = scope.getSortOption(); if (so == null || so.getNumber() == 0) { if (browseIndex.getSortOption() != null) { so = browseIndex.getSortOption(); } } String col = "sort_1"; if (so.getNumber() > 0) { col = "sort_" + Integer.toString(so.getNumber()); } // now get the DAO to do the query for us, returning the highest // string value in the given column in the given table for the // item (I think) return dao.doOffsetQuery(col, value, scope.isAscending()); }
String max = dao.doMaxQuery(col, tableName, id);