org.panteleyev:persistence-kt

Annotation wrapper for SQLite and MySQL database.

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

org.panteleyev
ArtifactId

ArtifactId

persistence-kt
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

org.panteleyev:persistence-kt
Annotation wrapper for SQLite and MySQL database.
Project URL

Project URL

https://github.com/petr-panteleyev/persistence-kt
Source Code Management

Source Code Management

https://github.com/petr-panteleyev/persistence-kt/tree/master

Download persistence-kt

How to add to project

<!-- https://jarcasting.com/artifacts/org.panteleyev/persistence-kt/ -->
<dependency>
    <groupId>org.panteleyev</groupId>
    <artifactId>persistence-kt</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.panteleyev/persistence-kt/
implementation 'org.panteleyev:persistence-kt:1.2.0'
// https://jarcasting.com/artifacts/org.panteleyev/persistence-kt/
implementation ("org.panteleyev:persistence-kt:1.2.0")
'org.panteleyev:persistence-kt:jar:1.2.0'
<dependency org="org.panteleyev" name="persistence-kt" rev="1.2.0">
  <artifact name="persistence-kt" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.panteleyev', module='persistence-kt', version='1.2.0')
)
libraryDependencies += "org.panteleyev" % "persistence-kt" % "1.2.0"
[org.panteleyev/persistence-kt "1.2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jre8 jar 1.1.4

test (3)

Group / Artifact Type Version
org.xerial : sqlite-jdbc jar 3.15.1
mysql : mysql-connector-java jar 5.1.42
org.testng : testng jar 6.10

Project Modules

There are no modules declared in this project.

PersistenceKt

Kotlin version of annotation based wrapper for SQLite and MySQL.

Note: this library uses the same packages and classes as java-persistence which makes them mutually exclusive in class path.

Maven Central

Releases

https://oss.sonatype.org/content/repositories/releases/org/panteleyev/persistence-kt/

API Documentation

https://petr-panteleyev.github.io/persistence-kt/persistence-kt

Implementation Details

Database

Database manipulation is beyond the scope of this API. Calling code must supply correct DataSource and ensure database does exist and proper access control is established.

Mutable Objects

Mutable object must implement mutable properties annotated as shown below:

@Table("book")
class Book (
        @param:Field("id")
        @get:Field(value = "id", primaryKey = true)
        override var id: Integer
        
        @param:Field("title")
        @get:Field("title")
        var title: String
): Record

Immutable Objects

Immutable objects are supported by annotation @RecordBuilder as shown below.

@Table("book")
class Book @RecordBuilder constructor (
        @param:Field("id")
        @get:Field(value = "id", primaryKey = true)
        override val id: Integer
        
        @param:Field("title")
        @get:Field("title")
        val title: String
): Record

Data Types

The following data types are supported:

Java SQLite MySQL Comment
int
Integer
INTEGER INTEGER
long
Long
INTEGER BIGINT
bool
Boolean
BOOLEAN BOOLEAN
String VARCHAR (Field.length) VARCHAR (Field.length)
BigDecimal VARCHAR (Field.precision + 1) DECIMAL (Field.precision, Field.scale) MySQL representation does not guarantee that retrieved value will be equal to original one by means of Object.equals(Object). Use BigDecimal.compareTo(BigDecimal) instead.
Date INTEGER BIGINT Dates are stored as long using Date.getTime()

Indexes and Foreign Keys

Parent Table

@Table("parent_table")
data class ParentTable : Record {
    @get:Field("data")
    @get:Index("data", unique = true)
    var data: String?
}

This will produce the following SQL for indexed field:

CREATE UNIQUE INDEX data ON parent_table(data)

Child Table

@Table("child_table")
data class ChildTable : Record {
        // ...
        @get:Field("cascade_value")
        @get:ForeignKey(table = ParentTable::class, field = "data",
                onDelete = ReferenceOption.RESTRICT, onUpdate = ReferenceOption.CASCADE)
        val cascadeValue: String?
        // ...
}

This will produce the following SQL for the foreign key:

CREATE FOREIGN KEY(parent_data) REFERENCES parent_table(data) ON DELETE RESTRICT ON UPDATE CASCADE

Versions

Version
1.2.0
1.1.0
1.0.0