maznag / generator-jhipster-multitenancy

JHipster module to support multitenant entity models

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Greetings, Java Hipster!

generator-jhipster-multitenancy

NPM version Build Status Dependency Status License

A JHipster module for creating multitenant applications

Introduction

This module is used for creating multitenant applications. The module will:

  • Generate a Tenant entity.
  • Make the User, and any other entities, tenant aware.

Table of contents

Prerequisites

As this is a JHipster module, we expect you have JHipster and its related tools already installed:

Installation

If you are using Yarn:

# install the module
yarn global add generator-jhipster-multitenancy

# update the module
yarn global upgrade generator-jhipster-multitenancy

If you are using npm:

#install the module
npm install -g generator-jhipster-multitenancy

# update the module
npm update -g generator-jhipster-multitenancy

Usage

After installation, run the module on a JHipster generated application:

yo jhipster-multitenancy

You will then be prompted for the name of your tenant entity.

Making an entity tenant aware

Once the module has been run on the JHipster generated application, any entity in the application can be made tenant aware. This is done using the jhipster-multitenancy:entity sub-generator.

For an existing entity:

yo jhipster-multitenancy:entity Book

This sub-generator also hooks into the jhipster:entity sub-generator. When creating a new entity, you will be prompted to make an entity tenant aware.

yo jhipster:entity Book

# upon generation, you will be asked
Do you want to make Book tenant aware? (Y/n)

Applying the tenant filter

Tenancy is enforced using a Hibernate filter. The filter identifies a discriminator column that is used to used to uniquely identify a tenant. By default, jhipster-multitenancy adds the filter to the User class. For other entities, you must add the filter manually. See below for an example.

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;

/**
 * A book.
 */
@Entity
@Table(name = "book")
@FilterDef(name = "COMPANY_FILTER", parameters = {@ParamDef(name = "companyId", type = "long")})
@Filter(name = "COMPANY_FILTER", condition = "company_id = :companyId")
public class Book extends AbstractAuditingEntity implements Serializable {
    ...
}

License

Apache-2.0

About

JHipster module to support multitenant entity models


Languages

Language:Java 44.9%Language:JavaScript 23.3%Language:TypeScript 19.6%Language:HTML 12.2%