Example usage for java.sql Statement getResultSet

List of usage examples for java.sql Statement getResultSet

Introduction

In this page you can find the example usage for java.sql Statement getResultSet.

Prototype

ResultSet getResultSet() throws SQLException;

Source Link

Document

Retrieves the current result as a ResultSet object.

Usage

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/*  ww  w .  ja va 2s.  co  m*/
 */
public boolean exists(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 (selectExistSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(selectExistSQL, new Object[] { parentDir, name });
            rs = stmt.getResultSet();

            // a file system entry exists if the result set
            // has at least one entry
            return rs.next();
        } catch (SQLException e) {
            String msg = "failed to check existence of file system entry: " + path;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/*  ww  w . j  a v  a  2  s  . c om*/
 */
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 {
            Statement stmt = executeStmt(selectChildCountSQL, new Object[] { path });
            rs = stmt.getResultSet();
            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 {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/*from   w  w w  . j a v  a2s. c  o m*/
 */
public long length(String filePath) throws FileSystemException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }

    FileSystemPathUtil.checkFormat(filePath);

    String parentDir = FileSystemPathUtil.getParentDir(filePath);
    String name = FileSystemPathUtil.getName(filePath);

    synchronized (selectLengthSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(selectLengthSQL, new Object[] { parentDir, name });
            rs = stmt.getResultSet();
            if (!rs.next()) {
                throw new FileSystemException("no such file: " + filePath);
            }
            return rs.getLong(1);
        } catch (SQLException e) {
            String msg = "failed to determine length of file: " + filePath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}//from  w ww  .ja  v a 2 s.  c  o m
 */
public String[] listFiles(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 (selectFileNamesSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(selectFileNamesSQL, new Object[] { folderPath });
            rs = stmt.getResultSet();
            ArrayList names = new ArrayList();
            while (rs.next()) {
                names.add(rs.getString(1));
            }
            return (String[]) names.toArray(new String[names.size()]);
        } catch (SQLException e) {
            String msg = "failed to list file entries of folder: " + folderPath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}

From source file:migration.ProjektMigration.java

/**
 * Creates the nutzung.//from   w ww.  j a v  a  2 s .  c  om
 */
public void createNutzung() {

    String load_sql;
    Statement load_stmt;
    ResultSet load_rs;

    String store_sql;
    PreparedStatement store_prepstmt;
    final ResultSet store_rs;

    try {

        load_sql = "SELECT Zugriffe, Zeitraum, Nutzungsjahr, Rechnungsbetrag, Titelnummer FROM Nutzungstabelle";
        load_stmt = this.leg_con.createStatement();

        store_sql = "insert into Nutzung (journal_id, nutzungsjahr, rechnungsbetrag, zeitraum, zugriffe) values (?, ?, ?, ?, ?)";
        store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl.
        // brauchen
        // wir
        // was
        // in
        // Richtung:
        // Statement.RETURN_GENERATED_KEYS

        // logger.info("Lese von Nutzungstabelle");
        load_stmt.execute(load_sql);
        load_rs = load_stmt.getResultSet();

        // logger.info("Schreibe nach Nutzung");
        while (load_rs.next()) {
            final int titelnummer = load_rs.getInt("Titelnummer");
            final int journalID = this.help.getIdFromIntArray(this.help.getJournals(), titelnummer);
            // System.out.println("Titelnummer: " + titelnummer +
            // " JournalID " + journalID);
            if ((titelnummer > 0) && (journalID > 0)) {
                store_prepstmt.setLong(1, journalID);
                store_prepstmt.setLong(2, load_rs.getLong("Nutzungsjahr"));
                store_prepstmt.setFloat(3, load_rs.getFloat("Rechnungsbetrag"));
                store_prepstmt.setLong(4, load_rs.getLong("Zeitraum"));
                store_prepstmt.setLong(5, load_rs.getLong("Zugriffe"));
                store_prepstmt.executeUpdate();
            }
        }

    } catch (final SQLException e) {
        e.printStackTrace(); // To change body of catch statement use File |
                             // Settings | File Templates.
    }

    // insert into Interesse (besteller_bestellerId, interesse, journal_id)
    // values (?, ?, ?)
    // insert into Nutzung (journal_id, nutzungsjahr, rechnungsbetrag,
    // zeitraum, zugriffe) values (?, ?, ?, ?, ?)
    // insert into Rechnung (betrag, bezugsform, bezugsjahr,
    // exemplar_exemplarId, sigel_sigelId) values (?, ?, ?, ?, ?)

}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/*from www . ja  v  a  2s. c  om*/
 */
public boolean isFile(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 (selectFileExistSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(selectFileExistSQL, new Object[] { parentDir, name });
            rs = stmt.getResultSet();

            // a file exists if the result set has at least one entry
            return rs.next();
        } catch (SQLException e) {
            String msg = "failed to check existence of file: " + path;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/*from   w ww.j  a v a2s . c o  m*/
 */
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 {
            Statement stmt = executeStmt(selectFolderExistSQL, new Object[] { parentDir, name });
            rs = stmt.getResultSet();

            // 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 {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}/* w ww. j a  v a 2  s. co  m*/
 */
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 {
            Statement stmt = executeStmt(selectLastModifiedSQL, new Object[] { parentDir, name });
            rs = stmt.getResultSet();
            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 {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java

/**
 * {@inheritDoc}//w  w  w.j a v  a  2 s. com
 */
public String[] listFolders(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 (selectFolderNamesSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(selectFolderNamesSQL, new Object[] { folderPath });
            rs = stmt.getResultSet();
            ArrayList names = new ArrayList();
            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 (String[]) names.toArray(new String[names.size()]);
        } catch (SQLException e) {
            String msg = "failed to list folder entries of folder: " + folderPath;
            log.error(msg, e);
            throw new FileSystemException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}

From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java

/**
 * Performs a consistency check./*from   w  w w.j  a  v  a 2s . c om*/
 */
private void checkConsistency() {
    int count = 0;
    int total = 0;
    log.info("{}: checking workspace consistency...", name);

    Collection modifications = new ArrayList();
    ResultSet rs = null;
    DataInputStream din = null;
    try {
        String sql;
        if (getStorageModel() == SM_BINARY_KEYS) {
            sql = "select NODE_ID, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE";
        } else {
            sql = "select NODE_ID_HI, NODE_ID_LO, BUNDLE_DATA from " + schemaObjectPrefix + "BUNDLE";
        }
        Statement stmt = connectionManager.executeStmt(sql, new Object[0]);
        rs = stmt.getResultSet();
        while (rs.next()) {
            NodeId id;
            Blob blob;
            if (getStorageModel() == SM_BINARY_KEYS) {
                id = new NodeId(new UUID(rs.getBytes(1)));
                blob = rs.getBlob(2);
            } else {
                id = new NodeId(new UUID(rs.getLong(1), rs.getLong(2)));
                blob = rs.getBlob(3);
            }
            din = new DataInputStream(blob.getBinaryStream());
            try {
                NodePropBundle bundle = binding.readBundle(din, id);
                Collection missingChildren = new ArrayList();
                Iterator iter = bundle.getChildNodeEntries().iterator();
                while (iter.hasNext()) {
                    NodePropBundle.ChildNodeEntry entry = (NodePropBundle.ChildNodeEntry) iter.next();
                    if (entry.getId().toString().endsWith("babecafebabe")) {
                        continue;
                    }
                    if (id.toString().endsWith("babecafebabe")) {
                        continue;
                    }
                    try {
                        NodePropBundle child = loadBundle(entry.getId());
                        if (child == null) {
                            log.error("NodeState " + id.getUUID() + " references inexistent child "
                                    + entry.getName() + " with id " + entry.getId().getUUID());
                            missingChildren.add(entry);
                        } else {
                            NodeId cp = child.getParentId();
                            if (cp == null) {
                                log.error("ChildNode has invalid parent uuid: null");
                            } else if (!cp.equals(id)) {
                                log.error("ChildNode has invalid parent uuid: " + cp + " (instead of "
                                        + id.getUUID() + ")");
                            }
                        }
                    } catch (ItemStateException e) {
                        log.error("Error while loading child node: " + e);
                    }
                }
                if (consistencyFix && !missingChildren.isEmpty()) {
                    Iterator iterator = missingChildren.iterator();
                    while (iterator.hasNext()) {
                        bundle.getChildNodeEntries().remove(iterator.next());
                    }
                    modifications.add(bundle);
                }

                NodeId parentId = bundle.getParentId();
                if (parentId != null) {
                    if (!exists(parentId)) {
                        log.error("NodeState " + id + " references inexistent parent id " + parentId);
                    }
                }
            } catch (IOException e) {
                log.error("Error in bundle " + id + ": " + e);
                din = new DataInputStream(blob.getBinaryStream());
                binding.checkBundle(din);
            }
            count++;
            if (count % 1000 == 0) {
                log.info(name + ": checked " + count + "/" + total + " bundles...");
            }
        }
    } catch (Exception e) {
        log.error("Error in bundle", e);
    } finally {
        IOUtils.closeQuietly(din);
        closeResultSet(rs);
    }

    if (consistencyFix && !modifications.isEmpty()) {
        log.info(name + ": Fixing " + modifications.size() + " inconsistent bundle(s)...");
        Iterator iterator = modifications.iterator();
        while (iterator.hasNext()) {
            NodePropBundle bundle = (NodePropBundle) iterator.next();
            try {
                log.info(name + ": Fixing bundle " + bundle.getId());
                bundle.markOld(); // use UPDATE instead of INSERT
                storeBundle(bundle);
            } catch (ItemStateException e) {
                log.error(name + ": Error storing fixed bundle: " + e);
            }
        }
    }

    log.info(name + ": checked " + count + "/" + total + " bundles.");
}