From ec80c96d01d736a5c8eb8a2acbc42b75686b9c05 Mon Sep 17 00:00:00 2001 From: Bhargav MS Date: Sat, 5 Nov 2016 23:40:03 +0530 Subject: [PATCH] publish jitpack --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++- build.gradle | 2 +- library/build.gradle | 3 +++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99ab795..22cf478 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # SQLite based Persistent Queue. +[![Build Status](https://travis-ci.org/bhargavms/sqlite-persistent-queue.svg?branch=master)](https://travis-ci.org/bhargavms/sqlite-persistent-queue) +[![Coverage Status](https://coveralls.io/repos/github/bhargavms/sqlite-persistent-queue/badge.svg?branch=master)](https://coveralls.io/github/bhargavms/sqlite-persistent-queue?branch=master) +[![Release](https://jitpack.io/v/bhargavms/sqlite-persistent-queue.svg)](https://jitpack.io/bhargavms/sqlite-persistent-queue) -A Java Queue interface implementation that stores directly to SqliteDb +> A Java Queue interface implementation that stores directly to SqliteDb ## How it works @@ -19,3 +22,47 @@ A Java Queue interface implementation that stores directly to SqliteDb 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. + +## How to use + + You need to implement the `QueueObjectConverter` 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 + +```java +public class GsonPayloadConverter implements QueueObjectConverter { + 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: +```java +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? diff --git a/build.gradle b/build.gradle index f89dace..0c85a38 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:2.2.2' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3' - + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/library/build.gradle b/library/build.gradle index 39272e5..ff111eb 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,5 +1,8 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.kt3k.coveralls' +apply plugin: 'com.github.dcendents.android-maven' + +group='com.github.bhargavms' android { compileSdkVersion 24