use of org.neo4j.helpers.collection.ClosableIterable in project neo4j-mobile-android by neo4j-contrib.
the class NeoStoreXaDataSource method listStoreFiles.
@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) {
final Collection<File> files = new ArrayList<File>();
File neostoreFile = null;
Pattern logFilePattern = getXaContainer().getLogicalLog().getHistoryFileNamePattern();
for (File dbFile : new File(storeDir).listFiles()) {
String name = dbFile.getName();
// maybe should be
if (dbFile.isFile()) {
if (name.equals(NeoStore.DEFAULT_NAME)) {
neostoreFile = dbFile;
} else if ((name.startsWith(NeoStore.DEFAULT_NAME) || name.equals(IndexStore.INDEX_DB_FILE_NAME)) && !name.endsWith(".id")) {
// Store files
files.add(dbFile);
} else if (includeLogicalLogs && logFilePattern.matcher(dbFile.getName()).matches()) {
// Logs
files.add(dbFile);
}
}
}
files.add(neostoreFile);
return new ClosableIterable<File>() {
public Iterator<File> iterator() {
return files.iterator();
}
public void close() {
}
};
}
use of org.neo4j.helpers.collection.ClosableIterable in project graphdb by neo4j-attic.
the class LuceneDataSource method listStoreFiles.
@Override
public ClosableIterable<File> listStoreFiles() throws IOException {
final Collection<File> files = new ArrayList<File>();
final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
for (Map.Entry<IndexIdentifier, Triplet<IndexWriter, AtomicBoolean, SnapshotDeletionPolicy>> writer : indexWriters.entrySet()) {
SnapshotDeletionPolicy deletionPolicy = writer.getValue().third();
File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
for (String fileName : deletionPolicy.snapshot().getFileNames()) {
files.add(new File(indexDirectory, fileName));
}
snapshots.add(deletionPolicy);
}
files.add(providerStore.getFile());
return new ClosableIterable<File>() {
public Iterator<File> iterator() {
return files.iterator();
}
public void close() {
for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
deletionPolicy.release();
}
}
};
}
use of org.neo4j.helpers.collection.ClosableIterable in project neo4j-mobile-android by neo4j-contrib.
the class LuceneDataSource method listStoreFiles.
@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) throws IOException {
// Never include logical logs since they are of little importance
final Collection<File> files = new ArrayList<File>();
final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
makeSureAllIndexesAreInstantiated();
for (Map.Entry<IndexIdentifier, Pair<IndexWriter, AtomicBoolean>> writer : indexWriters.entrySet()) {
SnapshotDeletionPolicy deletionPolicy = (SnapshotDeletionPolicy) writer.getValue().first().getConfig().getIndexDeletionPolicy();
File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
try {
// Throws IllegalStateException if no commits yet
IndexCommit commit = deletionPolicy.snapshot(SNAPSHOT_ID);
for (String fileName : commit.getFileNames()) {
files.add(new File(indexDirectory, fileName));
}
snapshots.add(deletionPolicy);
} catch (IllegalStateException e) {
// TODO Review this
/*
* This is insane but happens if we try to snapshot an existing index
* that has no commits. This is a bad API design - it should return null
* or something. This is not exceptional.
*/
}
}
files.add(providerStore.getFile());
return new ClosableIterable<File>() {
public Iterator<File> iterator() {
return files.iterator();
}
public void close() {
for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
try {
deletionPolicy.release(SNAPSHOT_ID);
} catch (IOException e) {
// TODO What to do?
e.printStackTrace();
}
}
}
};
}
Aggregations