Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import io.appform.dropwizard.sharding.metrics.TransactionMetricManager;
import io.appform.dropwizard.sharding.metrics.TransactionMetricObserver;
import io.appform.dropwizard.sharding.observers.TransactionObserver;
import io.appform.dropwizard.sharding.observers.bucket.BucketIdObserver;
import io.appform.dropwizard.sharding.observers.bucket.BucketIdSaver;
import io.appform.dropwizard.sharding.observers.internal.FilteringObserver;
import io.appform.dropwizard.sharding.observers.internal.ListenerTriggeringObserver;
import io.appform.dropwizard.sharding.observers.internal.TerminalTransactionObserver;
Expand All @@ -48,6 +50,7 @@
import io.appform.dropwizard.sharding.sharding.ShardBlacklistingStore;
import io.appform.dropwizard.sharding.sharding.ShardManager;
import io.appform.dropwizard.sharding.sharding.impl.ConsistentHashBucketIdExtractor;
import io.appform.dropwizard.sharding.utils.BucketCalculator;
import io.appform.dropwizard.sharding.utils.ShardCalculator;
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
Expand Down Expand Up @@ -79,7 +82,7 @@
* Base for bundles. This cannot be used by clients. Use one of the derived classes.
*/
@Slf4j
public abstract class DBShardingBundleBase<T extends Configuration> implements ConfiguredBundle<T> {

Check warning on line 85 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Split this “Monster Class” into smaller and more specialized ones to reduce its dependencies on other classes from 21 to the maximum authorized 20 or less.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIo&open=AZ0-BmCCitXswBv5tlIo&pullRequest=97

private static final String DEFAULT_NAMESPACE = "default";
private static final String SHARD_ENV = "db.shards";
Expand Down Expand Up @@ -141,7 +144,7 @@

public List<Class<?>> getInitialisedEntities() {
if(this.initialisedEntities == null){
throw new RuntimeException("DB sharding bundle is not initialised !");

Check warning on line 147 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIp&open=AZ0-BmCCitXswBv5tlIp&pullRequest=97
}
return this.initialisedEntities;
}
Expand Down Expand Up @@ -178,7 +181,7 @@
public void run(T configuration, Environment environment) {
val shardConfigurationListSize = getConfig(configuration).getShards().size();
if (numShards != shardConfigurationListSize) {
throw new RuntimeException(

Check warning on line 184 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIq&open=AZ0-BmCCitXswBv5tlIq&pullRequest=97
"Shard count provided through environment does not match the size of the shard configuration list");
}
sessionFactories = shardBundles.stream().map(HibernateBundle::getSessionFactory).collect(Collectors.toList());
Expand Down Expand Up @@ -227,13 +230,13 @@
hibernateBundle.run(configuration, environment);
} catch (Exception e) {
log.error("Error initializing db sharding bundle", e);
throw new RuntimeException(e);

Check warning on line 233 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIr&open=AZ0-BmCCitXswBv5tlIr&pullRequest=97
}
});
}

@VisibleForTesting
public void initBundles(Bootstrap bootstrap) {

Check warning on line 239 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Provide the parametrized type for this generic.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIs&open=AZ0-BmCCitXswBv5tlIs&pullRequest=97
shardBundles.forEach(hibernameBundle -> initialize(bootstrap));
}

Expand All @@ -253,10 +256,14 @@
}

private ShardingBundleOptions getShardingOptions(T configuration) {
val shardingOptions = getConfig(configuration).getShardingOptions();

Check warning on line 259 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "shardingOptions" which hides the field declared at line 100.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIy&open=AZ0-BmCCitXswBv5tlIy&pullRequest=97
return Objects.nonNull(shardingOptions) ? shardingOptions : new ShardingBundleOptions();
}

public BucketCalculator<String> bucketCalculator() {
return new BucketCalculator<>(new ConsistentHashBucketIdExtractor<>(this.shardManager));
}

public <EntityType, T extends Configuration>
LookupDao<EntityType> createParentObjectDao(Class<EntityType> clazz) {
return new LookupDao<>(this.sessionFactories, clazz,
Expand Down Expand Up @@ -293,7 +300,7 @@
rootObserver);
}

public <EntityType, T extends Configuration>

Check warning on line 303 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "T" which hides a type parameter from the outer scope.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIt&open=AZ0-BmCCitXswBv5tlIt&pullRequest=97

Check warning on line 303 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

T is not used in the method.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIz&open=AZ0-BmCCitXswBv5tlIz&pullRequest=97

