Skip to content

Commit bd218ca

Browse files
authored
Merge pull request #2 from consoleau/tidyup
Tidyup
2 parents a6b69af + 58cf9ef commit bd218ca

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
# Spring Data JPA Specification DSL for Kotlin [![Build Status](https://travis-ci.org/consoleau/kotlin-jpa-specification-dsl.svg?branch=master)](https://travis-ci.org/consoleau/kotlin-jpa-specification-dsl)
1+
# Spring Data JPA Specification DSL for Kotlin
2+
[![Build Status](https://travis-ci.org/consoleau/kotlin-jpa-specification-dsl.svg?branch=master)](https://travis-ci.org/consoleau/kotlin-jpa-specification-dsl) [ ![Download](https://api.bintray.com/packages/consoleau/kotlin/kotlin-jpa-specification-dsl/images/download.svg) ](https://bintray.com/consoleau/kotlin/kotlin-jpa-specification-dsl/_latestVersion)
23

34
This library provides a fluent DSL for querying spring data JPA repositories using spring data Specifications (i.e. the JPA Criteria API), without boilerplate code or a generated metamodel.
45

5-
# Example #
6+
Hat tip to [Mike Buhot](https://github.com/mbuhot) for the initial implementation.
7+
8+
# Quick Start
9+
10+
```groovy
11+
repositories {
12+
jcenter()
13+
}
614
15+
dependencies {
16+
compile("au.com.console:kotlin-jpa-specification-dsl:0.1.0")
17+
}
718
```
8-
import com.console.specificationsdsl.* // 1. Import Kotlin magic
19+
20+
# Example #
21+
22+
```kotlin
23+
import au.com.console.jpaspecificationsdsl.* // 1. Import Kotlin magic
924

1025
////
1126
// 2. Declare JPA Entities
@@ -55,7 +70,7 @@ class MyService @Inject constructor(val tvShowRepo: TvShowRepository) {
5570
For more complex and dynamic queries it's good practice to create functions that use the DSL to make queries more readable,
5671
and to allow for their composition in complex dynamic queries.
5772

58-
```
73+
```kotlin
5974
fun hasName(name: String?): Specifications<TvShow>? = name?.let {
6075
TvShow::name.equal(it)
6176
}
@@ -75,7 +90,7 @@ fun hasKeyword(keyword: String?): Specifications<TvShow>? = keyword?.let {
7590

7691
These functions can be combined with and() and or() for complex nested queries:
7792

78-
```
93+
```kotlin
7994
val shows = tvShowRepo.findAll(
8095
or(
8196
and(
@@ -95,7 +110,7 @@ These functions can be combined with and() and or() for complex nested queries:
95110

96111
Or they can be combined with a service-layer query DTO and mapping extension function
97112

98-
```
113+
```kotlin
99114
/**
100115
* A TV show query DTO - typically used at the service layer.
101116
*/
@@ -118,7 +133,7 @@ Or they can be combined with a service-layer query DTO and mapping extension fun
118133

119134
for powerful dynamic queries:
120135

121-
```
136+
```kotlin
122137
val query = TvShowQuery(availableOnNetflix = false, keywords = listOf("Rick", "Jimmy"))
123138
val shows = tvShowRepo.findAll(query.toSpecification())
124139
```
@@ -131,7 +146,7 @@ This DSL builds on [Spring Data's Specifications abstraction](http://docs.spring
131146

132147
The code `TvShow::releaseDate.equal("2010")` is a call to the Kotlin extension function:
133148

134-
```
149+
```kotlin
135150
fun <T, R> KProperty1<T, R?>.equal(x: R): Specifications<T> = spec { equal(it, x) }
136151
```
137152

@@ -145,7 +160,7 @@ This is a bit dense, but makes sense when it's broken down:
145160

146161
This is implemented using a private helper function `spec` that captures the common use case of taking an Entity property, and using a `CriteriaBuilder` to create a `Predicate`:
147162

148-
```
163+
```kotlin
149164
private fun <T, R> KProperty1<T, R?>.spec(makePredicate: CriteriaBuilder.(path: Path<R>) -> Predicate): Specifications<T> =
150165
this.let { property -> where { root -> makePredicate(root.get(property)) } }
151166
```
@@ -161,6 +176,6 @@ The `makePredicate` function passed to `spec` is an extension function on `Crite
161176

162177
# Contributing to the Project #
163178

164-
If you like to contribute code to this project you can do so through GitHub by forking the repository and generating a pull request.
179+
If you'd like to contribute code to this project you can do so through GitHub by forking the repository and generating a pull request.
165180

166-
By contributing your code, you agree to license your contribution under the terms of the Apache License v2.0.
181+
By contributing your code, you agree to license your contribution under the terms of the Apache License v2.0.

build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ dependencies {
2424
testCompile 'junit:junit:4.12'
2525
}
2626

27+
tasks.bintrayUpload.dependsOn tasks.check
28+
tasks.artifactoryPublish.dependsOn tasks.check
29+
30+
gradle.taskGraph.whenReady { graph ->
31+
tasks.bintrayUpload.onlyIf {
32+
graph.hasTask(':final') || graph.hasTask(':candidate')
33+
}
34+
tasks.artifactoryPublish.onlyIf {
35+
graph.hasTask(':snapshot') || graph.hasTask(':devSnapshot')
36+
}
37+
}
38+
2739
bintray {
2840
user = System.getenv('BINTRAY_USER')
2941
key = System.getenv('BINTRAY_KEY')

gradle/travisBuild.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This script will build the project.
33
# Based on https://github.com/nebula-plugins/nebula-kotlin-plugin/blob/master/gradle/buildViaTravis.sh
44

5-
SWITCHES="--info --stacktrace"
5+
SWITCHES="-x artifactoryPublish --info --stacktrace"
66

77
GRADLE_VERSION=$(./gradlew -version | grep Gradle | cut -d ' ' -f 2)
88

@@ -11,8 +11,7 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
1111
./gradlew build $SWITCHES
1212
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
1313
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
14-
#./gradlew -Prelease.travisci=true snapshot $SWITCHES
15-
./gradlew build $SWITCHES
14+
./gradlew -Prelease.travisci=true snapshot $SWITCHES
1615
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
1716
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
1817
case "$TRAVIS_TAG" in

0 commit comments

Comments
 (0)