當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSourceUtils.releaseConnection方法代碼示例

本文整理匯總了Java中org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSourceUtils.releaseConnection方法的具體用法?Java DataSourceUtils.releaseConnection怎麽用?Java DataSourceUtils.releaseConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.jdbc.datasource.DataSourceUtils的用法示例。


在下文中一共展示了DataSourceUtils.releaseConnection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkAbnormalSlaves

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * 自動上線可用數據源<br/>
 * 檢查AbnormalSlaves,如果正常則丟回normalSlaves 
 */
protected void checkAbnormalSlaves(){
	//循環檢查所有的失效從庫數據源
	for(int i = 0; i < abnormalSlaves.size();i++){ 
		DataSource ds = null;
		Connection conn = null;
		try {
			ds = abnormalSlaves.get(i);
			//step檢測可連接性
			String ipAndPort = getMapKey(ds);
			if(ConnUtil.isReachable(ipAndPort, validationQueryTimeout)){
				//step:  數據庫直連檢測
				conn = ds.getConnection(); 
				validateSlaveStatus(conn);
				online(ds);
			}
			break;
		} catch (Throwable e) { 
			continue;
		}finally{
			if(conn != null && ds != null) DataSourceUtils.releaseConnection(conn, ds);
		} 
	}
}
 
開發者ID:w775450,項目名稱:DynamicDataSource,代碼行數:28,代碼來源:DynamicMysqlDataSource.java

示例2: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * Execute the given {@link DatabasePopulator} against the given {@link DataSource}.
 * @param populator the {@code DatabasePopulator} to execute
 * @param dataSource the {@code DataSource} to execute against
 * @throws DataAccessException if an error occurs, specifically a {@link ScriptException}
 */