Check warning on line 303 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI0&open=AZ0-BmCCitXswBv5tlI0&pullRequest=97
CacheableLookupDao<EntityType> createParentObjectDao(
Class<EntityType> clazz,
BucketIdExtractor<String> bucketIdExtractor,
Expand All @@ -308,7 +315,7 @@
}


public <EntityType, T extends Configuration>

Check warning on line 318 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI2&open=AZ0-BmCCitXswBv5tlI2&pullRequest=97

Check warning on line 318 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "T" which hides a type parameter from the outer scope.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIu&open=AZ0-BmCCitXswBv5tlIu&pullRequest=97

Check warning on line 318 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

T is not used in the method.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI1&open=AZ0-BmCCitXswBv5tlI1&pullRequest=97
RelationalDao<EntityType> createRelatedObjectDao(Class<EntityType> clazz) {
return new RelationalDao<>(this.sessionFactories, clazz,
new ShardCalculator<>(this.shardManager,
Expand All @@ -334,7 +341,7 @@
}


public <EntityType, T extends Configuration>

Check warning on line 344 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI4&open=AZ0-BmCCitXswBv5tlI4&pullRequest=97

Check warning on line 344 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

T is not used in the method.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI3&open=AZ0-BmCCitXswBv5tlI3&pullRequest=97

Check warning on line 344 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "T" which hides a type parameter from the outer scope.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIv&open=AZ0-BmCCitXswBv5tlIv&pullRequest=97
RelationalDao<EntityType> createRelatedObjectDao(
Class<EntityType> clazz,
BucketIdExtractor<String> bucketIdExtractor) {
Expand All @@ -346,7 +353,7 @@
rootObserver);
}

public <EntityType, T extends Configuration>

Check warning on line 356 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "T" which hides a type parameter from the outer scope.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIw&open=AZ0-BmCCitXswBv5tlIw&pullRequest=97

Check warning on line 356 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

T is not used in the method.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI5&open=AZ0-BmCCitXswBv5tlI5&pullRequest=97

Check warning on line 356 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI6&open=AZ0-BmCCitXswBv5tlI6&pullRequest=97
CacheableRelationalDao<EntityType> createRelatedObjectDao(
Class<EntityType> clazz,
BucketIdExtractor<String> bucketIdExtractor,
Expand All @@ -369,7 +376,7 @@
new ConsistentHashBucketIdExtractor<>(this.shardManager)));
}

public <EntityType, DaoType extends AbstractDAO<EntityType>, T extends Configuration>

Check warning on line 379 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI8&open=AZ0-BmCCitXswBv5tlI8&pullRequest=97

Check warning on line 379 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this generic name to match the regular expression '^[A-Z][0-9]?$'.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI9&open=AZ0-BmCCitXswBv5tlI9&pullRequest=97

Check warning on line 379 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename "T" which hides a type parameter from the outer scope.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlIx&open=AZ0-BmCCitXswBv5tlIx&pullRequest=97

Check warning on line 379 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

