-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPerson.kt
65 lines (54 loc) · 1.87 KB
/
Person.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package example.crudflow.person
import com.github.vokorm.KEntity
import com.gitlab.mvysny.jdbiorm.Dao
import org.jdbi.v3.core.mapper.reflect.ColumnName
import java.time.LocalDate
import java.util.*
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
/**
* A very simple bean representing a database table. The SELECT column -> bean property mapping is done by vok-orm.
* Notice how Kotlin generates toString, equals, hashcode and all getters/setters automatically (for data classes).
*
* See [vok-orm](https://github.com/mvysny/vok-orm) for more details.
* @property id person ID
* @property name person name
* @property age the person age, 15..100
* @property dateOfBirth date of birth, optional.
* @property created when the record was created
* @property maritalStatus the marital status
* @property alive whether the person is alive (true) or deceased (false).
*/
data class Person(
override var id: Long? = null,
@field:NotNull
@field:Size(min = 1, max = 200)
@field:ColumnName("PERSON_NAME")
var name: String? = null,
@field:NotNull
@field:Min(15)
@field:Max(100)
var age: Int? = null,
var dateOfBirth: LocalDate? = null,
@field:NotNull
var created: Date? = null,
@field:NotNull
var maritalStatus: MaritalStatus? = null,
@field:NotNull
var alive: Boolean? = null
) : KEntity<Long> {
// this brings in tons of useful static methods such as findAll(), findById() etc.
companion object : Dao<Person, Long>(Person::class.java)
override fun save(validate: Boolean) {
if (created == null) created = Date()
super.save(validate)
}
}
enum class MaritalStatus {
Single,
Married,
Divorced,
Widowed
}