public void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result, ResourcePolicy rp) { if (isReadOnly()) { readOnlyCache.cacheAuthorizedAction(dspaceObject, action, eperson, result); try { uncacheEntity(rp); } catch (SQLException e) { log.warn("Unable to uncache a resource policy when in read-only mode", e); } } }
private void checkLastItem(Item item) throws SQLException { if (item != null) { if (lastItem == null) { lastItem = item; } else if (!lastItem.getID().equals(item.getID())) { numUncache++; context.uncacheEntity(lastItem); lastItem = item; } } }
private void checkLastBitstream(Bitstream bitstream) throws SQLException { if (bitstream != null) { if (lastBitstream == null) { lastBitstream = bitstream; } else if (!lastBitstream.getID().equals(bitstream.getID())) { numUncache++; context.uncacheEntity(lastBitstream); lastBitstream = bitstream; } } }
protected void deleteItem(Context c, String myhandle) throws Exception { // bit of a hack - to remove an item, you must remove it // from all collections it's a part of, then it will be removed Item myitem = (Item) handleService.resolveToObject(c, myhandle); if (myitem == null) { System.out.println("Error - cannot locate item - already deleted?"); } else { deleteItem(c, myitem); c.uncacheEntity(myitem); } }
Item item = i.next(); exportItem(c, item, fullPath, mySequenceNumber, migrate, excludeBitstreams); c.uncacheEntity(item); mySequenceNumber++;
@Override public void deleteItems(Context c, String mapFile) throws Exception { System.out.println("Deleting items listed in mapfile: " + mapFile); // read in the mapfile Map<String, String> myhash = readMapFile(mapFile); // now delete everything that appeared in the mapFile Iterator<String> i = myhash.keySet().iterator(); while (i.hasNext()) { String itemID = myhash.get(i.next()); if (itemID.indexOf('/') != -1) { String myhandle = itemID; System.out.println("Deleting item " + myhandle); deleteItem(c, myhandle); } else { // it's an ID Item myitem = itemService.findByIdOrLegacyId(c, itemID); System.out.println("Deleting item " + itemID); deleteItem(c, myitem); c.uncacheEntity(myitem); } } }
c.uncacheEntity(oldItem); c.uncacheEntity(newItem);
/** * Run task for Collection along with all Items in that collection. * * @param tr TaskRunner * @param coll Collection * @return true if successful, false otherwise * @throws IOException if IO error */ protected boolean doCollection(TaskRunner tr, Collection coll) throws IOException { try { if (!tr.run(coll)) { return false; } Context context = curationContext(); Iterator<Item> iter = itemService.findByCollection(context, coll); while (iter.hasNext()) { Item item = iter.next(); boolean shouldContinue = tr.run(item); context.uncacheEntity(item); if (!shouldContinue) { return false; } } } catch (SQLException sqlE) { throw new IOException(sqlE.getMessage(), sqlE); } return true; }
/** * Indexes all items in the given collection. * * @param indexingService * @param itemService * @param context The relevant DSpace Context. * @param collection collection to index * @throws IOException A general class of exceptions produced by failed or interrupted I/O operations. * @throws SearchServiceException in case of a solr exception * @throws SQLException An exception that provides information on a database access error or other errors. */ private static long indexItems(final IndexingService indexingService, final ItemService itemService, final Context context, final Collection collection) throws IOException, SearchServiceException, SQLException { long count = 0; final Iterator<Item> itemIterator = itemService.findByCollection(context, collection); while (itemIterator.hasNext()) { Item item = itemIterator.next(); indexingService.indexContent(context, item, true, false); count++; //To prevent memory issues, discard an object from the cache after processing context.uncacheEntity(item); } indexingService.commit(); return count; }
/** * Run the export * * @return the exported CSV lines */ public DSpaceCSV export() { try { Context.Mode originalMode = context.getCurrentMode(); context.setMode(Context.Mode.READ_ONLY); // Process each item DSpaceCSV csv = new DSpaceCSV(exportAll); while (toExport.hasNext()) { Item item = toExport.next(); csv.addItem(item); context.uncacheEntity(item); } context.setMode(originalMode); // Return the results return csv; } catch (Exception e) { // Something went wrong... System.err.println("Error exporting to CSV:"); e.printStackTrace(); return null; } }
@Override public void applyFiltersItem(Context c, Item item) throws Exception { //only apply filters if item not in skip-list if (!inSkipList(item.getHandle())) { //cache this item in MediaFilterManager //so it can be accessed by MediaFilters as necessary currentItem = item; if (filterItem(c, item)) { // increment processed count ++processed; } // clear item objects from context cache and internal cache c.uncacheEntity(currentItem); currentItem = null; } }
context.uncacheEntity(item);
toIndexValues.put(authorityValue.getId(), authorityValue); context.uncacheEntity(item);
context.uncacheEntity(bitstream);
indexContent(context, item, force); context.uncacheEntity(item);
context.uncacheEntity(bitstream); bitstream = dispatcher.next();
Item item = iter.next(); performObject(item); Curator.curationContext().uncacheEntity(item);
System.out.println("Deleting: " + item.getHandle()); collectionService.removeItem(context, collection, item); context.uncacheEntity(item);// Dispatch events every 50 items if (i % 50 == 0) { context.dispatchEvents();
@Override public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument document) { try { List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, dso, Constants.READ); for (ResourcePolicy resourcePolicy : policies) { String fieldValue; if (resourcePolicy.getGroup() != null) { //We have a group add it to the value fieldValue = "g" + resourcePolicy.getGroup().getID(); } else { //We have an eperson add it to the value fieldValue = "e" + resourcePolicy.getEPerson().getID(); } document.addField("read", fieldValue); //remove the policy from the cache to save memory context.uncacheEntity(resourcePolicy); } } catch (SQLException e) { log.error(LogManager.getHeader(context, "Error while indexing resource policies", "DSpace object: (id " + dso.getID() + " type " + dso.getType() + ")")); } }
count += indexAll(indexingService, itemService, context, subcommunity); context.uncacheEntity(subcommunity); count += indexItems(indexingService, itemService, context, collection); context.uncacheEntity(collection);