T is not used in the method.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI7&open=AZ0-BmCCitXswBv5tlI7&pullRequest=97
WrapperDao<EntityType, DaoType> createWrapperDao(
Class<DaoType> daoTypeClass,
BucketIdExtractor<String> bucketIdExtractor) {
Expand Down Expand Up @@ -400,6 +407,7 @@
}
this.rootObserver = observer.setNext(rootObserver);
}
rootObserver = new BucketIdObserver(new BucketIdSaver(bucketCalculator()));
rootObserver = new TransactionMetricObserver(new TransactionMetricManager(getMetricConfig(config),
metricRegistry)).setNext(rootObserver);
rootObserver = new FilteringObserver(rootObserver).addFilters(filters);
Expand All @@ -408,11 +416,11 @@
log.debug("Observer chain");
rootObserver.visit(observer -> {
log.debug(" Observer: {}", observer.getClass().getSimpleName());
if (observer instanceof FilteringObserver) {

Check warning on line 419 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof FilteringObserver filteringobserver'

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI-&open=AZ0-BmCCitXswBv5tlI-&pullRequest=97
log.debug(" Filters:");
((FilteringObserver) observer).getFilters().forEach(filter -> log.debug(" - {}", filter.getClass().getSimpleName()));
}
if (observer instanceof ListenerTriggeringObserver) {

Check warning on line 423 in src/main/java/io/appform/dropwizard/sharding/DBShardingBundleBase.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this instanceof check and cast with 'instanceof ListenerTriggeringObserver listenertriggeringobserver'

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-BmCCitXswBv5tlI_&open=AZ0-BmCCitXswBv5tlI_&pullRequest=97
log.debug(" Listeners:");
((ListenerTriggeringObserver) observer).getListeners().forEach(filter -> log.debug(" - {}", filter.getClass().getSimpleName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@

<T, R> P visit(Get<T, R> opContext);

<T> P visit(GetAndUpdate<T> opContext);
<T> P visit(GetAndUpdate<T> opContext) throws Exception;

Check warning on line 36 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIb&open=AZ0-Bl9gitXswBv5tlIb&pullRequest=97

<T, R> P visit(GetByLookupKey<T, R> opContext);

<T> P visit(GetAndUpdateByLookupKey<T> opContext);
<T> P visit(GetAndUpdateByLookupKey<T> opContext) throws Exception;

Check warning on line 40 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIc&open=AZ0-Bl9gitXswBv5tlIc&pullRequest=97

<T> P visit(ReadOnlyForLookupDao<T> opContext);

<T> P visit(ReadOnlyForRelationalDao<T> opContext);

<T> P visit(LockAndExecute<T> opContext);
<T> P visit(LockAndExecute<T> opContext) throws Exception;

Check warning on line 46 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlId&open=AZ0-Bl9gitXswBv5tlId&pullRequest=97

P visit(UpdateByQuery opContext);
P visit(UpdateByQuery opContext) throws Exception;

Check warning on line 48 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIe&open=AZ0-Bl9gitXswBv5tlIe&pullRequest=97

<T> P visit(UpdateWithScroll<T> opContext);
<T> P visit(UpdateWithScroll<T> opContext) throws Exception;

Check warning on line 50 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIf&open=AZ0-Bl9gitXswBv5tlIf&pullRequest=97

<T> P visit(UpdateAll<T> opContext);
<T> P visit(UpdateAll<T> opContext) throws Exception;

Check warning on line 52 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIg&open=AZ0-Bl9gitXswBv5tlIg&pullRequest=97

<T> P visit(SelectAndUpdate<T> opContext);
<T> P visit(SelectAndUpdate<T> opContext) throws Exception;

Check warning on line 54 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIh&open=AZ0-Bl9gitXswBv5tlIh&pullRequest=97

<T> P visit(RunInSession<T> opContext);

<T> P visit(RunWithCriteria<T> opContext);

P visit(DeleteByLookupKey opContext);

<U, V> P visit(Save<U, V> opContext);
<U, V> P visit(Save<U, V> opContext) throws Exception;

Check warning on line 62 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIi&open=AZ0-Bl9gitXswBv5tlIi&pullRequest=97

<T> P visit(SaveAll<T> opContext);
<T> P visit(SaveAll<T> opContext) throws Exception;

Check warning on line 64 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIj&open=AZ0-Bl9gitXswBv5tlIj&pullRequest=97

<T> P visit(CreateOrUpdateByLookupKey<T> opContext);
<T> P visit(CreateOrUpdateByLookupKey<T> opContext) throws Exception;

Check warning on line 66 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIk&open=AZ0-Bl9gitXswBv5tlIk&pullRequest=97

<T> P visit(CreateOrUpdate<T> opContext);
<T> P visit(CreateOrUpdate<T> opContext) throws Exception;

Check warning on line 68 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIl&open=AZ0-Bl9gitXswBv5tlIl&pullRequest=97

<T, U> P visit(CreateOrUpdateInLockedContext<T, U> opContext);
<T, U> P visit(CreateOrUpdateInLockedContext<T, U> opContext) throws Exception;

Check warning on line 70 in src/main/java/io/appform/dropwizard/sharding/dao/operations/OpContext.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=santanusinha_dropwizard-db-sharding-bundle&issues=AZ0-Bl9gitXswBv5tlIm&open=AZ0-Bl9gitXswBv5tlIm&pullRequest=97

<T, R> P visit(Select<T, R> opContext);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.appform.dropwizard.sharding.observers.bucket;

import io.appform.dropwizard.sharding.execution.TransactionExecutionContext;
import io.appform.dropwizard.sharding.observers.TransactionObserver;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;

@Slf4j
public class BucketIdObserver extends TransactionObserver {
private BucketIdSaver bucketIdSaver;
private volatile boolean initDone;

public BucketIdObserver(BucketIdSaver bucketIdSaver) {
super(null);
this.bucketIdSaver = bucketIdSaver;
log.info("BucketId observer constructor called ");
}
public void init(BucketIdSaver bucketIdSaver) {
this.bucketIdSaver = bucketIdSaver;
this.initDone = true;
log.info("BucketId observer initialisation completed ");
}

@Override
public <T> T execute(TransactionExecutionContext context, Supplier<T> supplier) {
context.getOpContext().visit(this.bucketIdSaver);
return proceed(context, supplier);
}

}
Loading