Spring Framework SingleConnectionDataSource - 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 SingleConnectionDataSource class.

This code example shows how to use the following methods:setDriverClassName
    private JdbcTokenRepositoryImpl repo; 
    private JdbcTemplate template; 
 
    @BeforeClass 
    public static void createDataSource() { 
        dataSource = new SingleConnectionDataSource("jdbc:hsqldb:mem:tokenrepotest", "sa", "", true); 
        dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver"); 
    } 
 
    @AfterClass 
    public static void clearDataSource() throws Exception { 
        dataSource.destroy(); 
        dataSource = null; 
    } 
 
    @Before 
    public void populateDatabase() { 
        repo = new JdbcTokenRepositoryImpl(); 
        ReflectionTestUtils.setField(repo, "logger", logger); 
        repo.setDataSource(dataSource); 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    @Override 
    public void execute(Connection connection) { 
        try { 
            springJdbcMigration.migrate(new org.springframework.jdbc.core.JdbcTemplate( 
                    new SingleConnectionDataSource(connection, true))); 
        } catch (Exception e) { 
            throw new FlywayException("Migration failed !", e); 
        } 
    } 
 
    @Override 
    public boolean executeInTransaction() { 
        return true; 
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getConnection
 
    protected SimpleJdbcTemplate simpleJdbcTemplate;
 
    @Before 
    public void before() throws Exception {
        SingleConnectionDataSource dataSource = new SingleConnectionDataSource("jdbc:h2:mem:jmx-demo-db", "sa", "", false);
 
        Connection connection = dataSource.getConnection();
        String createUsersTable = "create table users(username varchar(256), password varchar(256), enabled int, allowedRemoteAddresses varchar(256), comments varchar(256))";
        connection.createStatement().execute(createUsersTable);
 
        String createAuthoritiesTable = "create table authorities(username varchar(256), authority varchar(256))";
        connection.createStatement().execute(createAuthoritiesTable);
 
        userDetailsManager = new ExtendedJdbcUserDetailsManager();
 
        userDetailsManager.setDataSource(dataSource);
        simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
 
    } 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        private final DataSource[] dataSources;
        private int count;
 
        public TwoConnectionsDataSource(DataSource dataSource) throws SQLException {
            dataSources = new DataSource[] {
                    new SingleConnectionDataSource(dataSource.getConnection(), true),
                    new SingleConnectionDataSource(dataSource.getConnection(), true)
            }; 
        } 
 
        public Connection getConnection() throws SQLException {
            return dataSources[count++ % dataSources.length].getConnection();
        } 
 
        public Connection getConnection(String username, String password) throws SQLException {
            return null; 
        } 
 
        public Logger getParentLogger() {
            throw new UnsupportedOperationException("getParentLogger");
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:destroy
        jdbcTemplate.execute(sql); 
    } 
 
    @AfterClass 
    public static void dropDatabase() throws Exception { 
        dataSource.destroy(); 
    } 
 
    @AfterClass 
    public static void shutdownCacheManager() { 
        cacheManager.removalAll(); 
        cacheManager.shutdown(); 
    } 
 
    @Before 
    public void populateDatabase() { 
        String query = "INSERT INTO acl_sid(ID,PRINCIPAL,SID) VALUES (1,1,'ben');" 
                + "INSERT INTO acl_class(ID,CLASS) VALUES (2,'" + TARGET_CLASS + "');" 
                + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (1,2,100,null,1,1);" 
                + "INSERT INTO acl_object_identity(ID,OBJECT_ID_CLASS,OBJECT_ID_IDENTITY,PARENT_OBJECT,OWNER_SID,ENTRIES_INHERITING) VALUES (2,2,101,1,1,1);" 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	 
	JdbcTemplate template; 
	 
	@Before 
	public void setUp() throws SQLException { 
		template = new JdbcTemplate(new SingleConnectionDataSource(DbHelper.objectDb(), true)); 
	} 
 
	@Test 
	public void testRowMapper() throws SQLException, ParseException  { 
		RowMapper<DbObject> mapper = JdbcTemplateMapperFactory.newInstance().newRowMapper(DbObject.class); 
		List<DbObject> results = template.query(DbHelper.TEST_DB_OBJECT_QUERY, mapper); 
		DbHelper.assertDbObjectMapping(results.get(0)); 
	} 
	 
	@Test 
	public void testPreparedStatementCallback() throws SQLException, ParseException  { 
		PreparedStatementCallback<List<DbObject>> mapper = JdbcTemplateMapperFactory.newInstance().newPreparedStatementCallback(DbObject.class); 
		List<DbObject> results = template.execute(DbHelper.TEST_DB_OBJECT_QUERY, mapper); 
		DbHelper.assertDbObjectMapping(results.get(0)); 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        return new DBDriver(createTemplate(url)); 
    } 
 
    private static JdbcTemplate createTemplate(String url) throws ClassNotFoundException, SQLException { 
        Connection conn = DriverManager.getConnection(url, "auser", "sa"); 
        SingleConnectionDataSource dataSource = new SingleConnectionDataSource(conn, false); 
 
        return new JdbcTemplate(dataSource); 
    } 
 
    public void createSchema() { 
        dropTables(); 
 
        jdbcTemplate.execute("CREATE TABLE experiments (id INT AUTO_INCREMENT, experiment MEDIUMTEXT, last_update_date BIGINT, orig_id INT, PRIMARY KEY(id, last_update_date))"); 
        jdbcTemplate.execute("CREATE TABLE specs (id INT PRIMARY KEY AUTO_INCREMENT, fqn VARCHAR (255) NOT NULL, spec MEDIUMTEXT, UNIQUE KEY (fqn))"); 
    } 
 
    public void dropTables() { 
        jdbcTemplate.execute("DROP TABLE IF EXISTS experiments"); 
        jdbcTemplate.execute("DROP TABLE IF EXISTS specs"); 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
@Configuration 
public class ColumnRangePartitionerConfiguration { 
 
	@Bean 
	DataSource dataSource() { 
		return new SingleConnectionDataSource("jdbc:hsqldb:mem:test", "sa", "", true); 
	} 
 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
			url = url + name;
		} 
		String username = H2_JDBC_USERNAME;
		String password = H2_JDBC_PASSWORD;
 
		return new SingleConnectionDataSource(url, username, password, true);
	} 
 
	// Create DataSet 
 
	public static IDataSet createDataSet(String tableName, Object[][] data)
			throws DataSetException { 
		return new DefaultDataSet(createTable(tableName, data));
	} 
 
	public static ITable createTable(String tableName, Object[][] data)
			throws DataSetException { 
		if (data.length == 0) {
			throw new DataSetException("data is empty."); 
		} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:destroy, getConnection, setAutoCommit
		 
		int result = 0; 
		int userDataSet = 0;	 
		int insertDataResult = 0; 
		try { 
			ds.setAutoCommit(false);	// 트랜잭션 초기화  
			 
			// 어드민 기본 데이터를 입력한다. WE_USER, WE_PROFILE 
			userDataSet = this.insertAdminInfo(ds, weUser, weProfile); 
			 
			if(userDataSet == 1) { 
				try { 
					// 기본 데이터들을 테이블에 저장한다. TODOLIST : 공지사항 및 Static pages 정보들을 추가해야 한다.  
					insertDataResult = this.runInsertScript(ds, tableInitPath, enc);		 
					ds.getConnection().commit();		// 기본 데이터 완료 후 커밋  
					result = 1; 
				} catch (Exception e) { 
					ds.getConnection().rollback(); 
					result = -2; 
					e.printStackTrace(); 

3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework SingleConnectionDataSource Methods: