/** * Retrieve a list of sets that satisfy the specified criteria * * @return a Map object containing "sets" Iterator object (contains <setSpec/> XML Strings) as * well as an optional resumptionMap Map. * @throws OAIInternalServerError signals an http status code 500 problem */ public Map listSets() throws NoSetHierarchyException, OAIInternalServerError { StatementResultSet stmtRs = null; if (setQuery == null) { if (sets.size() == 0) { throw new NoSetHierarchyException(); } Map<String, Object> listSetsMap = new HashMap<String, Object>(); listSetsMap.put("sets", sets.iterator()); return listSetsMap; } else { purge(); // clean out old resumptionTokens Map<String, Object> listSetsMap = new HashMap<String, Object>(); List<String> sets = new ArrayList<String>(); try { LOGGER.debug(setQuery); /* Get some records from your database */ stmtRs = new StatementResultSet(setQuery); stmtRs.last(); int numRows = stmtRs.getRow(); stmtRs.beforeFirst(); int count; /* load the sets ArrayLists. */ for (count = 0; count < maxListSize && stmtRs.next(); ++count) { /* Use the RecordFactory to extract header/set pairs for each item */ Map<String, Object> nativeItem = stmtRs.getColumnValues(); sets.add(getSetXML(nativeItem)); LOGGER.debug("JDBCOAICatalog.listSets: adding an entry"); } /* decide if you're done */ if (count < numRows) { String resumptionId = getResumptionId(); /** * *************************************************************** Note that storing the * ResultSet in the resumptionResult means the token can't be reused. * *************************************************************** */ resumptionResults.put(resumptionId, stmtRs); /** * *************************************************************** Construct the * resumptionToken String however you see fit. * *************************************************************** */ StringBuilder resumptionTokenSb = new StringBuilder(); resumptionTokenSb.append(resumptionId); resumptionTokenSb.append("!"); resumptionTokenSb.append(Integer.toString(count)); resumptionTokenSb.append("!"); resumptionTokenSb.append(Integer.toString(numRows)); /** * *************************************************************** Use the following line * if you wish to include the optional resumptionToken attributes in the response. * Otherwise, use the line after it that I've commented out. * *************************************************************** */ listSetsMap.put( "resumptionMap", getResumptionMap(resumptionTokenSb.toString(), numRows, 0)); } else { stmtRs.close(); stmtRs = null; } } catch (SQLException e) { if (stmtRs != null) { try { stmtRs.close(); } catch (SQLException e1) { e1.printStackTrace(); } } LOGGER.error("An Exception occured", e); throw new OAIInternalServerError(e.getMessage()); } listSetsMap.put("sets", sets.iterator()); return listSetsMap; } }
/** * Retrieve a list of records that satisfy the specified criteria. Note, though, that unlike the * other OAI verb type methods implemented here, both of the listRecords methods are already * implemented in AbstractCatalog rather than abstracted. This is because it is possible to * implement ListRecords as a combination of ListIdentifiers and GetRecord combinations. * Nevertheless, I suggest that you override both the AbstractCatalog.listRecords methods here * since it will probably improve the performance if you create the response in one fell swoop * rather than construct it one GetRecord at a time. * * @param from beginning date using the proper granularity * @param until ending date using the proper granularity * @param set the set name or null if no such limit is requested * @param metadataPrefix the OAI metadataPrefix or null if no such limit is requested * @return a Map object containing entries for a "records" Iterator object (containing XML * <record/> Strings) and an optional "resumptionMap" Map. * @throws OAIInternalServerError signals an http status code 500 problem * @throws CannotDisseminateFormatException the metadataPrefix isn't supported by the item. */ public Map listRecords(String from, String until, String set, String metadataPrefix) throws CannotDisseminateFormatException, NoItemsMatchException, OAIInternalServerError { purge(); // clean out old resumptionTokens Map<String, Object> listRecordsMap = new HashMap<String, Object>(); List<String> records = new ArrayList<String>(); StatementResultSet stmtRs = null; try { stmtRs = new StatementResultSet(populateRangeQuery(from, until, set)); stmtRs.last(); int numRows = stmtRs.getRow(); if (numRows == 0) { throw new NoItemsMatchException(); } stmtRs.beforeFirst(); int count; /* load the records ArrayList */ for (count = 0; count < maxListSize && stmtRs.next(); ++count) { Map<String, Object> nativeItem = stmtRs.getColumnValues(); String record = constructRecord(nativeItem, metadataPrefix); records.add(record); } /* decide if you're done */ if (count < numRows) { String resumptionId = getResumptionId(); resumptionResults.put(resumptionId, stmtRs); /** * *************************************************************** Construct the * resumptionToken String however you see fit. * *************************************************************** */ StringBuilder resumptionTokenSb = new StringBuilder(); resumptionTokenSb.append(resumptionId); resumptionTokenSb.append("!"); resumptionTokenSb.append(Integer.toString(count)); resumptionTokenSb.append("!"); resumptionTokenSb.append(Integer.toString(numRows)); resumptionTokenSb.append("!"); resumptionTokenSb.append(metadataPrefix); /** * *************************************************************** Use the following line if * you wish to include the optional resumptionToken attributes in the response. Otherwise, * use the line after it that I've commented out. * *************************************************************** */ listRecordsMap.put( "resumptionMap", getResumptionMap(resumptionTokenSb.toString(), numRows, 0)); } else { stmtRs.close(); stmtRs = null; } } catch (SQLException e) { if (stmtRs != null) { try { stmtRs.close(); } catch (SQLException e1) { e1.printStackTrace(); } } LOGGER.error("An Exception occured", e); throw new OAIInternalServerError(e.getMessage()); } listRecordsMap.put("records", records.iterator()); return listRecordsMap; }