Package fr.dyade.aaa.util
Class FileRepository
- java.lang.Object
-
- fr.dyade.aaa.util.FileRepository
-
- All Implemented Interfaces:
Repository
public final class FileRepository extends Object implements Repository
This class allows to use a filesystem directory as repository with the NTransaction module.- See Also:
NTransaction,Repository
-
-
Field Summary
Fields Modifier and Type Field Description private intbaddeletedThe number of useless delete operation on repository.(package private) Filedirprivate Stringmodeprivate intnbdeletedThe number of delete operation on repository.private intnbloadedThe number of load operation from repository.private intnbsavedThe number of save operation to repository.private booleansyncOnWriteprivate booleanuseFileOutputStreamBoolean value to force the use of FileOutputStream rather than RandomAccessFile.
-
Constructor Summary
Constructors Constructor Description FileRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackup(BackupFile backup)Backups the repository (may be unimplemented).private voidbackupDir(BackupFile backup, File currentDir, String path)private voidbackupFile(BackupFile backup, File file, String path)voidclose()Closes the repository.voidcommit()Commits all changes to the repository.voiddelete(String dirName, String name)Deletes the corresponding objects in repository.private voiddeleteDir(File dir)Delete the specified directory if it is empty.intgetNbBadDeletedObjects()Returns the number of useless delete operation on repository.intgetNbDeletedObjects()Returns the number of delete operation on repository.intgetNbLoadedObjects()Returns the number of load operation from repository.intgetNbSavedObjects()Returns the number of save operation to repository.voidinit(Transaction transaction, File dir)Initializes the repository.String[]list(String prefix)Gets a list of persistent objects that name corresponds to prefix.byte[]load(String dirName, String name)Loads the byte array.voidsave(String dirName, String name, byte[] content)Save the corresponding bytes array.
-
-
-
Field Detail
-
dir
File dir
-
nbsaved
private int nbsaved
The number of save operation to repository.
-
nbdeleted
private int nbdeleted
The number of delete operation on repository.
-
baddeleted
private int baddeleted
The number of useless delete operation on repository.
-
nbloaded
private int nbloaded
The number of load operation from repository.
-
useFileOutputStream
private boolean useFileOutputStream
Boolean value to force the use of FileOutputStream rather than RandomAccessFile. By default this value is false, it can be set to true using the FileRepository.useRandomAccessFile java property.This property can be fixed only from
javalaunching command, or through System.property method.
-
syncOnWrite
private boolean syncOnWrite
-
mode
private String mode
-
-
Method Detail
-
getNbSavedObjects
public int getNbSavedObjects()
Returns the number of save operation to repository.- Specified by:
getNbSavedObjectsin interfaceRepository- Returns:
- The number of save operation to repository.
-
getNbDeletedObjects
public int getNbDeletedObjects()
Returns the number of delete operation on repository.- Specified by:
getNbDeletedObjectsin interfaceRepository- Returns:
- The number of delete operation on repository.
-
getNbBadDeletedObjects
public int getNbBadDeletedObjects()
Returns the number of useless delete operation on repository.- Specified by:
getNbBadDeletedObjectsin interfaceRepository- Returns:
- The number of useless delete operation on repository.
-
getNbLoadedObjects
public int getNbLoadedObjects()
Returns the number of load operation from repository.- Specified by:
getNbLoadedObjectsin interfaceRepository- Returns:
- The number of load operation from repository.
-
init
public void init(Transaction transaction, File dir) throws IOException
Initializes the repository.- Specified by:
initin interfaceRepository- Parameters:
transaction- the transaction object.dir- the directory.- Throws:
IOException- an error occurs.
-
list
public String[] list(String prefix) throws IOException
Gets a list of persistent objects that name corresponds to prefix.- Specified by:
listin interfaceRepository- Parameters:
prefix- the prefix.- Returns:
- The list of corresponding names.
- Throws:
IOException- an error occurs.
-
save
public void save(String dirName, String name, byte[] content) throws IOException
Save the corresponding bytes array.- Specified by:
savein interfaceRepository- Parameters:
dirName- the directory.name- the object name.content- the serialized object view.- Throws:
IOException- an error occurs.
-
load
public byte[] load(String dirName, String name) throws IOException
Loads the byte array.- Specified by:
loadin interfaceRepository- Parameters:
dirName- the directory.name- the object name.- Returns:
- the serialized object view.
- Throws:
IOException- an error occurs.
-
delete
public void delete(String dirName, String name) throws IOException
Deletes the corresponding objects in repository.- Specified by:
deletein interfaceRepository- Parameters:
dirName- the directory.name- the object name.- Throws:
IOException- an error occurs.
-
deleteDir
private final void deleteDir(File dir)
Delete the specified directory if it is empty. Also recursively delete the parent directories if they are empty.- Parameters:
dir- the directory to delete.
-
commit
public void commit() throws IOExceptionCommits all changes to the repository.- Specified by:
commitin interfaceRepository- Throws:
IOException- an error occurs.
-
backup
public void backup(BackupFile backup) throws IOException
Description copied from interface:RepositoryBackups the repository (may be unimplemented).- Specified by:
backupin interfaceRepository- Parameters:
backup- The backup file.- Throws:
IOException
-
backupDir
private void backupDir(BackupFile backup, File currentDir, String path) throws IOException
- Throws:
IOException
-
backupFile
private void backupFile(BackupFile backup, File file, String path) throws IOException
- Throws:
IOException
-
close
public void close() throws IOExceptionCloses the repository.- Specified by:
closein interfaceRepository- Throws:
IOException- an error occurs.
-
-