SlideShare a Scribd company logo
1 of 37
Download to read offline
Supporting Multi-tenancy 
Applications with Java EE 
Rodrigo Cândido da Silva 
@rcandidosilva 
JavaOne 2014 
CON4959
About Me 
• Brazilian guy ;) 
• Work for Integritas company 
• http://integritastech.com 
• Software Architect 
• Java Platform 
• JUG Leader of GUJavaSC 
• http://gujavasc.org 
• Twitter 
• @rcandidosilva 
• Personal 
• http://rodrigocandido.me
Agenda 
• Cloud Services Model 
• SaaS Market 
• Multi-tenancy 
• Challenges 
• Pros and Cons 
• Strategy Types 
• Java EE + Multi-tenancy 
• Multi-tenancy at Cloud
Cloud Services Model
SaaS Market
Multi-tenancy 
• One application 
instance to multiple 
clients (tenant) 
• Inverse of the multiple 
instances architecture
Multi-instances vs. Multi-tenant
Multi-instances vs. Multi-tenant 
Feature Multi-instances Multi-tenant 
Cost Structure Can support only tiered or 
flat pricing 
Supports usage based pricing 
as well as tiered or flat 
Resources Dedicated resources Shared resources 
Operation and 
Maintenance 
Manage and administer 
as many instances as 
customers 
Manager and administer a 
single instance for a number 
of customers 
Scalable Model Not scalable. As the 
number of customers 
increase the maintenance 
requirements increase 
proporcionally 
Scalable, since a number of 
customers are serviced by 
one instance
Cloud != Multi-tenancy
Challenges 
• Data separation 
• UI and business rules customization 
• Access control by tenant 
• Resource provisioning 
• Integration 
• Application update 
• Failover tolerance
Pros and Cons 
• Pros 
• Low maintenance cost 
• Same source code for all customers 
• High scalability 
• Sharing resources between customers 
• Cons 
• High complexity 
• Separation by tenant-id 
• More failure risks 
• If code breaks -> breaks to all customers 
• Low flexibility available to the customers
Multi-tenancy 
• Adoption levels 
• Level 1 (Customized) 
• [N] applications and [N] databases 
• Level 2 (Configurable) 
• [1] application and [N] databases 
• Level 3 (Scalable) 
• [1] application and [1] database
Level 1 - Customized 
• [N] applications and [N] databases
Level 2 - Configurable 
• [1] application and [N] databases
Level 3 - Scalable 
• [1] application and [1] database
What is the Best Choice? 
• Depends on… 
• Data Customization 
• Addition or removal of columns in the data store 
• Function Customization 
• The functionality executed for a specific business can vary by 
customers 
• Process Customization 
• The business process can vary for each customer 
• Licensing Features 
• The product has multiple licenses which define the functionality 
that is enabled for the customer
Database Strategy 
Separate Databases 
Separate Tables 
Shared Database
Database Strategy 
Feature Separate DBs Separate Tables Shared Database 
Data 
Customization 
Security 
Inter-dependency 
and Performance 
Scalable Model 
Customer On-boarding
Java EE + Multi-tenancy 
• Database 
• JPA + Multi-tenancy 
• UI Customization 
• JSF + Multi-tenancy 
• Java EE 8 with Cloud support
JPA + Multi-tenancy 
• There is no standard at this time 
• EclipseLink 
• Multi-tenancy support using @Multitenant 
• Multitenant strategies 
• @Multitenant(SINGLE_TABLE) – default 
• @Multitenant(TABLE_PER_TENANT) 
• @Multitenant(VPD) 
• Hibernate 
• Supports tenant identifier features 
• MultiTenantConnectionProvider 
• CurrentTenantIdentifierResolver
EclipseLink SINGLE_TABLE 
@Entity 
@Table(name=“EMP”) 
@Multitenant(SINGLE_TABLE) 
@TenantDiscriminatorColumn(name = “TENANT_ID”, 
contextProperty = “tenant-id”) 
public class Employee { 
... 
} 
HashMap properties = new HashMap(); 
properties.put("tenant.id", "707"); 
... 
EntityManager em = Persistence 
.createEntityManagerFactory( 
"multi-tenant”,properties) 
.createEntityManager(); 
<persistence-unit name="multi-tenant"> 
... 
<properties> 
<property name="tenant.id" 
value="707"/> 
... 
</properties> 
</persistence-unit>
EclipseLink TABLE_PER_TENANT 
<entity class="Employee"> 
<multitenant type="TABLE_PER_TENANT"> 
<tenant-table-discriminator type="SCHEMA" context-property=" 
eclipselink.tenant-id"/> 
</multitenant> 
<table name="EMP"> 
... 
</entity> 
@Entity 
@Table(name=“EMP”) 
@Multitenant(TABLE_PER_TENANT) 
@TenantTableDiscriminator(type=SCHEMA, 
contextProperty="eclipselink.tenant-id") 
public class Employee { 
... 
}
EclipseLink VPD 
@Entity 
@Multitenant 
@TenantDiscriminatorColumn(name = "USER_ID", 
contextProperty = "tenant.id") 
@Cacheable(false) 
public class Task implements Serializable { 
... 
CALL DBMS_RLS.ADD_POLICY 
('SCOTT', 'TASK', 'todo_list_policy', 
'SCOTT', 'ident_func', 'select, update, 
delete')); 
<properties> 
<property name="eclipselink.session.customizer" 
value="example.VPDSessionCustomizer" /> 
<property name="eclipselink.session-event-listener" 
value="example.VPDSessionEventAdapter" /> 
<property 
name="eclipselink.jdbc.exclusive-connection.mode" 
value="Always" /> 
</properties>
Hibernate MultiTenantConnectionProvider 
public class MultiTenantProvider 
implements MultiTenantConnectionProvider { 
public Connection getConnection(String tenantIdentifier) throws 
SQLException { 
final Connection connection = getAnyConnection(); 
connection.createStatement().execute( 
"SET SCHEMA '" + tenantIdentifier + "'"); 
return connection; 
} 
public void releaseConnection(String tenantIdentifier, Connection 
connection) throws SQLException { 
releaseAnyConnection(connection); 
} 
}
Hibernate CurrentTenantIdentifierResolver 
public class SchemaResolver implements 
CurrentTenantIdentifierResolver { 
@Override 
public String resolveCurrentTenantIdentifier() { 
return resolveTenant(); 
} 
@Override 
public boolean validateExistingCurrentSessions() { 
return false; 
} 
}
Hibernate persistence.xml 
<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/ 
persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http:// 
java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
<persistence-unit name="default"> 
<properties> 
<property name="javax.persistence.provider" 
value="org.hibernate.ejb.HibernatePersistence" /> 
<property name="hibernate.multiTenancy" value="SCHEMA"/> 
<property name="hibernate.tenant_identifier_resolver" 
value="yourpackage.SchemaResolver"/> 
<property name="hibernate.multi_tenant_connection_provider" 
value="yourpackage.MultiTenantProvider"/> 
</properties> 
</persistence-unit> 
</persistence>
JPA Caching 
• Shared Cache disabled
JPA Caching 
• Shared Cache by tenant
JSF + Multi-tenancy 
• Flexible software architecture 
• Artifacts packaged in separated JAR’s 
• Composition at runtime 
• Templates and contracts 
• Resource library 
• Look-and-feel customization 
• RenderKit features 
• Localization support
JSF Facelets 
The Facelets Gazette 
Site 
Navigation 
●Events 
●Docs 
●Forums 
About Contact Site Map 
Template File name 
_template.html 
Insertion points 
Resources 
css classes, scripts, images
JSF Multi-templating 
• Resource Library Contracts 
• Convention 
• All available contracts discovered at startup 
• Configuration 
• faces-config.xml by <resource-library-contract> 
• contracts attribute in <f:view> 
<web-app-root>/contracts 
contractA 
contractB 
• Declared Templates 
• Declared Insertion contractC 
Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
JAR files in WEB-INF/lib 
contractD 
contractE 
• Declared Templates 
• Declared Insertion contractF 
Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources
JSF Multi-templating 
<web-app-root>/contracts 
contractA 
contractB 
• Declared Templates 
• Declared Insertion contractC 
Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
JAR files in WEB-INF/lib 
contractD 
contractE 
• Declared Templates 
• Declared Insertion contractF 
Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
• Declared Templates 
• Declared Insertion Points 
• Declared Resources 
Set of available contracts 
Facelet 1 
<f:view contracts="contractA"> 
... 
faces-config.xml 
Facelet 2 Facelet 3
JSF Multi-templating 
<html xmlns="http://www.w3.org/1999/xhtml” 
xmlns:h="http://java.sun.com/jsf/html” 
xmlns:ui="http://java.sun.com/jsf/ 
facelets"> 
<body> 
<ui:composition template="#{template}”> 
... 
</ui:composition> 
</body> 
</html> 
<?xml version="1.0" encoding="UTF-8"?> 
<web-app> 
<context-param> 
<param-name>javax.faces.view.TEMPLATE</param-name> 
<param-value>mybusiness</param-value> 
</context-param> 
</web-app>
Demo 
• EclipseLink MySports Demo 
• http://wiki.eclipse.org/EclipseLink/Examples/MySports 
• http://git.eclipse.org/c/eclipselink/examples.git
Questions 
?
References 
• http://msdn.microsoft.com/en-us/library/aa479086.aspx 
• https://developers.google.com/appengine/docs/java/multitenancy/ 
• http://www.ibm.com/developerworks/java/library/j-multitenant-java/index.html 
• http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_multitenant.htm 
• http://2012.con-fess.com/sessions/-/details/122/JSF-and-JavaEE-7-for-multi-tenant-applications 
• http://jdevelopment.nl/jsf-22/ 
• http://picketlink.org 
• https://developers.google.com/appengine/docs/java/multitenancy/ 
• http://www.jboss.org/quickstarts/picketlink/picketlink-authentication-idm-multi-tenancy/ 
• http://wiki.eclipse.org/EclipseLink/Examples/MySports
Thank you! 
@rcandidosilva 
rodrigocandido.me

More Related Content

What's hot

What's hot (20)

Introduction to soa suite 12c in 20 slides
Introduction to soa suite 12c in 20 slidesIntroduction to soa suite 12c in 20 slides
Introduction to soa suite 12c in 20 slides
 
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
 
Hyvä: Compatibility Modules
Hyvä: Compatibility ModulesHyvä: Compatibility Modules
Hyvä: Compatibility Modules
 
Microservices and docker
Microservices and dockerMicroservices and docker
Microservices and docker
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Event Storming and Saga
Event Storming and SagaEvent Storming and Saga
Event Storming and Saga
 
Systems Integration in the Cloud Era with Apache Camel @ ApacheCon Europe 2012
Systems Integration in the Cloud Era with Apache Camel @ ApacheCon Europe 2012Systems Integration in the Cloud Era with Apache Camel @ ApacheCon Europe 2012
Systems Integration in the Cloud Era with Apache Camel @ ApacheCon Europe 2012
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Introduction to Domain Driven Design
Introduction to Domain Driven DesignIntroduction to Domain Driven Design
Introduction to Domain Driven Design
 
Work shop eventstorming
Work shop  eventstormingWork shop  eventstorming
Work shop eventstorming
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Live cache support guide
Live cache support guideLive cache support guide
Live cache support guide
 
Badis
Badis Badis
Badis
 
Migrate Custom data/object in SAP S/4 HANA
Migrate Custom data/object in SAP S/4 HANA Migrate Custom data/object in SAP S/4 HANA
Migrate Custom data/object in SAP S/4 HANA
 
Django In The Real World
Django In The Real WorldDjango In The Real World
Django In The Real World
 
Shaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patternsShaping serverless architecture with domain driven design patterns
Shaping serverless architecture with domain driven design patterns
 
Sap abap material
Sap abap materialSap abap material
Sap abap material
 
Mirth Connect - Informations.pptx
Mirth Connect - Informations.pptxMirth Connect - Informations.pptx
Mirth Connect - Informations.pptx
 
Ground-Cloud-Cloud-Ground - NAB 2022 IP Showcase
Ground-Cloud-Cloud-Ground - NAB 2022 IP ShowcaseGround-Cloud-Cloud-Ground - NAB 2022 IP Showcase
Ground-Cloud-Cloud-Ground - NAB 2022 IP Showcase
 
SAP ABAP OVERVIEW
SAP ABAP OVERVIEWSAP ABAP OVERVIEW
SAP ABAP OVERVIEW
 

Viewers also liked

How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
Stephan Hochdörfer
 
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
mfrancis
 
How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11
Stephan Hochdörfer
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
Stephan Hochdörfer
 
Cloudproject
CloudprojectCloudproject
Cloudproject
anushv24
 

Viewers also liked (20)

Multi-tenancy in Java
Multi-tenancy in JavaMulti-tenancy in Java
Multi-tenancy in Java
 
Multi-Tenancy with Spring Boot
Multi-Tenancy with Spring Boot Multi-Tenancy with Spring Boot
Multi-Tenancy with Spring Boot
 
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EEConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
ConFoo 2015 - Supporting Multi-tenancy Applications with Java EE
 
How to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring EditionHow to build customizable multitenant web applications - IPC11 Spring Edition
How to build customizable multitenant web applications - IPC11 Spring Edition
 
Multi-Tenant Approach
Multi-Tenant ApproachMulti-Tenant Approach
Multi-Tenant Approach
 
Suportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EESuportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EE
 
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
Building Multi-Tenant and SaaS products in PHP - CloudConf 2015
 
Multi Tenancy In The Cloud
Multi Tenancy In The CloudMulti Tenancy In The Cloud
Multi Tenancy In The Cloud
 
A Multi-tenant Architecture for Business Process Executions
A Multi-tenant Architecture for Business Process ExecutionsA Multi-tenant Architecture for Business Process Executions
A Multi-tenant Architecture for Business Process Executions
 
JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)
 
Multi-tenancy in the cloud
Multi-tenancy in the cloudMulti-tenancy in the cloud
Multi-tenancy in the cloud
 
Porque você deveria usar CDI nos seus projetos Java! - JavaOne LA 2012 - Sérg...
Porque você deveria usar CDI nos seus projetos Java! - JavaOne LA 2012 - Sérg...Porque você deveria usar CDI nos seus projetos Java! - JavaOne LA 2012 - Sérg...
Porque você deveria usar CDI nos seus projetos Java! - JavaOne LA 2012 - Sérg...
 
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
OSGi Technology Based Product-Service Packages for Multi-tenant-Mudwelling Re...
 
How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
Java EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasJava EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e Mudanças
 
Cloudproject
CloudprojectCloudproject
Cloudproject
 
OpenStack London Meetup, 18 Nov 2015
OpenStack London Meetup, 18 Nov 2015OpenStack London Meetup, 18 Nov 2015
OpenStack London Meetup, 18 Nov 2015
 
Padrões de UI - Blank Slate
Padrões de UI - Blank SlatePadrões de UI - Blank Slate
Padrões de UI - Blank Slate
 
DevOps - Higor Nucci
DevOps - Higor NucciDevOps - Higor Nucci
DevOps - Higor Nucci
 

Similar to JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE

C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
cummings49
 
SaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloudSaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloud
uEngine Solutions
 
Android webinar class_5
Android webinar class_5Android webinar class_5
Android webinar class_5
Edureka!
 

Similar to JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE (20)

Angular js firebase-preso
Angular js firebase-presoAngular js firebase-preso
Angular js firebase-preso
 
Frame - Feature Management for Productive Machine Learning
Frame - Feature Management for Productive Machine LearningFrame - Feature Management for Productive Machine Learning
Frame - Feature Management for Productive Machine Learning
 
Building multi tenancy enterprise applications - quick
Building multi tenancy enterprise applications - quickBuilding multi tenancy enterprise applications - quick
Building multi tenancy enterprise applications - quick
 
One App, Many Clients: Converting an APEX Application to Multi-Tenant
One App, Many Clients: Converting an APEX Application to Multi-TenantOne App, Many Clients: Converting an APEX Application to Multi-Tenant
One App, Many Clients: Converting an APEX Application to Multi-Tenant
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
SaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloudSaaS transformation with OCE - uEngineCloud
SaaS transformation with OCE - uEngineCloud
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
 
CloudDesignPatterns
CloudDesignPatternsCloudDesignPatterns
CloudDesignPatterns
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
 
Designing For Multicloud, CF Summit Frankfurt 2016
Designing For Multicloud, CF Summit Frankfurt 2016Designing For Multicloud, CF Summit Frankfurt 2016
Designing For Multicloud, CF Summit Frankfurt 2016
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
Liquibase – a time machine for your data
Liquibase – a time machine for your dataLiquibase – a time machine for your data
Liquibase – a time machine for your data
 
Newt global meetup microservices
Newt global meetup microservicesNewt global meetup microservices
Newt global meetup microservices
 
Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)Can you keep a secret? (XP Days 2017)
Can you keep a secret? (XP Days 2017)
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
 
Paa sing a java ee 6 application kshitiz saxena
Paa sing a java ee 6 application   kshitiz saxenaPaa sing a java ee 6 application   kshitiz saxena
Paa sing a java ee 6 application kshitiz saxena
 
Android webinar class_5
Android webinar class_5Android webinar class_5
Android webinar class_5
 
Chinnasamy Manickam
Chinnasamy ManickamChinnasamy Manickam
Chinnasamy Manickam
 
Developing saas application in azure
Developing saas application in azureDeveloping saas application in azure
Developing saas application in azure
 
Cnam azure ze cloud resource manager
Cnam azure ze cloud  resource managerCnam azure ze cloud  resource manager
Cnam azure ze cloud resource manager
 

More from Rodrigo Cândido da Silva

QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
Rodrigo Cândido da Silva
 

More from Rodrigo Cândido da Silva (20)

Java 9, 10 e ... 11
Java 9, 10 e ... 11Java 9, 10 e ... 11
Java 9, 10 e ... 11
 
Cloud Native Java EE
Cloud Native Java EECloud Native Java EE
Cloud Native Java EE
 
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de ImplementaçãoProtegendo Microservices: Boas Práticas e Estratégias de Implementação
Protegendo Microservices: Boas Práticas e Estratégias de Implementação
 
Protecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and StrategiesProtecting Java Microservices: Best Practices and Strategies
Protecting Java Microservices: Best Practices and Strategies
 
As novidades da nova versão do Java 9
As novidades da nova versão do Java 9As novidades da nova versão do Java 9
As novidades da nova versão do Java 9
 
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e KubernetesWorkshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
Workshop Microservices - Distribuindo os Microservices com Docker e Kubernetes
 
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSSWorkshop Microservices - Microservices com Spring Cloud e Netflix OSS
Workshop Microservices - Microservices com Spring Cloud e Netflix OSS
 
Workshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring BootWorkshop Microservices - Construindo APIs RESTful com Spring Boot
Workshop Microservices - Construindo APIs RESTful com Spring Boot
 
Workshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura MicroservicesWorkshop Microservices - Arquitetura Microservices
Workshop Microservices - Arquitetura Microservices
 
GUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em JavaGUJavaSC - Protegendo Microservices em Java
GUJavaSC - Protegendo Microservices em Java
 
TDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com JavaTDC Floripa 2017 - Criando Microservices Reativos com Java
TDC Floripa 2017 - Criando Microservices Reativos com Java
 
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOpsGUJavaSC - Combinando Micro-serviços com Práticas DevOps
GUJavaSC - Combinando Micro-serviços com Práticas DevOps
 
GUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com JavaGUJavaSC - Criando Micro-serviços Reativos com Java
GUJavaSC - Criando Micro-serviços Reativos com Java
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EE
 
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EEJavaOne LATAM 2016 - Combinando AngularJS com Java EE
JavaOne LATAM 2016 - Combinando AngularJS com Java EE
 
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data RESTJavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
JavaOne LATAM 2016 - RESTful Services Simplificado com Spring Data REST
 
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring CloudTDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
TDC Floripa 2016 - Decolando seus micro-serviços na Spring Cloud
 
GUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EEGUJavaSC - Combinando AngularJS com Java EE
GUJavaSC - Combinando AngularJS com Java EE
 
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
QCon SP 2016 - Construindo Microservices Auto-curáveis com Spring Cloud e Net...
 
QCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EEQCon 2015 - Combinando AngularJS com Java EE
QCon 2015 - Combinando AngularJS com Java EE
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE

  • 1. Supporting Multi-tenancy Applications with Java EE Rodrigo Cândido da Silva @rcandidosilva JavaOne 2014 CON4959
  • 2. About Me • Brazilian guy ;) • Work for Integritas company • http://integritastech.com • Software Architect • Java Platform • JUG Leader of GUJavaSC • http://gujavasc.org • Twitter • @rcandidosilva • Personal • http://rodrigocandido.me
  • 3. Agenda • Cloud Services Model • SaaS Market • Multi-tenancy • Challenges • Pros and Cons • Strategy Types • Java EE + Multi-tenancy • Multi-tenancy at Cloud
  • 6. Multi-tenancy • One application instance to multiple clients (tenant) • Inverse of the multiple instances architecture
  • 8. Multi-instances vs. Multi-tenant Feature Multi-instances Multi-tenant Cost Structure Can support only tiered or flat pricing Supports usage based pricing as well as tiered or flat Resources Dedicated resources Shared resources Operation and Maintenance Manage and administer as many instances as customers Manager and administer a single instance for a number of customers Scalable Model Not scalable. As the number of customers increase the maintenance requirements increase proporcionally Scalable, since a number of customers are serviced by one instance
  • 10. Challenges • Data separation • UI and business rules customization • Access control by tenant • Resource provisioning • Integration • Application update • Failover tolerance
  • 11. Pros and Cons • Pros • Low maintenance cost • Same source code for all customers • High scalability • Sharing resources between customers • Cons • High complexity • Separation by tenant-id • More failure risks • If code breaks -> breaks to all customers • Low flexibility available to the customers
  • 12. Multi-tenancy • Adoption levels • Level 1 (Customized) • [N] applications and [N] databases • Level 2 (Configurable) • [1] application and [N] databases • Level 3 (Scalable) • [1] application and [1] database
  • 13. Level 1 - Customized • [N] applications and [N] databases
  • 14. Level 2 - Configurable • [1] application and [N] databases
  • 15. Level 3 - Scalable • [1] application and [1] database
  • 16. What is the Best Choice? • Depends on… • Data Customization • Addition or removal of columns in the data store • Function Customization • The functionality executed for a specific business can vary by customers • Process Customization • The business process can vary for each customer • Licensing Features • The product has multiple licenses which define the functionality that is enabled for the customer
  • 17. Database Strategy Separate Databases Separate Tables Shared Database
  • 18. Database Strategy Feature Separate DBs Separate Tables Shared Database Data Customization Security Inter-dependency and Performance Scalable Model Customer On-boarding
  • 19. Java EE + Multi-tenancy • Database • JPA + Multi-tenancy • UI Customization • JSF + Multi-tenancy • Java EE 8 with Cloud support
  • 20. JPA + Multi-tenancy • There is no standard at this time • EclipseLink • Multi-tenancy support using @Multitenant • Multitenant strategies • @Multitenant(SINGLE_TABLE) – default • @Multitenant(TABLE_PER_TENANT) • @Multitenant(VPD) • Hibernate • Supports tenant identifier features • MultiTenantConnectionProvider • CurrentTenantIdentifierResolver
  • 21. EclipseLink SINGLE_TABLE @Entity @Table(name=“EMP”) @Multitenant(SINGLE_TABLE) @TenantDiscriminatorColumn(name = “TENANT_ID”, contextProperty = “tenant-id”) public class Employee { ... } HashMap properties = new HashMap(); properties.put("tenant.id", "707"); ... EntityManager em = Persistence .createEntityManagerFactory( "multi-tenant”,properties) .createEntityManager(); <persistence-unit name="multi-tenant"> ... <properties> <property name="tenant.id" value="707"/> ... </properties> </persistence-unit>
  • 22. EclipseLink TABLE_PER_TENANT <entity class="Employee"> <multitenant type="TABLE_PER_TENANT"> <tenant-table-discriminator type="SCHEMA" context-property=" eclipselink.tenant-id"/> </multitenant> <table name="EMP"> ... </entity> @Entity @Table(name=“EMP”) @Multitenant(TABLE_PER_TENANT) @TenantTableDiscriminator(type=SCHEMA, contextProperty="eclipselink.tenant-id") public class Employee { ... }
  • 23. EclipseLink VPD @Entity @Multitenant @TenantDiscriminatorColumn(name = "USER_ID", contextProperty = "tenant.id") @Cacheable(false) public class Task implements Serializable { ... CALL DBMS_RLS.ADD_POLICY ('SCOTT', 'TASK', 'todo_list_policy', 'SCOTT', 'ident_func', 'select, update, delete')); <properties> <property name="eclipselink.session.customizer" value="example.VPDSessionCustomizer" /> <property name="eclipselink.session-event-listener" value="example.VPDSessionEventAdapter" /> <property name="eclipselink.jdbc.exclusive-connection.mode" value="Always" /> </properties>
  • 24. Hibernate MultiTenantConnectionProvider public class MultiTenantProvider implements MultiTenantConnectionProvider { public Connection getConnection(String tenantIdentifier) throws SQLException { final Connection connection = getAnyConnection(); connection.createStatement().execute( "SET SCHEMA '" + tenantIdentifier + "'"); return connection; } public void releaseConnection(String tenantIdentifier, Connection connection) throws SQLException { releaseAnyConnection(connection); } }
  • 25. Hibernate CurrentTenantIdentifierResolver public class SchemaResolver implements CurrentTenantIdentifierResolver { @Override public String resolveCurrentTenantIdentifier() { return resolveTenant(); } @Override public boolean validateExistingCurrentSessions() { return false; } }
  • 26. Hibernate persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/ persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http:// java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="default"> <properties> <property name="javax.persistence.provider" value="org.hibernate.ejb.HibernatePersistence" /> <property name="hibernate.multiTenancy" value="SCHEMA"/> <property name="hibernate.tenant_identifier_resolver" value="yourpackage.SchemaResolver"/> <property name="hibernate.multi_tenant_connection_provider" value="yourpackage.MultiTenantProvider"/> </properties> </persistence-unit> </persistence>
  • 27. JPA Caching • Shared Cache disabled
  • 28. JPA Caching • Shared Cache by tenant
  • 29. JSF + Multi-tenancy • Flexible software architecture • Artifacts packaged in separated JAR’s • Composition at runtime • Templates and contracts • Resource library • Look-and-feel customization • RenderKit features • Localization support
  • 30. JSF Facelets The Facelets Gazette Site Navigation ●Events ●Docs ●Forums About Contact Site Map Template File name _template.html Insertion points Resources css classes, scripts, images
  • 31. JSF Multi-templating • Resource Library Contracts • Convention • All available contracts discovered at startup • Configuration • faces-config.xml by <resource-library-contract> • contracts attribute in <f:view> <web-app-root>/contracts contractA contractB • Declared Templates • Declared Insertion contractC Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources JAR files in WEB-INF/lib contractD contractE • Declared Templates • Declared Insertion contractF Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources
  • 32. JSF Multi-templating <web-app-root>/contracts contractA contractB • Declared Templates • Declared Insertion contractC Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources JAR files in WEB-INF/lib contractD contractE • Declared Templates • Declared Insertion contractF Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources • Declared Templates • Declared Insertion Points • Declared Resources Set of available contracts Facelet 1 <f:view contracts="contractA"> ... faces-config.xml Facelet 2 Facelet 3
  • 33. JSF Multi-templating <html xmlns="http://www.w3.org/1999/xhtml” xmlns:h="http://java.sun.com/jsf/html” xmlns:ui="http://java.sun.com/jsf/ facelets"> <body> <ui:composition template="#{template}”> ... </ui:composition> </body> </html> <?xml version="1.0" encoding="UTF-8"?> <web-app> <context-param> <param-name>javax.faces.view.TEMPLATE</param-name> <param-value>mybusiness</param-value> </context-param> </web-app>
  • 34. Demo • EclipseLink MySports Demo • http://wiki.eclipse.org/EclipseLink/Examples/MySports • http://git.eclipse.org/c/eclipselink/examples.git
  • 36. References • http://msdn.microsoft.com/en-us/library/aa479086.aspx • https://developers.google.com/appengine/docs/java/multitenancy/ • http://www.ibm.com/developerworks/java/library/j-multitenant-java/index.html • http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_multitenant.htm • http://2012.con-fess.com/sessions/-/details/122/JSF-and-JavaEE-7-for-multi-tenant-applications • http://jdevelopment.nl/jsf-22/ • http://picketlink.org • https://developers.google.com/appengine/docs/java/multitenancy/ • http://www.jboss.org/quickstarts/picketlink/picketlink-authentication-idm-multi-tenancy/ • http://wiki.eclipse.org/EclipseLink/Examples/MySports
  • 37. Thank you! @rcandidosilva rodrigocandido.me