Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from crain/develop
Browse files Browse the repository at this point in the history
Add null checks for tenant identifier
  • Loading branch information
crain committed Apr 19, 2017
2 parents 0b71ce2 + 25dd7af commit 68b4f0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Expand Up @@ -9,6 +9,11 @@ public class DelegatingTenantContextCallable<V> implements Callable<V> {
private final Callable<V> delegate;
private final String tenantIdentifier;

DelegatingTenantContextCallable(Callable<V> delegate) {
this.delegate = delegate;
this.tenantIdentifier = null;
}

DelegatingTenantContextCallable(final Callable<V> delegate, final String tenantIdentifier) {
super();
this.delegate = delegate;
Expand All @@ -19,7 +24,9 @@ public class DelegatingTenantContextCallable<V> implements Callable<V> {
public V call() throws Exception {
try {
TenantContextHolder.clear();
TenantContextHolder.setIdentifier(this.tenantIdentifier);
if(this.tenantIdentifier != null) {
TenantContextHolder.setIdentifier(this.tenantIdentifier);
}
return this.delegate.call();
} finally {
TenantContextHolder.clear();
Expand Down
Expand Up @@ -41,10 +41,16 @@ public void execute(final Runnable task) {
}

private Runnable wrap(final Runnable task) {
return new DelegatingTenantContextRunnable(task, TenantContextHolder.checkedGetIdentifier());
if(TenantContextHolder.identifier().isPresent()) {
return new DelegatingTenantContextRunnable(task, TenantContextHolder.checkedGetIdentifier());
}
return new DelegatingTenantContextRunnable(task);
}

private <T> Callable<T> wrap(final Callable<T> task) {
return new DelegatingTenantContextCallable<>(task, TenantContextHolder.checkedGetIdentifier());
if(TenantContextHolder.identifier().isPresent()) {
return new DelegatingTenantContextCallable<>(task, TenantContextHolder.checkedGetIdentifier());
}
return new DelegatingTenantContextCallable<>(task);
}
}
Expand Up @@ -7,6 +7,11 @@ public class DelegatingTenantContextRunnable implements Runnable {
private final Runnable delegate;
private final String tenantIdentifier;

DelegatingTenantContextRunnable(final Runnable delegate) {
this.delegate = delegate;
this.tenantIdentifier = null;
}

DelegatingTenantContextRunnable(final Runnable delegate, final String tenantIdentifier) {
super();
this.delegate = delegate;
Expand All @@ -17,7 +22,9 @@ public class DelegatingTenantContextRunnable implements Runnable {
public void run() {
try {
TenantContextHolder.clear();
TenantContextHolder.setIdentifier(this.tenantIdentifier);
if(this.tenantIdentifier != null) {
TenantContextHolder.setIdentifier(this.tenantIdentifier);
}
this.delegate.run();
} finally {
TenantContextHolder.clear();
Expand Down

0 comments on commit 68b4f0c

Please sign in to comment.