在游戏框架中的动态名称Database
我正在运行一个Java Play Framework设置,我希望在其中根据客户打电话来拥有多个数据库。我有一个JWT设置,那里有一个房客ID。但是,我无法掌握有关此最佳练习的头脑。到目前为止,我有这样的代码:
public class JavaNamedDatabase {
private Database db;
private DatabaseExecutionContext executionContext;
private static final Logger.ALogger LOGGER = Logger.of(JavaNamedDatabase.class);
@Inject
public JavaNamedDatabase(
@NamedDatabase("xxx") Database db, DatabaseExecutionContext executionContext) {
this.db = db;
this.executionContext = executionContext;
}
我想在哪里进行“ xxx”动态,具体取决于租户的要求。 是否可以传递此参数,还是我需要分开的类?
也许最好的解决方案是只要每个客户运行一个实例,并将@namedDatabase作为运行时配置参数?
I'm running a java play framework setup where I would like to have several databases depending on what customer is making the call. I have a jwt setup where there is a tenant id. However I can't get my head around what's best practise in Play regarding this. As for now I have this code:
public class JavaNamedDatabase {
private Database db;
private DatabaseExecutionContext executionContext;
private static final Logger.ALogger LOGGER = Logger.of(JavaNamedDatabase.class);
@Inject
public JavaNamedDatabase(
@NamedDatabase("xxx") Database db, DatabaseExecutionContext executionContext) {
this.db = db;
this.executionContext = executionContext;
}
where I would like to make "xxx" dynamic depending on which tenant is making the request.
Is it possible to pass this parameter or do I need to have separate classes?
Or maybe the best solution is just to have one instance running per customer and have the @NamedDatabase as a runtime config parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了DBAPI,那里有一个数据库。
I found DBApi where there is a getter for Database.