use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method list.
/**
* {@inheritDoc}
*/
public String[] list(String folderPath) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(folderPath);
if (!isFolder(folderPath)) {
throw new FileSystemException("no such folder: " + folderPath);
}
synchronized (selectFileAndFolderNamesSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectFileAndFolderNamesSQL, new Object[] { folderPath }, false, 0);
ArrayList<String> names = new ArrayList<String>();
while (rs.next()) {
String name = rs.getString(1);
if (name.length() == 0 && FileSystemPathUtil.denotesRoot(folderPath)) {
// this is the file system root entry, skip...
continue;
}
names.add(name);
}
return names.toArray(new String[names.size()]);
} catch (SQLException e) {
String msg = "failed to list child entries of folder: " + folderPath;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method isFolder.
/**
* {@inheritDoc}
*/
public boolean isFolder(String path) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(path);
String parentDir = FileSystemPathUtil.getParentDir(path);
String name = FileSystemPathUtil.getName(path);
synchronized (selectFolderExistSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectFolderExistSQL, new Object[] { parentDir, name }, false, 0);
// a folder exists if the result set has at least one entry
return rs.next();
} catch (SQLException e) {
String msg = "failed to check existence of folder: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method init.
//-----------------------------------------------------------< FileSystem >
/**
* {@inheritDoc}
*/
public void init() throws FileSystemException {
if (initialized) {
throw new IllegalStateException("already initialized");
}
try {
conHelper = createConnectionHelper(getDataSource());
// make sure schemaObjectPrefix consists of legal name characters only
schemaObjectPrefix = conHelper.prepareDbIdentifier(schemaObjectPrefix);
// check if schema objects exist and create them if necessary
if (isSchemaCheckEnabled()) {
createCheckSchemaOperation().run();
}
// build sql statements
buildSQLStatements();
// finally verify that there's a file system root entry
verifyRootExists();
initialized = true;
} catch (Exception e) {
String msg = "failed to initialize file system";
log.error(msg, e);
throw new FileSystemException(msg, e);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method lastModified.
/**
* {@inheritDoc}
*/
public long lastModified(String path) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(path);
String parentDir = FileSystemPathUtil.getParentDir(path);
String name = FileSystemPathUtil.getName(path);
synchronized (selectLastModifiedSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectLastModifiedSQL, new Object[] { parentDir, name }, false, 0);
if (!rs.next()) {
throw new FileSystemException("no such file system entry: " + path);
}
return rs.getLong(1);
} catch (SQLException e) {
String msg = "failed to determine lastModified of file system entry: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.
the class DatabaseFileSystem method hasChildren.
/**
* {@inheritDoc}
*/
public boolean hasChildren(String path) throws FileSystemException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
FileSystemPathUtil.checkFormat(path);
if (!exists(path)) {
throw new FileSystemException("no such file system entry: " + path);
}
synchronized (selectChildCountSQL) {
ResultSet rs = null;
try {
rs = conHelper.exec(selectChildCountSQL, new Object[] { path }, false, 0);
if (!rs.next()) {
return false;
}
int count = rs.getInt(1);
if (FileSystemPathUtil.denotesRoot(path)) {
// ingore file system root entry
count--;
}
return (count > 0);
} catch (SQLException e) {
String msg = "failed to determine child count of file system entry: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
} finally {
DbUtility.close(rs);
}
}
}
Aggregations