WaspDb


Source link: https://github.com/rehacktive/waspdb

last release: 1.1.1

(note: this version is NOT compatible with 1.0, read the release message)

#WaspDb WaspDB is a pure Java key/value (NoSQL) database library for Android. It supports AES256 encryption for all the disk storage. It's very small (the aar file is ~189 KB).

Keys and Values are simple Java Objects. Everything is automatically serialized using the Kryo serialization library.

Data is stored by an implementation of hashmaps on disk.

###QuickStart

To use it with gradle (using jitpack.io):

Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {

...
maven {
 url "https://jitpack.io" 
}
  
}
 
}

Add the dependency

dependencies {
  ...  compile 'com.github.rehacktive:waspdb:1.1.1' 
}

Ok, let's start.

Let's assume a POJO (even with nested object, like Address):

class User {
  private String username;  private String email;  private String telephone;  private Address address;
 public User() {
  
}

 // getters and setters... 
}

No need to be Serializable or Parcelable or annotations or extending/implementing from other classes/interfaces, the only important thing is to have an empty constructor.

Create a database, a WaspHash and store a POJO

// create a database, using the default files dir as path, database name and a password String path = getFilesDir().getPath();
 String databaseName = "myDb"; String password = "passw0rd";

WaspDb db = WaspFactory.openOrCreateDatabase(path,databaseName,password);

// now create an WaspHash, it's like a sql table WaspHash users = db.openOrCreateHash("users");
  // now let's have a POJO User p = new User();
 ... // do your stuff with your POJO!  // and simply store it! users.put(p.getUsername(), p);

To retrieve it, it's just

User p = users.get("username1");

Need all your objects?

List<User> allUsers = users.getAllValues();

It returns all the users, in a standard java List.

Or you can get all the keys used

List<String> keys = users.getAllKeys();

or the actual key/value map (it's again a standard java class)

HashMap<String, User> usersMap = users.getAllData();

Please note that the process of creating an encrypted database is computationally expensive (10000 iterations to create the AES256 key), so also an async method is available:

WaspFactory.openOrCreateDatabase(path, databaseName, password, new WaspListener<WaspDb>() {

@Override

public void onDone(WaspDb waspDb) {

 ....

}

  
}
);

###Why WaspDb I hate to store objects on sqlite! It's a lot of boiler code...for what? Okay, let's say in the polite way :)

The object-relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is being used by a program written in an object-oriented programming language or style; particularly when objects or class definitions are mapped in a straightforward way to database tables or relational schema.  

(from wikipedia https://en.wikipedia.org/wiki/Object-relational_impedance_mismatch)

###What WaspDb is NOT This is not a SQL database. It does not have a relational data model, it does not support SQL queries, and it provides no support for indexes, nor transactions.

###Features

  • it's pure java, it's standalone, no native stuff, it's not an ORM to SqlLite!

  • the database addresses up to 4294967296 keys for WaspHash...enough? :)

###Limitations

  • it's NOT transactional. So if you wanna store 10000, it will make 10000 actual write operations to disk in sequence. That means it will be slower (in this case) compared to transactional databases. (of course, if you store 100 items as a java List - so actually a single object - it will make a single(ish) write operation)

###Proguard If you use Proguard in your project, add this to your proguard rules in order to skip WaspDB/Kryo classes:

-keep class net.rehacktive.waspdb.** {
 *; 
}
 -keep class com.esotericsoftware.kryo.** {
 *; 
}
 

###Performances

I've used this project https://github.com/Raizlabs/AndroidDatabaseLibraryComparison to make some benchmarking.

This is the "simple trial" (storing 50 objects) on a Nexus 5, using WaspDb's encryption feature:

It's even faster if you don't need encryption.

Resources

Droidux is "predictable state container" implementation, inspired by Redux.

Android-RateThisApp is an library to show "Rate this app" dialog.

Android library for the gov.uk Flood Monitoring API.

A small library to get the current running processes on Android.

A utility that answers the question: is my user running on at least this SDK?

This is an Android project allowing to realize a beautiful circular fillable loaders to be used for splashscreen for example.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes