DataManagement Library for Easy Android Database Storage

Search This thread

PunchInThroat

Member
Dec 22, 2012
12
18
Storing objects to a Database for an Android application should be fast and easy as:
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:
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:
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:
dm.open();
This method must be called before the database is used in any way.

Closing a Database After Use:

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

Adding an Object to the Database:

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:
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:
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:
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:
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:
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.
 
Last edited:

skmpowdjy

Senior Member
Mar 2, 2011
97
63
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 :D
 

aegis123

New member
Sep 6, 2008
2
0
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/
 
Last edited:

dancer_69

Senior Member
Jan 2, 2007
2,011
617
Hello,
I'm trying to build a simple project the test and learn how this lib works, but I'me quite new in programming and I have some difficulties to understand how to use dm.
The project will be a simple song database with edittexts for song and artist. I created the storableClass as the example, but I cannot understand how to connect it with the main activity, so I can use the output of the editTexts.
1st question is: do I need to have the String variables as private? I'm thinking that must have them as public, so I can connect them with the editTexts output.
2nd: question: all these methods needed to be called from storableClass, or from main activity, after I connected the storableClass with main activity? And how I do this?
Probably with the use of context you descibed, but I cannot understand how to do it. I tried sometimes but always get errors and a specific one "The constructor DataManager(Context) is not visible".
Is there any example project' source code which use this lib to get an Idea, or can you explain the context step more extensively?
Thanks in advance and sorry for noob questions.
 

-star-

Senior Member
Aug 29, 2011
235
36
Hello,
I'm trying to build a simple project the test and learn how this lib works, but I'me quite new in programming and I have some difficulties to understand how to use dm.
The project will be a simple song database with edittexts for song and artist. I created the storableClass as the example, but I cannot understand how to connect it with the main activity, so I can use the output of the editTexts.
1st question is: do I need to have the String variables as private? I'm thinking that must have them as public, so I can connect them with the editTexts output.
2nd: question: all these methods needed to be called from storableClass, or from main activity, after I connected the storableClass with main activity? And how I do this?
Probably with the use of context you descibed, but I cannot understand how to do it. I tried sometimes but always get errors and a specific one "The constructor DataManager(Context) is not visible".
Is there any example project' source code which use this lib to get an Idea, or can you explain the context step more extensively?
Thanks in advance and sorry for noob questions.

Here is a sample project: https://github.com/epsilonlabsllc/D.../net/epsilonlabs/datamanagementefficient/test

(It's in the github project.)

You can set the strings on private, because you can grab the values of the edittext on your layout. Eclipse should generate your set/ get methods if you create your private strings. The methods. Take the values and insert them into your db, Look at the sample:

Code:
public DataSample(){
		num1 = 3;
		numderp = 3.0;
		num3 = "three";
		num4 = true;
		ds2depier = new ArrayList<DataSample2>();
		ds2depier.add(new DataSample2());
		ds2depier.add(new DataSample2());
	}

That is the basic constructor of the DataSample class. If you do an insert like
int id = dm.add(new StorableClass());
The basic constructor will be called and it sets your values for example the num1 =3. You could overwrite the basic constructor with your costum constructor to insert your values.

You activity call:
dm.add(DataSample(sSong,sTitle));
The constructor could be something like this:
public DataSample(String sSong, String sTitle){
sYourTitleDataBaseColumnCaption = sTitle;
sYourSongDataBaseColumnCaption = sSong;
}

Or use the set/get methods, my custom constructor are just an idea to show you an example. Just take a closer look at the github sample and it should work for you.
 
  • Like
Reactions: dancer_69

SkzBR

Senior Member
Oct 26, 2010
209
16
Porto Alegre
How to is very outdated. I can't initialize via new DataManager() but via getInstance(), also delete and update method doesn't have Id argument anymore.

Also,
I can't get this to work. I can't even add a member to collection because it needs to use db.add(new MyClass()); but i already have MyClass() initialized with their members. I have tried to do something like copy the Id from add, update into my other instance of this class and run a db.update() but it throws a RuntimeException.

Not usable at this time.
 

furius

Senior Member
Sep 6, 2009
380
56
Sounds good! ;)
I'll give it a try as soon as I start a new project that requires data storage ...
I really hate SQLiteOpenHelper, cursor and all this strange syntax ...
 

tiwiz

Retired Recognized Developer
Nov 8, 2010
267
83
Torino
roberto.orgiu.net
Hello mate,

I'd like to use your library and backup the data with Google/Dropbox Sync... can you tell me the name of the file on which you save data?
Thanks,

Tiwiz
 

Top Liked Posts

  • There are no posts matching your filters.
  • 17
    Storing objects to a Database for an Android application should be fast and easy as:
    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:
    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:
    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:
    dm.open();
    This method must be called before the database is used in any way.

    Closing a Database After Use:

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

    Adding an Object to the Database:

    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:
    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:
    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:
    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:
    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:
    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.
    1
    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.
    1
    Hello,
    I'm trying to build a simple project the test and learn how this lib works, but I'me quite new in programming and I have some difficulties to understand how to use dm.
    The project will be a simple song database with edittexts for song and artist. I created the storableClass as the example, but I cannot understand how to connect it with the main activity, so I can use the output of the editTexts.
    1st question is: do I need to have the String variables as private? I'm thinking that must have them as public, so I can connect them with the editTexts output.
    2nd: question: all these methods needed to be called from storableClass, or from main activity, after I connected the storableClass with main activity? And how I do this?
    Probably with the use of context you descibed, but I cannot understand how to do it. I tried sometimes but always get errors and a specific one "The constructor DataManager(Context) is not visible".
    Is there any example project' source code which use this lib to get an Idea, or can you explain the context step more extensively?
    Thanks in advance and sorry for noob questions.

    Here is a sample project: https://github.com/epsilonlabsllc/D.../net/epsilonlabs/datamanagementefficient/test

    (It's in the github project.)

    You can set the strings on private, because you can grab the values of the edittext on your layout. Eclipse should generate your set/ get methods if you create your private strings. The methods. Take the values and insert them into your db, Look at the sample:

    Code:
    public DataSample(){
    		num1 = 3;
    		numderp = 3.0;
    		num3 = "three";
    		num4 = true;
    		ds2depier = new ArrayList<DataSample2>();
    		ds2depier.add(new DataSample2());
    		ds2depier.add(new DataSample2());
    	}

    That is the basic constructor of the DataSample class. If you do an insert like
    int id = dm.add(new StorableClass());
    The basic constructor will be called and it sets your values for example the num1 =3. You could overwrite the basic constructor with your costum constructor to insert your values.

    You activity call:
    dm.add(DataSample(sSong,sTitle));
    The constructor could be something like this:
    public DataSample(String sSong, String sTitle){
    sYourTitleDataBaseColumnCaption = sTitle;
    sYourSongDataBaseColumnCaption = sSong;
    }

    Or use the set/get methods, my custom constructor are just an idea to show you an example. Just take a closer look at the github sample and it should work for you.