Package org.openl.rules.repository.db
Class DatasourceDBRepository
- java.lang.Object
-
- org.openl.rules.repository.db.DatasourceDBRepository
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Repository
public class DatasourceDBRepository extends Object
-
-
Constructor Summary
Constructors Constructor Description DatasourceDBRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileDatacheck(String name)Read a file descriptor by the given path name.FileDatacheckHistory(String name, String version)Read a file descriptor by the given path name of the given version.voidclose()FileDatacopyHistory(String srcName, FileData destData, String version)Copy a file of the given version to the destination file.protected ConnectioncreateConnection()booleandelete(List<FileData> data)Delete multiple files or mark it as deleted in one transaction.booleandelete(FileData path)Delete a file or mark it as deleted.booleandeleteHistory(FileData data)Delete a file from the history.StringgetId()Get unique identifier for Repository.StringgetName()Get repository name shown on UI.voidinitialize()List<FileData>list(String path)Return a list of files recursively in the given folder.List<FileData>listHistory(String name)List a versions of the given file.FileItemread(String name)Read a file by the given path name.FileItemreadHistory(String name, String version)Read a file by the given path name of the given version.List<FileData>save(List<FileItem> fileItems)Save multiple projects in one transaction.FileDatasave(FileData data, InputStream stream)Save a file.voidsetDataSource(DataSource dataSource)voidsetId(String id)voidsetListener(Listener callback)Set a listener to monitor changes in the repository.voidsetListenerTimerPeriod(int listenerTimerPeriod)voidsetLogin(String login)voidsetName(String name)voidsetPassword(String password)voidsetUri(String uri)Featuressupports()Get the features supported by the repository.voidvalidateConnection()Validate underlying connection.
-
-
-
Method Detail
-
setDataSource
public void setDataSource(DataSource dataSource)
-
setUri
public void setUri(String uri)
-
setLogin
public void setLogin(String login)
-
setPassword
public void setPassword(String password)
-
createConnection
protected Connection createConnection() throws SQLException
- Throws:
SQLException
-
initialize
public void initialize()
-
setId
public void setId(String id)
-
getId
public String getId()
Description copied from interface:RepositoryGet unique identifier for Repository. Used to distinguish one repository from another. Must be unique.- Specified by:
getIdin interfaceRepository- Returns:
- repository id.
-
setName
public void setName(String name)
-
getName
public String getName()
Description copied from interface:RepositoryGet repository name shown on UI.- Specified by:
getNamein interfaceRepository- Returns:
- repository name
-
setListenerTimerPeriod
public void setListenerTimerPeriod(int listenerTimerPeriod)
-
list
public List<FileData> list(String path) throws IOException
Description copied from interface:RepositoryReturn a list of files recursively in the given folder.- Specified by:
listin interfaceRepository- Parameters:
path- the folder to scan. The path must be ended by '/' or be empty.- Returns:
- the list of the file descriptors. Invalid files are ignored.
- Throws:
IOException- if not possible to read the directory.
-
check
public FileData check(String name) throws IOException
Description copied from interface:RepositoryRead a file descriptor by the given path name.- Specified by:
checkin interfaceRepository- Parameters:
name- the path name of the file to read.- Returns:
- the file descriptor or null if the file is absent.
- Throws:
IOException- if not possible to read the file descriptor.
-
read
public FileItem read(String name) throws IOException
Description copied from interface:RepositoryRead a file by the given path name.- Specified by:
readin interfaceRepository- Parameters:
name- the path name of the file to read.- Returns:
- the file descriptor or null if the file is absent.
- Throws:
IOException- if not possible to read the file.
-
save
public FileData save(FileData data, InputStream stream) throws IOException
Description copied from interface:RepositorySave a file.- Specified by:
savein interfaceRepository- Parameters:
data- the file descriptor.stream- the stream to save with the specified file descriptor.- Returns:
- the resulted file descriptor after successful writing.
- Throws:
IOException- if not possible to save the file.
-
save
public List<FileData> save(List<FileItem> fileItems) throws IOException
Description copied from interface:RepositorySave multiple projects in one transaction. Used only in deployment services- Specified by:
savein interfaceRepository- Parameters:
fileItems- list of file descriptor and stream pairs- Throws:
IOException- if not possible to save the file.
-
delete
public boolean delete(FileData path) throws IOException
Description copied from interface:RepositoryDelete a file or mark it as deleted.- Specified by:
deletein interfaceRepository- Parameters:
path- the file descriptor to delete.- Returns:
- true if file has been deleted successfully or false if the file is absent.
- Throws:
IOException- if not possible to delete the file.
-
delete
public boolean delete(List<FileData> data) throws IOException
Description copied from interface:RepositoryDelete multiple files or mark it as deleted in one transaction.- Specified by:
deletein interfaceRepository- Parameters:
data- list of files to delete- Returns:
- true if at least one file is deleted
- Throws:
IOException- if not possible to delete the file
-
setListener
public void setListener(Listener callback)
Description copied from interface:RepositorySet a listener to monitor changes in the repository.- Specified by:
setListenerin interfaceRepository- Parameters:
callback- the listener.
-
listHistory
public List<FileData> listHistory(String name) throws IOException
Description copied from interface:RepositoryList a versions of the given file. If the repository does not support file versions, then it will return one record of the given file. The order of the file descriptions is undefined, but the first element is the actual file which can be access byRepository.read(String)method.- Specified by:
listHistoryin interfaceRepository- Parameters:
name- the file name.- Returns:
- the list of file descriptions.
- Throws:
IOException- if not possible to read the directory.
-
checkHistory
public FileData checkHistory(String name, String version) throws IOException
Description copied from interface:RepositoryRead a file descriptor by the given path name of the given version. If the version is null, then it will work likeRepository.check(String)method.- Specified by:
checkHistoryin interfaceRepository- Parameters:
name- the path name of the file to read.version- the version of the file to read, can be null.- Returns:
- the file descriptor or null if the file is absent.
- Throws:
IOException- if not possible to read the file descriptor.- See Also:
Repository.read(String)
-
readHistory
public FileItem readHistory(String name, String version) throws IOException
Description copied from interface:RepositoryRead a file by the given path name of the given version. If the version is null, then it will work likeRepository.read(String)method.- Specified by:
readHistoryin interfaceRepository- Parameters:
name- the path name of the file to read.version- the version of the file to read, can be null.- Returns:
- the file descriptor or null if the file is absent.
- Throws:
IOException- if not possible to read the file.- See Also:
Repository.read(String)
-
deleteHistory
public boolean deleteHistory(FileData data) throws IOException
Description copied from interface:RepositoryDelete a file from the history. If the version is null, then it will delete all versions of the file from the history.- Specified by:
deleteHistoryin interfaceRepository- Parameters:
data- the file descriptor to delete. The fields "name", "version", "author" and "comment" must be initialized.- Returns:
- true if file has been deleted successfully or false if the file is absent.
- Throws:
IOException- if not possible to delete the file.- See Also:
Repository.delete(FileData)
-
copyHistory
public FileData copyHistory(String srcName, FileData destData, String version) throws IOException
Description copied from interface:RepositoryCopy a file of the given version to the destination file. If the version is null, then copy latest version.- Specified by:
copyHistoryin interfaceRepository- Parameters:
srcName- the file to copy.destData- the destination file descriptor.version- the version of the file to copy- Returns:
- the file descriptor of the resulted file.
- Throws:
IOException- if not possible to copy the file
-
supports
public Features supports()
Description copied from interface:RepositoryGet the features supported by the repository. If specific feature is supported, repository instance can be casted to interface class that support that feature.- Specified by:
supportsin interfaceRepository- Returns:
- Supported features
-
validateConnection
public void validateConnection() throws IOExceptionDescription copied from interface:RepositoryValidate underlying connection. Default implementation does nothing.- Specified by:
validateConnectionin interfaceRepository- Throws:
IOException- if connection cannot be established
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRepository
-
-