Search in sources :

Example 31 with FileSystemException

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);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Example 32 with FileSystemException

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);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 33 with FileSystemException

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);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) IOException(java.io.IOException) SQLException(java.sql.SQLException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException)

Example 34 with FileSystemException

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);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 35 with FileSystemException

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);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Aggregations

FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)54 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)18 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)16 IOException (java.io.IOException)15 SQLException (java.sql.SQLException)15 File (java.io.File)11 ResultSet (java.sql.ResultSet)10 InputStream (java.io.InputStream)7 RepositoryException (javax.jcr.RepositoryException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 OutputStreamWriter (java.io.OutputStreamWriter)4 ArrayList (java.util.ArrayList)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 BufferedInputStream (java.io.BufferedInputStream)3 BufferedWriter (java.io.BufferedWriter)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Properties (java.util.Properties)3 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2