velvetdb-mapdb

MapDB backend for velvetdb

License

License

Categories

Categories

MapDB Data Databases
GroupId

GroupId

com.github.zakgof
ArtifactId

ArtifactId

velvetdb-mapdb
Last Version

Last Version

0.3.3.android
Release Date

Release Date

Type

Type

jar
Description

Description

velvetdb-mapdb
MapDB backend for velvetdb
Project URL

Project URL

https://github.com/zakgof/velvetdb
Source Code Management

Source Code Management

https://github.com/zakgof/velvetdb/tree/android/velvetdb-mapdb

Download velvetdb-mapdb

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
com.github.zakgof : velvetdb-core jar 0.3.3.android
org.mapdb : mapdb jar 2.0.0-SNAPSHOT

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status

Maven Central

Overview

Velvetdb is a high-level API for NoSQL storage perfectly fitting for small websites, desktop and mobile applications. With zero configuration and simple API you'll need just 5 minutes to start using velvetdb. Velvetdb abstracts out the underlying database concepts like columns or tables and provides essentially storage for you Java classes.

Velvetdb is implemented on top the following backends:

  • xodus - extremely fast embedded database
  • dynamodb - cloud database

Velvetdb's design is based on these principles making it distinct:

  • Least intrusive.
    We won't force developers to design their data model around the persistence framework. No need to extend framework's base classes or implement framework's interfaces. Persist your POJOs with no or minimal limitations and no or minimal framework dependencies. You can even use 3rd party model classes if needed.
  • Decoupled where possible.
    In our API we try to keep all concepts separated as much as possible. Entities do not know anything about their Relationships. Queries are objects that can be pre-created and separated from application's business logics.

More on philosophy on Wiki...

Data model fundamentals

  • Data is a Graph. Graph is a natural structure for most real data. Nodes are entities, edges represent relationships.
  • Entity is a POJO. Basic CRUD operations are applicable.
  • An entity should either have a Primary key or framework will assign it an autogenerated key. Range queries are supported for sortable primary keys.
  • Secondary indexes are supported with range queries applicable.
  • One-to-one, one-to-many and many-to-many relationships are supported. Range queries on linked entities are supported.

Main features

  • Pure Java 8. No xmls or other config files needed
  • Transactional (on backends that support transactions)
  • Pluggable serialization library (kryo is the default; elsa also supported)
  • Android support (on xodus), min SDK version is 19
  • Join queries
  • Automatic schema migration support

Android notes

Velvetdb uses Java 8 features and Java 8 APIs. In order to use them on older Android platforms, use Android Gradle plugin 4.0.0+ with system lib desugaring. For ProGuard/R8 config refer to consumer-rules.pro.

Getting Started

Setup

velvetdb is on Maven Central

Select the artifact matching your choice of backend: velvetdb-xodus, velvetdb-mapdb or velvetdb-dynamodb

<dependency>
    <groupId>com.github.zakgof</groupId>
    <artifactId>velvetdb-xodus</artifactId>
    <version>0.9.0</version>
</dependency>

or, using Gradle:

compile 'com.github.zakgof:velvetdb-xodus:0.9.0'

For Android version:

compile 'com.github.zakgof:velvetdb-xodus-android:0.3.3'    

Define entities using annotations

   public class Book {
        @Key
        private String isbn;
        private String title;
        private int year;
    }

    @Keyless // key will be autogenerated
    public class Author {
        private String firstName;
        private String lastName;
    }
    
    // define entities
    IEntityDef<String, Book> BOOK = Entities.create(Book.class);
    IKeylessEntityDef<Author> AUTHOR = Entities.keyless(Author.class);

    // define one-to-many relationship
    IMultiLink<Long, Author, String, Book> AUTHOR_BOOKS = Links.multi(AUTHOR, BOOKS); 

Working with velvetdb

    // Say you have some POJOs to store
    Book book = new Book...
    Author author = new Author...

    // Use /home/velvuser/db as embedded database folder
    IVelvetEnvironment env = VelvetFactory.open("velvetdb://xodus/home/velvuser/db"));
    
    // Run in a transaction
    env.execute(velvet -> {
    	   AUTHOR.put(velvet, author);
    });
       
    // We'll skip wrapping into transaction in the subsequent examples.
    
    // Store book and connect it with its author
    BOOK.put(velvet, book);
    AUTHOR_BOOKS.connect(velvet, author, book);
    
    // Get all books
    List<Book> allBooks = BOOK.batchGetAll(velvet);
    
    // Or fetch by a key
    Book book = BOOK.get(velvet, isbn);
    
    // Now get all books of a specific author:
    List<Book> authorsBooks = AUTHOR_BOOKS.get(velvet, author);

More on Wiki...

Versions

Version
0.3.3.android
0.3.2