当前位置: 首页>>代码示例>>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;未经允许,请勿转载。