Java EE 6中的多租户支持 [英] Multi tenancy support in Java EE 6

查看:129
本文介绍了Java EE 6中的多租户支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的Java EE 6应用程序(部署在Glassfish v 3.1中),并希望支持多个租户。我目前在我的应用程序中使用的技术/ API是

I have an existing Java EE 6 application (deployed in Glassfish v 3.1) and want to support multiple tenants. Technologies/APIs I'm currently using in my app are


  • EJB(包括EJB计时器服务)

  • JPA 2.0(EclipseLink)

  • JSF 2.0

  • JMS

  • JAX-RS

  • 我打算也使用CDI

  • EJB (including the EJB timer service)
  • JPA 2.0 (EclipseLink)
  • JSF 2.0
  • JMS
  • JAX-RS
  • I plan to use CDI as well

据我所知,增加多租户支持影响只有持久层。我的问题:有人之前做过这个吗?转换应用程序的步骤是什么?这会影响除持久性以外的其他层吗?

As far as I know, adding multi-tenancy support affects only the persistence layer. My question: Has anybody done this before? What are the steps to convert the application? Will this affect other layers other than persistence?

将有大量租户,因此,所有数据都将驻留在同一个数据库架构中。

There will be a high number of tenants, therefore, all data will reside in the same DB schema.

推荐答案

持久层



从持久层开始。完成后,向上滚动您的架构。

Persistence Layer

Start with the persistence layer. Roll upwards through your architecture once you have that done.

您提议的架构将具有标识租户的ID(例如TenantId)。每个表都有此ID。在所有查询中,您必须确保TenantId与登录用户的TenantId匹配。

The Schema that you are proposing would have an ID that identifies the tenant (eg. TenantId). Each table would have this ID. In all of your queries you would have to ensure that the TenantId matches the logged in User's TenantId.

这样做的难点在于它是一个非常手动的过程。

The difficulty with this is that it is a very manual process.

如果你使用Hibernate作为JPA提供者,那么有一些工具可以帮助解决这个问题。即 Hibernate过滤器

If you go with Hibernate as your JPA provider then there are some tools that will help with this; namely Hibernate Filters.

这些通常用于限制多租户架构的访问(参见这里这里还有更多内容

These are commonly used to restrict access on multi-tenant Schemas (see here and here for some more)

我没有使用过EclipseLink但看起来确实如此也对多租户提供了很好的支持。 DiscriminatorColumn看起来与Hibernate Filters非常相似。

I haven't used EclipseLink but it does look like it has good support for Multi-Tenancy as well. The DiscriminatorColumn looks like a very similar concept to Hibernate Filters.

我认为你是将JAX-RS和JMS用于服务层。如果是这样,那么你还需要考虑如何通过tenantId和验证您的租户。您如何阻止一个租户访问另一个租户的REST服务? JMS也是如此。

I assume that you're using JAX-RS and JMS for a Service Layer. If so then you will also need to think about how you are going to pass the tenantId around and authenticate your Tenants. How are you going to prevent one tenant from accessing the REST service of another? Same thing for JMS.

您将不得不在UI中连接登录到Bean(Hibernate或Eclipselink)为过滤器/鉴别器设置TenantId。

You are going to have to hook up your login in your UI to a Bean (Hibernate or Eclipselink) that sets the TenantId for the Filter/Discriminator.

这篇关于Java EE 6中的多租户支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