当前位置: 首页>>代码示例>>Java>>正文


Java PGPoolingDataSource类代码示例

本文整理汇总了Java中org.postgresql.ds.PGPoolingDataSource的典型用法代码示例。如果您正苦于以下问题:Java PGPoolingDataSource类的具体用法?Java PGPoolingDataSource怎么用?Java PGPoolingDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PGPoolingDataSource类属于org.postgresql.ds包,在下文中一共展示了PGPoolingDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpDataSource

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
@BeforeClass(alwaysRun = true)
static public void setUpDataSource() throws Exception {
    File propertiesFile = new File("config/application.properties");
    if (!propertiesFile.exists()) {
        throw new IllegalStateException(
                "Missing configuration file, please create config/application.properties based on sample.");
    }
    Properties props = new Properties();
    try (FileInputStream fis = new FileInputStream(propertiesFile)) {
        props.load(fis);
    }

    PGPoolingDataSource dataSource = new PGPoolingDataSource();
    dataSource.setServerName(props.getProperty("db.server"));
    dataSource.setDatabaseName(props.getProperty("db.database"));
    dataSource.setUser(props.getProperty("db.user"));
    dataSource.setPassword(props.getProperty("db.password"));
    dataSource.setPortNumber(Integer.parseInt(props.getProperty("db.port")));
    BaseITest.dataSource = dataSource;
}
 
开发者ID:OasisDigital,项目名称:nges,代码行数:21,代码来源:BaseITest.java

示例2: 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;
}
 
开发者ID:Exorath,项目名称:ServiceCommons,代码行数:24,代码来源:EnvironmentPGProvider.java

示例3: 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;
}
 
开发者ID:peter-mount,项目名称:opendata-common,代码行数:19,代码来源:DataSourceProducer.java

示例4: 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;
}
 
开发者ID:gurelkaynak,项目名称:recommendationengine,代码行数:22,代码来源:DataSourceFactory.java

示例5: run

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
@Override
public void run(RecommenderConfiguration configuration,
                Environment environment) {
    
    PGPoolingDataSource pgPoolingDataSource = configuration.getDataSourceFactory().build(environment);
    ReloadFromJDBCDataModel dataModel = null;
    try {
        dataModel = configuration.getDataModelFactory().build(pgPoolingDataSource);
    } catch (TasteException e) {
        System.err.println(e);
        System.exit(-1);
    }
    
    Recommender userBasedRecommender = configuration.getRecommenderFactory().buildUserBasedRecommender(dataModel);
    ItemBasedRecommender itemBasedRecommender = configuration.getRecommenderFactory().buildItemBasedRecommender(dataModel);
    
    final RecommendationResource userRecommendationResource = new RecommendationResource(userBasedRecommender, itemBasedRecommender);
    final DataModelResource dataModelResource = new DataModelResource(dataModel);
    environment.jersey().register(userRecommendationResource);
    environment.jersey().register(dataModelResource);
}
 
开发者ID:gurelkaynak,项目名称:recommendationengine,代码行数:22,代码来源:RecommenderApplication.java

示例6: close

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
/**
 * Closes all active connections to the database and cleans up any resources. Depending on your context, you may
 * wish to revoke connect permissions before invoking this.
 */
public void close()
{
  if (this.dataSource instanceof PGPoolingDataSource)
  {
    ((PGPoolingDataSource)this.dataSource).close();
  }
  else
  {
    // Terminate all connections manually.
    LinkedList<String> statements = new LinkedList<String>();
    String dbName = DatabaseProperties.getDatabaseName();
    
    statements.add(
        "SELECT \n" + 
        "    pg_terminate_backend(pid) \n" + 
        "FROM \n" + 
        "    pg_stat_activity \n" + 
        "WHERE \n" + 
        "    pid <> pg_backend_pid()\n" + 
        "    AND datname = '" + dbName + "'\n" + 
        "    ;");
    
    executeAsRoot(statements, true);
  }
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:30,代码来源:PostgreSQL.java

示例7: 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);
}
 
开发者ID:dola,项目名称:Telesto,代码行数:25,代码来源:DBTests.java

示例8: 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

示例9: test18

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
@Test(timeout = 4000)
public void test18() throws Throwable {
    Product product0 = new Product();
    PGPoolingDataSource pGPoolingDataSource0 = PGPoolingDataSource.getDataSource("");
    SQLDialect sQLDialect0 = SQLDialect.MARIADB;
    Settings settings0 = new Settings();
    DefaultDSLContext defaultDSLContext0 = new DefaultDSLContext(pGPoolingDataSource0,
                                                                 sQLDialect0,
                                                                 settings0);
    try {
        new WorkspaceSnapshot(product0, defaultDSLContext0);
        fail("Expecting exception: NullPointerException");

    } catch (NullPointerException e) {
        //
        // no message in exception (getMessage() returned null)
        //
        assertThrownBy("org.jooq.impl.DataSourceConnectionProvider", e);
    }
}
 
开发者ID:ChiralBehaviors,项目名称:Ultrastructure,代码行数:21,代码来源:WorkspaceSnapshot_ESTest.java

示例10: getDbConnection

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
public static Connection getDbConnection(){
    PGPoolingDataSource source = new PGPoolingDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    source.setLoginTimeout(10);
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:14,代码来源:DbUtil.java

示例11: 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;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:16,代码来源:Chapter06Database01.java

示例12: getDbConnection

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
private static Connection getDbConnection(){
    PGPoolingDataSource source = new PGPoolingDataSource();
    source.setServerName("localhost");
    source.setDatabaseName("cookbook");
    try {
        return source.getConnection();
    }
    catch(Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:13,代码来源:Chapter12Memory.java

示例13: PostgresStore

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
public PostgresStore(PostgresConfiguration config, String schema) {
    this.pool = new PGPoolingDataSource();
    this.pool.setUrl(config.getJdbcUrl());
    this.pool.setUser(config.getUsername());
    this.pool.setPassword(config.getPassword());
    this.pool.setCurrentSchema(schema);
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:8,代码来源:PostgresStore.java

示例14: datasource

import org.postgresql.ds.PGPoolingDataSource; //导入依赖的package包/类
@Bean
public DataSource datasource(Environment env) {
    PGPoolingDataSource source = new PGPoolingDataSource();
    source.setServerName(env.getProperty(POSTGRES_HOST_KEY));
    source.setDatabaseName(env.getProperty(POSTGRES_DB));
    source.setUser(env.getProperty(POSTGRES_USER));
    source.setPassword(env.getProperty(POSTGRES_PASSWORD));
    return source;
}
 
开发者ID:cf-platform-eng,项目名称:my-postgres-broker,代码行数:10,代码来源:PostgresConfig.java

示例15: 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;
}
 
开发者ID:bjfish,项目名称:stellar-core-es-indexer,代码行数:12,代码来源:StellarCoreElasticsearchIndexer.java


注:本文中的org.postgresql.ds.PGPoolingDataSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。