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

This plugin generates Android string resource XML files from CSV file. Generation has to be invoked as additional gradle task.

Supported features:

  • non-translatable resources - translatable="false" XML attribute
  • auto-escaping double quotes, apostrophes and newlines
  • auto-quoting leading and trailing spaces
  • syntax validation - duplicated, empty, invalid names detection
  • comments

TokenAutoComplete is a Android Gmail style token auto-complete text field and filter. It's designed to have an extremely simple API to make it easy for anyone to implement this functionality while still exposing enough customization to let you make it awesome.

openpgp-api-lib provides methods to execute OpenPGP operations, such as sign, encrypt, decrypt, verify, and more without user interaction from background threads. This is done by connecting your client application to a remote service provided by OpenKeychain or other OpenPGP providers.

Auth0Client is a Gradle based Android library, to let developers have a basic Auth0 API.

This library is compatible from API 7 (Android 2.1).

EditText component for Android that can show password with new a concept. Press on eye to show hidden password.

PullToDismissPager is an Android Open Source Library for showing ViewPager in similar way that Facebook app does in its Friend Request Section. This library is based on awesome AndroidSlidingUpPanel library.

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