Skip to content

Commit

Permalink
Add example model classes, update Gradle to v8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijsiez committed Nov 7, 2023
1 parent 667806c commit ed26c84
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ plugins {
dependencies {
implementation(project(":library"))
ksp(project(":library"))
testImplementation("io.quarkus:quarkus-jdbc-h2")
}

allOpen {
annotation("jakarta.persistence.Entity")
}

ksp {
Expand Down
17 changes: 17 additions & 0 deletions examples/src/main/kotlin/ch/icken/Examples.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken
44 changes: 44 additions & 0 deletions examples/src/main/kotlin/ch/icken/model/Assignment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken.model

import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
import jakarta.persistence.*

@Entity
@Table(name = "ASSIGNMENT")
class Assignment(

@OneToOne(optional = false)
@JoinColumn(name = "EMPLOYEE_ID", unique = true, nullable = false)
val employee: Employee,

@ManyToOne(optional = false)
@JoinColumn(name = "CLIENT_ID", nullable = false)
val client: Client,

@Column(name = "ROLE", nullable = false)
var role: String

) : PanacheEntity() {

@Column(name = "DESCRIPTION")
var description: String? = null

companion object : PanacheCompanion<Assignment>
}
43 changes: 43 additions & 0 deletions examples/src/main/kotlin/ch/icken/model/Client.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken.model

import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
import jakarta.persistence.*

@Entity
@Table(name = "CLIENT")
class Client(

@Column(name = "NAME", unique = true, nullable = false)
var name: String

) : PanacheEntity() {

@OneToMany(cascade = [CascadeType.ALL], mappedBy = "client", orphanRemoval = true)
val assignments = HashSet<Assignment>()

operator fun plusAssign(assignment: Assignment) {
assignments.add(assignment)
}
operator fun minusAssign(assignment: Assignment) {
assignments.remove(assignment)
}

companion object : PanacheCompanion<Client>
}
43 changes: 43 additions & 0 deletions examples/src/main/kotlin/ch/icken/model/Department.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken.model

import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
import jakarta.persistence.*

@Entity
@Table(name = "DEPARTMENT")
class Department(

@Column(name = "NAME", unique = true, nullable = false)
var name: String

) : PanacheEntity() {

@OneToMany(cascade = [CascadeType.ALL], mappedBy = "department", orphanRemoval = true)
val employees = HashSet<Employee>()

operator fun plusAssign(employee: Employee) {
employees.add(employee)
}
operator fun minusAssign(employee: Employee) {
employees.remove(employee)
}

companion object : PanacheCompanion<Department>
}
61 changes: 61 additions & 0 deletions examples/src/main/kotlin/ch/icken/model/Employee.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken.model

import io.quarkus.hibernate.orm.panache.kotlin.PanacheCompanion
import io.quarkus.hibernate.orm.panache.kotlin.PanacheEntity
import jakarta.persistence.*
import java.time.LocalDateTime

@Entity
@Table(name = "EMPLOYEE")
class Employee(

@Column(name = "EMPLOYEE_NO", unique = true, nullable = false, updatable = false)
val employeeNumber: Int,

@Column(name = "FIRST_NAME", nullable = false)
var firstName: String,

@Column(name = "LAST_NAME", nullable = false)
var lastName: String,

@Column(name = "GENDER", nullable = false)
@Enumerated(EnumType.STRING)
var gender: Gender,

@Column(name = "BIRTH_DATE", nullable = false, updatable = false)
var birthDate: LocalDateTime,

@ManyToOne(optional = false)
@JoinColumn(name = "DEPARTMENT_ID", nullable = false)
var department: Department,

@Column(name = "SALARY", nullable = false)
var salary: Double

) : PanacheEntity() {

@OneToOne(cascade = [CascadeType.ALL], mappedBy = "employee", orphanRemoval = true)
var assignment: Assignment? = null

companion object : PanacheCompanion<Employee>

enum class Gender {
M, F, X
}
}
29 changes: 29 additions & 0 deletions examples/src/test/kotlin/ch/icken/model/EmployeeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 Thijs Koppen
*
* 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 ch.icken.model

import io.quarkus.test.junit.QuarkusTest
import org.junit.jupiter.api.Test

@QuarkusTest
class EmployeeTest {

@Test
fun test() {

}
}
21 changes: 21 additions & 0 deletions examples/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright 2023 Thijs Koppen
#
# 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.
#

quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.url=jdbc:h2:mem:test

quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.packages=ch.icken.model
12 changes: 12 additions & 0 deletions examples/src/test/resources/import.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
INSERT INTO DEPARTMENT (ID, NAME) VALUES
(1, 'Sales'),
(2, 'HR');

--INSERT INTO EMPLOYEE (ID, EMPLOYEE_NO, FIRST_NAME, LAST_NAME, GENDER, BIRTH_DATE, DEPARTMENT_ID, SALARY) VALUES
--;

--INSERT INTO CLIENT (ID, NAME) VALUES
--;

--INSERT INTO ASSIGNMENT (ID, EMPLOYEE_ID, CLIENT_ID, ROLE) VALUES
--;
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
18 changes: 17 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#
# Copyright 2023 Thijs Koppen
#
# 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.
#

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright 2023 Thijs Koppen
#
# 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
#
# https://www.apache.org/licenses/LICENSE-2.0
# 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,
Expand Down Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down

0 comments on commit ed26c84

Please sign in to comment.