-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDataSourceConfiguration.java
84 lines (71 loc) · 2.95 KB
/
AppDataSourceConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.test;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import com.zaxxer.hikari.HikariDataSource;
@Configuration
public class AppDataSourceConfiguration {
// @Bean
// @Primary
// public DataSource datasource() {
// HikariDataSource hikariDataSource = (HikariDataSource) DataSourceBuilder
// .create(HikariDataSource.class.getClassLoader()).username("sa").password("")
// .url("jdbc:h2:mem:prime;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false").driverClassName("org.h2.Driver")
// .build();
// hikariDataSource.setMaximumPoolSize(1);
// hikariDataSource.setConnectionTimeout(5000);
// hikariDataSource.setPoolName("PrimayPool");
// return hikariDataSource;
// }
@Bean
@Primary
public DataSource datasource() {
HikariDataSource hikariDataSource = (HikariDataSource) DataSourceBuilder
.create(HikariDataSource.class.getClassLoader()).username("sa").password("")
.url("jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1;").driverClassName("org.hsqldb.jdbc.JDBCDriver").build();
hikariDataSource.setMaximumPoolSize(1);
hikariDataSource.setConnectionTimeout(5000);
hikariDataSource.setPoolName("PrimayPool");
return hikariDataSource;
}
@Bean("metaDs")
public DataSource metaDatasource() throws SQLException {
DataSource dataSource = DataSourceBuilder
.create()
.username("sa")
.password("")
.url("jdbc:hsqldb:mem:metadb;sql.enforce_strict_size=true;hsqldb.txt=mvcc;DB_CLOSE_DELAY=-1")
.driverClassName("org.hsqldb.jdbc.JDBCDriver")
.build();
// initialize with metadata tables
DefaultResourceLoader drl = new DefaultResourceLoader();
ResourceDatabasePopulator rdp = new ResourceDatabasePopulator();
rdp.addScript(drl.getResource("/org/springframework/batch/core/schema-hsqldb.sql"));
DatabasePopulatorUtils.execute(rdp, dataSource);
return dataSource;
}
// @Bean
// @BatchDataSource
// public DataSource embeddedDatasource() {
//// HikariDataSource hikariDataSource = (HikariDataSource) DataSourceBuilder
//// .create(HikariDataSource.class.getClassLoader()).username("sa").password("")
//// .url("jdbc:h2:mem:meta;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false").driverClassName("org.h2.Driver")
//// .build();
//// hikariDataSource.setMaximumPoolSize(5);
//// hikariDataSource.setConnectionTimeout(5000);
////
//// hikariDataSource.setPoolName("MetaPool");
//// return hikariDataSource;
// return new EmbeddedDatabaseBuilder()
// .generateUniqueName(true)
// .addScript("/org/springframework/batch/core/schema-h2.sql")
// .setType(EmbeddedDatabaseType.H2)
// .build();
// }
}