-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a53a07
commit 28fee0f
Showing
5 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/code/shubham/commons/annotations/SpringBootJpaApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/code/shubham/commons/contexts/RequestContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/code/shubham/commons/contexts/TenantContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/main/java/code/shubham/commons/contexts/UserContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |