Skip to content

Commit

Permalink
Merge pull request #9 from BryceCicada/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Chris Nix committed Feb 21, 2015
2 parents 32f369b + 3556d94 commit b1247b3
Show file tree
Hide file tree
Showing 92 changed files with 509 additions and 156 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
local.properties
/wrapper
gradle.properties
changelog.txt
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: android

script:
- ./gradlew clean :Library:test :AndroidLibrary:connectedCheck -Psonatype_username='' -Psonatype_password=''
15 changes: 7 additions & 8 deletions AndroidLibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'android-library'
apply plugin: 'com.android.library'

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.0.1'
}
}

Expand All @@ -16,7 +16,7 @@ repositories {
}

group = 'ninja.ugly'
version = prevail_version
version = project.prevailVersion
ext.artifact = 'android-prevail'

signing {
Expand All @@ -43,26 +43,25 @@ artifacts {
}

android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId 'ninja.ugly.prevail'
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName project.version
}
buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'ninja.ugly:prevail:' + prevail_version
compile project(':Library')
}

uploadArchives {
Expand Down
4 changes: 1 addition & 3 deletions AndroidLibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ninja.ugly.prevail">

<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<application android:allowBackup="true">

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.os.RemoteException;

import com.google.common.base.Function;
import com.google.common.collect.Iterators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import android.os.CancellationSignal;
import android.os.OperationCanceledException;
import android.util.Log;

import com.google.common.base.Optional;
import ninja.ugly.prevail.chunk.QueryResult;
import ninja.ugly.prevail.datamodel.DataModel;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.concurrent.ExecutionException;

import ninja.ugly.prevail.chunk.QueryResult;
import ninja.ugly.prevail.datamodel.DataModel;

public abstract class ChunkLoader<K, V> extends AsyncTaskLoader<QueryResult<V>> {

private static final String TAG = ChunkLoader.class.getSimpleName();
Expand Down
3 changes: 0 additions & 3 deletions AndroidLibrary/src/main/res/values/strings.xml

This file was deleted.

28 changes: 14 additions & 14 deletions Library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'maven'
apply plugin: 'signing'

group = 'ninja.ugly'
version = prevail_version
version = project.prevailVersion
ext.artifact = 'prevail'

buildscript {
Expand Down Expand Up @@ -99,16 +99,16 @@ dependencies {
}
}

sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000"
property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar"
property "sonar.jdbc.driverClassName", "org.h2.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
property "sonar.branch", "gradle"
property "sonar.dynamicAnalysis", "reuseReports"
property "sonar.junit.reportsPath", "build/test-results/"
property "sonar.pitest.reportsDirectory", "build/reports/pitest/"
}
}
//sonarRunner {
// sonarProperties {
// property "sonar.host.url", "http://localhost:9000"
// property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar"
// property "sonar.jdbc.driverClassName", "org.h2.Driver"
// property "sonar.jdbc.username", "sonar"
// property "sonar.jdbc.password", "sonar"
// property "sonar.branch", "gradle"
// property "sonar.dynamicAnalysis", "reuseReports"
// property "sonar.junit.reportsPath", "build/test-results/"
// property "sonar.pitest.reportsDirectory", "build/reports/pitest/"
// }
//}
10 changes: 9 additions & 1 deletion Library/src/main/java/ninja/ugly/prevail/chunk/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import ninja.ugly.prevail.exception.QueryException;
import ninja.ugly.prevail.exception.UpdateException;

