Android-LazyDatabase


Source link: https://github.com/redwarp/Android-LazyDatabase

Android-LazyDatabase

A fast way to store POJO in sqlite on an Android device without troubling yourself with database creation.

Deprecated

Google introduced Room which does the same thing, but better. I thereby deprecate Android-LazyDatabase, it's not useful anymore. It's still a good tutorial about how to upload artifacts to JCenter though.

What is it?

If you are working on a proof of concept app for Android (you should probably not use it for production in it's current state), and you need to store some good old POJO, this library is there for you. As the title says, it's a database for lazy people.

Warning

Seriously, don't use it for production, only for proof of concept or stuff like that. I mean, really, I might break everything with the next release. It's far from being future proof yet.

Usage

For Maven

<dependency>
  <groupId>net.redwarp.android.library</groupId>
  <artifactId>lazy-database</artifactId>
  <version>0.2.3</version>
  <type>aar</type> </dependency> 

For Gradle

compile 'net.redwarp.android.library:lazy-database:0.2.3' 

How to?

Let's say you have a good old POJO class, like this:

public class GoodOldPojo {

public String name;
private int randomNumber;
private float someValue;
 public GoodOldPojo(float someValue){

  this.someValue = someValue;

}

 public float getSomeValue() {

  return someValue;

}
 
}

First, modify it by setting a primary key, like that, and add an empty constructor:

import net.redwarp.library.database.annotation.PrimaryKey;  public class GoodOldPojo {

@PrimaryKey
public long key;
public String name;
private int randomNumber;
private float someValue;
 public GoodOldPojo(){

}

 (...) 
}
 

You will then have to create a DatabaseHelper object, using a Context, that you will use to save and retrieve all your objects.

import net.redwarp.library.database.DatabaseHelper;  (...)  GoodOldPojo pojo = new GoodOldPojo(0.45f);
 DatabaseHelper helper = new DatabaseHelper(context);

Saving

Saving is then straightforward:

helper.save(pojo);

It will create the database if it doesn't exist yet, and then save the object, and setting the long key to the inserted row value.

Saving in batch

helper.beginTransaction();
 helper.save(pojo1);
 helper.save(pojo2);
 helper.save(pojo3);
 helper.save(pojo4);
 helper.setTransactionSuccessful();
 helper.endTransaction();

Retrieving all data

List<GoodOldPojo> allPojos = helper.getAll(GoodOldPojo.class);

Retrieving one single POJO

GoodOldPojo retrievedPojo = helper.getWithId(GoodOldPojo.class, 2);

Object count

long count = helper.getCount(GoodOldPojo.class);

Chaining stuff

Let's say you have one POJO containing another POJO, like that:

public class GoodOldPojo {

private OtherPojo object; 
}

By default, it won't be saved. If you want it to be saved, you have to add the annotation @Chain to the field, like that:

public class GoodOldPojo {

@Chain private OtherPojo otherPojo; 
}

And voila, the otherPojo will be saved as well. By default, deleting the first one will also delete the second one. If you don't want the first item deletion to cascade on the second one, modify your class this way:

public class GoodOldPojo {

@Chain(delete = false) private OtherPojo otherPojo; 
}

What's left to do?

  • A shit load
  • Clear should also deleted chain elements
  • Relations of type one to many
  • Benchmarking (I mean, how fast is it compared to an hand written database)
  • Search
  • Unique keyword, etc...
  • Nothing, it's deprecated

Resources

Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed).

NodeFlow is an Android library that provides a simple way to visualize hierarchical content. Perfect for displaying items that are organized in categories / subcategories.

Android library for boilerplate destruction - "Just code what is worth coding"

  • Generates boilerplate code based on used annotations and lets you focus on what matters.
  • Generated code is fully traceable.
  • Everything is generated during compile time.
  • No reflection used!
  • Consists of modules.

Android Library for checking the current uploaded version on the Google Play.

ProperDroid is a gradle plugin and an Android library that simplifies the way that config different variant on your project.

A polite way to ask for ratings.

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