@Override public void removeInstalledPackages(Resource resource, Set<InstalledPackage> doomedPackages, long timestamp) { // first, create history records to audit that the previously discovered package was no longer found for (InstalledPackage doomedPackage : doomedPackages) { InstalledPackageHistory history = new InstalledPackageHistory(); history.setPackageVersion(doomedPackage.getPackageVersion()); history.setResource(resource); history.setStatus(InstalledPackageHistoryStatus.MISSING); history.setTimestamp(timestamp); entityManager.persist(history); } // let's flush these to not buffer too much entityManager.flush(); // now, remove the installed packages (in batches to protect against oracle limit) Query query = entityManager.createNamedQuery(InstalledPackage.QUERY_DELETE_BY_IDS); final int batchSize = 200; List<Integer> doomedIds = new ArrayList(doomedPackages.size()); for (InstalledPackage ip : doomedPackages) { doomedIds.add(ip.getId()); } while (!doomedIds.isEmpty()) { int size = doomedIds.size(); int end = (batchSize < size) ? batchSize : size; List<Integer> idBatch = doomedIds.subList(0, end); query.setParameter("ids", idBatch); query.executeUpdate(); // Advance our progress and possibly help GC. This will remove the processed ids from the backing list idBatch.clear(); } }
public void retrieveBackingContent(String fileName) throws IOException { InstalledPackage installedPackage = getBackingContent(); if (installedPackage != null) { if (fileName == null) { fileName = installedPackage.getPackageVersion().getFileName(); } File file = new File(fileName); byte[] data = remoteClient.getProxy(ContentManagerRemote.class).getPackageBytes( remoteClient.getSubject(), resourceClientProxy.resourceId, installedPackage.getId()); FileOutputStream fos = new FileOutputStream(file); try { fos.write(data); } finally { fos.close(); } } else { throw new RuntimeException( "Content not available in the content repository. If you recently deployed content to this resource, then the content repository has not yet received the content or content information. The content for a resource is available only after the deployment and discovery process completes. Please try again in a few minutes."); } }