*
* @param aDir Directory where the album is located.
* @param aPath Path that this album represents.
- * @param aCache Cache to use.
+ * @param aCache Cache to use. Note that a cache usedin one album hierarachy should not be used in another.
* @throws IOException
*/
public FileSystemAlbum(File aDir, String aPath, Cache<String, ArrayList<PhotoEntry>> aCache) throws IOException {
}
_dir = aDir;
_path = aPath;
- _entries = new CachedObject<String, ArrayList<PhotoEntry>>(aCache, aPath, new AlbumComputation(this));
+ _entries = new CachedObject<String, ArrayList<PhotoEntry>>(aCache, "fs:" + aPath, new AlbumComputation(this));
}
/**
* @see org.wamblee.photos.database.Album#addAlbum(java.lang.String)
*/
public void addAlbum(String aId) throws IOException {
- PhotoEntry entry = find(aId);
- if (entry != null) {
- throw new IOException("Entry already exists in album " + getId() +
- " : " + aId);
- }
- // Entry not yet found. Try to create it.
- File albumDir = new File(_dir, aId);
- if (!albumDir.mkdir()) {
- throw new IOException("Could not create album: " + aId);
- }
- File photosDir = new File(albumDir, PHOTOS_DIR);
- if (!photosDir.mkdir()) {
- throw new IOException("Could not create photo storage dir: " + photosDir.getPath());
- }
- File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
- if (!thumbnailsDir.mkdir()) {
- throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+ try {
+ PhotoEntry entry = find(aId);
+ if (entry != null) {
+ throw new IOException("Entry already exists in album " + getId() +
+ " : " + aId);
+ }
+ // Entry not yet found. Try to create it.
+ File albumDir = new File(_dir, aId);
+ if (!albumDir.mkdir()) {
+ throw new IOException("Could not create album: " + aId);
+ }
+ File photosDir = new File(albumDir, PHOTOS_DIR);
+ if (!photosDir.mkdir()) {
+ throw new IOException("Could not create photo storage dir: " + photosDir.getPath());
+ }
+ File thumbnailsDir = new File(albumDir, THUMBNAILS_DIR);
+ if (!thumbnailsDir.mkdir()) {
+ throw new IOException("Coul dnot create thumbnails storage dir: " + thumbnailsDir.getPath());
+ }
+ String newPath = _path + "/" + aId;
+ newPath = newPath.replaceAll("//", "/");
+ FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
+ addEntry(album);
+ } finally {
+ _entries.invalidate();
}
- String newPath = _path + "/" + aId;
- newPath = newPath.replaceAll("//", "/");
- FileSystemAlbum album = new FileSystemAlbum(albumDir, newPath, _entries.getCache());
- addEntry(album);
}
/*
* @see org.wamblee.photos.database.Album#removeAlbum(java.lang.String)
*/
public void removeEntry(String aId) throws IOException {
- PhotoEntry entry = find(aId);
- if (entry == null) {
- throw new IOException("Entry " + aId + " not found.");
- }
- if (entry instanceof FileSystemAlbum) {
- // album.
- removeAlbum((FileSystemAlbum) entry);
- } else {
- // regular photo
- removePhoto(entry);
+ try {
+ PhotoEntry entry = find(aId);
+ if (entry == null) {
+ throw new IOException("Entry " + aId + " not found.");
+ }
+ if (entry instanceof FileSystemAlbum) {
+ // album.
+ removeAlbum((FileSystemAlbum) entry);
+ } else {
+ // regular photo
+ removePhoto(entry);
+ }
+ } finally {
+ _entries.invalidate();
}
}