Skip to content

Blazebit/blaze-domain

Repository files navigation

Build Status

Maven Central Slack Status

Javadoc - Domain

Blaze-Domain

Blaze-Domain is a toolkit that can be used to build a runtime model of a domain as a set of entities with attributes, basic types, functions and operators as well as metadata.

What is it?

Blaze-Domain provides a builder API and runtime model to describe a domain in an extensible way.

The domain description does not require that Java classes or methods/fields exist for domain entity types and their attributes or functions. The declarative submodule allows to determine a domain model based on class structures and their annotations which can be combined with the builder API to combine static and dynamic domain models. The Blaze-Expression project builds on top of this project which allows to create an expression/predicate DSL based on a domain model defined via Blaze-Domain. In the end, this allows to model expressions or predicates with a simplified DSL and custom domain model that can be transformed into JPQL.Next expressions to be consumed via Blaze-Persistence.

Features

Blaze-Domain has support for

  • Definition of structured types(Entity) with attributes
  • Definition of custom functions
  • Definition of custom basic types
  • Definition of enumeration types
  • Definition of collection types
  • Configuration of enabled arithmetic operators and predicates per type
  • Extensible metadata for every domain element
  • Metadata extension for JPA related models
  • Declarative definition of domain models
  • TypeScript implementation for the client side validation of models

How to use it?

Blaze-Domain is split up into different modules. We recommend that you define a version property in your parent pom that you can use for all artifacts. Modules are all released in one batch so you can safely increment just that property.

<properties>
    <blaze-domain.version>2.0.2</blaze-domain.version>
</properties>

Alternatively you can also use our BOM in the dependencyManagement section.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.blazebit</groupId>
            <artifactId>blaze-domain-bom</artifactId>
            <version>${blaze-domain.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>    
    </dependencies>
</dependencyManagement>

Manual setup

For compiling you will only need API artifacts and for the runtime you need impl and integration artifacts.

Blaze-Domain Core module dependencies

<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-core-api</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-core-impl</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>runtime</scope>
</dependency>

Blaze-Domain Declarative module dependencies

<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-declarative-api</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-declarative-impl</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>runtime</scope>
</dependency>

Blaze-Domain Declarative CDI integration dependencies

<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-declarative-integration-cdi</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>runtime</scope>
</dependency>

Blaze-Domain Persistence module dependencies

<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-persistence</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.blazebit</groupId>
    <artifactId>blaze-domain-declarative-persistence</artifactId>
    <version>${blaze-domain.version}</version>
    <scope>compile</scope>
</dependency>

Documentation

Currently there is no documentation other than the Javadoc.

Core quick-start

Building a domain model works through the DomainBuilder API.

DomainBuilder domainBuilder = Domain.getDefaultProvider().createDefaultBuilder();
domainBuilder.createEntityType("Cat")
    .addAttribute("name", "String")
    .addAttribute("age", "Integer")
  .build();
DomainModel domain = domainBuilder.build();

This will build an entity type with the domain type name Cat containing two attributes name and age. The domain model can then be queried.

// Returns a basic domain type for the java type String
domain.getEntityType("Cat").getAttribute("name").getType();

This alone is not very spectacular, but the declarative module allows to interpret class structures as domain types which saves a lot of typing and is safer.

Declarative usage

The declarative module allows to define domain models through java class definitions:

@DomainType
interface Cat {
  String getName();
  Integer getAge();
}

which can then be registered like this:

DeclarativeDomainConfiguration config = DeclarativeDomain.getDefaultProvider().createDefaultConfiguration();
config.addDomainType(Cat.class);
DomainModel domain = config.createDomainModel();

The discovery and registering can be automated by making use of the CDI integration blaze-domain-declarative-integration-cdi.

Licensing

This distribution, as a whole, is licensed under the terms of the Apache License, Version 2.0 (see LICENSE.txt).

References

Project Site: https://domain.blazebit.com (coming at some point)