add example

This commit is contained in:
f43nd1r 2021-04-10 18:13:27 +02:00
parent bac95caec6
commit 56ab5ff818
4 changed files with 186 additions and 0 deletions

View File

@ -26,6 +26,7 @@
<module>querydsl-example-jpa-guice</module>
<module>querydsl-example-kotlin-jpa</module>
<module>querydsl-example-kotlin-mongodb</module>
<module>querydsl-example-kotlin-codegen</module>
</modules>
<build>

View File

@ -0,0 +1,112 @@
<?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>querydsl-examples</artifactId>
<groupId>com.querydsl</groupId>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>querydsl-example-kotlin-codegen</artifactId>
<name>Querydsl example - Kotlin Codegen</name>
<properties>
<kotlin.version>1.4.32</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<compilerPlugins>
<plugin>jpa</plugin>
</compilerPlugins>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-kotlin-codegen</artifactId>
<version>${project.version}</version>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${project.version}</version>
<classifier>jpa</classifier>
</annotationProcessorPath>
</annotationProcessorPaths>
<jvmTarget>1.8</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-kapt</id>
<goals>
<goal>test-kapt</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,36 @@
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team).
*
* 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.querydsl.examples.kotlin.entity
import javax.persistence.*
@Entity
data class ExampleEntity(
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
val id: Int,
@Column
val name: String,
@OneToMany(mappedBy = "parent")
val children: List<ExampleEntity>? = null,
@ManyToOne
val parent: ExampleEntity? = null
) {
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2015, The Querydsl Team (http://www.querydsl.com/team).
*
* 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.querydsl.examples.kotlin
import com.querydsl.examples.kotlin.entity.ExampleEntity
import com.querydsl.examples.kotlin.entity.QExampleEntity
import com.querydsl.examples.kotlin.entity.QExampleEntity.Companion.exampleEntity
import com.querydsl.jpa.impl.JPAQuery
import org.junit.Test
class ExampleEntityTest {
@Test
fun basicMetamodelExpression() {
val child : QExampleEntity = QExampleEntity("child")
JPAQuery<ExampleEntity>()
.from(exampleEntity)
.innerJoin(exampleEntity.children, child)
.select(exampleEntity.name, child.name)
}
}