Skip to content

Commit bd22bf9

Browse files
author
Gerald Unterrainer
committed
trying to make builder-api for tenant mechanism
1 parent abcc995 commit bd22bf9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/info/unterrainer/commons/httpserver/GenericHandlerGroup.java

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public class GenericHandlerGroup<P extends BasicJpa, J extends BasicJson, E> imp
4646
private final LinkedHashMap<Endpoint, Role[]> accessRoles;
4747
private final ExecutorService executorService;
4848
private final HandlerUtils hu = new HandlerUtils();
49+
private final String tenantIdRowName;
50+
private final BasicDao<? extends BasicJpa, E> tenantDao;
51+
private final Class<? extends BasicJpa> tenantJpaType;
52+
private final String fieldRowName;
53+
private final String tenantRowName;
4954

5055
@Override
5156
public void addHandlers(final HttpServer server) {

src/main/java/info/unterrainer/commons/httpserver/GenericHandlerGroupBuilder.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class GenericHandlerGroupBuilder<P extends BasicJpa, J extends BasicJson,
3939
private List<GetListInterceptor> getListInterceptors = new ArrayList<>();
4040
private ExecutorService executorService;
4141

42+
private String tenantIdRowName;
43+
private String tenantRowName;
44+
private String tenantFieldRowName;
45+
private BasicDao<? extends BasicJpa, E> tenantDao;
46+
private Class<? extends BasicJpa> tenantJpaType;
47+
4248
HandlerExtensions<P, J, E> extensions = new HandlerExtensions<>();
4349
private LinkedHashMap<Endpoint, Role[]> accessRoles = new LinkedHashMap<>();
4450

@@ -51,7 +57,8 @@ public HttpServer add() {
5157
executorService = server.executorService;
5258
GenericHandlerGroup<P, J, E> handlerGroupInstance = new GenericHandlerGroup<>(dao, jpaType, jsonType,
5359
daoTransactionManager, jsonMapper, orikaFactory.getMapperFacade(), path, endpoints, getListInterceptors,
54-
extensions, accessRoles, executorService);
60+
extensions, accessRoles, executorService, tenantIdRowName, tenantDao, tenantJpaType, tenantFieldRowName,
61+
tenantRowName);
5562
server.addHandlerGroup(handlerGroupInstance);
5663
return server;
5764
}
@@ -65,6 +72,21 @@ public GenericHandlerGroupBuilder<P, J, E> addRoleFor(final Endpoint endpoint, f
6572
return this;
6673
}
6774

75+
public GenericHandlerGroupBuilder<P, J, E> isMultiTenantEnabledByIdRow(final String tenantIdRowName) {
76+
this.tenantIdRowName = tenantIdRowName;
77+
return this;
78+
}
79+
80+
public <TP extends BasicJpa> GenericHandlerGroupBuilder<P, J, E> isMultiTenantEnabledByTable(
81+
final BasicDao<TP, E> tenantDao, final Class<TP> tenantJpaType, final String fieldRowName,
82+
final String tenantRowName) {
83+
this.tenantDao = tenantDao;
84+
this.tenantJpaType = tenantJpaType;
85+
this.tenantFieldRowName = fieldRowName;
86+
this.tenantRowName = tenantRowName;
87+
return this;
88+
}
89+
6890
public GenericHandlerGroupBuilder<P, J, E> dao(final BasicDao<P, E> dao) {
6991
this.dao = dao;
7092
return this;

0 commit comments

Comments
 (0)