Skip to content

Commit

Permalink
Renamed everything with jdbc prefix to use more generic database
Browse files Browse the repository at this point in the history
…prefix, since we don't use jdbc anymore.

Removed unused provider class field from DatabaseType enum.
  • Loading branch information
And1sS committed Apr 26, 2024
1 parent 1da745f commit cfb8062
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 188 deletions.
12 changes: 6 additions & 6 deletions docs/config-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ available: `/cache/invalidate?account={accountId}` which remove account from the
- `settings.in-memory-cache.http-update.amp-endpoint` - the url to fetch AMP stored request updates.
- `settings.in-memory-cache.http-update.refresh-rate` - refresh period in ms for stored request updates.
- `settings.in-memory-cache.http-update.timeout` - timeout for obtaining stored request updates.
- `settings.in-memory-cache.jdbc-update.init-query` - initial query for fetching all stored requests at the startup.
- `settings.in-memory-cache.jdbc-update.update-query` - a query for periodical update of stored requests, that should
- `settings.in-memory-cache.database-update.init-query` - initial query for fetching all stored requests at the startup.
- `settings.in-memory-cache.database-update.update-query` - a query for periodical update of stored requests, that should
contain 'WHERE last_updated > ?' to fetch only the records that were updated since previous check.
- `settings.in-memory-cache.jdbc-update.amp-init-query` - initial query for fetching all AMP stored requests at the startup.
- `settings.in-memory-cache.jdbc-update.amp-update-query` - a query for periodical update of AMP stored requests, that should
- `settings.in-memory-cache.database-update.amp-init-query` - initial query for fetching all AMP stored requests at the startup.
- `settings.in-memory-cache.database-update.amp-update-query` - a query for periodical update of AMP stored requests, that should
contain 'WHERE last_updated > ?' to fetch only the records that were updated since previous check.
- `settings.in-memory-cache.jdbc-update.refresh-rate` - refresh period in ms for stored request updates.
- `settings.in-memory-cache.jdbc-update.timeout` - timeout for obtaining stored request updates.
- `settings.in-memory-cache.database-update.refresh-rate` - refresh period in ms for stored request updates.
- `settings.in-memory-cache.database-update.timeout` - timeout for obtaining stored request updates.

For targeting available next options:
- `settings.targeting.truncate-attr-chars` - set the max length for names of targeting keywords (0 means no truncation).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* stored requests and imps) from the source.
*
* @see FileApplicationSettings
* @see JdbcApplicationSettings
* @see DatabaseApplicationSettings
* @see HttpApplicationSettings
* @see CachingApplicationSettings
* @see CompositeApplicationSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import org.prebid.server.execution.Timeout;
import org.prebid.server.json.DecodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.settings.helper.JdbcStoredDataResultMapper;
import org.prebid.server.settings.helper.JdbcStoredResponseResultMapper;
import org.prebid.server.settings.helper.DatabaseStoredDataResultMapper;
import org.prebid.server.settings.helper.DatabaseStoredResponseResultMapper;
import org.prebid.server.settings.helper.ParametrizedQueryHelper;
import org.prebid.server.settings.model.Account;
import org.prebid.server.settings.model.StoredDataResult;
import org.prebid.server.settings.model.StoredResponseDataResult;
import org.prebid.server.util.ObjectUtil;
import org.prebid.server.vertx.jdbc.JdbcClient;
import org.prebid.server.vertx.database.CircuitBreakerSecuredDatabaseClient;
import org.prebid.server.vertx.database.DatabaseClient;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -33,12 +34,12 @@
* <p>
* Reads an application settings from the database source.
* <p>
* In order to enable caching and reduce latency for read operations {@link JdbcApplicationSettings}
* In order to enable caching and reduce latency for read operations {@link DatabaseApplicationSettings}
* can be decorated by {@link CachingApplicationSettings}.
*/
public class JdbcApplicationSettings implements ApplicationSettings {
public class DatabaseApplicationSettings implements ApplicationSettings {

private final JdbcClient jdbcClient;
private final DatabaseClient databaseClient;
private final JacksonMapper mapper;
private final ParametrizedQueryHelper parametrizedQueryHelper;

Expand Down Expand Up @@ -81,15 +82,15 @@ public class JdbcApplicationSettings implements ApplicationSettings {
*/
private final String selectStoredResponsesQuery;

public JdbcApplicationSettings(JdbcClient jdbcClient,
JacksonMapper mapper,
ParametrizedQueryHelper parametrizedQueryHelper,
String selectAccountQuery,
String selectStoredRequestsQuery,
String selectAmpStoredRequestsQuery,
String selectStoredResponsesQuery) {
public DatabaseApplicationSettings(DatabaseClient databaseClient,
JacksonMapper mapper,
ParametrizedQueryHelper parametrizedQueryHelper,
String selectAccountQuery,
String selectStoredRequestsQuery,
String selectAmpStoredRequestsQuery,
String selectStoredResponsesQuery) {

this.jdbcClient = Objects.requireNonNull(jdbcClient);
this.databaseClient = Objects.requireNonNull(databaseClient);
this.mapper = Objects.requireNonNull(mapper);
this.parametrizedQueryHelper = Objects.requireNonNull(parametrizedQueryHelper);
this.selectAccountQuery = parametrizedQueryHelper.replaceAccountIdPlaceholder(
Expand All @@ -105,7 +106,7 @@ public JdbcApplicationSettings(JdbcClient jdbcClient,
*/
@Override
public Future<Account> getAccountById(String accountId, Timeout timeout) {
return jdbcClient.executeQuery(
return databaseClient.executeQuery(
selectAccountQuery,
Collections.singletonList(accountId),
result -> mapToModelOrError(result, this::toAccount),
Expand All @@ -122,7 +123,7 @@ public Future<Map<String, String>> getCategories(String primaryAdServer, String
* Transforms the first row of {@link RowSet<Row>} to required object or returns null.
* <p>
* Note: mapper should never throws exception in case of using
* {@link org.prebid.server.vertx.jdbc.CircuitBreakerSecuredJdbcClient}.
* {@link CircuitBreakerSecuredDatabaseClient}.
*/
private <T> T mapToModelOrError(RowSet<Row> rowSet, Function<Row, T> mapper) {
final RowIterator<Row> rowIterator = rowSet != null ? rowSet.iterator() : null;
Expand Down Expand Up @@ -197,8 +198,8 @@ public Future<StoredResponseDataResult> getStoredResponses(Set<String> responseI
IntStream.rangeClosed(1, responseIdPlaceholderCount)
.forEach(i -> idsQueryParameters.addAll(responseIds));

return jdbcClient.executeQuery(queryResolvedWithParameters, idsQueryParameters,
result -> JdbcStoredResponseResultMapper.map(result, responseIds), timeout);
return databaseClient.executeQuery(queryResolvedWithParameters, idsQueryParameters,
result -> DatabaseStoredResponseResultMapper.map(result, responseIds), timeout);
}

/**
Expand All @@ -223,8 +224,8 @@ private Future<StoredDataResult> fetchStoredData(String query, String accountId,
requestIds.size(),
impIds.size());

future = jdbcClient.executeQuery(parametrizedQuery, idsQueryParameters,
result -> JdbcStoredDataResultMapper.map(result, accountId, requestIds, impIds),
future = databaseClient.executeQuery(parametrizedQuery, idsQueryParameters,
result -> DatabaseStoredDataResultMapper.map(result, accountId, requestIds, impIds),
timeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.prebid.server.settings.model.StoredDataType;
import org.prebid.server.settings.model.StoredItem;
import org.prebid.server.util.ObjectUtil;
import org.prebid.server.vertx.database.CircuitBreakerSecuredDatabaseClient;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -22,11 +23,11 @@
/**
* Utility class for mapping {@link RowSet<Row>} to {@link StoredDataResult}.
*/
public class JdbcStoredDataResultMapper {
public class DatabaseStoredDataResultMapper {

private static final Logger logger = LoggerFactory.getLogger(JdbcStoredDataResultMapper.class);
private static final Logger logger = LoggerFactory.getLogger(DatabaseStoredDataResultMapper.class);

private JdbcStoredDataResultMapper() {
private DatabaseStoredDataResultMapper() {
}

/**
Expand All @@ -39,7 +40,7 @@ private JdbcStoredDataResultMapper() {
* @return - a {@link StoredDataResult} object
* <p>
* Note: mapper should never throws exception in case of using
* {@link org.prebid.server.vertx.jdbc.CircuitBreakerSecuredJdbcClient}.
* {@link CircuitBreakerSecuredDatabaseClient}.
*/
public static StoredDataResult map(RowSet<Row> rowSet,
String accountId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import java.util.Map;
import java.util.Set;

public class JdbcStoredResponseResultMapper {
public class DatabaseStoredResponseResultMapper {

private JdbcStoredResponseResultMapper() {
private DatabaseStoredResponseResultMapper() {
}

public static StoredResponseDataResult map(RowSet<Row> rowSet, Set<String> responseIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import org.prebid.server.metric.MetricName;
import org.prebid.server.metric.Metrics;
import org.prebid.server.settings.CacheNotificationListener;
import org.prebid.server.settings.helper.JdbcStoredDataResultMapper;
import org.prebid.server.settings.helper.DatabaseStoredDataResultMapper;
import org.prebid.server.settings.model.StoredDataResult;
import org.prebid.server.vertx.Initializable;
import org.prebid.server.vertx.jdbc.JdbcClient;
import org.prebid.server.vertx.database.DatabaseClient;

import java.time.Clock;
import java.time.Instant;
Expand Down Expand Up @@ -42,9 +42,9 @@
* If data is not empty, depending on TYPE, it should be put to corresponding map with ID as a key and DATA as value.
* </p>
*/
public class JdbcPeriodicRefreshService implements Initializable {
public class DatabasePeriodicRefreshService implements Initializable {

private static final Logger logger = LoggerFactory.getLogger(JdbcPeriodicRefreshService.class);
private static final Logger logger = LoggerFactory.getLogger(DatabasePeriodicRefreshService.class);

/**
* Example of initialize query:
Expand All @@ -71,24 +71,24 @@ public class JdbcPeriodicRefreshService implements Initializable {
private final MetricName cacheType;
private final CacheNotificationListener cacheNotificationListener;
private final Vertx vertx;
private final JdbcClient jdbcClient;
private final DatabaseClient databaseClient;
private final TimeoutFactory timeoutFactory;
private final Metrics metrics;
private final Clock clock;

private Instant lastUpdate;

public JdbcPeriodicRefreshService(String initQuery,
String updateQuery,
long refreshPeriod,
long timeout,
MetricName cacheType,
CacheNotificationListener cacheNotificationListener,
Vertx vertx,
JdbcClient jdbcClient,
TimeoutFactory timeoutFactory,
Metrics metrics,
Clock clock) {
public DatabasePeriodicRefreshService(String initQuery,
String updateQuery,
long refreshPeriod,
long timeout,
MetricName cacheType,
CacheNotificationListener cacheNotificationListener,
Vertx vertx,
DatabaseClient databaseClient,
TimeoutFactory timeoutFactory,
Metrics metrics,
Clock clock) {

this.initQuery = Objects.requireNonNull(StringUtils.stripToNull(initQuery));
this.updateQuery = Objects.requireNonNull(StringUtils.stripToNull(updateQuery));
Expand All @@ -97,7 +97,7 @@ public JdbcPeriodicRefreshService(String initQuery,
this.cacheType = Objects.requireNonNull(cacheType);
this.cacheNotificationListener = Objects.requireNonNull(cacheNotificationListener);
this.vertx = Objects.requireNonNull(vertx);
this.jdbcClient = Objects.requireNonNull(jdbcClient);
this.databaseClient = Objects.requireNonNull(databaseClient);
this.timeoutFactory = Objects.requireNonNull(timeoutFactory);
this.metrics = Objects.requireNonNull(metrics);
this.clock = Objects.requireNonNull(clock);
Expand All @@ -115,10 +115,10 @@ public void initialize(Promise<Void> initializePromise) {
private void getAll() {
final long startTime = clock.millis();

jdbcClient.executeQuery(
databaseClient.executeQuery(
initQuery,
Collections.emptyList(),
JdbcStoredDataResultMapper::map,
DatabaseStoredDataResultMapper::map,
createTimeout())
.map(storedDataResult ->
handleResult(storedDataResult, Instant.now(clock), startTime, MetricName.initialize))
Expand All @@ -139,7 +139,7 @@ private Void handleResult(StoredDataResult storedDataResult,
}

private Future<Void> handleFailure(Throwable exception, long startTime, MetricName refreshType) {
logger.warn("Error occurred while request to jdbc refresh service", exception);
logger.warn("Error occurred while request to database refresh service", exception);

metrics.updateSettingsCacheRefreshTime(cacheType, refreshType, clock.millis() - startTime);
metrics.updateSettingsCacheRefreshErrorMetric(cacheType, refreshType);
Expand All @@ -151,10 +151,10 @@ private void refresh() {
final Instant updateTime = Instant.now(clock);
final long startTime = clock.millis();

jdbcClient.executeQuery(
databaseClient.executeQuery(
updateQuery,
Collections.singletonList(Date.from(lastUpdate)),
JdbcStoredDataResultMapper::map,
DatabaseStoredDataResultMapper::map,
createTimeout())
.map(storedDataResult ->
handleResult(invalidate(storedDataResult), updateTime, startTime, MetricName.update))
Expand Down
Loading

0 comments on commit cfb8062

Please sign in to comment.