|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jackrabbit.core.fs.db.DbFileSystem
DbFileSystem
is a generic JDBC-based FileSystem
implementation for Jackrabbit that persists file system entries in a
database table.
driver
: the FQN name of the JDBC driver classurl
: the database url of the form jdbc:subprotocol:subname
user
: the database userpassword
: the user's passwordschema
: type of schema to be used
(e.g. mysql
, mssql
, etc.); schemaObjectPrefix
: prefix to be prepended to schema objectsgetClass().getResourceAsStream(schema + ".ddl")
.
Every line in the specified .ddl file is executed separatly by calling
java.sql.Statement.execute(String)
where every occurence of the
the string "${schemaObjectPrefix}"
has been replaced with the
value of the property schemaObjectPrefix
.
The following is a fragment from a sample configuration using MySQL:
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="com.mysql.jdbc.Driver"/> <param name="url" value="jdbc:mysql:///test"/> <param name="schema" value="mysql"/> <param name="schemaObjectPrefix" value="rep_"/> </FileSystem>The following is a fragment from a sample configuration using Daffodil One$DB Embedded:
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="in.co.daffodil.db.jdbc.DaffodilDBDriver"/> <param name="url" value="jdbc:daffodilDB_embedded:rep;path=${rep.home}/databases;create=true"/> <param name="user" value="daffodil"/> <param name="password" value="daffodil"/> <param name="schema" value="daffodil"/> <param name="schemaObjectPrefix" value="rep_"/> </FileSystem>The following is a fragment from a sample configuration using MSSQL:
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/> <param name="url" value="jdbc:microsoft:sqlserver://localhost:1433;;DatabaseName=test;SelectMethod=Cursor;"/> <param name="schema" value="mssql"/> <param name="user" value="sa"/> <param name="password" value=""/> <param name="schemaObjectPrefix" value="rep_"/> </FileSystem>The following is a fragment from a sample configuration using PostgreSQL:
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem"> <param name="driver" value="org.postgresql.Driver"/> <param name="url" value="jdbc:postgresql://localhost/test"/> <param name="schema" value="postgresql"/> <param name="user" value="postgres"/> <param name="password" value="postgres"/> <param name="schemaObjectPrefix" value="rep_"/> </FileSystem>See also
DerbyFileSystem
, DB2FileSystem
.
Fields inherited from interface org.apache.jackrabbit.core.fs.FileSystem |
SEPARATOR, SEPARATOR_CHAR |
Constructor Summary | |
DbFileSystem()
Default constructor |
Method Summary | |
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. After calling this method, the file system is no longer accessible. |
protected void |
closeResultSet(ResultSet rs)
|
protected void |
closeStatement(Statement stmt)
|
protected void |
closeStream(InputStream in)
|
void |
copy(String srcPath,
String destPath)
Copies a file or folder to a new location. |
protected void |
copyDeepFolder(String srcPath,
String destPath)
Recursively copies the given folder to the given destination. |
protected void |
copyFile(String srcPath,
String destPath)
Copies the given file entry to the given destination path. |
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. Note that if this operation fails it may have succeeded in creating some of the necessary parent folders. |
void |
deleteFile(String filePath)
Deletes the file denoted by this path. |
void |
deleteFolder(String folderPath)
Deletes the folder denoted by this path. Any contents of this folder (folders and files) will be deleted recursively. |
boolean |
equals(Object obj)
|
boolean |
exists(String path)
Tests whether the file system entry denoted by this path exists. |
String |
getDriver()
|
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. The file will be created if it doesn't exist. If the file exists, its contents will be overwritten. |
String |
getPassword()
|
RandomAccessOutputStream |
getRandomAccessOutputStream(String filePath)
Returns an output stream for writing bytes to the file denoted by this path. The file will be created if it doesn't exist. The current position of the file pointer is set to 0 . See also
RandomAccessOutputStream.seek(long) ; |
String |
getSchema()
|
String |
getSchemaObjectPrefix()
|
String |
getUrl()
|
String |
getUser()
|
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 system |
boolean |
isFile(String path)
Tests whether the file system entry denoted by this path is a file. |
boolean |
isFolder(String path)
Tests whether the file system entry denoted by this path is a folder. |
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 |
move(String srcPath,
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 void |
resetStatement(PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters
and warnings contained. |
void |
setDriver(String driver)
|
void |
setPassword(String password)
|
void |
setSchema(String schema)
|
void |
setSchemaObjectPrefix(String schemaObjectPrefix)
|
void |
setUrl(String url)
|
void |
setUser(String user)
|
void |
touch(String filePath)
Set the modified time of an existing file to now. |
protected void |
verifyRoodExists()
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 String SCHEMA_OBJECT_PREFIX_VARIABLE
protected boolean initialized
protected String driver
protected String url
protected String user
protected String password
protected String schema
protected String schemaObjectPrefix
protected static final int INITIAL_BUFFER_SIZE
protected Connection con
protected PreparedStatement selectExistStmt
protected PreparedStatement selectFileExistStmt
protected PreparedStatement selectFolderExistStmt
protected PreparedStatement selectChildCountStmt
protected PreparedStatement selectDataStmt
protected PreparedStatement selectLastModifiedStmt
protected PreparedStatement selectLengthStmt
protected PreparedStatement selectFileNamesStmt
protected PreparedStatement selectFolderNamesStmt
protected PreparedStatement selectFileAndFolderNamesStmt
protected PreparedStatement deleteFileStmt
protected PreparedStatement deleteFolderStmt
protected PreparedStatement insertFileStmt
protected PreparedStatement insertFolderStmt
protected PreparedStatement updateDataStmt
protected PreparedStatement updateLastModifiedStmt
protected PreparedStatement copyFileStmt
protected PreparedStatement copyFilesStmt
Constructor Detail |
public DbFileSystem()
Method Detail |
public String getUrl()
public void setUrl(String url)
public String getUser()
public void setUser(String user)
public String getPassword()
public void setPassword(String password)
public String getDriver()
public void setDriver(String driver)
public String getSchemaObjectPrefix()
public void setSchemaObjectPrefix(String schemaObjectPrefix)
public String getSchema()
public void setSchema(String schema)
public boolean equals(Object obj)
public int hashCode()
Object.hashCode()
public void init() throws FileSystemException
init
in interface FileSystem
FileSystemException
- if the file system initialization failspublic void close() throws FileSystemException
close
in interface FileSystem
FileSystemException
public void createFolder(String folderPath) throws FileSystemException
createFolder
in interface FileSystem
folderPath
- 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(String filePath) throws FileSystemException
deleteFile
in interface FileSystem
filePath
- 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(String folderPath) throws FileSystemException
deleteFolder
in interface FileSystem
folderPath
- 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(String path) throws FileSystemException
exists
in interface FileSystem
path
- the path of a file system entry.
FileSystemException
public boolean isFile(String path) throws FileSystemException
isFile
in interface FileSystem
path
- the path of a file system entry.
FileSystemException
public boolean isFolder(String path) throws FileSystemException
isFolder
in interface FileSystem
path
- the path of a file system entry.
FileSystemException
public long lastModified(String path) throws FileSystemException
lastModified
in interface FileSystem
path
- the path of a file system entry.
FileSystemException
- if the file system entry does not exist.public long length(String filePath) throws FileSystemException
length
in interface FileSystem
filePath
- the path of the file.
FileSystemException
- if the path does not denote an existing file.public boolean hasChildren(String path) throws FileSystemException
hasChildren
in interface FileSystem
path
- the path of a file system entry.
FileSystemException
public String[] list(String folderPath) throws FileSystemException
list
in interface FileSystem
folderPath
- 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 String[] listFiles(String folderPath) throws FileSystemException
listFiles
in interface FileSystem
folderPath
- 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 String[] listFolders(String folderPath) throws FileSystemException
listFolders
in interface FileSystem
folderPath
- 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(String filePath) throws FileSystemException
touch
in interface FileSystem
filePath
- the path of the file.
FileSystemException
- if the path does not denote an existing file.public InputStream getInputStream(String filePath) throws FileSystemException
getInputStream
in interface FileSystem
filePath
- the path of the file.
FileSystemException
- if the file does not exist
or if it cannot be read frompublic OutputStream getOutputStream(String filePath) throws FileSystemException
getOutputStream
in interface FileSystem
filePath
- the path of the file.
FileSystemException
- if the file cannot be written to or createdpublic RandomAccessOutputStream getRandomAccessOutputStream(String filePath) throws FileSystemException, UnsupportedOperationException
0
. See also
RandomAccessOutputStream.seek(long)
;
getRandomAccessOutputStream
in interface FileSystem
filePath
- the path of the file.
UnsupportedOperationException
- if the implementation does
not support file access through a
RandomAccessOutputStream
.
FileSystemException
- if the file could not be created or
if the output stream cannot be obtained.public void copy(String srcPath, String destPath) throws FileSystemException
copy
in interface FileSystem
srcPath
- 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 failspublic void move(String srcPath, String destPath) throws FileSystemException
move
in interface FileSystem
srcPath
- 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 failsprotected void prepareSchemaObjectPrefix() throws Exception
schemaObjectPrefix
does only consist of
characters that are allowed in names on the target database. Illegal
characters will be escaped as necessary.
Exception
- if an error occursprotected void checkSchema() throws Exception
Exception
- if an error occursprotected void verifyRoodExists() throws Exception
Exception
- if an error occursprotected void createDeepFolder(String folderPath) throws FileSystemException
folderPath
- folder entry to create
FileSystemException
- if an error occursprotected void copyDeepFolder(String srcPath, String destPath) throws FileSystemException
srcPath
- folder to be copieddestPath
- destination path to which the folder is to be copied
FileSystemException
- if an error occursprotected void copyFile(String srcPath, 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(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(ResultSet rs)
protected void closeStream(InputStream in)
protected void closeStatement(Statement stmt)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |