本文整理汇总了Java中org.postgresql.ds.PGPoolingDataSource.setMaxConnections方法的典型用法代码示例。如果您正苦于以下问题:Java PGPoolingDataSource.setMaxConnections方法的具体用法?Java PGPoolingDataSource.setMaxConnections怎么用?Java PGPoolingDataSource.setMaxConnections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.postgresql.ds.PGPoolingDataSource
的用法示例。
在下文中一共展示了PGPoolingDataSource.setMaxConnections方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataSource
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
@Override
public DataSource getDataSource() {
URI uri = getURIFromEnv();
String host = uri.getHost();
int port = uri.getPort();
String db = uri.getPath().substring(1);
String username = uri.getUserInfo().split(":")[0];
String password = uri.getUserInfo().split(":")[1];
PGPoolingDataSource ds = new PGPoolingDataSource();
ds.setSsl(true);
ds.setSslMode("verify-full");
ds.setUser(username);
ds.setServerName(host);
ds.setPortNumber(port);
ds.setPassword(password);
ds.setDatabaseName(db);
ds.setInitialConnections(0);
Integer maxConnections = getMaxConnectionsFromEnv();
if(maxConnections != null)
ds.setMaxConnections(maxConnections);
return ds;
}
示例2: lookup
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
private DataSource lookup( String name )
{
Configuration map = configurationService.getConfiguration( name );
PGPoolingDataSource ds = new PGPoolingDataSource();
ds.setApplicationName( "OpenData" );
ds.setDataSourceName( map.getString( "name", () -> map.getString( "database" ) ) );
ds.setMaxConnections( map.getInt( "connections.max", 10 ) );
ds.setInitialConnections( map.getInt( "connections.initial", 0 ) );
ds.setUser( Objects.requireNonNull( map.getString( "username" ), "username required" ) );
ds.setPassword( Objects.requireNonNull( map.getString( "password" ), "password required" ) );
ds.setServerName( Objects.requireNonNull( map.getString( "hostname" ), "hostname required" ) );
ds.setDatabaseName( map.getString( "database", () -> map.getString( "name" ) ) );
ds.setPortNumber( map.getInt( "port", 0 ) );
return ds;
}
示例3: build
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
public PGPoolingDataSource build(Environment environment) {
final PGPoolingDataSource pg_ds = new PGPoolingDataSource();
pg_ds.setDataSourceName("pg_ds");
pg_ds.setServerName(this.getHost());
pg_ds.setDatabaseName(this.getDb());
pg_ds.setUser(this.getUser());
pg_ds.setPassword(this.getPassword());
pg_ds.setPortNumber(this.getPort());
pg_ds.setMaxConnections(this.getMaxConnections());
environment.lifecycle().manage(new Managed() {
@Override
public void start() {
}
@Override
public void stop() {
pg_ds.close();
}
});
return pg_ds;
}
示例4: createConnectionPool
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
@Test
public void createConnectionPool() throws SQLException {
PGPoolingDataSource connectionPool = new PGPoolingDataSource();
connectionPool.setApplicationName(CONFIG.DB_SERVER_NAME);
connectionPool.setServerName(CONFIG.DB_SERVER_NAME);
connectionPool.setPortNumber(CONFIG.DB_PORT_NUMBER);
connectionPool.setDatabaseName(CONFIG.DB_NAME);
connectionPool.setUser(CONFIG.DB_USER);
connectionPool.setPassword(CONFIG.DB_PASSWORD);
connectionPool.setMaxConnections(CONFIG.DB_MAX_CONNECTIONS);
Connection c = connectionPool.getConnection();
// request id for user dola with mode 1
CallableStatement s = c.prepareCall("{ ? = call request_id( ? , ? ) }");
s.registerOutParameter(1, Types.INTEGER);
s.setString(2, "blubbedi");
s.setInt(3, 1);
s.execute();
Integer client_id = s.getInt(1);
s.close();
assertNotNull("returned client id is null", client_id);
}
示例5: PostgresqlConnectionProvider
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
public PostgresqlConnectionProvider(@NonNls @NotNull final String serverDnsHostName, @NonNls @NotNull final String databaseName, @NonNls @NotNull final String applicationName, @NonNls @NotNull final String userName, @NonNls @NotNull final String password)
{
dataSource = new PGPoolingDataSource();
dataSource.setDataSourceName(randomUUID().toString());
dataSource.setInitialConnections(2);
dataSource.setMaxConnections(10);
dataSource.setServerName(serverDnsHostName);
dataSource.setPortNumber(DefaultPostgresPort);
dataSource.setTcpKeepAlive(true);
dataSource.setSocketTimeout(ThirtySeconds);
dataSource.setSsl(false);
dataSource.setProtocolVersion(0);
dataSource.setSendBufferSize(FourKilobytes);
dataSource.setReceiveBufferSize(FourKilobytes);
dataSource.setBinaryTransfer(true);
dataSource.setDatabaseName(databaseName);
dataSource.setApplicationName(applicationName);
dataSource.setUser(userName);
dataSource.setPassword(password);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:24,代码来源:PostgresqlConnectionProvider.java
示例6: getDbConnection
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
private static Connection getDbConnection(){
PGPoolingDataSource source = new PGPoolingDataSource();
source.setServerName("localhost");
source.setDatabaseName("cookbook");
source.setInitialConnections(3);
source.setMaxConnections(10);
source.setLoginTimeout(10);
try {
return source.getConnection();
}
catch(Exception ex) {
ex.printStackTrace();
return null;
}
}
示例7: getDataSource
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
private static DataSource getDataSource(SCEIApplicationConfig config) {
final PGPoolingDataSource source = new PGPoolingDataSource();
source.setDataSourceName("PostgresDB");
source.setServerName(config.getDatabaseServerName());
source.setDatabaseName(config.getDatabaseName());
source.setPortNumber(config.getDatabasePort());
source.setUser(config.getDatabaseUser());
source.setPassword(config.getDatabasePassword());
source.setMaxConnections(10);
return source;
}
示例8: PgConnectionProvider
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
public PgConnectionProvider(String host, String database, String username, String password, int maxConnections) throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
log.error("Error loading class for PostgreSQL JDBC driver", e);
throw new RuntimeException(e);
}
String jdbcUrl = String.format("jdbc:postgresql://%s/%s", host, database);
log.info("Starting HikariDataSource with Url: {}, Username: {}, maxPoolSize: {}", jdbcUrl, username, maxConnections);
dataSource = new PGPoolingDataSource();
dataSource.setUrl(jdbcUrl);
dataSource.setProperty("user", username);
dataSource.setProperty("password", password);
dataSource.setMaxConnections(maxConnections);
}
示例9: PgConnectionProvider
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
public PgConnectionProvider(String host, String database, String username, String password, int maxConnections) throws SQLException {
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
log.error("Error loading class for PostgreSQL JDBC driver", e);
throw new RuntimeException(e);
}
dataSource = new PGPoolingDataSource();
dataSource.setUrl(String.format("jdbc:postgresql://%s/%s", host, database));
dataSource.setProperty("user", username);
dataSource.setProperty("password", password);
dataSource.setMaxConnections(maxConnections);
}
示例10: getDataSource
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
@Bean
public DataSource getDataSource(DataSourceProperties props) {
// TODO: change to any middleware
PGPoolingDataSource source = new PGPoolingDataSource();
source.setDataSourceName("eetds");
source.setServerName("localhost");
source.setDatabaseName(props.getName());
source.setUser(props.getUsername());
source.setPassword(props.getPassword());
source.setMaxConnections(10);
// source.setUrl("");
return source;
}
示例11: dataSource
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
@Primary
@Bean(destroyMethod = "")
public DataSource dataSource() {
log.debug("Configuring Datasource");
if (propertyResolver.getProperty("url") == null && propertyResolver.getProperty("jndi") == null) {
log.error("Your database connection pool configuration is incorrect! The application" +
"cannot start. Please check your Spring profile, current profiles are: {}");
throw new ApplicationContextException("Database connection pool is not configured correctly");
}
try {
String jndi = propertyResolver.getProperty("jndi");
if (jndi != null) {
log.debug("Getting datasource from JNDI global resource link {}", jndi);
JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
return dataSourceLookup.getDataSource(jndi);
} else {
String url = propertyResolver.getProperty("url");
String username = propertyResolver.getProperty("username");
log.debug("Initializing PGPoolingDataSource: url={}, username={}", url, username);
PGPoolingDataSource source = new PGPoolingDataSource();
source.setUrl(url);
source.setUser(username);
source.setPassword(propertyResolver.getProperty("password"));
source.setMaxConnections(10);
return source;
}
} catch (Exception e) {
log.error("dataSource: msg=" + e.getMessage(), e);
throw new ApplicationContextException("Database connection pool creation resulted in error");
}
}
示例12: connectToDatabase
import org.postgresql.ds.PGPoolingDataSource; //导入方法依赖的package包/类
private void connectToDatabase() throws ClassNotFoundException {
String type = getConfig().getString("database.type"),
host = getConfig().getString("database.host"),
dbName = getConfig().getString("database.db_name"),
user = getConfig().getString("database.user"),
pass = getConfig().getString("database.pass");
int port = getConfig().getInt("database.port");
SQLBackend dbType = SQLBackend.parse(type);
stmts = new StatementProvider("/db", dbType);
switch(dbType) {
case MYSQL:
Class.forName("com.mysql.jdbc.Driver");
MysqlConnectionPoolDataSource msqlpool = new MysqlConnectionPoolDataSource();
msqlpool.setDatabaseName(dbName);
msqlpool.setUser(user);
msqlpool.setPassword(pass);
msqlpool.setServerName(host);
msqlpool.setPort(port);
connections = msqlpool;
break;
case POSTGRES:
Class.forName("org.postgresql.Driver");
PGPoolingDataSource pgpool = new PGPoolingDataSource();
pgpool.setDataSourceName("mcanalytics-pg-pool");
pgpool.setServerName(host);
pgpool.setPortNumber(port);
pgpool.setDatabaseName(dbName);
pgpool.setUser(user);
pgpool.setPassword(pass);
pgpool.setMaxConnections(10);
connections = pgpool;
break;
default:
throw new IllegalStateException("unsupported database type in config.yml");
}
}