public interface Chunk<K, V> {
import java.io.Closeable;
import java.io.IOException;

public interface Chunk<K, V> extends Closeable {
/**
* Insert a value into this Chunk, returning the key at which the get can be retrieved later.
*
Expand Down Expand Up @@ -141,5 +144,10 @@ public void addEventFactory(final UpdateEventFactory updateEventFactory) {
public void addEventFactory(final DeleteEventFactory deleteEventFactory) {
// Empty implementation
}

@Override
public void close() throws IOException {
// Empty implementation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface QueryResult<V> extends Iterable<V>, Closeable {

/**
* Returns if this QueryResult is already closed.
* @return
* @return a boolean true if this query result is close, false otherwise
*/
boolean isClosed();

Expand All @@ -47,7 +47,7 @@ public boolean isClosed() {

/**
* Returns an empty iterator.
* @return
* @return An iterator over this QueryResult, containing no elements.
*/
@Override
public Iterator<V> iterator() {
Expand All @@ -74,7 +74,7 @@ public SingletonQueryResult(final V t) {
* <p>
* This implementation cannot be closed, ie calls to close() do nothing and
* calls to isClosed() always return false.
* @return
* @return An iterator over this QueryResult, containing a single element.
*/
@Override
public Iterator<V> iterator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.base.Functions;
import com.google.common.collect.Maps;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -67,9 +68,9 @@ protected K doInsert(final V value, final OnProgressUpdateListener onProgressUpd
protected QueryResult<V> doQuery(final K key, final OnProgressUpdateListener onProgressUpdateListener) throws QueryException {
final QueryResult<V> result;
if (mMap.containsKey(key)) {
result = new QueryResult.SingletonQueryResult<V>(mMap.get(key));
result = new QueryResult.SingletonQueryResult<>(mMap.get(key));
} else {
result = new QueryResult.EmptyQueryResult<V>();
result = new QueryResult.EmptyQueryResult<>();
}
return result;
}
Expand Down Expand Up @@ -121,6 +122,11 @@ protected Collection<V> getValues() {
return Collections.unmodifiableCollection(mMap.values());
}

@Override
public void close() throws IOException {
mMap.clear();
}

/**
* A factory class for producing keys from values.
*/
Expand Down
38 changes: 36 additions & 2 deletions Library/src/main/java/ninja/ugly/prevail/datamodel/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;

import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -34,10 +37,10 @@
* registered on a DataModel they can be accessed asynchronously. Chunks are registered on the DataModel
* with an optional 'segment', that is a key that addresses possibly many Chunks.
*/
public class DataModel {
public class DataModel implements Closeable {
private static final String NO_SEGMENT = "NO SEGMENT";
private static final ExecutorService DEFAULT_CHUNK_EXECUTOR = Executors.newSingleThreadExecutor();
private Map<String, List<ChunkAndExecutor>> mChunks = new HashMap<String, List<ChunkAndExecutor>>();
private final Map<String, List<ChunkAndExecutor>> mChunks = new HashMap<>();

/**
* Add a Chunk to the default segment of this DataModel.
Expand Down Expand Up @@ -320,6 +323,37 @@ private List<ChunkAndExecutor> putIfAbsent(final String segment, final List<Chun
return l;
}

/** Close all registered chunks */
@Override
public void close() throws CompositeIOException {
synchronized (mChunks) {
List<IOException> exceptions = Lists.newArrayList();
for (ChunkAndExecutor chunkAndExecutor : Iterables.concat(mChunks.values())) {
try {
chunkAndExecutor.getChunk().close();
} catch (IOException e) {
exceptions.add(e);
}
}

if (!exceptions.isEmpty()) {
throw new CompositeIOException(exceptions);
}
}
}

public class CompositeIOException extends IOException {
private final List<IOException> mExceptions;

public CompositeIOException(List<IOException> exceptions) {
mExceptions = exceptions;
}

public List<IOException> getExceptions() {
return mExceptions;
}
}

private static final class ChunkAndExecutor {
private final Chunk mChunk;
private final ExecutorService mExecutor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ninja.ugly.prevail.event;

public interface DataChangeEvent {
public interface DataChangeEvent extends Event {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseDataChangeEndEvent extends DataChangeEndEvent, DatabaseEndEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseDataChangeEvent extends DataChangeEvent, DatabaseEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseDataChangeExceptionEvent extends DataChangeExceptionEvent, DatabaseExceptionEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseDataChangeStartEvent extends DataChangeStartEvent, DatabaseEvent, DatabaseStartEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseDeleteEndEvent<K> extends DeleteEndEvent<K> implements DatabaseDataChangeEndEvent, DatabaseDeleteEvent {
public DatabaseDeleteEndEvent(K key, int numValuesDeleted) {
super(key, numValuesDeleted);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseDeleteEvent extends DeleteEvent, DatabaseEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseDeleteExceptionEvent<K> extends DeleteExceptionEvent<K> implements DatabaseDataChangeExceptionEvent, DatabaseDeleteEvent {
public DatabaseDeleteExceptionEvent(K key, Exception exception) {
super(key, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseDeleteStartEvent<K> extends DeleteStartEvent<K> implements DatabaseDataChangeStartEvent, DatabaseDeleteEvent {
public DatabaseDeleteStartEvent(K key) {
super(key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseEndEvent extends EndEvent, DatabaseEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseEvent extends Event {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseExceptionEvent extends ExceptionEvent, DatabaseEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseInsertEndEvent<K, V> extends InsertEndEvent<K, V> implements DatabaseDataChangeEndEvent, DatabaseInsertEvent {
public DatabaseInsertEndEvent(K key, V data) {
super(key, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package ninja.ugly.prevail.event;

public interface DatabaseInsertEvent extends InsertEvent, DatabaseEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseInsertExceptionEvent<K> extends InsertExceptionEvent<K> implements DatabaseDataChangeExceptionEvent, DatabaseInsertEvent {
public DatabaseInsertExceptionEvent(K value, Exception exception) {
super(value, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ninja.ugly.prevail.event;

public class DatabaseInsertStartEvent<V> extends InsertStartEvent<V> implements DatabaseDataChangeStartEvent, DatabaseInsertEvent {
public DatabaseInsertStartEvent(V value) {
super(value);
}
}
Loading

0 comments on commit b1247b3

Please sign in to comment.