public static void execute(DatabasePopulator populator, DataSource dataSource) throws DataAccessException {
	Assert.notNull(populator, "DatabasePopulator must be provided");
	Assert.notNull(dataSource, "DataSource must be provided");
	try {
		Connection connection = DataSourceUtils.getConnection(dataSource);
		try {
			populator.populate(connection);
		}
		finally {
			if (connection != null) {
				DataSourceUtils.releaseConnection(connection, dataSource);
			}
		}
	}
	catch (Exception ex) {
		if (ex instanceof ScriptException) {
			throw (ScriptException) ex;
		}

		throw new UncategorizedScriptException("Failed to execute database script", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:DatabasePopulatorUtils.java

示例3: getNextKey

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * Executes the SQL as specified by {@link #getSequenceQuery()}.
 */
@Override
protected long getNextKey() throws DataAccessException {
	Connection con = DataSourceUtils.getConnection(getDataSource());
	Statement stmt = null;
	ResultSet rs = null;
	try {
		stmt = con.createStatement();
		DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
		rs = stmt.executeQuery(getSequenceQuery());
		if (rs.next()) {
			return rs.getLong(1);
		}
		else {
			throw new DataAccessResourceFailureException("Sequence query did not return a result");
		}
	}
	catch (SQLException ex) {
		throw new DataAccessResourceFailureException("Could not obtain sequence value", ex);
	}
	finally {
		JdbcUtils.closeResultSet(rs);
		JdbcUtils.closeStatement(stmt);
		DataSourceUtils.releaseConnection(con, getDataSource());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:AbstractSequenceMaxValueIncrementer.java

示例4: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * Execute the given DatabasePopulator against the given DataSource.
 * @param populator the DatabasePopulator to execute
 * @param dataSource the DataSource to execute against
 */
public static void execute(DatabasePopulator populator, DataSource dataSource) {
	Assert.notNull(populator, "DatabasePopulator must be provided");
	Assert.notNull(dataSource, "DataSource must be provided");
	try {
		Connection connection = DataSourceUtils.getConnection(dataSource);
		try {
			populator.populate(connection);
		}
		finally {
			if (connection != null) {
				DataSourceUtils.releaseConnection(connection, dataSource);
			}
		}
	}
	catch (Exception ex) {
		throw new DataAccessResourceFailureException("Failed to execute database script", ex);
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:24,代碼來源:DatabasePopulatorUtils.java

示例5: getColumns

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
public List<Column> getColumns(String tableName) throws SQLException {
    List<Column> columns = new ArrayList<Column>();
    Connection connection = DataSourceUtils.getConnection(dataSource);
    DatabaseMetaData metaData = connection.getMetaData();
    ResultSet columnsResultSet = metaData.getColumns(null, metaData.getUserName(), tableName, "%");
    while (columnsResultSet.next()) {
        Column column = new Column();
        column.setColumnName(columnsResultSet.getString("COLUMN_NAME").toLowerCase());
        column.setDataType(columnsResultSet.getInt("DATA_TYPE"));
        column.setTypeName(columnsResultSet.getString("TYPE_NAME"));
        column.setColumnSize(columnsResultSet.getInt("COLUMN_SIZE"));
        column.setNullable(columnsResultSet.getInt("NULLABLE"));
        column.setRemarks(columnsResultSet.getString("REMARKS"));
        column.setColumnDef(columnsResultSet.getString("COLUMN_DEF"));
        column.setOrdinalPosition(columnsResultSet.getInt("ORDINAL_POSITION"));
        column.setIsNullable(columnsResultSet.getString("IS_NULLABLE"));
        column.setIsAutoincrement(columnsResultSet.getString("IS_AUTOINCREMENT"));
        columns.add(column);
    }
    DataSourceUtils.releaseConnection(connection, dataSource);
    return columns;
}
 
開發者ID:mynah,項目名稱:oblatum,代碼行數:23,代碼來源:SqlGenerator.java

示例6: delete

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
@Override
public String delete(final String accountid) throws ProvisioningException {
    LOG.debug("Delete request received");

    Connection conn = null;
    try {
        conn = DataSourceUtils.getConnection(dataSource);

        try (PreparedStatement statement = conn.prepareStatement("DELETE FROM user WHERE userId=?")) {
            statement.setString(1, accountid);

            String query = "DELETE FROM user WHERE userId='" + accountid + "';";
            LOG.debug("Execute query: " + query);

            statement.executeUpdate();
        }

        return accountid;
    } catch (SQLException e) {
        throw new ProvisioningException("Delete operation failed", e);
    } finally {
        DataSourceUtils.releaseConnection(conn, dataSource);
    }
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:25,代碼來源:ProvisioningImpl.java

示例7: isRunningElsewhere

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
private boolean isRunningElsewhere(final JobKey jobKey) throws SchedulerException {
    if (!scheduler.getScheduler().getMetaData().isJobStoreClustered()) {
        return false;
    }

    DataSource dataSource = domainsHolder.getDomains().get(SyncopeConstants.MASTER_DOMAIN);
    Connection conn = DataSourceUtils.getConnection(dataSource);
    PreparedStatement stmt = null;
    ResultSet resultSet = null;
    try {
        stmt = conn.prepareStatement(
                "SELECT 1 FROM " + Constants.DEFAULT_TABLE_PREFIX + "FIRED_TRIGGERS "
                + "WHERE JOB_NAME = ? AND JOB_GROUP = ?");
        stmt.setString(1, jobKey.getName());
        stmt.setString(2, jobKey.getGroup());

        resultSet = stmt.executeQuery();
        return resultSet.next();
    } catch (SQLException e) {
        throw new SchedulerException(e);
    } finally {
        IOUtil.quietClose(resultSet);
        IOUtil.quietClose(stmt);
        DataSourceUtils.releaseConnection(conn, dataSource);
    }
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:27,代碼來源:JobManagerImpl.java

示例8: getQueryRunner

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * 添加支持jdbc datasource Transaction 支持的QueryRunner處理方式
 */
@Override
protected QueryRunner getQueryRunner() {
	
	return new QueryRunner(dataSource){

		/* (non-Javadoc)
		 * @see org.apache.commons.dbutils.AbstractQueryRunner#prepareConnection()
		 */
		@Override
		protected Connection prepareConnection() throws SQLException {
			return DataSourceUtils.getConnection(this.getDataSource());
		}

		/* (non-Javadoc)
		 * @see org.apache.commons.dbutils.AbstractQueryRunner#close(java.sql.Connection)
		 */
		@Override
		protected void close(Connection conn) throws SQLException {
			DataSourceUtils.releaseConnection(conn, getDataSource());
		}
		
	};
}
 
開發者ID:bluesky8318,項目名稱:CommonDao,代碼行數:27,代碼來源:JdbcTxCommonDao.java

示例9: getRateTableColumnNames

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * Returns a list of column names read from the rate table in the database.
 * @return column names
 */
public List<String> getRateTableColumnNames() {
    DataSource dataSource = jdbcTemplate.getDataSource();
    Connection connection = DataSourceUtils.getConnection(dataSource);

    List<String> columns = Collections.emptyList();

    try {
        columns = JDBCUtils.getAllColumnNames(connection, rateCard.getTableName());
    } catch (SQLException e) {
        throw new SessionInternalError("Could not read columns from rate card table.", e,
                                       new String[] { "RateCardWS,rates,rate.card.cannot.read.rating.table" });

    } finally {
        DataSourceUtils.releaseConnection(connection, dataSource);
    }

    return columns;
}
 
開發者ID:maxdelo77,項目名稱:replyit-master-3.2-final,代碼行數:23,代碼來源:RateCardBL.java

示例10: testLoader

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
public void testLoader() throws Exception {
    assertEquals("rules_table", loader.getTableName());

    // count the number of records loaded
    DataSource dataSource = getDataSource();
    Connection connection = DataSourceUtils.getConnection(dataSource);

    Statement statement = connection.createStatement();
    ResultSet result = statement.executeQuery("select count(*) as REC_COUNT from " + loader.getTableName());
    result.next();

    long recordsCount = result.getLong("REC_COUNT");
   
    assertTrue("Loader successfully populated records in the database",recordsCount > 0);
    assertEquals("Loaded correct number of records", 1769, recordsCount);

    // cleanup
    result.close();
    statement.close();
    DataSourceUtils.releaseConnection(connection, dataSource);
}
 
開發者ID:maxdelo77,項目名稱:replyit-master-3.2-final,代碼行數:22,代碼來源:HSQLDBCacheTest.java

示例11: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
public Object execute(StatementCallback action) throws DataAccessException {
	Assert.notNull(action, "Callback object must not be null");

	Connection con = DataSourceUtils.getConnection(getDataSource());
	Statement stmt = null;
	try {
		Connection conToUse = con;
		if (getNativeJdbcExtractor() != null &&
				getNativeJdbcExtractor().isNativeConnectionNecessaryForNativeStatements()) {
			conToUse = getNativeJdbcExtractor().getNativeConnection(con);
		}
		stmt = conToUse.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		applyStatementSettings(stmt);
		Statement stmtToUse = stmt;
		if (getNativeJdbcExtractor() != null) {
			stmtToUse = getNativeJdbcExtractor().getNativeStatement(stmt);
		}
		Object result = action.doInStatement(stmtToUse);
		handleWarnings(stmt);
		return result;
	}
	catch (SQLException ex) {
		// Release Connection early, to avoid potential connection pool deadlock
		// in the case when the exception translator hasn't been initialized yet.
		JdbcUtils.closeStatement(stmt);
		stmt = null;
		DataSourceUtils.releaseConnection(con, getDataSource());
		con = null;
		throw getExceptionTranslator().translate("StatementCallback", getSql(action), ex);
	}
	finally {
		JdbcUtils.closeStatement(stmt);
		DataSourceUtils.releaseConnection(con, getDataSource());
	}
}
 
開發者ID:quickbundle,項目名稱:javasec,代碼行數:36,代碼來源:RmJdbcTemplate.java

示例12: query

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
/**
 * 
 * */
public Map<String, Map<String, Object>> query(String sql, String key) {
	try {
		Map<String, Map<String, Object>> resultMap = new KeyMap<Map<String, Object>>();
		Connection conn = DataSourceUtils.getConnection(dataSource);
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			ResultSetMetaData rsmd = rs.getMetaData();
			while (rs.next()) {
				Map<String, Object> itemMap = new KeyMap<Object>();
				for (int x = 0; x < rsmd.getColumnCount(); x++) {
					itemMap.put(rsmd.getColumnLabel(x + 1), rs.getObject(x + 1));
				}
				resultMap.put(StringTools.toString(itemMap.get(key)), itemMap);
			}
		} catch (Exception e) {
			MyDogLog.getLog().error(" query ", e);
		} finally {
			JdbcUtils.closeResultSet(rs);
			JdbcUtils.closeStatement(ps);
			DataSourceUtils.releaseConnection(conn, dataSource);
		}

		return resultMap;
	} finally {
		DataSourceUtils.releaseConnection(DataSourceUtils.getConnection(dataSource), dataSource);
	}
}
 
開發者ID:hpgary,項目名稱:mylion-mvn,代碼行數:34,代碼來源:SpringJdbc.java

示例13: close

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
@Override
public void close() throws OdaException
{
	try
	{
		if( resultSet != null )
		{
			resultSet.close();
		}
		if( statement != null )
		{
			statement.close();
		}
		if( connection != null )
		{
			DataSourceUtils.releaseConnection(connection, dataSource);
		}
		statement = null;
		connection = null;
		dataSource = null;
		rowData = null;
		resultSet = null;
	}
	catch( SQLException e )
	{
		throw new OdaException(e);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:29,代碼來源:JDBCOdaResultSet.java

示例14: execute

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
@Override
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
	Assert.notNull(action, "Callback object must not be null");

	Connection con = DataSourceUtils.getConnection(getDataSource());
	try {
		Connection conToUse = con;
		if (this.nativeJdbcExtractor != null) {
			// Extract native JDBC Connection, castable to OracleConnection or the like.
			conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
		}
		else {
			// Create close-suppressing Connection proxy, also preparing returned Statements.
			conToUse = createConnectionProxy(con);
		}
		return action.doInConnection(conToUse);
	}
	catch (SQLException ex) {
		// Release Connection early, to avoid potential connection pool deadlock
		// in the case when the exception translator hasn't been initialized yet.
		DataSourceUtils.releaseConnection(con, getDataSource());
		con = null;
		throw getExceptionTranslator().translate("ConnectionCallback", getSql(action), ex);
	}
	finally {
		DataSourceUtils.releaseConnection(con, getDataSource());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:JdbcTemplate.java

示例15: closeConnection

import org.springframework.jdbc.datasource.DataSourceUtils; //導入方法依賴的package包/類
void closeConnection(Connection connection, DataSource dataSource) {
    if (connection != null && dataSource != null) {
        DataSourceUtils.releaseConnection(connection, dataSource);
    } else {
        Util.closeDBObjects(connection, null, null);
    }
}
 
開發者ID:mhewedy,項目名稱:spwrap,代碼行數:8,代碼來源:ConnectionManager.java


注:本文中的org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。