Java Repository Bridge

Provides support for databases

License

License

GroupId

GroupId

nl.42
ArtifactId

ArtifactId

jarb
Last Version

Last Version

5.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

Java Repository Bridge
Provides support for databases
Source Code Management

Source Code Management

https://github.com/42BV/jarb

Download jarb

How to add to project

<!-- https://jarcasting.com/artifacts/nl.42/jarb/ -->
<dependency>
    <groupId>nl.42</groupId>
    <artifactId>jarb</artifactId>
    <version>5.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/nl.42/jarb/
implementation 'nl.42:jarb:5.3.1'
// https://jarcasting.com/artifacts/nl.42/jarb/
implementation ("nl.42:jarb:5.3.1")
'nl.42:jarb:jar:5.3.1'
<dependency org="nl.42" name="jarb" rev="5.3.1">
  <artifact name="jarb" type="jar" />
</dependency>
@Grapes(
@Grab(group='nl.42', module='jarb', version='5.3.1')
)
libraryDependencies += "nl.42" % "jarb" % "5.3.1"
[nl.42/jarb "5.3.1"]

Dependencies

provided (18)

Group / Artifact Type Version
org.springframework : spring-context jar 5.1.3.RELEASE
org.springframework : spring-orm jar 5.1.3.RELEASE
org.springframework : spring-jdbc jar 5.1.3.RELEASE
org.springframework : spring-webmvc jar 5.1.3.RELEASE
org.hibernate : hibernate-entitymanager jar 5.4.0.Final
org.hibernate : hibernate-validator jar 6.0.13.Final
javax.el : javax.el-api jar 3.0.0
javassist : javassist jar 3.12.0.GA
org.glassfish.web : el-impl jar 2.2
org.liquibase : liquibase-core jar 3.6.2
com.mattbertolini : liquibase-slf4j jar 1.2.1
org.slf4j : slf4j-api jar 1.7.25
org.slf4j : slf4j-log4j12 jar 1.7.25
org.hsqldb : hsqldb jar 2.4.1
com.h2database : h2 jar 1.3.171
postgresql : postgresql jar 9.0-801.jdbc4
mysql : mysql-connector-java jar 5.1.9
com.oracle » ojdbc6 jar 11.2.0.3

test (6)

Group / Artifact Type Version
org.jmockit : jmockit jar 1.44
junit : junit jar 4.12
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3
org.mockito : mockito-core jar 2.23.0
org.springframework : spring-test jar 5.1.3.RELEASE

Project Modules

There are no modules declared in this project.

Java Repository Bridge (JaRB)

JaRB aims to improve database usage in Java enterprise applications.

http://www.jarbframework.org

Features

  • Bean validation on database schema
    • Specify rules once in database
    • Publish constraints via REST
    • Honor constraints on frontend
  • Translate JDBC driver specific exceptions into global constraint exceptions
    • Common exceptions regardless of driver
    • Access to constraint violation information
    • Map named constraint violations to project specific exceptions
  • Populate database on application startup
    • SQL (file, directory)
    • Java based
    • Asyncronous

Developers

License

Copyright 2011-2019 42BV (http://www.42.nl)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Database constraints

Validation

To validate database constraints with JSR303 validation, we often need to duplicate constraint information in both the database and entity class. Duplication is never good, so we made a @DatabaseConstrained annotation that dynamically validates all simple database constraints based on JDBC metadata.

@DatabaseConstrained
@Entity
public class Person {
  @Id @GeneratedValue
  private Long id;
  private String name;
  ...
}

Database constraint exceptions

Whenever a database constraint is violated, the JDBC driver will convert it into a runtime exception. This SQLException is hard to use in the application because all metadata is held inside its message. By using exception translation we can convert the driver exception into a more intuitive exception, e.g. the UniqueKeyAlreadyExistsException. Inside our translated exception we have full access to the constraint violation and any desired metadata.

It is even possible to map custom exceptions on named constraints.

@NamedConstraint("uk_posts_title")
public class PostTitleAlreadyExistsException extends UniqueKeyViolationException {
	...
}

Configuration

The configuration is as follows:

@EnableDatabaseConstraints(basePackage = "nl._42.jarb.sample")

We also support XML configuration:

<constraints:enable-constraints data-source="dataSource" base-package="nl._42.jarb.sample"/>
<constraints:enable-constraints entity-manager-factory="entityManagerFactory" base-package="nl._42.jarb.sample"/>

Data insertion

Whenever we require data to be inserted during application startup, the database updater interface can be used.

Below we demonstrate how to run an insert script at startup:

@Bean
public PopulateApplicationListener populateAppliationListener() {
    return new PopulateApplicationListenerBuilder()
                    .initializer()
                        .add(new SqlDatabasePopulator(dataSource, new ClassPathResource("import.sql")))
                        .add(new ExcelDatabasePopulator(entityManagerFactory, new ClassPathResource("import.xls")))
                        .add(postPopulator())
                        .done()
                    .destroyer()
                        .add(new SqlDatabasePopulator(dataSource, new ClassPathResource("clean.sql")))
               .build();
}

For XML configurations we provide a namespace:

<populator:populate initializer="populator"/>

<bean id="populator" class="nl._42.jarb.populator.SqlDatabasePopulator">
    <constructor-arg ref="dataSource"/>
    <constructor-arg value="classpath:import.sql"/>
</bean>

Components

  • constraints (simplifies the managing of (database) constraints by preventing and translating JDBC exceptions)
  • populator (populate the database with data on startup, SQL script implementation and building blocks)
  • utils (common utility library, used by other components)

Release notes

  • Version 3.0.0
    • Java version below 1.8 not supported anymore
    • Hibernate version below 5.0 not supported anymore
nl.42

Versions

Version
5.3.1
5.3.0
5.2.0
5.1.1
5.1.0
5.0.1
5.0.0.JAVA.11