Java Code Examples for java.sql.Connection#getHoldability()

The following examples show how to use java.sql.Connection#getHoldability() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Zebra   File: GroupStatement.java    License: Apache License 2.0 6 votes vote down vote up
private Statement createInnerStatement(Connection conn, boolean isBatch) throws SQLException {
	Statement stmt;
	if (isBatch) {
		stmt = conn.createStatement();
	} else {
		int tmpResultSetHoldability = this.resultSetHoldability;
		if (tmpResultSetHoldability == -1) {
			tmpResultSetHoldability = conn.getHoldability();
		}

		stmt = conn.createStatement(this.resultSetType, this.resultSetConcurrency, tmpResultSetHoldability);
	}

	stmt.setQueryTimeout(queryTimeout);
	stmt.setFetchSize(fetchSize);
	stmt.setMaxRows(maxRows);

	setInnerStatement(stmt);
	return stmt;
}
 
Example 2
Source Project: Zebra   File: GroupPreparedStatement.java    License: Apache License 2.0 6 votes vote down vote up
private PreparedStatement createPreparedStatementInternal(Connection conn, String sql) throws SQLException {
	PreparedStatement pstmt;
	if (autoGeneratedKeys != -1) {
		pstmt = conn.prepareStatement(sql, autoGeneratedKeys);
	} else if (columnIndexes != null) {
		pstmt = conn.prepareStatement(sql, columnIndexes);
	} else if (columnNames != null) {
		pstmt = conn.prepareStatement(sql, columnNames);
	} else {
		int resultSetHoldability = this.resultSetHoldability;
		if (resultSetHoldability == -1) {
			resultSetHoldability = conn.getHoldability();
		}

		pstmt = conn.prepareStatement(sql, this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
	}

	pstmt.setQueryTimeout(queryTimeout);
	pstmt.setFetchSize(fetchSize);
	pstmt.setMaxRows(maxRows);

	setInnerStatement(pstmt);

	return pstmt;
}
 
Example 3
Source Project: tddl5   File: TGroupStatement.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 会调用setBaseStatement以关闭已有的Statement
 */
private Statement createStatementInternal(Connection conn, String sql, boolean isBatch) throws SQLException {
    Statement stmt;
    if (isBatch) {
        stmt = conn.createStatement();
    } else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) {// 未调用过setResultSetHoldability
            resultSetHoldability = conn.getHoldability();
        }
        stmt = conn.createStatement(this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }

    setBaseStatement(stmt); // 会关闭已有的Statement
    stmt.setQueryTimeout(queryTimeout); // 这句也有可能抛出异常,放在最后
    stmt.setFetchSize(fetchSize);
    stmt.setMaxRows(maxRows);
    // 填充sql元信息
    if (stmt instanceof DataChannel) {
        ((DataChannel) stmt).fillMetaData(sqlMetaData);
    }
    return stmt;
}
 
Example 4
Source Project: tddl   File: TGroupStatement.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 会调用setBaseStatement以关闭已有的Statement
 */
private Statement createStatementInternal(Connection conn, String sql, boolean isBatch) throws SQLException {
    Statement stmt;
    if (isBatch) {
        stmt = conn.createStatement();
    } else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) {// 未调用过setResultSetHoldability
            resultSetHoldability = conn.getHoldability();
        }
        stmt = conn.createStatement(this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }

    setBaseStatement(stmt); // 会关闭已有的Statement
    stmt.setQueryTimeout(queryTimeout); // 这句也有可能抛出异常,放在最后
    stmt.setFetchSize(fetchSize);
    stmt.setMaxRows(maxRows);
    // 填充sql元信息
    fillSqlMetaData(stmt, sql);
    return stmt;
}
 
Example 5
Source Project: tddl   File: TGroupPreparedStatement.java    License: Apache License 2.0 6 votes vote down vote up
private PreparedStatement createPreparedStatementInternal(Connection conn, String sql) throws SQLException {
    PreparedStatement ps;
    if (autoGeneratedKeys != -1) {
        ps = conn.prepareStatement(sql, autoGeneratedKeys);
    } else if (columnIndexes != null) {
        ps = conn.prepareStatement(sql, columnIndexes);
    } else if (columnNames != null) {
        ps = conn.prepareStatement(sql, columnNames);
    } else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) // 未调用过setResultSetHoldability
        resultSetHoldability = conn.getHoldability();

        ps = conn.prepareStatement(sql, this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }
    setBaseStatement(ps);
    ps.setQueryTimeout(queryTimeout); // 这句可能抛出异常,所以要放到setBaseStatement之后
    ps.setFetchSize(fetchSize);
    ps.setMaxRows(maxRows);
    fillSqlMetaData(ps, sql);
    return ps;
}
 
