Skip to content

Commit ec80c96

Browse files
committed
publish jitpack
1 parent 3bf9531 commit ec80c96

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# SQLite based Persistent Queue.
2+
[![Build Status](https://travis-ci.org/bhargavms/sqlite-persistent-queue.svg?branch=master)](https://travis-ci.org/bhargavms/sqlite-persistent-queue)
3+
[![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)
4+
[![Release](https://jitpack.io/v/bhargavms/sqlite-persistent-queue.svg)](https://jitpack.io/bhargavms/sqlite-persistent-queue)
25

3-
A Java Queue interface implementation that stores directly to SqliteDb
6+
> A Java Queue interface implementation that stores directly to SqliteDb
47
58
## How it works
69

@@ -19,3 +22,47 @@ A Java Queue interface implementation that stores directly to SqliteDb
1922
for new developers would be to hold only a single instance of the `SQLitePersistentQueue` class
2023
in your Application class, and retrieve this wherever you want. Also **DO NOT** forget to call `close()`
2124
to close the connection to the Database once you are finished using the Queue.
25+
26+
## How to use
27+
28+
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.
29+
30+
A Sample implementation of the `QueueObjectConverter` interface:
31+
> Here I use Gson to convert objects to/from json strings
32+
33+
```java
34+
public class GsonPayloadConverter implements QueueObjectConverter<Payload> {
35+
private final Gson gson;
36+
37+
public GsonPayloadConverter(Gson gson) {
38+
this.gson = gson;
39+
}
40+
41+
@Override
42+
public Payload deserialize(String value) {
43+
return gson.fromJson(value, Payload.class);
44+
}
45+
46+
@Override
47+
public String serialize(Payload queueObject) {
48+
return gson.toJson(queueObject);
49+
}
50+
}
51+
```
52+
53+
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.
54+
55+
Example:
56+
```java
57+
Gson gson = new Gson()
58+
queue = new SQLitePersistentQueue<>(c, new GsonPayloadConverter(gson));
59+
```
60+
61+
This instantiated queue you can use it like any other java queue as it implements the `java.util.Queue` interface.
62+
63+
##### Important
64+
65+
Call `queue.close()` when you are done using the queue to close the connection to the Database.
66+
67+
## TODO:
68+
- Make Sqlite writes in chunks by providing `save()` api?

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
dependencies {
88
classpath 'com.android.tools.build:gradle:2.2.2'
99
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3'
10-
10+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
1313
}

library/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.github.kt3k.coveralls'
3+
apply plugin: 'com.github.dcendents.android-maven'
4+
5+
group='com.github.bhargavms'
36

47
android {
58
compileSdkVersion 24

0 commit comments

Comments
 (0)