Skip to content

Commit

Permalink
Blazebit#328 deltaspike-data integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed Nov 22, 2017
1 parent e60b882 commit 4982ab9
Show file tree
Hide file tree
Showing 115 changed files with 6,117 additions and 103 deletions.
26 changes: 25 additions & 1 deletion README.md
Expand Up @@ -155,10 +155,34 @@ Blaze-Persistence Spring Data integration dependencies
```xml
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data</artifactId>
<artifactId>blaze-persistence-integration-spring-data-api</artifactId>
<version>${blaze-persistence.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data-impl</artifactId>
<version>${blaze-persistence.version}</version>
<scope>runtime</scope>
</dependency>
```

Blaze-Persistence DeltaSpike Data integration

```xml
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-deltaspike-data-api</artifactId>
<version>${blaze-persistence.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-deltaspike-data-impl</artifactId>
<version>${blaze-persistence.version}</version>
<scope>runtime</scope>
</dependency>
```

Blaze-Persistence JPA provider integration module dependencies
Expand Down
Expand Up @@ -83,10 +83,16 @@ When you work with Spring Data you can additionally have first class integration
----
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data</artifactId>
<artifactId>blaze-persistence-integration-spring-data-api</artifactId>
<version>${blaze-persistence.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data-impl</artifactId>
<version>${blaze-persistence.version}</version>
<scope>runtime</scope>
</dependency>
----

NOTE: The Spring Data integration depends on the _jpa-criteria_ module
Expand Down
Expand Up @@ -8,18 +8,24 @@ there is also a Spring Data integration module which tries to make using entity
=== Setup

To setup the project for Spring Data you have to add dependencies as described in the <<getting-started-setup>> section
and make a beans available for `CriteriaBuilderFactory` and `EntityViewManager` instances as laid out in the <<anchor-environment-spring,Spring environment>> section.
and make beans available for `CriteriaBuilderFactory` and `EntityViewManager` instances as laid out in the <<anchor-environment-spring,Spring environment>> section.

In short, the following Maven dependencies are required

[source,xml]
----
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data</artifactId>
<artifactId>blaze-persistence-integration-spring-data-api</artifactId>
<version>${blaze-persistence.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data-impl</artifactId>
<version>${blaze-persistence.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-hibernate-5.2</artifactId>
Expand Down Expand Up @@ -77,7 +83,7 @@ Optionally specify a custom basePackage for repository class scanning and a cust
[[spring-data-features]]
=== Features

The integration comes with a convenience base interface `com.blazebit.persistence.impl.springdata.repository.EntityViewRepository`
The integration comes with a convenience base interface `com.blazebit.persistence.impl.springdata.api.repository.EntityViewRepository`
that you can use for your repository definitions.

Assume we have the following entity view:
Expand Down
@@ -0,0 +1,69 @@
[[deltaspike-data-integration]]
== DeltaSpike Data integration

{projectname} provides an integration with https://deltaspike.apache.org/documentation/data.html[DeltaSpike Data] to create entity view based repositories.

[[deltaspike-data-setup]]
=== Setup

To setup the project for DeltaSpike Data you have to add the entity view and CDI integration dependencies as described
in the <<getting-started-setup, getting started>> section along with the integration dependencies for your JPA provider
as described in the link:{core_doc}#maven-setup[core module setup section].

In addition, the following Maven dependencies are required:

[source,xml]
----
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-deltaspike-data-api</artifactId>
<version>${blaze-persistence.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-deltaspike-data-impl</artifactId>
<version>${blaze-persistence.version}</version>
<scope>runtime</scope>
</dependency>
----

You also need to make beans available for `CriteriaBuilderFactory` and `EntityViewManager` as laid out in the
<<anchor-environments-cdi,CDI environment>> section.

[[deltaspike-data-features]]
=== Features

To mark a class or an interface as repository, use the DeltaSpike `org.apache.deltaspike.data.api.Repository` annotation.

[source,java]
----
@Repository(forEntity = PersonView.class)
public interface PersonViewRepository {
PersonView findAnyByName(String name);
}
----

The integration provides the following base interfaces that you may optionally extend to define entity view repositories:

* `com.balzebit.persistence.impl.deltaspikedata.api.EntityViewRepository` provides simple base methods.
* `com.balzebit.persistence.impl.deltaspikedata.api.CriteriaSupport` adds support for the JPA Criteria API to an entity view
repository. See the https://deltaspike.apache.org/documentation/data.html#_jpa_criteria_api_support[DeltaSpike documentation]
for more details.
* `com.balzebit.persistence.impl.deltaspikedata.api.FullEntityViewRepository` combines the capabilities of the above
interfaces.

[source,java]
----
@Repository
public abstract class PersonViewRepository extends FullEntityViewRepository<Person, PersonView, String> {
public abstract PersonView findAnyByName(String name);
public List<PersonView> getPersonsByComplexCondition() {
return criteria().or(
criteria().gt(Person_.position, 3),
criteria().likeIgnoreCase(Person_.name, "john%")
).orderAsc(Person_.id).getResultList();
}
}
----
Expand Up @@ -37,6 +37,8 @@ include::10_change_model.adoc[]

include::11_spring_data.adoc[]

include::12_metamodel.adoc[]
include::12_deltaspike_data.adoc[]

include::13_configuration.adoc[]
include::13_metamodel.adoc[]

include::14_configuration.adoc[]
27 changes: 10 additions & 17 deletions examples/cdi-showcase/pom.xml
Expand Up @@ -25,22 +25,6 @@
<name>Blazebit Persistence Examples CDI Showcase</name>
<artifactId>blaze-persistence-cdi-showcase</artifactId>

<properties>
<version.deltaspike>1.7.1</version.deltaspike>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.deltaspike.distribution</groupId>
<artifactId>distributions-bom</artifactId>
<version>${version.deltaspike}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>javax</groupId>
Expand Down Expand Up @@ -92,7 +76,6 @@
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.4.0.Final</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -124,6 +107,16 @@
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-weld</artifactId>
<scope>runtime</scope>
<exclusions>
<exclusion>
<artifactId>weld-api</artifactId>
<groupId>org.jboss.weld</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-logging</artifactId>
<groupId>org.jboss.logging</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Expand Up @@ -21,11 +21,10 @@
import org.apache.deltaspike.cdise.api.CdiContainerLoader;
import org.apache.deltaspike.cdise.api.ContextControl;
import org.apache.deltaspike.core.api.provider.BeanProvider;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.util.ServiceLoader;

import javax.enterprise.context.ApplicationScoped;
import java.util.Iterator;
import java.util.ServiceLoader;

/**
* @author Moritz Becker (moritz.becker@gmx.at)
Expand All @@ -44,12 +43,12 @@ public static void main(String[] args) {
contextControl.startContext(ApplicationScoped.class);

ServiceLoader<Showcase> showcaseLoader = ServiceLoader.load(Showcase.class);
Iterator<Metadata<Showcase>> showcaseIterator = showcaseLoader.iterator();
Iterator<Showcase> showcaseIterator = showcaseLoader.iterator();
if (!showcaseIterator.hasNext()) {
throw new RuntimeException("No showcases found");
}
while (showcaseIterator.hasNext()) {
BeanProvider.injectFields(showcaseIterator.next().getValue()).run();
BeanProvider.injectFields(showcaseIterator.next()).run();
}

cdiContainer.shutdown();
Expand Down
Expand Up @@ -16,7 +16,7 @@

package com.blazebit.persistence.examples.springdata;

import com.blazebit.persistence.impl.springdata.repository.EntityViewRepositoryFactoryBean;
import com.blazebit.persistence.spring.data.impl.repository.EntityViewRepositoryFactoryBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

Expand Down
Expand Up @@ -17,7 +17,7 @@
package com.blazebit.persistence.examples.springdata.repository;

import com.blazebit.persistence.examples.springdata.view.CatView;
import com.blazebit.persistence.impl.springdata.repository.EntityViewRepository;
import com.blazebit.persistence.spring.data.api.repository.EntityViewRepository;

import java.util.List;

Expand Down
Expand Up @@ -17,7 +17,7 @@
package com.blazebit.persistence.examples.spring;

import com.blazebit.persistence.examples.spi.Showcase;
import com.blazebit.persistence.impl.springdata.repository.EntityViewRepositoryFactoryBean;
import com.blazebit.persistence.spring.data.impl.repository.EntityViewRepositoryFactoryBean;
import com.blazebit.persistence.view.impl.spring.EnableEntityViews;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.boot.CommandLineRunner;
Expand Down
29 changes: 29 additions & 0 deletions integration/deltaspike-data/api/pom.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>blaze-persistence-integration-deltaspike-data</artifactId>
<groupId>com.blazebit</groupId>
<version>1.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>blaze-persistence-integration-deltaspike-data-api</artifactId>

<name>Blazebit Persistence Integration DeltaSpike Data API</name>

<dependencies>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-data-module-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,54 @@
/*
* Copyright 2014 - 2017 Blazebit.
*
* 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.
*/

package com.balzebit.persistence.impl.deltaspikedata.api;

import org.apache.deltaspike.data.api.criteria.Criteria;

import javax.persistence.criteria.JoinType;

/**
* @author Moritz Becker
* @since 1.2.0
*/
public interface CriteriaSupport<E, R> {

/**
* Create a {@link Criteria} instance.
*
* @return Criteria instance related to the Repository entity class.
*/
Criteria<E, R> criteria();

/**
* Create a {@link Criteria} instance.
*
* @param <T> Type related to the current criteria class.
* @param clazz Class other than the current entity class.
* @return Criteria instance related to a join type of the current entity class.
*/
<T> Criteria<T, R> where(Class<T> clazz);

/**
* Create a {@link Criteria} instance with a join type.
*
* @param <T> Type related to the current criteria class.
* @param clazz Class other than the current entity class.
* @param joinType Join type to apply.
* @return Criteria instance related to a join type of the current entity class.
*/
<T> Criteria<T, R> where(Class<T> clazz, JoinType joinType);
}

0 comments on commit 4982ab9

Please sign in to comment.