Example 6
/**
 * Verify connection holdablity is expected holdability
 * @param conn
 * @param expectedHoldability 
 *   * @throws SQLException
 */
private static void assertConnHoldability(
    Connection conn, int expectedHoldability) throws SQLException 
{
    int holdability = conn.getHoldability();
    assertEquals (expectedHoldability, holdability);
}
 
Example 7
Source Project: cosmic   File: ConnectionConcierge.java    License: Apache License 2.0 5 votes vote down vote up
public ConnectionConcierge(final String name, final Connection conn, final boolean keepAlive) {
    _name = name + s_mgr.getNextId();
    _keepAlive = keepAlive;
    try {
        _autoCommit = conn.getAutoCommit();
        _isolationLevel = conn.getTransactionIsolation();
        _holdability = conn.getHoldability();
    } catch (final SQLException e) {
        throw new CloudRuntimeException("Unable to get information from the connection object", e);
    }
    reset(conn);
}
 
Example 8
protected static int getHoldability(String holdability, Connection connection) throws SQLException
{
	if (HOLD_CURSORS_OVER_COMMIT.equals(holdability))
	{
		return ResultSet.HOLD_CURSORS_OVER_COMMIT;
	}
	else if (CLOSE_CURSORS_AT_COMMIT.equals(holdability))
	{
		return ResultSet.CLOSE_CURSORS_AT_COMMIT;
	}
	
	return connection.getHoldability();
}
 
Example 9
/**
 * Verify connection holdablity is expected holdability
 * @param conn
 * @param expectedHoldability 
 *   * @throws SQLException
 */
private static void assertConnHoldability(
    Connection conn, int expectedHoldability) throws SQLException 
{
    int holdability = conn.getHoldability();
    assertEquals (expectedHoldability, holdability);
}
 
Example 10
Source Project: tddl5   File: TGroupPreparedStatement.java    License: Apache License 2.0 5 votes vote down vote up
private PreparedStatement createPreparedStatementInternal(Connection conn, String sql) throws SQLException {
    PreparedStatement ps;
    if (autoGeneratedKeys != -1) {
        ps = conn.prepareStatement(sql, autoGeneratedKeys);
    } else if (columnIndexes != null) {
        ps = conn.prepareStatement(sql, columnIndexes);
    } else if (columnNames != null) {
        ps = conn.prepareStatement(sql, columnNames);
    } else {
        int resultSetHoldability = this.resultSetHoldability;
        if (resultSetHoldability == -1) // 未调用过setResultSetHoldability
        resultSetHoldability = conn.getHoldability();

        ps = conn.prepareStatement(sql, this.resultSetType, this.resultSetConcurrency, resultSetHoldability);
    }
    setBaseStatement(ps);
    ps.setQueryTimeout(queryTimeout); // 这句可能抛出异常,所以要放到setBaseStatement之后
    ps.setFetchSize(fetchSize);
    ps.setMaxRows(maxRows);
    if (this.getLocalInfileInputStream() != null) {
        LoadFileUtils.setLocalInfileInputStream(ps, this.getLocalInfileInputStream());
    }

    if (ps instanceof DataChannel) {
        ((DataChannel) ps).fillMetaData(this.sqlMetaData);
    }
    return ps;
}
 
Example 11
Source Project: cloudstack   File: ConnectionConcierge.java    License: Apache License 2.0 5 votes vote down vote up
public ConnectionConcierge(String name, Connection conn, boolean keepAlive) {
    _name = name + s_mgr.getNextId();
    _keepAlive = keepAlive;
    try {
        _autoCommit = conn.getAutoCommit();
        _isolationLevel = conn.getTransactionIsolation();
        _holdability = conn.getHoldability();
    } catch (SQLException e) {
        throw new CloudRuntimeException("Unable to get information from the connection object", e);
    }
    reset(conn);
}
 
Example 12
/**
 * Verify connection holdablity is expected holdability
 * @param conn
 * @param expectedHoldability
 *   * @throws SQLException
 */
private static void assertConnHoldability(
        Connection conn, int expectedHoldability) throws SQLException
{
    int holdability = conn.getHoldability();
    assertEquals (expectedHoldability, holdability);
}