CompassDirEntryCache implements DirEntryCache { @Override public void update(final Map<String, DirEntry.Kind> entriesToDelete, final List<DirEntry> entriesToAdd) { CompassSession session = null; CompassTransaction transaction = null; try { session = compass.openSession(); logger.debug("Applying changes inside transaction(s)..."); int count = 0; transaction = session.beginTransaction(); for (String id : entriesToDelete.keySet()) { final Kind kind = entriesToDelete.get(id); if (kind == Kind.DIR) { logger.debug(id + " is a directory. Doing a recursive delete"); removeAllEntriesInDirectory(session, id); } else { removeFileEntry(session, id); } if (++count % maxEntriesPerCommit == 0) { logger.debug("Committing transaction at count: " + count); transaction.commit(); transaction = session.beginTransaction(); } } transaction.commit(); count = 0; transaction = session.beginTransaction(); for (DirEntry entry : entriesToAdd) { session.save(entry); if (++count % maxEntriesPerCommit == 0) { logger.debug("Committing transaction at count: " + count); transaction.commit(); transaction = session.beginTransaction(); } } transaction.commit(); } catch (Exception ex) { if (transaction != null) { transaction.rollback(); } logger.error("Error during index update", ex); } finally { if (session != null) session.close(); } } CompassDirEntryCache(final File cacheRootDirectory);  CompassDirEntryCache(final File cacheDirectory, final boolean useDiskStore); @Override void init(); @Override void shutdown(); @Override void setLatestCachedRevisionNumber(final long revision); @Override long getLatestCachedRevisionNumber(); @Override int getSize(); @Override void add(final DirEntry... entries); @Override void clear(); @Override void removeFile(final String pathAndName); @Override void update(final Map<String, DirEntry.Kind> entriesToDelete,
                     final List<DirEntry> entriesToAdd); @Override void removeDirectory(final String pathAndName); @Override List<DirEntry> findEntries(final String searchString, final String startPath); @Override List<DirEntry> findEntriesByCamelCasePattern(final CamelCasePattern camelCasePattern,
                                                      final String startPath); @Override List<DirEntry> findDirectories(final String startPath); @Override void flush(); void setMaxEntriesPerCommit(final int maxEntriesPerCommit);  }
@Test public void testUpdate() throws Exception { assertEquals(0, entryCache.getSize()); addAll(entryCache, TestUtils.getDirectoryList()); assertEquals(13, entryCache.getSize()); final Map<String, DirEntry.Kind> toDelete = new LinkedHashMap<String, DirEntry.Kind>(); toDelete.put("/trunk", DirEntry.Kind.DIR); toDelete.put("/TAGS", DirEntry.Kind.DIR); toDelete.put("/file1.java", DirEntry.Kind.FILE); toDelete.put("/file2.html", DirEntry.Kind.FILE); final DirEntry dirEntry = new DirEntry("/", "fileInRoot", null, new Date(), DirEntry.Kind.FILE, 3, 1); entryCache.update(toDelete, Collections.singletonList(dirEntry)); Thread.sleep(500L); assertEquals(1, entryCache.getSize()); }