Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,262 Members 50,491 Now Online
XDA Developers Android and Mobile Development Forum

DataManagement Library for Easy Android Database Storage

Tip us?
 
PunchInThroat
Old
(Last edited by PunchInThroat; 10th January 2013 at 03:19 AM.)
#1  
Junior Member - OP
Thanks Meter 18
Posts: 12
Join Date: Dec 2012
Default DataManagement Library for Easy Android Database Storage

Storing objects to a Database for an Android application should be fast and easy as:
Code:
Select Code
dm.add(new StorableClass());
DataManagement is a new open source library that allows you to do just that.

DataManagement is a Java Android library designed to help easily and efficiently store aggregate classes to an SQLite database. It eliminates the need to write separate classes to manage database – object interactions and allows developers to use simple methods to store, query, update, and delete objects. The library is capable of storing all objects of classes whose instance variables are either primitive data types or are themselves objects of another storable class. The DataManagement Library condenses many standard database features into several simple methods. It is fully open source and the code can be found at http://epsilonlabsllc.github.com/DataManagement

Examples:
Creating a Storable Class:

Code:
Select Code
public class StorableClass{
    @Id
    private int ident;
    private int num1;
    private double num2;
    private String num3;
    private boolean num4;
    public static final int num5 = 3;
    private OtherStorableClass[] ds2;
}
A storable class must meet two requirements. First, the class must have a private instance variable of type int that will be used as the id number of the object. This variable may be read by the application, but the application should not have the capability to write to or change this variable in anyway. This variable is identified by the system with an @Id annotation. In addition, the class should not have any instance variables that are not either primitive types, strings, or other storable objects.

Instantiating a DataManager Object:

Code:
Select Code
DataManager dm = new DataManager(context);
The open method accepts the calling Context that is going to use the database. Usually this should be the calling Activity.

Opening a Database for Use:

Code:
Select Code
dm.open();
This method must be called before the database is used in any way.

Closing a Database After Use:

Code:
Select Code
dm.close();
This method should be called after all database operations have been performed.

Adding an Object to the Database:

Code:
Select Code
int id = dm.add(new StorableClass());
The add method accepts an object of a storable class as its only parameter and adds it to the database. It returns its id in the database for future use.

Retrieving a Specific Item from the Database by ID:

Code:
Select Code
StorableClass storableObject = dm.get(StorableClass.class, id);
The get method accepts two parameters: the data type of the stored object and the Id number of the object (the return value of the add method).

Retrieving All Objects of a Given Type Stored in the Database as a Collection:

Code:
Select Code
storableObjectCollection = dm.getAll(StorableClass.class);
The getAll method’s only parameter is the class of the objects that should be retrieved.

Retrieving a Collection of Storable Objects that match a given criteria:

Code:
Select Code
Collection<StorableClass> storableObjectCollection = dm.find(StorableClass.class, 5, "num1");
The find method accepts three parameters: the data type of the stored object, the value that is being searched for, and the name of the instance variable as a string. This method is overloaded in such a way that the second parameter may be any primitive value or a string.

Updating an Object in the Database:

Code:
Select Code
dm.update(id, updatedObject);
The update method accepts two parameters: The id number of the object being updated and the updated object that will replace the existing one I the database. If the id number of the new object and the id number given as the first parameter do not match, the object’s id will be overwritten.

Deleting an Object by its Id number:

Code:
Select Code
dm.delete(StorableClass.class, id);
The delete method accepts two parameters: The data type and id number of the object to be deleted.

Additional Notes:
Id numbers are used by the database to ensure that objects are put in the correct place and to allow the program to access these objects. It is important that programs using this library do not attempt to set these variables as they will be initialized and managed by the library. These id numbers are unique for objects of a given type; objects of different types may have the same id number. In addition, if objects are deleted from the database their id numbers are left empty and are not reused.

Licensing:
DataManagement is Currently Licensed under the GNU General Public License, version 3 (GPL-3.0). It is intended for open source use by anyone who would like to use it.
The Following 17 Users Say Thank You to PunchInThroat For This Useful Post: [ Click to Expand ]
 
skmpowdjy
Old
#2  
Member
Thanks Meter 57
Posts: 77
Join Date: Mar 2011
This is awesome!!

Tried it out for an app today-- incredibly simple! For those looking-- this library essentially replaces loads of SQL helper classes and queries with an interface that's similar to ArrayList.

