@Override protected DataSource createDataSource() { final PGSimpleDataSource datasource = new PGSimpleDataSource(); datasource.setServerName(hostname); datasource.setPortNumber(port); datasource.setUser(username); datasource.setPassword(password); datasource.setDatabaseName(database); datasource.setApplicationName("Hermes Unit Tests"); return datasource; }
@Override public DataSource getConfiguredDataSource(DbBackendConfiguration configuration, String poolName) { PGSimpleDataSource dataSource = new PGSimpleDataSource(); dataSource.setUser(configuration.getUsername()); dataSource.setPassword(configuration.getPassword()); dataSource.setServerName(configuration.getDbHost()); dataSource.setPortNumber(configuration.getDbPort()); dataSource.setDatabaseName(configuration.getDbName()); dataSource.setApplicationName("torodb-" + poolName); dataSource.setLogLevel(Driver.DEBUG); dataSource.setLogWriter(LOGGER_WRITER); Connection conn = null; try { conn = dataSource.getConnection(); stat = conn.createStatement(); rs = stat.executeQuery("SELECT 1");
"PostgreSQL JDBC Driver version not supported by GeoGig: " + driverVersion); PGSimpleDataSource pgSimpleDataSource = new PGSimpleDataSource(); pgSimpleDataSource.setBinaryTransfer(true); pgSimpleDataSource.setApplicationName("geogig"); pgSimpleDataSource.setServerName(connInfo.server); pgSimpleDataSource.setDatabaseName(connInfo.databaseName); pgSimpleDataSource.setPortNumber(connInfo.portNumber); pgSimpleDataSource.setUser(connInfo.user); pgSimpleDataSource.setPassword(connInfo.password); pgSimpleDataSource.setAssumeMinServerVersion("9.4"); pgSimpleDataSource.setPrepareThreshold(-1); pgSimpleDataSource.setTcpKeepAlive(true);
private void addTenantConnectionProvider(String tenantId) { PGSimpleDataSource defaultDataSource = (PGSimpleDataSource) database().dataSourceProvider().dataSource(); Properties properties = properties(); PGSimpleDataSource tenantDataSource = new PGSimpleDataSource(); tenantDataSource.setDatabaseName(defaultDataSource.getDatabaseName()); tenantDataSource.setCurrentSchema(tenantId); tenantDataSource.setServerName(defaultDataSource.getServerName()); tenantDataSource.setUser(defaultDataSource.getUser()); tenantDataSource.setPassword(defaultDataSource.getPassword()); properties.put( Environment.DATASOURCE, dataSourceProxyType().dataSource(tenantDataSource) ); addTenantConnectionProvider(tenantId, tenantDataSource, properties); }
final PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setServerName("localhost"); ds.setDatabaseName(NAME); ds.setApplicationName("Apache SIS test database"); ds.setCurrentSchema(schema); ds.setProperty(PGProperty.LOGGER_LEVEL, "OFF"); // For avoiding warning when no PostgreSQL server is running. try (Connection c = ds.getConnection()) { try (ResultSet reflect = c.getMetaData().getSchemas(null, schema)) { if (reflect.next()) {
/** * Returns a connection to the specified database with autocommit on. * * @param host_name * @param database * @return * @throws SQLException */ public synchronized Connection getConnection(final String host_name, final String database) throws SQLException { data_source.setDatabaseName(database); data_source.setServerName(host_name); return data_source.getConnection(); }
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
public static synchronized void INIT() { PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setUrl(PG_URL); try (final Connection cnx = ds.getConnection(); final Statement st = cnx.createStatement()) { st.execute(TestSuite.getResourceAsString(PG_SQL)); } catch (Exception ex) { throw new RuntimeException(ex); } TestSuite.setupSessionFactoryBuilder(ds); } }
@BeforeClass public static void init() throws SQLException, IOException { PGSimpleDataSource pgDs = new PGSimpleDataSource(); pgDs.setUrl(PG_URL); sessionFactory = JsonHandlersTestApi.setUpDb(pgDs, PG_SQL); }
@Override public void close() throws SQLException { final PGSimpleDataSource ds = (PGSimpleDataSource) source; try (Connection c = ds.getConnection()) { try (Statement s = c.createStatement()) { s.execute("DROP SCHEMA \"" + ds.getCurrentSchema() + "\" CASCADE"); } } } };
public PostgresTestSupport() throws Exception { ds = createTestDataSource(); conn = ds.getConnection(); try { insert = conn.prepareStatement( "INSERT INTO resources (name, parent, content) VALUES (?, ?, ?) RETURNING oid;"); } finally { if (insert == null) conn.close(); } }
"PostgreSQL JDBC Driver version not supported by GeoGig: " + driverVersion); PGSimpleDataSource pgSimpleDataSource = new PGSimpleDataSource(); pgSimpleDataSource.setBinaryTransfer(true); pgSimpleDataSource.setApplicationName("geogig"); pgSimpleDataSource.setServerName(connInfo.server); pgSimpleDataSource.setDatabaseName(connInfo.databaseName); pgSimpleDataSource.setPortNumber(connInfo.portNumber); pgSimpleDataSource.setUser(connInfo.user); pgSimpleDataSource.setPassword(connInfo.password); pgSimpleDataSource.setAssumeMinServerVersion("9.4"); pgSimpleDataSource.setPrepareThreshold(-1); pgSimpleDataSource.setTcpKeepAlive(true);
/** * Returns a connection to the specified database with autocommit on. * * @param host_name * @param database * @param user * @param password * @return * @throws SQLException */ public synchronized Connection getConnection(final String host_name, final String database, final String user, final String password) throws SQLException { data_source.setDatabaseName(database); data_source.setServerName(host_name); return data_source.getConnection(user, password); } }
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
/** Returns a data source for the PostgreSQL database. */ protected DataSource createDataSource() throws SQLException { DataSource candidate = super.createDataSource(); if (candidate instanceof BaseDataSource) { // Any kind of DataSource from the PostgreSQL driver. return candidate; } final PGSimpleDataSource source = new PGSimpleDataSource(); final Properties p = load(); int portNumber; try { portNumber = Integer.parseInt(p.getProperty("portNumber", "5432")); } catch (NumberFormatException exception) { portNumber = 5432; Logging.unexpectedException( "org.geotools.referencing.factory", DataSource.class, "<init>", exception); } source.setPortNumber(portNumber); source.setServerName(p.getProperty("serverName", "localhost")); source.setDatabaseName(p.getProperty("databaseName", "EPSG")); source.setUser(p.getProperty("user", "Geotools")); source.setPassword(p.getProperty("password", "Geotools")); source.setProperty("stringtype", "unspecified"); schema = p.getProperty("schema", null); return source; }
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
ic.createSubcontext("java:comp"); ic.createSubcontext("java:comp/env"); ic.createSubcontext("java:comp/env/jdbc"); final PGSimpleDataSource ds = new PGSimpleDataSource(); ds.setUrl("jdbc:postgresql://localhost:5432/mydb"); ds.setUser("postgres"); ds.setPassword("pg"); ic.bind("java:comp/env/jdbc/mydb", ds);
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
Database() { data_source = new PGSimpleDataSource(); data_source.setServerName(Config.INSTANCE.db_host); data_source.setPortNumber(Config.INSTANCE.db_port); data_source.setDatabaseName(Config.INSTANCE.db_database); data_source.setUser(Config.INSTANCE.db_user); data_source.setPassword(Config.INSTANCE.db_password); data_source.setApplicationName("jpgAgent: " + Config.INSTANCE.hostname); if (Config.INSTANCE.disable_prepared_statement) { data_source.setPreparedStatementCacheQueries(0); } }
@Override public void initialize() throws IOException, SQLException { super.initialize(); dataSource = new PGSimpleDataSource(); ((PGSimpleDataSource) dataSource).setDatabaseName(databaseName); ((PGSimpleDataSource) dataSource).setUser(username); ((PGSimpleDataSource) dataSource).setPassword(password); ((PGSimpleDataSource) dataSource).setUrl(jdbcConnectionString); }