Spring Framework DelegatingDataSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework DelegatingDataSource class.

This code example shows how to use the following methods:afterPropertiesSet, setTargetDataSource
	 
	/** 
	 * Create a new DynamicDataSourceProxy. 
	 * @param targetDataSource the target DataSource 
	 */ 
	public DynamicDataSourceProxy(DataSource targetDataSource) {
		setTargetDataSource(targetDataSource);
		afterPropertiesSet();
	} 
	 
	/** 
	 * Default constructor. 
	 */ 
	public DynamicDataSourceProxy(){ 
		// default constructor 
	} 
	 
	/** Switch to a new DataSource using the given configuration. 
	 * @param newConfig BoneCP DataSource to use. 
	 * @throws SQLException 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	public void testSwitchDataSource() throws SQLException, ClassNotFoundException {
 
		BoneCPDataSource mockDataSource = createNiceMock(BoneCPDataSource.class);
		DynamicDataSourceProxy ddsp = new DynamicDataSourceProxy();
		// Test #1: Check for correct instance. 
		ddsp.setTargetDataSource(new DelegatingDataSource());
		try{ 
			ddsp.switchDataSource(null);
			fail("Should throw an exception"); 
		} catch(SQLException e){
			// do nothing 
		} 
		 
		// Test #2: Given a good config, should initialize pool and switch datasource to it 
		BoneCPConfig config = new BoneCPConfig();
		config.setJdbcUrl("jdbc:mock");
		config.setUsername("sa");
		config.setPassword("");
		config.setMinConnectionsPerPartition(2);
		config.setMaxConnectionsPerPartition(2);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    } 
 
    private class TransactionAwareDataSource extends DelegatingDataSource {
 
        public TransactionAwareDataSource(DataSource dataSource) {
            super(dataSource);
        } 
 
        @Override 
        public java.sql.Connection getConnection() throws SQLException {
            java.sql.Connection con = DataSourceUtils.getConnection(getTargetDataSource());
            java.sql.Connection conToUse = con;
            if (!(con instanceof OracleConnection)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Unwrapping JDBC Connection of type:" + con.getClass().getName());
                } 
                try { 
                    conToUse = nativeJdbcExtractor.getNativeConnection(con);
                } catch (SQLException e) { 
                    throw new NonTransientDataAccessResourceException( 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Spring Framework DelegatingDataSource Methods: