Package org.opensolaris.opengrok.jdbc

Examples of org.opensolaris.opengrok.jdbc.ConnectionResource


    public void initialize() throws HistoryException {
        try {
            connectionManager =
                    new ConnectionManager(jdbcDriverClass, jdbcConnectionURL);
            for (int i = 0;; i++) {
                final ConnectionResource conn =
                        connectionManager.getConnectionResource();
                try {
                    try (Statement stmt = conn.createStatement()) {
                        initDB(stmt);
                    }
                    conn.commit();
                    // Success! Break out of the loop.
                    return;
                } catch (SQLException sqle) {
                    handleSQLException(sqle, i);
                } finally {
View Full Code Here


    public boolean hasCacheForDirectory(File file, Repository repository)
            throws HistoryException {
        assert file.isDirectory();
        try {
            for (int i = 0;; i++) {
                final ConnectionResource conn =
                        connectionManager.getConnectionResource();
                try {
                    PreparedStatement ps = conn.getStatement(IS_DIR_IN_CACHE);
                    ps.setString(1, toUnixPath(repository.getDirectoryName()));
                    ps.setString(2, getSourceRootRelativePath(file));
                    try (ResultSet rs = ps.executeQuery()) {
                        return rs.next();
                    }
View Full Code Here

     * GET_FILE_HISTORY very well.
     * @return number of rows in the FILEMOVES table
     * @throws SQLException
     */
    private int getFilemovesCount() throws SQLException {
        final ConnectionResource conn;
        conn = connectionManager.getConnectionResource();

        try {
            final PreparedStatement cntPS = conn.getStatement(GET_FILEMOVES_COUNT);
            try (ResultSet rs = cntPS.executeQuery()) {
                if (rs.next()) {
                    return rs.getInt(1);
                }
            }
View Full Code Here

            File file, Repository repository, boolean withFiles)
            throws HistoryException, SQLException {
        final String filePath = getSourceRootRelativePath(file);
        final String reposPath = toUnixPath(repository.getDirectoryName());
        final ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>();
        final ConnectionResource conn =
                connectionManager.getConnectionResource();
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();

        try {
            final PreparedStatement ps;
            if (file.isDirectory()) {
                // Fetch history for all files under this directory.
                ps = conn.getStatement(GET_DIR_HISTORY);
                ps.setString(2, filePath);
            } else {
                // Fetch history for a single file only.
                ps = conn.getStatement(RuntimeEnvironment.isRenamedFilesEnabled() && (getFilemovesCount() > 0) ?
                    GET_FILE_HISTORY : GET_FILE_HISTORY_FOLDED);
                ps.setString(2, getParentPath(filePath));
                ps.setString(3, getBaseName(filePath));
            }
            ps.setString(1, reposPath);

            final PreparedStatement filePS =
                    withFiles ? conn.getStatement(GET_CS_FILES) : null;

            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    // Get the information about a changeset
                    String revision = rs.getString(1);
View Full Code Here

     */
    @Override
    public void store(History history, Repository repository)
            throws HistoryException {
        try {
            final ConnectionResource conn =
                    connectionManager.getConnectionResource();
            try {
                storeHistory(conn, history, repository);
            } finally {
                connectionManager.releaseConnection(conn);
View Full Code Here

     * Get ID value for revision string by querying the DB.
     * @param revision
     * @return ID
     */
    private int getIdForRevision(String revision, int repoId) throws SQLException {
        final ConnectionResource conn =
                connectionManager.getConnectionResource();
        try {
            PreparedStatement ps = conn.getStatement(GET_REV_ID);
            ps.setString(1, revision);
            ps.setInt(2, repoId);
            ResultSet rs = ps.executeQuery();
            return rs.next() ? Integer.valueOf(rs.getString(1)).intValue() : -1;
        } catch (java.sql.SQLException e) {
View Full Code Here

     * @throws HistoryException if an error happens when optimizing the cache
     */
    @Override
    public void optimize() throws HistoryException {
        try {
            final ConnectionResource conn =
                    connectionManager.getConnectionResource();
            try {
                updateIndexCardinalityStatistics(conn);
                checkpointDatabase(conn);
            } finally {
View Full Code Here

    /**
     * Helper for {@link #getLatestCachedRevision(Repository)}.
     */
    private String getLatestRevisionForRepository(Repository repository)
            throws SQLException {
        final ConnectionResource conn =
                connectionManager.getConnectionResource();
        try {
            PreparedStatement ps = conn.getStatement(GET_LATEST_REVISION);
            ps.setString(1, toUnixPath(repository.getDirectoryName()));
            try (ResultSet rs = ps.executeQuery()) {
                return rs.next() ? rs.getString(1) : null;
            }
        } finally {
View Full Code Here

            File directory, Repository repository)
        throws HistoryException, SQLException
    {
        final Map<String, Date> map = new HashMap<>();

        final ConnectionResource conn =
                connectionManager.getConnectionResource();
        try {
            PreparedStatement ps = conn.getStatement(GET_LAST_MODIFIED_TIMES);
            ps.setString(1, toUnixPath(repository.getDirectoryName()));
            ps.setString(2, getSourceRootRelativePath(directory));
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    map.put(rs.getString(1), rs.getTimestamp(2));
View Full Code Here

    /**
     * Helper for {@link #clear(Repository)}.
     */
    private void clearHistoryForRepository(Repository repository)
            throws SQLException {
        final ConnectionResource conn =
                connectionManager.getConnectionResource();
        try {
            try (PreparedStatement ps = conn.prepareStatement(
                         getQuery("clearRepository"))) {
                ps.setInt(1, getRepositoryId(conn, repository));
                ps.execute();
                conn.commit();
            }
        } finally {
            connectionManager.releaseConnection(conn);
        }
    }
View Full Code Here

TOP

Related Classes of org.opensolaris.opengrok.jdbc.ConnectionResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.