Skip to content

Commit

Permalink
Merge branch 'release/2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgr committed May 11, 2020
2 parents 34f374d + 19adb49 commit 0e4e76a
Show file tree
Hide file tree
Showing 27 changed files with 310 additions and 146 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Change Log
==========

Version 2.7.1 *(2020-05-11)*
----------------------------

Fixes:
* Ignore backup files in getAllKeys
* Fix exception on simultaneous write and destroy

Thanks Alexandre Boucey, Mohamed Wael and other contributors to make this happen!


Version 2.6 *(2017-10-21)*
----------------------------

Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ Paper's aim is to provide a simple yet [fast](#benchmark-results) object storage

![Paper icon](/paper_icon.png)

#### What's [new](/CHANGELOG.md) in 2.6

New API:
* `Paper.bookOn(path)` to set custom storage location;
* `book.getPath()` or `book.getPath(key)` to get path for content of book or key.

Improvements:
* simultaneous read/write for different keys, up to 97% performance gain per thread.
* name change: use `book.contains(key)` instead of deprecated `book.exist(key)`

Thanks [@hiperioncn](https://github.com/hiperioncn) and [@cezar-carneiro](https://github.com/cezar-carneiro) for your contribution!
#### What's [new](/CHANGELOG.md) in 2.7.1

Fixes:
* Ignore backup files in getAllKeys
* Fix exception on simultaneous write and destroy

Thanks Alexandre Boucey, Mohamed Wael and other contributors to make this happen!

### Add dependency
```groovy
implementation 'io.paperdb:paperdb:2.6'
implementation 'io.paperdb:paperdb:2.7.1'
```

RxJava wrapper for Paper is available as a separate lib [RxPaper2](https://github.com/pakoito/RxPaper2). Thanks [@pakoito](https://github.com/pakoito) for it!
Expand Down
17 changes: 8 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 29
// Must be the same version as in travis.xml
buildToolsVersion "26.0.1"

defaultConfig {
applicationId "paperdb.io.paperdb"
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -22,12 +21,12 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
//compile project(':paperdb')
compile 'io.paperdb:paperdb:2.6'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation project(':paperdb')
implementation 'io.paperdb:paperdb:2.7.1'

androidTestCompile('com.android.support.test:runner:0.5') {
androidTestImplementation('androidx.test.ext:junit:1.1.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package paperdb.io.paperdb;

import android.os.SystemClock;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.util.Log;

import org.junit.Before;
Expand All @@ -17,7 +17,7 @@
import paperdb.io.paperdb.testdata.Person;
import paperdb.io.paperdb.testdata.TestDataGenerator;

import static android.support.test.InstrumentationRegistry.getTargetContext;
import static androidx.test.InstrumentationRegistry.getTargetContext;
import static org.junit.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package paperdb.io.paperdb.testdata;

import android.support.annotation.NonNull;
import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
100 changes: 83 additions & 17 deletions app/src/main/java/paperdb/io/paperdb/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package paperdb.io.paperdb;

import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import io.paperdb.Paper;

import static java.util.Arrays.asList;


public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();
public static final String PERSON = "person";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -29,29 +30,51 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.test_write).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LongHolder o1 = new LongHolder(12L);
LongListHolder o2 = new LongListHolder(asList(23L));
Paper.book().write("o1", o1);
Paper.book().write("o2", o2);
new SimpleWrite().execute();
}
});

final Button btnRead = (Button) findViewById(R.id.test_read);
final Button btnRead = findViewById(R.id.test_read);

btnRead.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
public void onClick(View v) {
LongHolder o1 = Paper.book().read("o1", new LongHolder(-1L));
LongListHolder o2 = Paper.book().read("o2", new LongListHolder(asList(-1L)));

//long lastModified = Paper.book().lastModified("o1");
//Log.d(TAG, "lastModified: " + lastModified);
new SimpleRead(btnRead).execute();
}
});

btnRead.setText("Read: " + o1.getValue() + " : " + o2.getValue().get(0));
final Button btnReadWriteAsync = findViewById(R.id.test_read_write_async);
btnReadWriteAsync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
testReadWriteAsync();
}
});
}

private void testReadWriteAsync() {
final int iterations = 1000;
writeReadDestroy("key1", iterations);
writeReadDestroy("key2", iterations);
}

@SuppressWarnings("SameParameterValue")
private void writeReadDestroy(final String key, final int iterations) {
new Thread() {
@Override
public void run() {
for (int i = 0; i < iterations; i++) {
Paper.book().write(key, "key:" + key + " iteration#" + i);
Log.d(Thread.currentThread().getName(), "All keys:" + Paper.book().getAllKeys().toString());
Log.d(Thread.currentThread().getName(), "read key:" + key + "=" + Paper.book().<String>read(key));
// This caused the issue on multi-thread paper db dir creation
Paper.book().destroy();
}
}
}.start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand Down Expand Up @@ -116,4 +139,47 @@ static class LongListHolder extends AbstractValueListHolder<Long> {
super(value);
}
}

// So fun to write async tasks in java in 2020. How did we live with that?
private static class SimpleRead extends AsyncTask<Void, Void, ArrayList<AbstractValueHolder>> {
private final WeakReference<Button> wrBtnRead;

private SimpleRead(Button btnRead) {
wrBtnRead = new WeakReference<>(btnRead);
}

@Override
protected ArrayList<AbstractValueHolder> doInBackground(Void... voids) {
LongHolder o1 = Paper.book().read("o1", new LongHolder(-1L));
LongListHolder o2 = Paper.book().read("o2",
new LongListHolder(Collections.singletonList(-1L)));
ArrayList<AbstractValueHolder> result = new ArrayList<>();
result.add(o1);
result.add(o2);
return result;
}

@SuppressLint("SetTextI18n")
@Override
protected void onPostExecute(ArrayList<AbstractValueHolder> result) {
Button btnRead = wrBtnRead.get();
LongHolder o1 = (LongHolder) result.get(0);
LongListHolder o2 = (LongListHolder) result.get(1);
if (btnRead != null) {
btnRead.setText("Read: " + o1.getValue() + " : " + o2.getValue().get(0));
}
}
}

private static class SimpleWrite extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
LongHolder o1 = new LongHolder(12L);
LongListHolder o2 = new LongListHolder(Collections.singletonList(23L));
Paper.book().write("o1", o1);
Paper.book().write("o2", o2);
return null;
}
}

}
43 changes: 28 additions & 15 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
tools:ignore="HardcodedText">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is an simple utility app. Do not use it as reference Paper client implementation."
android:textSize="24sp" />

<Button
android:id="@+id/test_write"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="Write"/>
android:text="Write" />

<Button
android:id="@+id/test_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/test_write"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Read"/>
android:text="Read" />

<Button
android:id="@+id/test_read_write_async"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Read/Write async" />

</RelativeLayout>
</LinearLayout>
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -21,10 +18,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Oct 05 10:39:58 BST 2016
#Fri Feb 21 23:37:43 EET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Loading

0 comments on commit 0e4e76a

Please sign in to comment.