diff --git a/CHANGELOG.md b/CHANGELOG.md index daca7b7..bfda942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)* ---------------------------- diff --git a/README.md b/README.md index 6db19e3..a6c262d 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/app/build.gradle b/app/build.gradle index 9e228ce..044446c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { @@ -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' } } diff --git a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java index dea7f5b..4e639c2 100644 --- a/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java +++ b/app/src/androidTest/java/paperdb/io/paperdb/ReadBenchmark.java @@ -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; @@ -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) diff --git a/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java b/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java index 9448c84..81c8da6 100644 --- a/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java +++ b/app/src/androidTest/java/paperdb/io/paperdb/testdata/TestDataGenerator.java @@ -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; diff --git a/app/src/main/java/paperdb/io/paperdb/MainActivity.java b/app/src/main/java/paperdb/io/paperdb/MainActivity.java index 2fa9225..dc89084 100644 --- a/app/src/main/java/paperdb/io/paperdb/MainActivity.java +++ b/app/src/main/java/paperdb/io/paperdb/MainActivity.java @@ -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); @@ -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().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. @@ -116,4 +139,47 @@ static class LongListHolder extends AbstractValueListHolder { super(value); } } + + // So fun to write async tasks in java in 2020. How did we live with that? + private static class SimpleRead extends AsyncTask> { + private final WeakReference