Skip to content

ShieldDB is a simple embedded database with JSON file backend with optional in-memory read cache.

License

Notifications You must be signed in to change notification settings

Kara3/ShieldDB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShieldDB

ShieldDB is a simple embedded database with JSON file backend with optional in-memory read cache.

Features

  • Easy to use : use ShieldDB like you use a standard Java List
  • Easy to extends
  • No mandatory external dependencies
  • No reflection API usage (except for some json mapper implementation like Gson)

How to use it?

Add the core dependency

...
<dependencies>
	...
	<dependency>
		<groupId>nf.fr.k49</groupId>
		<artifactId>shielddb-core</artifactId>
		<version>0.1.1</version>
	</dependency>
	...
</dependencies>
...

Add as dependency a mapper

...
<dependencies>
	...
	<dependency>
		<groupId>nf.fr.k49</groupId>
		<artifactId>shielddb-gson-backend</artifactId>
		<version>0.1.1</version>
	</dependency>
	...
</dependencies>
...

Note: At this time, there is only a Gson mapper implementation. But you can make yours and maybe make a Pull Request :-)

Initialize a ShieldDB instance

Create a bean class:

public class User {
	private String firstname;
	private String lastname;
	private int age;
	private LocalDate birthDate;
	...
}
final List<User> userDb = ShieldDB.<User>builder()
		.mapper(new ShieldDBGson<User>())
		.storage(new FileStorage("User.json"))
		.build();

Note: If you want to store a type that has no custom equals implementation, you may have some issues.

(Optional) Add some shield to customize the way ShieldDB will read/write

final List<User> userDb = ShieldDB.<User>builder()
		.shield(new AtomicShield())// ensure only one thread use userDb
		.shield(new ReadOnlyShield())// throw an UnsupportedOperationException on write access
		//.shield(new SilentReadOnlyShield())// do nothing on write access (no exception)
		.shield(new InMemoryArrayListReadCacheShield())// add an in memory read cache
		.mapper(new ShieldDBGson<User>())
		.storage(new FileStorage("User.json"))
		.build();

See more usage example here: https://github.com/kuroidoruido/ShieldDB/tree/master/shielddb-demo-app/

About

ShieldDB is a simple embedded database with JSON file backend with optional in-memory read cache.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%