Skip to content

An android library which makes storing of objects on disk easier. Just implement the StoredObject interface and you should be able to easily store and retreive objects and list of objects.

Notifications You must be signed in to change notification settings

mathcamp/storedobject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An easy way to store & fetch objects on disk in android.

Usage:

//Storing:
Database.with(context).saveObject(obj);

//Fetching with id:
Database.with(context).load(TYPE.person).withId(id).execute();

//Fetching with tags:
Database.with(context).load(TYPE.person).tagEquals("name", "john").execute();

//Fetching a list of objects sorted by ts:
Database.with(context).load(TYPE.person).orderByTs(SORT_ORDER.DESC).limit(20).execute();

Here obj implements Database.StoredObject and TYPE implements Database.StoredObject.TYPE

Example:

public enum TYPE implements Database.StoredObject.TYPE {
  person(Person.class);
  
  private Class cls;
  
  TYPE(Class cls) {
    this.cls = cls;
  }
  
  @Override
  public Class getTypeClass() {
    return cls;
  }
  
  @Override
  public String getTypeName() {
    return name();
  }
}
public class Person implements Database.StoredObject {
  String name;
  String id;
  String image_url;
  ...
  ...
  
  TYPE getStoredObjectType() {
    return TYPE.person;
  }
  
  /** Unique id for the object. **/
  String getStoredObjectId() {
    return id;
  }
  
  /** Return a list of tags that you want to be able to search for this object by **/
  List<Pair<String, String>> getStoredObjectSearchableTags() {
    List<Pair<String, String>> retval = new LinkedList<Pair<String, String>>();
    retval.add(new Pair("name", name));
    return retval;
  }
  
  // Timestamp in seconds
  Double getStoredObjectTimestamp() {
    return System.currentTimeMillis()/1000;
  }

}

About

An android library which makes storing of objects on disk easier. Just implement the StoredObject interface and you should be able to easily store and retreive objects and list of objects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages