Package fr.dyade.aaa.util
Class DBRepository
- java.lang.Object
-
- fr.dyade.aaa.util.DBRepository
-
- All Implemented Interfaces:
Repository
public final class DBRepository extends Object implements Repository
This class allows to use a database through JDBC as repository with the NTransaction module.- See Also:
NTransaction,Repository
-
-
Field Summary
Fields Modifier and Type Field Description private intbaddeleted(package private) Connectionconn(package private) Stringconnurl(package private) PreparedStatementdeleteStmt(package private) Filedir(package private) Stringdriver(package private) PreparedStatementinsertStmtprivate intnbdeletedprivate intnbloadedprivate intnbsaved(package private) PreparedStatementupdateStmt
-
Constructor Summary
Constructors Constructor Description DBRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackup(BackupFile backup)Backups the repository (may be unimplemented).voidclose()Closes the repository.voidcommit()Commits all changes to the repository.voiddelete(String dirName, String name)Deletes the corresponding objects in repository.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
-
driver
String driver
-
connurl
String connurl
-
dir
File dir
-
nbsaved
private int nbsaved
-
nbdeleted
private int nbdeleted
-
baddeleted
private int baddeleted
-
nbloaded
private int nbloaded
-
conn
Connection conn
-
insertStmt
PreparedStatement insertStmt
-
updateStmt
PreparedStatement updateStmt
-
deleteStmt
PreparedStatement deleteStmt
-
-
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. Opens the connection, evntually creates the database and tables.- 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 loaded bytes array.
- 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.
-
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
-
close
public void close() throws IOExceptionCloses the repository.- Specified by:
closein interfaceRepository- Throws:
IOException- an error occurs.
-
-