org.panteleyev:persistence-kt

Annotation wrapper for SQLite and MySQL database.

Лицензия

Лицензия

Категории

Категории

Ant Компиляция и сборка
Группа

Группа

org.panteleyev
Идентификатор

Идентификатор

persistence-kt
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

org.panteleyev:persistence-kt
Annotation wrapper for SQLite and MySQL database.
Ссылка на сайт

Ссылка на сайт

https://github.com/petr-panteleyev/persistence-kt
Система контроля версий

Система контроля версий

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

Скачать persistence-kt

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jre8 jar 1.1.4

test (3)

Идентификатор библиотеки Тип Версия
org.xerial : sqlite-jdbc jar 3.15.1
mysql : mysql-connector-java jar 5.1.42
org.testng : testng jar 6.10

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.2.0
1.1.0
1.0.0