@Override public JDBCPoolDataSource get() { return JDBCPoolDataSource.getOrCreateDataSource(asyncClientConfig); } }
@Override public List<Set<String>> load(String project) throws Exception { try (Connection conn = connectionPool.getConnection()) { return getKeys(conn, project); } } });
@PostConstruct public void setup() { try (Connection connection = connectionPool.getConnection()) { Statement statement = connection.createStatement(); URI uri = URI.create(connectionPool.getConfig().getUrl().replaceAll("^jdbc:", "")); String primaryKey; if (uri.getScheme().equals("mysql")) { primaryKey = " id MEDIUMINT NOT NULL AUTO_INCREMENT,\n"; } else if (uri.getScheme().equals("postgresql")) { primaryKey = " id SERIAL,\n"; } else { throw new IllegalStateException(); } statement.execute("CREATE TABLE IF NOT EXISTS api_key (" + primaryKey + " project VARCHAR(255) NOT NULL,\n" + " read_key VARCHAR(255) NOT NULL,\n" + " write_key VARCHAR(255) NOT NULL,\n" + " master_key VARCHAR(255) NOT NULL,\n" + " created_at TIMESTAMP default current_timestamp NOT NULL," + "PRIMARY KEY (id)\n" + " )"); } catch (SQLException e) { throw new RuntimeException(e); } }
.toInstance(metadataDataSource); String url = metadataDataSource.getConfig().getUrl(); if (url.startsWith("jdbc:mysql")) { binder.bind(ConfigManager.class).to(MysqlConfigManager.class);
public static JDBCPoolDataSource getOrCreateDataSource(JDBCConfig config, String initialQuery) { return pools.computeIfAbsent(config, key -> new JDBCPoolDataSource(config, Optional.of(initialQuery))); }
public static JDBCPoolDataSource getOrCreateDataSource(JDBCConfig config) { return pools.computeIfAbsent(config, key -> new JDBCPoolDataSource(config, Optional.empty())); }
@Override protected void setup(Binder binder) { JDBCConfig config = buildConfigObject(JDBCConfig.class, "store.adapter.postgresql"); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named("store.adapter.postgresql")) .toInstance(JDBCPoolDataSource.getOrCreateDataSource(config)); binder.bind(PostgresqlQueryExecutor.class).in(Scopes.SINGLETON); binder.bind(UserStorage.class).to(AbstractPostgresqlUserStorage.class) .in(Scopes.SINGLETON); binder.bind(boolean.class).annotatedWith(Names.named("user.storage.postgresql")) .toInstance("postgresql".equals(true)); }
@Override public Connection getConnection() throws SQLException { return getConnection(disablePool); }
private JDBCPoolDataSource bindJDBCConfig(Binder binder, String config) { JDBCPoolDataSource dataSource = JDBCPoolDataSource.getOrCreateDataSource( buildConfigObject(JDBCConfig.class, config)); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named(config)) .toInstance(dataSource); return dataSource; }
public Connection getConnection() throws SQLException { return connectionPool.getConnection(); }
@Override protected void setup(Binder binder) { JDBCConfig config = buildConfigObject(JDBCConfig.class, "report.metadata.store.jdbc"); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named("report.metadata.store.jdbc")) .toInstance(JDBCPoolDataSource.getOrCreateDataSource(config)); binder.bind(QueryMetadataStore.class).to(JDBCQueryMetadata.class); }
@Override public List<SchemaField> load(ProjectCollection key) throws Exception { try (Connection conn = connectionPool.getConnection()) { List<SchemaField> schema = getSchema(conn, key.project, key.collection); if (schema == null) { return ImmutableList.of(); } return schema; } } });
@Override protected void setup(Binder binder) { JDBCConfig config = buildConfigObject(JDBCConfig.class, "store.adapter.postgresql"); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named("store.adapter.postgresql")) .toInstance(JDBCPoolDataSource.getOrCreateDataSource(config)); binder.install(getAsyncClientModule(config)); binder.bind(UserMailboxStorage.class).to(PostgresqlUserMailboxStorage.class); }
@Override public void revokeAllKeys(String project) { try (Connection conn = connectionPool.getConnection()) { PreparedStatement ps = conn.prepareStatement("DELETE FROM api_key WHERE project = ?"); ps.setString(1, project); ps.execute(); } catch (SQLException e) { throw Throwables.propagate(e); } }
MetadataConfig metadataConfig = buildConfigObject(MetadataConfig.class); JDBCPoolDataSource orCreateDataSource = JDBCPoolDataSource.getOrCreateDataSource(config, "set time zone 'UTC'"); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named("store.adapter.postgresql"))
@Override public void revokeApiKeys(String project, String masterKey) { try (Connection conn = connectionPool.getConnection()) { PreparedStatement ps = conn.prepareStatement("DELETE FROM api_key WHERE project = ? AND master_key = ?"); ps.setString(1, project); ps.setString(2, masterKey); ps.execute(); } catch (SQLException e) { throw Throwables.propagate(e); } }
customParameters.addBinding().toProvider(UIPermissionParameterProvider.class); JDBCPoolDataSource pool = JDBCPoolDataSource.getOrCreateDataSource(buildConfigObject(JDBCConfig.class, "ui.metadata.jdbc")); binder.bind(JDBCPoolDataSource.class) .annotatedWith(Names.named("ui.metadata.jdbc"))
@Override public void setup() { try (Connection connection = connectionPool.getConnection()) { Statement statement = connection.createStatement(); statement.execute("CREATE TABLE IF NOT EXISTS api_key (" + " id SERIAL NOT NULL,\n" + " project VARCHAR(255) NOT NULL,\n" + " read_key VARCHAR(255) NOT NULL,\n" + " write_key VARCHAR(255) NOT NULL,\n" + " master_key VARCHAR(255) NOT NULL,\n" + " created_at TIMESTAMP default current_timestamp NOT NULL," + "PRIMARY KEY (id)\n" + " )"); } catch (SQLException e) { throw new RuntimeException(e); } } }
@BeforeSuite public void setupPostgresql() { TestingEnvironmentPg10 testingEnvironment = new TestingEnvironmentPg10(); JDBCPoolDataSource apiKeyServiceDataSource = JDBCPoolDataSource .getOrCreateDataSource(testingEnvironment.getPostgresqlConfig()); apiKeyService = new PostgresqlApiKeyService(apiKeyServiceDataSource); apiKeyService.setup(); }
public HashSet<String> getViews(String project) { try (Connection conn = connectionPool.getConnection()) { HashSet<String> tables = new HashSet<>(); ResultSet tableRs = conn.getMetaData().getTables("", project, null, new String[]{"VIEW"}); while (tableRs.next()) { String tableName = tableRs.getString("table_name"); if (!tableName.startsWith("_")) { tables.add(tableName); } } return tables; } catch (SQLException e) { throw Throwables.propagate(e); } }