Skip to content

Commit

Permalink
uf
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamv108 committed Sep 7, 2023
1 parent 5a53a07 commit 28fee0f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ run-test:
migrations:

format:
./gradlew googleJavaFormat
./gradlew verifyGoogleJavaFormat

install:
./gradlew format

install: setup

clean:
clear
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package code.shubham.commons.annotations;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(java.lang.annotation.ElementType.TYPE)
@SpringBootApplication
@ComponentScan("code.shubham")
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public @interface SpringBootJpaApplication {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package code.shubham.commons.contexts;

public class RequestContextHolder {

private static final ThreadLocal<java.util.Map<String, Object>> requestContext = getNew();

private static ThreadLocal<java.util.Map<String, Object>> getNew() {
ThreadLocal<java.util.Map<String, Object>> requestContext = new ThreadLocal<>();
requestContext.set(new java.util.LinkedHashMap<>());
return requestContext;
}

public static void set(String key, Object value) {
requestContext.get().put(key, value);
}

public static Object get(String key) {
return requestContext.get().get(key);
}

public static void clear() {
requestContext.remove();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package code.shubham.commons.contexts;

public class TenantContextHolder {

private static final ThreadLocal<String> CURRENT_TENANT = new ThreadLocal<>();

public static void setTenant(String userId) {
CURRENT_TENANT.set(userId);
}

public static String getTenant() {
return CURRENT_TENANT.get();
}

public static void clear() {
CURRENT_TENANT.remove();
}

}
19 changes: 19 additions & 0 deletions src/main/java/code/shubham/commons/contexts/UserContextHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package code.shubham.commons.contexts;

public class UserContextHolder {

private static final ThreadLocal<Integer> CURRENT_USER = new ThreadLocal<>();

public static void setUserId(Integer userId) {
CURRENT_USER.set(userId);
}

public static Integer getUserId() {
return CURRENT_USER.get();
}

public static void clear() {
CURRENT_USER.remove();
}

}

0 comments on commit 28fee0f

Please sign in to comment.