org.panteleyev:persistence

Annotation wrapper for SQLite and MySQL database.

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

org.panteleyev
ArtifactId

ArtifactId

persistence
Last Version

Last Version

19.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

org.panteleyev:persistence
Annotation wrapper for SQLite and MySQL database.
Source Code Management

Source Code Management

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

Download persistence

How to add to project

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

Dependencies

test (5)

Group / Artifact Type Version
org.testng : testng jar 6.14.3
org.xerial : sqlite-jdbc jar 3.15.1
mysql : mysql-connector-java jar 8.0.15
org.mockito : mockito-core jar 2.24.5
com.google.code.gson : gson jar 2.8.5

Project Modules

There are no modules declared in this project.

Persistence API

Annotation based wrapper for SQLite and MySQL.

The library is intended for desktop applications that perform insert/update/delete operations only.

BSD-2 license Maven Central Javadocs

Artifact

<dependency>
    <groupId>org.panteleyev</groupId>
    <artifactId>persistence</artifactId>
    <version>19.2.0</version>
</dependency>

Limitations

  • Each new version may introduce incompatible changes
  • No queries, either mapped or raw
  • Basic support for constraints
  • No support for schema migration in case of changes

Data Types

Java SQLite MySQL
String VARCHAR VARCHAR
String with Column.isJson() = true BLOB JSON
BigDecimal VARCHAR ( Column.precision() + 1 ) DECIMAL ( Column.precision(), Column.scale() )
Date INTEGER BIGINT
LocalDate INTEGER BIGINT
byte[] BLOB VARBINARY ( Column.length() )
UUID VARCHAR(36) BINARY(16) or VARCHAR(36)

java.util.Date are stored as long using Date.getTime() java.time.LocalDate is stored as long using LocalDate.toEpochDay()

The following types can be used as primary keys:

  • Integer, int
  • Long, long
  • String
  • UUID

Database independent auto-increment is supported for integer and long keys.

Usage Examples

Immutable Object

@Table("book")
public class Book implements Record {
    @PrimaryKey
    @Column(Field.ID)
    private final int id;
    
    @Column("title")
    private final String title;

    @RecordBuilder
    public Book(@Column(Column.ID) int id, 
                @Column("title") String title) 
    {
        this.id = id;
        this.title = title;
    }

    public int getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }
}

Foreign Keys

@Table("parent_table")
public class ParentTable implements Record {
    @Column(value = "data", unique = true)
    private String data;

    public String getData() {
        return data;
    }
}

@Table("child_table")
public class ChildTable implements Record {
    @Column("parent_data")
    @ForeignKey(table = ParentTable.class, column = "data",
        onDelete = ReferenceOption.RESTRICT, onUpdate = ReferenceOption.CASCADE)
    private final String parentData;

    public String getParentData() {
        return parentData;
    }
}

Versions

Version
19.2.0
19.1.0
18.1.1
18.1.0
3.2.1
3.2.0
3.1.0
3.0.0
2.2.1
2.2.0