|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.core.fs.db.DatabaseFileSystem
public class DatabaseFileSystem
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. Subclasses should override
the getConnection() method to return the configured database
connection.
See the DbFileSystem for a detailed description of the available
configuration options and database behaviour.
| Field Summary | |
|---|---|
protected java.sql.Connection |
con
|
protected java.lang.String |
copyFileSQL
|
protected java.lang.String |
copyFilesSQL
|
protected java.lang.String |
deleteFileSQL
|
protected java.lang.String |
deleteFolderSQL
|
protected static int |
INITIAL_BUFFER_SIZE
|
protected boolean |
initialized
|
protected java.lang.String |
insertFileSQL
|
protected java.lang.String |
insertFolderSQL
|
protected java.lang.String |
schema
|
protected static java.lang.String |
SCHEMA_OBJECT_PREFIX_VARIABLE
|
protected java.lang.String |
schemaObjectPrefix
|
protected java.lang.String |
selectChildCountSQL
|
protected java.lang.String |
selectDataSQL
|
protected java.lang.String |
selectExistSQL
|
protected java.lang.String |
selectFileAndFolderNamesSQL
|
protected java.lang.String |
selectFileExistSQL
|
protected java.lang.String |
selectFileNamesSQL
|
protected java.lang.String |
selectFolderExistSQL
|
protected java.lang.String |
selectFolderNamesSQL
|
protected java.lang.String |
selectLastModifiedSQL
|
protected java.lang.String |
selectLengthSQL
|
protected static int |
SLEEP_BEFORE_RECONNECT
|
protected java.lang.String |
updateDataSQL
|
protected java.lang.String |
updateLastModifiedSQL
|
| Fields inherited from interface org.apache.jackrabbit.core.fs.FileSystem |
|---|
SEPARATOR, SEPARATOR_CHAR |
| Constructor Summary | |
|---|---|
DatabaseFileSystem()
Default constructor |
|
| Method Summary | |
|---|---|
protected void |
buildSQLStatements()
Builds the SQL statements |
protected void |
checkSchema()
Checks if the required schema objects exist and creates them if they don't exist yet. |
void |
close()
Close the file system. |
protected void |
closeConnection(java.sql.Connection connection)
Closes the given database connection. |
protected void |
closeResultSet(java.sql.ResultSet rs)
|
protected void |
closeStatement(java.sql.Statement stmt)
|
void |
copy(java.lang.String srcPath,
java.lang.String destPath)
Copies a file or folder to a new location. |
protected void |
copyDeepFolder(java.lang.String srcPath,
java.lang.String destPath)
Recursively copies the given folder to the given destination. |
protected void |
copyFile(java.lang.String srcPath,
java.lang.String destPath)
Copies the given file entry to the given destination path. |
protected void |
createDeepFolder(java.lang.String folderPath)
Creates the specified files system folder entry, recursively creating any non-existing intermediate folder entries. |
void |
createFolder(java.lang.String folderPath)
Creates the folder named by this path, including any necessary but nonexistent parent folders. |
void |
deleteFile(java.lang.String filePath)
Deletes the file denoted by this path. |
void |
deleteFolder(java.lang.String folderPath)
Deletes the folder denoted by this path. |
boolean |
equals(java.lang.Object obj)
|
protected java.sql.Statement |
executeStmt(java.lang.String sql,
java.lang.Object[] params)
Executes the given SQL statement with the specified parameters. |
boolean |
exists(java.lang.String path)
Tests whether the file system entry denoted by this path exists. |
protected java.sql.Connection |
getConnection()
Abstract factory method for creating a new database connection. |
java.io.InputStream |
getInputStream(java.lang.String filePath)
Returns an input stream of the contents of the file denoted by this path. |
java.io.OutputStream |
getOutputStream(java.lang.String filePath)
Returns an output stream for writing bytes to the file denoted by this path. |
RandomAccessOutputStream |
getRandomAccessOutputStream(java.lang.String filePath)
Returns an output stream for writing bytes to the file denoted by this path. |
java.lang.String |
getSchema()
|
java.lang.String |
getSchemaObjectPrefix()
|
boolean |
hasChildren(java.lang.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 system |
protected void |
initConnection()
Initializes the database connection used by this file system. |
protected void |
initPreparedStatements()
Initializes the map of prepared statements. |
boolean |
isFile(java.lang.String path)
Tests whether the file system entry denoted by this path exists and is a file. |
boolean |
isFolder(java.lang.String path)
Tests whether the file system entry denoted by this path exists and is a folder. |
long |
lastModified(java.lang.String path)
Returns the time that the file system entry denoted by this path was last modified. |
long |
length(java.lang.String filePath)
Returns the length of the file denoted by this path. |
java.lang.String[] |
list(java.lang.String folderPath)
Returns an array of strings naming the files and folders in the folder denoted by this path. |
java.lang.String[] |
listFiles(java.lang.String folderPath)
Returns an array of strings naming the files in the folder denoted by this path. |
java.lang.String[] |
listFolders(java.lang.String folderPath)
Returns an array of strings naming the folders in the folder denoted by this path. |
void |
move(java.lang.String srcPath,
java.lang.String destPath)
Moves a file or folder to a new location. |
protected void |
prepareSchemaObjectPrefix()
Makes sure that schemaObjectPrefix does only consist of
characters that are allowed in names on the target database. |
protected boolean |
reestablishConnection()
Re-establishes the database connection. |
protected void |
resetStatement(java.sql.PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters
and warnings contained. |
void |
setSchema(java.lang.String schema)
|
void |
setSchemaObjectPrefix(java.lang.String schemaObjectPrefix)
|
void |
touch(java.lang.String filePath)
Set the modified time of an existing file to now. |
protected void |
verifyRootExists()
Verifies that the root file system entry exists. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.lang.String SCHEMA_OBJECT_PREFIX_VARIABLE
protected boolean initialized
protected java.lang.String schema
protected java.lang.String schemaObjectPrefix
protected static final int INITIAL_BUFFER_SIZE
protected java.sql.Connection con
protected static final int SLEEP_BEFORE_RECONNECT
protected java.lang.String selectExistSQL
protected java.lang.String selectFileExistSQL
protected java.lang.String selectFolderExistSQL
protected java.lang.String selectChildCountSQL
protected java.lang.String selectDataSQL
protected java.lang.String selectLastModifiedSQL
protected java.lang.String selectLengthSQL
protected java.lang.String selectFileNamesSQL
protected java.lang.String selectFolderNamesSQL
protected java.lang.String selectFileAndFolderNamesSQL
protected java.lang.String deleteFileSQL
protected java.lang.String deleteFolderSQL
protected java.lang.String insertFileSQL
protected java.lang.String insertFolderSQL
protected java.lang.String updateDataSQL
protected java.lang.String updateLastModifiedSQL
protected java.lang.String copyFileSQL
protected java.lang.String copyFilesSQL
| Constructor Detail |
|---|
public DatabaseFileSystem()
| Method Detail |
|---|
public java.lang.String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(java.lang.String schemaObjectPrefix)
public java.lang.String getSchema()
public void setSchema(java.lang.String schema)
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()
public void init()
throws FileSystemException
init in interface FileSystemFileSystemException - if the file system initialization fails
public void close()
throws FileSystemException
close in interface FileSystemFileSystemException
public void createFolder(java.lang.String folderPath)
throws FileSystemException
createFolder in interface FileSystemfolderPath - the path of the folder to be created.
FileSystemException - if a file system entry denoted by path
already exists or if another error occurs.
public void deleteFile(java.lang.String filePath)
throws FileSystemException
deleteFile in interface FileSystemfilePath - the path of the file to be deleted.
FileSystemException - if this path does not denote a file or if
another error occurs.
public void deleteFolder(java.lang.String folderPath)
throws FileSystemException
deleteFolder in interface FileSystemfolderPath - the path of the folder to be deleted.
FileSystemException - if this path does not denote a folder or if
another error occurs.
public boolean exists(java.lang.String path)
throws FileSystemException
exists in interface FileSystempath - the path of a file system entry.
FileSystemException
public boolean isFile(java.lang.String path)
throws FileSystemException
isFile in interface FileSystempath - the path of a file system entry.
FileSystemException
public boolean isFolder(java.lang.String path)
throws FileSystemException
isFolder in interface FileSystempath - the path of a file system entry.
FileSystemException
public long lastModified(java.lang.String path)
throws FileSystemException
lastModified in interface FileSystempath - the path of a file system entry.
FileSystemException - if the file system entry does not exist.
public long length(java.lang.String filePath)
throws FileSystemException
length in interface FileSystemfilePath - the path of the file.
FileSystemException - if the path does not denote an existing file.
public boolean hasChildren(java.lang.String path)
throws FileSystemException
hasChildren in interface FileSystempath - the path of a file system entry.
FileSystemException
public java.lang.String[] list(java.lang.String folderPath)
throws FileSystemException
list in interface FileSystemfolderPath - the path of the folder whose contents is to be listed.
FileSystemException - if this path does not denote a folder or if
another error occurs.
public java.lang.String[] listFiles(java.lang.String folderPath)
throws FileSystemException
listFiles in interface FileSystemfolderPath - the path of the folder whose contents is to be listed.
FileSystemException - if this path does not denote a folder or if
another error occurs.
public java.lang.String[] listFolders(java.lang.String folderPath)
throws FileSystemException
listFolders in interface FileSystemfolderPath - the path of the folder whose contents is to be listed.
FileSystemException - if this path does not denote a folder or if
another error occurs.
public void touch(java.lang.String filePath)
throws FileSystemException
touch in interface FileSystemfilePath - the path of the file.
FileSystemException - if the path does not denote an existing file.
public java.io.InputStream getInputStream(java.lang.String filePath)
throws FileSystemException
getInputStream in interface FileSystemfilePath - the path of the file.
FileSystemException - if the file does not exist
or if it cannot be read from
public java.io.OutputStream getOutputStream(java.lang.String filePath)
throws FileSystemException
getOutputStream in interface FileSystemfilePath - the path of the file.
FileSystemException - if the file cannot be written to or created
public RandomAccessOutputStream getRandomAccessOutputStream(java.lang.String filePath)
throws FileSystemException,
java.lang.UnsupportedOperationException
0. See also
RandomAccessOutputStream.seek(long);
getRandomAccessOutputStream in interface FileSystemfilePath - the path of the file.
FileSystemException - if the file could not be created or
if the output stream cannot be obtained.
java.lang.UnsupportedOperationException - if the implementation does
not support file access through a
RandomAccessOutputStream.
public void copy(java.lang.String srcPath,
java.lang.String destPath)
throws FileSystemException
copy in interface FileSystemsrcPath - the path of the file or folder to be copied.destPath - the destination path to which the file or folder is to be copied.
FileSystemException - if the copy fails
public void move(java.lang.String srcPath,
java.lang.String destPath)
throws FileSystemException
move in interface FileSystemsrcPath - the path of the file or folder to be moved.destPath - the destination path to which the file or folder is to be moved.
FileSystemException - if the move fails
protected void initConnection()
throws java.lang.Exception
Subclasses should normally override the getConnection()
method instead of this one. The default implementation calls
getConnection() to get the database connection and disables
the autocommit feature.
java.lang.Exception - if an error occurs
protected java.sql.Connection getConnection()
throws java.lang.Exception
initConnection() when the file system is
started. The returned connection should come with the default JDBC
settings, as the initConnection() method will explicitly set
the autoCommit and other properties as needed.
Note that the returned database connection is kept during the entire
lifetime of the file system, after which it is closed by
close() using the closeConnection(Connection) method.
java.lang.Exception - if an error occurs
protected void closeConnection(java.sql.Connection connection)
throws java.sql.SQLException
close() to close the connection acquired using
getConnection() when the file system was started.
The default implementation just calls the Connection.close()
method of the given connection, but subclasses can override this
method to provide more extensive database and connection cleanup.
connection - database connection
java.sql.SQLException - if an error occursprotected boolean reestablishConnection()
executeStmt(String, Object[]) after a SQLException
had been encountered.
protected java.sql.Statement executeStmt(java.lang.String sql,
java.lang.Object[] params)
throws java.sql.SQLException
SQLException is encountered one attempt is made
to re-establish the database connection and re-execute the statement.
sql - statement to executeparams - parameters to set
Statement object that had been executed
java.sql.SQLException - if an error occurs
protected void prepareSchemaObjectPrefix()
throws java.lang.Exception
schemaObjectPrefix does only consist of
characters that are allowed in names on the target database. Illegal
characters will be escaped as necessary.
java.lang.Exception - if an error occurs
protected void checkSchema()
throws java.lang.Exception
java.lang.Exception - if an error occursprotected void buildSQLStatements()
protected void initPreparedStatements()
throws java.sql.SQLException
java.sql.SQLException - if an error occurs
protected void verifyRootExists()
throws java.lang.Exception
java.lang.Exception - if an error occurs
protected void createDeepFolder(java.lang.String folderPath)
throws FileSystemException
folderPath - folder entry to create
FileSystemException - if an error occurs
protected void copyDeepFolder(java.lang.String srcPath,
java.lang.String destPath)
throws FileSystemException
srcPath - folder to be copieddestPath - destination path to which the folder is to be copied
FileSystemException - if an error occurs
protected void copyFile(java.lang.String srcPath,
java.lang.String destPath)
throws FileSystemException
srcPath - file to be copieddestPath - destination path to which the file is to be copied
FileSystemException - if an error occursprotected void resetStatement(java.sql.PreparedStatement stmt)
PreparedStatement by clearing the parameters
and warnings contained.
NOTE: This method MUST be called in a synchronized context as neither
this method nor the PreparedStatement instance on which it
operates are thread safe.
stmt - The PreparedStatement to reset. If
null this method does nothing.protected void closeResultSet(java.sql.ResultSet rs)
protected void closeStatement(java.sql.Statement stmt)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||