Skip to content

itadvc/jnsedb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jnsedb

Java NoSql Embeddable Database

Overview

If you need simple, persistable, fast and embeddable java nosql database you can use jnsedb just like this:

String dbDir = System.getProperty("user.dir") + "\.mydb";
String database = "mydatabase";

JnsedbManager dbManager = new JnsedbEmbeddedServer(dbDir).startup().getManager(database);

// store new entity
dbManager.store(myJavaObject);
// loads (lazy) all stored objects of class MyJavaObject
Collection<MyJavaObject> allMyJavaObjects = dbManager.loadAll(MyJavaObject.class);
// loads object of class MyJavaObject stored with id = 1
dbManager.load(MyJavaObject.class, 1);
// delete object of class MyJavaObject stored with id = 1
dbManager.delete(MyJavaObject.class, 1);

To use it in your maven project just add this code to your pom.xml file:

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

	<dependency>
	    <groupId>com.github.itadvc</groupId>
	    <artifactId>jnsedb</artifactId>
	    <version>jnsedb-0.0.1</version>
	</dependency>

gradle:

allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}
dependencies {
	compile 'com.github.itadvc:jnsedb:jnsedb-0.0.1'
}

Usage

Simple entity:

import com.github.itadvc.jnsedb.annotations.Cache;
import com.github.itadvc.jnsedb.annotations.Id;

@Cache
public class MyJavaObject {

	@Id
	private String internalId;
	private int myIntValue;
	private List<ChildClass> childs;

	public String getInternalId() {
		return internalId;
	}

	public void setInternalId(String id) {
		this.internalId = internalId;
	}
}

Setting cache size to 10MB (default is 100MB per class):

import com.github.itadvc.jnsedb.annotations.Cache;

@Cache(maxSizeMB = 10)
public class MyJavaObject {
...

Enity with integer (autogenerated) id

import com.github.itadvc.jnsedb.annotations.Id;

public class MyJavaObject {

	@Id
	private int id;
	...

Entity with integer id when autogeneration is global (one auto-increment unique for all classes)

import com.github.itadvc.jnsedb.annotations.Id;

public class MyJavaObject {

	@Id(globalAutoincrement = true)
	private int id;
	...

Database optional configuration

import com.github.itadvc.jnsedb.JnsedbEmbeddedServer;
...
JnsedbEmbeddedServer dbServer = new JnsedbEmbeddedServer(dbDir);
// log all stored entities
dbServer.getConfiguration().setLogStoresEnabled(true);
// use cache replacement policy LFU (default is MRU, another possibility is LRU)
dbServer.getConfiguration().setCacheReplacementPolicy(CacheReplacementPolicy.LeastFrequentlyUsed);
// disable cache (annotation @Cache is ignored)
dbServer.getConfiguration().disableCache();

Features

  • Simple to use
  • Fast
  • Persistable
  • Embeddable
  • Index is cached in memory
  • Loaded objects can be cached in memory
  • Serialization using jackson, jackson annotations are allowed (@JsonInclude, @JsonProperty etc)

Contribute

  • Issue Tracker: github.com/itadvc/jnsedb/issues
  • Source Code: github.com/itadvc/jnsedb
  • Tests: junit

License

This project is released under the Apache license. See the bundled LICENSE file for details.

Author

Krzysztof Andrzejczak