用户工具

站点工具


light4j:datasource
  • datasource,使用h2测试方便
MysqlDataSource:
  DriverClassName: com.mysql.jdbc.Driver
  jdbcUrl: jdbc:mysql://localhost:3306/eventuate?useSSL=false
  username: mysqluser
  password: mysqlpw
  maximumPoolSize: 2
  connectionTimeout: 500
  parameters:
    useServerPrepStmts: 'true'
    cachePrepStmts: 'true'
    cacheCallableStmts: 'true'
    prepStmtCacheSize: '4096'
    prepStmtCacheSqlLimit: '2048'
    verifyServerCertificate: 'false'
    useSSL: 'true'
    requireSSL: 'true'

MariaDataSource:
  DriverClassName: org.mariadb.jdbc.MariaDbDataSource
  jdbcUrl: jdbc:mariadb://mariadb:3306/oauth2?useSSL=false
  username: mysqluser
  password: mysqlpw
  maximumPoolSize: 2
  connectionTimeout: 500
  parameters:
    useServerPrepStmts: 'true'
    cachePrepStmts: 'true'
    cacheCallableStmts: 'true'
    prepStmtCacheSize: '4096'
    prepStmtCacheSqlLimit: '2048'

PostgresDataSource:
  DriverClassName: org.postgresql.ds.PGSimpleDataSource
  jdbcUrl: jdbc:postgresql://postgresdb:5432/oauth2
  username: postgres
  password: my-secret-pw
  maximumPoolSize: 2
  connectionTimeout: 500

SqlServerDataSource:
  DriverClassName: com.microsoft.sqlserver.jdbc.SQLServerDataSource
  jdbcUrl: jdbc:sqlserver://sqlserver:1433;databaseName=oauth2
  username: sa
  password: StrongPassw0rd
  maximumPoolSize: 2
  connectionTimeout: 500

OracleDataSource:
  DriverClassName: oracle.jdbc.pool.OracleDataSource
  jdbcUrl: jdbc:oracle:thin:@localhost:1521:XE
  username: SYSTEM
  password: oracle
  maximumPoolSize: 2
  connectionTimeout: 500
  parameters:
    useServerPrepStmts: 'true'
    cachePrepStmts: 'true'
    cacheCallableStmts: 'true'
    prepStmtCacheSize: '10'
    prepStmtCacheSqlLimit: '2048'

H2DataSource:
  DriverClassName: org.h2.jdbcx.JdbcDataSource
  jdbcUrl: jdbc:h2:mem:XE;MODE=MYSQL;INIT=runscript from 'classpath:scripts/test-oauth2.sql'\;runscript from 'classpath:scripts/test-todo.sql';
  # jdbcUrl: jdbc:h2:~/test
  username: sa
  password: sa
  maximumPoolSize: 2
  connectionTimeout: 500
  • DataSource,
public static Map<String, DataSource> dbMap = new HashMap<>();
// DbStartupHookProvider.onStartup
Map<String, Object> dataSourceMap = (Map<String, Object>) Config.getInstance().getJsonMapConfig(DATA_SOURCE);
dataSourceMap.forEach((k, v) -> {
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(((Map<String, String>)v).get("jdbcUrl"));
ds.setUsername(((Map<String, String>)v).get("username"));
ds.setPassword(((Map<String, String>)v).get("password"));
Map<String, String> configParams = (Map<String, String>)((Map<String, Object>)v).get("parameters");
configParams.forEach((p, q) -> ds.addDataSourceProperty(p, q));
dbMap.put(k, ds);
}); // DataSource ds = (DataSource) DbStartupHookProvider.dbMap.get("db1");
  • Beetlsql
SQLManager SQLMANAGER = SQLManager.newBuilder(ConnectionSourceHelper.getSingle(DATASOURCE)).setNc(new DefaultNameConversion() {
		@Override
		public  String getClassName(String tableName){
			return StringKit.toUpperCaseFirstOne(tableName); //类名使用表名+首字母大写,字段名与列名相同
		}
	}).setDbStyle(new MySqlStyle()).setSqlLoader("beetl/sql", "UTF-8").build();
SQLMANAGER.setInters(new Interceptor[]{new DebugInterceptor()}); // 调试模式,!SQLMANAGER.isProductMode()
# btsql-ext.properties
PRODUCT_MODE=true
CHARSET=UTF-8
OFFSET_START_ZERO=false
light4j/datasource.txt · 最后更改: 2021/11/30 22:49 由 admin