Skip to content

Commit

Permalink
publish jitpack
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavms committed Nov 5, 2016
1 parent 3bf9531 commit ec80c96
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<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
```java
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:
```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?
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ec80c96

Please sign in to comment.