Definitely going to use this for everything in the future!

Thanks
 
regaw_leinad
Old
#3  
regaw_leinad's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 3622
Posts: 3,662
Join Date: Jan 2010
Location: Seattle, WA
Did you change the license or something? The repo is no longer on github.
Device: HTC One (AT&T)
Recovery:TWRP 2.6.3.0 | Bootloader: S-OFF
ROM: Stock



My Development Threads

Watch my programming tutorials on YouTube - BetterCoder
I'm also a professional musician - YouTube - SoundCloud


Please don't post just to say "Thanks" - There's a button for that . Be sure to use it!
 
cmike21
Old
#4  
Member
Thanks Meter 4
Posts: 33
Join Date: Jun 2011
Location: Boulder

 
DONATE TO ME
Quote:
Originally Posted by regaw_leinad View Post
Did you change the license or something? The repo is no longer on github.
After a quick search on github, it looks like it's been moved here

https://github.com/epsilonlabsllc/DataManagement
 
PunchInThroat
Old
#5  
Junior Member - OP
Thanks Meter 18
Posts: 12
Join Date: Dec 2012
Quote:
Originally Posted by cmike21 View Post
After a quick search on github, it looks like it's been moved here

https://github.com/epsilonlabsllc/DataManagement

Thanks. I forgot to change it. I just edited my post with the correct url.
The Following User Says Thank You to PunchInThroat For This Useful Post: [ Click to Expand ]
 
S7evinK
Old
#6  
Junior Member
Thanks Meter 6
Posts: 23
Join Date: Dec 2010
Sounds awesome! Great work.

Gonna try it this evening.
 
Ruffstaarr
Old
#7  
Junior Member
Thanks Meter 0
Posts: 10
Join Date: Jan 2011
Anyone compared the performance with db4o?
 
aegis123
Old
(Last edited by aegis123; 10th January 2013 at 10:21 AM.)
#8  
Junior Member
Thanks Meter 0
Posts: 2
Join Date: Sep 2008
Location: Utrecht
are there any performance test with other DB libraries for android? and what about the this lib vs contentproviders?

activeandroid.com
code.google.com/p/orm-droid]orm-droid
satyan.github.com/sugar/
 
azoller1
Old
#9  
azoller1's Avatar
Senior Member
Thanks Meter 1605
Posts: 1,748
Join Date: Aug 2011
Location: Lenexa

 
DONATE TO ME
will definitly be using this once i learn some app development! thanks for this!
DONATIONS WOULD BE NICE!!-- HERE

Device: LG Spectrum 16GB 4G
Rom: Running Beanstalk Builds
Kernel: Running My S-Kernel JB

Device: Asus TF300T 32GB
Rom: Running My Own CyanogenMod Builds
Kernel: Running Stock CM Kernel

MY DEV
GOO.IM FILES/FOLDERS
ANDROID FILE HOST DEVICES
SOURCEFORGE FILES
 
JonnyPJohnston
Old
#10  
Junior Member
Thanks Meter 2
Posts: 18
Join Date: May 2011
Location: Fort Wayne, Indiana

 
DONATE TO ME
Just in time...
Current Devices

Samsung Galaxy Note II - Rooted Stock ROM mskip's method
Samsung Note 10.1 Stock ROM
HTC One X - CleanROM 5.1/CyanogenMod 10 Nightlies
ASUS Transformer Prime - CyanogenMod 10 Nightlies/Ubuntu
LG P509

Past Devices

LG Optimus - Rooted Stock ROM
HTC Desire HD
Motorola T720
HTC TYTN
Motorola Razr
Motorola MicroTAC

Know Your Power. Trust Your friends. Crush Your F*&#%&# Enemies

Tags
android, database, library
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Device Review: OnePlus One

Seemingly every day, there are a bunch of new devices being released. Some are budget devices and some are … more

Browse the Internet with the Innovative Atlas Web Browser

For the most part, Chrome, Firefox, and Dolphin Browser have no real rivals among … more

Choose from Over a Thousand Battery Styles with 3Minit Battery Mod

The battery style in stock Android looks pretty dull. It doesn’t … more

Organize Your Cloud Storage Files with Unclouded

Cloud storage services like Dropbox or Google Drive have grown in popularity dramatically … more