sqlite-persistent-queue


Source link: https://github.com/bhargavms/sqlite-persistent-queue

SQLite based Persistent Queue.

A Java Queue interface implementation that stores directly to SqliteDb

How it works

  • Implement the QueueObjectConverter<T> interface do decide how you want to serialize and deserialize the objects that you want to push to the Queue.

  • The SQLitePersistentQueue class uses the above implementation to serialize objects before storing it the Database.

  • Upon calling poll() or remove() on the SQLitePersistentQueue the item with the lowest primary key value (since the primary key is auto-incrementing) is removed from the Queue and returned. This co-incidentally is the HEAD of the queue (as queue is FIFO based).

  • Please remember each instance of SQLitePersistentQueue creates a new connection to the Database. I have kept the freedom of how many connections to be made to DB to the developer. The ideal usage for new developers would be to hold only a single instance of the SQLitePersistentQueue class in your Application class, and retrieve this wherever you want. Also DO NOT forget to call close() to close the connection to the Database once you are finished using the Queue.

Getting started

Add to your project level build.gradle's allprojects block like this

allprojects {

  repositories {

maven {
 url "https://jitpack.io" 
}

  
}
 
}

Next add to your module level (app) build.gradle's dependencies block like this

dependencies {

  compile 'com.github.bhargavms:sqlite-persistent-queue:1.0.0' 
}

You're all set, Now you can start using the SQLitePersistentQueue class.

How to use

You need to implement the QueueObjectConverter<T> class (T is the type of the object you are storing in the Queue) to decide how you want to serialize/deserialize objects as objects are converted to strings before being saved in the database.

A Sample implementation of the QueueObjectConverter interface:

Here I use Gson to convert objects to/from json strings

public class GsonPayloadConverter implements QueueObjectConverter<Payload> {

  private final Gson gson;

public GsonPayloadConverter(Gson gson) {

this.gson = gson;
  
}

@Override
  public Payload deserialize(String value) {

return gson.fromJson(value, Payload.class);

  
}

@Override
  public String serialize(Payload queueObject) {

return gson.toJson(queueObject);

  
}
 
}

This implementation you should pass to the constructor of SQLitePersistentQueue class. The SQLitePersistentQueue uses this implementation to convert objects to/from strings before returning storing/retreiving from the SqliteDb.

Example:

Gson gson = new Gson() queue = new SQLitePersistentQueue<>(c, new GsonPayloadConverter(gson));

This instantiated queue you can use it like any other java queue as it implements the java.util.Queue interface.

Important

Call queue.close() when you are done using the queue to close the connection to the Database.

TODO:

  • Make Sqlite writes in chunks by providing save() api?

Resources

Endpoint2mock2 is a library for mocking Retrofit 2 Http endpoint in your Android app. It works just by adding @MockedEndpoint annotation to the Retrofit calls.

A bar chart is a chart or graph that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally.

This is a library which allows you to create a record button view in android.

Custom slider for Android build from scratch.

A helper class for Toolbar configuration.

Convalida is a simple, lightweight and powerful field validation library for Android.

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