Package org.apache.jackrabbit.core.fs.db
Class DatabaseFileSystem
- java.lang.Object
-
- org.apache.jackrabbit.core.fs.db.DatabaseFileSystem
-
- All Implemented Interfaces:
FileSystem
- Direct Known Subclasses:
DbFileSystem
,JNDIDatabaseFileSystem
public abstract class DatabaseFileSystem extends Object implements FileSystem
Base class for database file systems. This class contains common functionality for database file system subclasses that normally differ only in the way the database connection is acquired.See the
DbFileSystem
for a detailed description of the available configuration options and database behaviour.
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionHelper
conHelper
theConnectionHelper
set in theinit()
methodprotected String
copyFileSQL
protected String
copyFilesSQL
protected String
deleteFileSQL
protected String
deleteFolderSQL
protected static int
INITIAL_BUFFER_SIZE
protected boolean
initialized
protected String
insertFileSQL
protected String
insertFolderSQL
protected String
schema
protected String
schemaObjectPrefix
protected String
selectChildCountSQL
protected String
selectDataSQL
protected String
selectExistSQL
protected String
selectFileAndFolderNamesSQL
protected String
selectFileExistSQL
protected String
selectFileNamesSQL
protected String
selectFolderExistSQL
protected String
selectFolderNamesSQL
protected String
selectLastModifiedSQL
protected String
selectLengthSQL
protected String
updateDataSQL
protected String
updateLastModifiedSQL
-
Fields inherited from interface org.apache.jackrabbit.core.fs.FileSystem
SEPARATOR, SEPARATOR_CHAR
-
-
Constructor Summary
Constructors Constructor Description DatabaseFileSystem()
Default constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
buildSQLStatements()
Builds the SQL statementsvoid
close()
Close the file system.protected CheckSchemaOperation
createCheckSchemaOperation()
This method is called frominit()
after thecreateConnectionHelper(DataSource)
method, and returns a defaultCheckSchemaOperation
.protected ConnectionHelper
createConnectionHelper(DataSource dataSrc)
This method is called from theinit()
method of this class and returns aConnectionHelper
instance which is assigned to theconHelper
field.protected void
createDeepFolder(String folderPath)
Creates the specified files system folder entry, recursively creating any non-existing intermediate folder entries.void
createFolder(String folderPath)
Creates the folder named by this path, including any necessary but nonexistent parent folders.void
deleteFile(String filePath)
Deletes the file denoted by this path.void
deleteFolder(String folderPath)
Deletes the folder denoted by this path.boolean
equals(Object obj)
boolean
exists(String path)
Tests whether the file system entry denoted by this path exists.protected abstract DataSource
getDataSource()
InputStream
getInputStream(String filePath)
Returns an input stream of the contents of the file denoted by this path.OutputStream
getOutputStream(String filePath)
Returns an output stream for writing bytes to the file denoted by this path.String
getSchema()
String
getSchemaObjectPrefix()
boolean
hasChildren(String path)
Tests whether the file system entry denoted by this path has child entries.int
hashCode()
Returns zero to satisfy the Object equals/hashCode contract.void
init()
Initialize the file systemboolean
isFile(String path)
Tests whether the file system entry denoted by this path exists and is a file.boolean
isFolder(String path)
Tests whether the file system entry denoted by this path exists and is a folder.boolean
isSchemaCheckEnabled()
long
lastModified(String path)
Returns the time that the file system entry denoted by this path was last modified.long
length(String filePath)
Returns the length of the file denoted by this path.String[]
list(String folderPath)
Returns an array of strings naming the files and folders in the folder denoted by this path.String[]
listFiles(String folderPath)
Returns an array of strings naming the files in the folder denoted by this path.String[]
listFolders(String folderPath)
Returns an array of strings naming the folders in the folder denoted by this path.void
setSchema(String schema)
void
setSchemaCheckEnabled(boolean enabled)
void
setSchemaObjectPrefix(String schemaObjectPrefix)
protected void
verifyRootExists()
Verifies that the root file system entry exists.
-
-
-
Field Detail
-
initialized
protected boolean initialized
-
schema
protected String schema
-
schemaObjectPrefix
protected String schemaObjectPrefix
-
INITIAL_BUFFER_SIZE
protected static final int INITIAL_BUFFER_SIZE
- See Also:
- Constant Field Values
-
conHelper
protected ConnectionHelper conHelper
theConnectionHelper
set in theinit()
method
-
selectExistSQL
protected String selectExistSQL
-
selectFileExistSQL
protected String selectFileExistSQL
-
selectFolderExistSQL
protected String selectFolderExistSQL
-
selectChildCountSQL
protected String selectChildCountSQL
-
selectDataSQL
protected String selectDataSQL
-
selectLastModifiedSQL
protected String selectLastModifiedSQL
-
selectLengthSQL
protected String selectLengthSQL
-
selectFileNamesSQL
protected String selectFileNamesSQL
-
selectFolderNamesSQL
protected String selectFolderNamesSQL
-
selectFileAndFolderNamesSQL
protected String selectFileAndFolderNamesSQL
-
deleteFileSQL
protected String deleteFileSQL
-
deleteFolderSQL
protected String deleteFolderSQL
-
insertFileSQL
protected String insertFileSQL
-
insertFolderSQL
protected String insertFolderSQL
-
updateDataSQL
protected String updateDataSQL
-
updateLastModifiedSQL
protected String updateLastModifiedSQL
-
copyFileSQL
protected String copyFileSQL
-
copyFilesSQL
protected String copyFilesSQL
-
-
Method Detail
-
getSchemaObjectPrefix
public String getSchemaObjectPrefix()
-
setSchemaObjectPrefix
public void setSchemaObjectPrefix(String schemaObjectPrefix)
-
getSchema
public String getSchema()
-
setSchema
public void setSchema(String schema)
-
isSchemaCheckEnabled
public final boolean isSchemaCheckEnabled()
- Returns:
- whether the schema check is enabled
-
setSchemaCheckEnabled
public final void setSchemaCheckEnabled(boolean enabled)
- Parameters:
enabled
- set whether the schema check is enabled
-
hashCode
public int hashCode()
Returns zero to satisfy the Object equals/hashCode contract. This class is mutable and not meant to be used as a hash key.- Overrides:
hashCode
in classObject
- Returns:
- always zero
- See Also:
Object.hashCode()
-
init
public void init() throws FileSystemException
Initialize the file system- Specified by:
init
in interfaceFileSystem
- Throws:
FileSystemException
- if the file system initialization fails
-
getDataSource
protected abstract DataSource getDataSource() throws Exception
- Returns:
- Throws:
Exception
-
createConnectionHelper
protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
This method is called from theinit()
method of this class and returns aConnectionHelper
instance which is assigned to theconHelper
field. Subclasses may override it to return a specialized connection helper.- Parameters:
dataSrc
- theDataSource
of this persistence manager- Returns:
- a
ConnectionHelper
- Throws:
Exception
- on error
-
createCheckSchemaOperation
protected CheckSchemaOperation createCheckSchemaOperation()
This method is called frominit()
after thecreateConnectionHelper(DataSource)
method, and returns a defaultCheckSchemaOperation
. Subclasses can overrride this implementation to get a customized implementation.- Returns:
- a new
CheckSchemaOperation
instance
-
close
public void close() throws FileSystemException
Close the file system. After calling this method, the file system is no longer accessible.- Specified by:
close
in interfaceFileSystem
- Throws:
FileSystemException
-
createFolder
public void createFolder(String folderPath) throws FileSystemException
Creates the folder named by this path, including any necessary but nonexistent parent folders. Note that if this operation fails it may have succeeded in creating some of the necessary parent folders.- Specified by:
createFolder
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder to be created.- Throws:
FileSystemException
- if a file system entry denoted by path already exists or if another error occurs.
-
deleteFile
public void deleteFile(String filePath) throws FileSystemException
Deletes the file denoted by this path.- Specified by:
deleteFile
in interfaceFileSystem
- Parameters:
filePath
- the path of the file to be deleted.- Throws:
FileSystemException
- if this path does not denote a file or if another error occurs.
-
deleteFolder
public void deleteFolder(String folderPath) throws FileSystemException
Deletes the folder denoted by this path. Any contents of this folder (folders and files) will be deleted recursively.- Specified by:
deleteFolder
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder to be deleted.- Throws:
FileSystemException
- if this path does not denote a folder or if another error occurs.
-
exists
public boolean exists(String path) throws FileSystemException
Tests whether the file system entry denoted by this path exists.- Specified by:
exists
in interfaceFileSystem
- Parameters:
path
- the path of a file system entry.- Returns:
- true if the file system entry at path exists; false otherwise.
- Throws:
FileSystemException
-
isFile
public boolean isFile(String path) throws FileSystemException
Tests whether the file system entry denoted by this path exists and is a file.- Specified by:
isFile
in interfaceFileSystem
- Parameters:
path
- the path of a file system entry.- Returns:
- true if the file system entry at path is a file; false otherwise.
- Throws:
FileSystemException
-
isFolder
public boolean isFolder(String path) throws FileSystemException
Tests whether the file system entry denoted by this path exists and is a folder.- Specified by:
isFolder
in interfaceFileSystem
- Parameters:
path
- the path of a file system entry.- Returns:
- true if the file system entry at path is a folder; false otherwise.
- Throws:
FileSystemException
-
lastModified
public long lastModified(String path) throws FileSystemException
Returns the time that the file system entry denoted by this path was last modified.- Specified by:
lastModified
in interfaceFileSystem
- Parameters:
path
- the path of a file system entry.- Returns:
- A long value representing the time the file system entry was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the modification time can't be determined.
- Throws:
FileSystemException
- if the file system entry does not exist.
-
length
public long length(String filePath) throws FileSystemException
Returns the length of the file denoted by this path.- Specified by:
length
in interfaceFileSystem
- Parameters:
filePath
- the path of the file.- Returns:
- The length, in bytes, of the file denoted by this path, or -1L if the length can't be determined.
- Throws:
FileSystemException
- if the path does not denote an existing file.
-
hasChildren
public boolean hasChildren(String path) throws FileSystemException
Tests whether the file system entry denoted by this path has child entries.- Specified by:
hasChildren
in interfaceFileSystem
- Parameters:
path
- the path of a file system entry.- Returns:
- true if the file system entry at path has child entries; false otherwise.
- Throws:
FileSystemException
-
list
public String[] list(String folderPath) throws FileSystemException
Returns an array of strings naming the files and folders in the folder denoted by this path.- Specified by:
list
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder whose contents is to be listed.- Returns:
- an array of strings naming the files and folders in the folder denoted by this path.
- Throws:
FileSystemException
- if this path does not denote a folder or if another error occurs.
-
listFiles
public String[] listFiles(String folderPath) throws FileSystemException
Returns an array of strings naming the files in the folder denoted by this path.- Specified by:
listFiles
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder whose contents is to be listed.- Returns:
- an array of strings naming the files in the folder denoted by this path.
- Throws:
FileSystemException
- if this path does not denote a folder or if another error occurs.
-
listFolders
public String[] listFolders(String folderPath) throws FileSystemException
Returns an array of strings naming the folders in the folder denoted by this path.- Specified by:
listFolders
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder whose contents is to be listed.- Returns:
- an array of strings naming the folders in the folder denoted by this path.
- Throws:
FileSystemException
- if this path does not denote a folder or if another error occurs.
-
getInputStream
public InputStream getInputStream(String filePath) throws FileSystemException
Returns an input stream of the contents of the file denoted by this path.- Specified by:
getInputStream
in interfaceFileSystem
- Parameters:
filePath
- the path of the file.- Returns:
- an input stream of the contents of the file.
- Throws:
FileSystemException
- if the file does not exist or if it cannot be read from
-
getOutputStream
public OutputStream getOutputStream(String filePath) throws FileSystemException
Returns an output stream for writing bytes to the file denoted by this path. The file will be created if it doesn't exist. If the file exists, its contents will be overwritten.- Specified by:
getOutputStream
in interfaceFileSystem
- Parameters:
filePath
- the path of the file.- Returns:
- an output stream for writing bytes to the file.
- Throws:
FileSystemException
- if the file cannot be written to or created
-
buildSQLStatements
protected void buildSQLStatements()
Builds the SQL statements
-
verifyRootExists
protected void verifyRootExists() throws Exception
Verifies that the root file system entry exists. If it doesn't exist yet it will be automatically created.- Throws:
Exception
- if an error occurs
-
createDeepFolder
protected void createDeepFolder(String folderPath) throws FileSystemException
Creates the specified files system folder entry, recursively creating any non-existing intermediate folder entries.- Parameters:
folderPath
- folder entry to create- Throws:
FileSystemException
- if an error occurs
-
-