Search in sources :

Example 46 with NonNull

use of android.support.annotation.NonNull in project storio by pushtorefresh.

the class DefaultDeleteResolver method performDelete.

/**
     * {@inheritDoc}
     */
@NonNull
@Override
public DeleteResult performDelete(@NonNull StorIOSQLite storIOSQLite, @NonNull T object) {
    final DeleteQuery deleteQuery = mapToDeleteQuery(object);
    final int numberOfRowsDeleted = storIOSQLite.lowLevel().delete(deleteQuery);
    return DeleteResult.newInstance(numberOfRowsDeleted, deleteQuery.table());
}
Also used : DeleteQuery(com.pushtorefresh.storio.sqlite.queries.DeleteQuery) NonNull(android.support.annotation.NonNull)

Example 47 with NonNull

use of android.support.annotation.NonNull in project storio by pushtorefresh.

the class PreparedDeleteObject method executeAsBlocking.

/**
     * Executes Delete Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return non-null result of Delete Operation.
     */
@SuppressWarnings("unchecked")
@WorkerThread
@NonNull
@Override
public DeleteResult executeAsBlocking() {
    try {
        final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
        final DeleteResolver<T> deleteResolver;
        if (explicitDeleteResolver != null) {
            deleteResolver = explicitDeleteResolver;
        } else {
            final SQLiteTypeMapping<T> typeMapping = lowLevel.typeMapping((Class<T>) object.getClass());
            if (typeMapping == null) {
                throw new IllegalStateException("Object does not have type mapping: " + "object = " + object + ", object.class = " + object.getClass() + ", " + "db was not affected by this operation, please add type mapping for this type");
            }
            deleteResolver = typeMapping.deleteResolver();
        }
        final DeleteResult deleteResult = deleteResolver.performDelete(storIOSQLite, object);
        if (deleteResult.numberOfRowsDeleted() > 0) {
            lowLevel.notifyAboutChanges(Changes.newInstance(deleteResult.affectedTables()));
        }
        return deleteResult;
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Delete operation. object = " + object, exception);
    }
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) StorIOException(com.pushtorefresh.storio.StorIOException) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 48 with NonNull

use of android.support.annotation.NonNull in project storio by pushtorefresh.

the class PreparedExecuteSQL method executeAsBlocking.

/**
     * Executes SQL Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return just a new instance of {@link Object}, actually Execute SQL should return {@code void},
     * but we can not return instance of {@link Void} so we just return {@link Object}
     * and you don't have to deal with {@code null}.
     */
@WorkerThread
@NonNull
@Override
public Object executeAsBlocking() {
    try {
        final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
        lowLevel.executeSQL(rawQuery);
        final Set<String> affectedTables = rawQuery.affectsTables();
        if (affectedTables.size() > 0) {
            lowLevel.notifyAboutChanges(Changes.newInstance(affectedTables));
        }
        return new Object();
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during ExecuteSQL operation. query = " + rawQuery, exception);
    }
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) StorIOException(com.pushtorefresh.storio.StorIOException) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 49 with NonNull

use of android.support.annotation.NonNull in project storio by pushtorefresh.

the class PreparedGetCursor method asRxObservable.

/**
     * Creates "Hot" {@link Observable} which will be subscribed to changes of tables from query
     * and will emit result each time change occurs.
     * <p>
     * First result will be emitted immediately after subscription,
     * other emissions will occur only if changes of tables from query will occur during lifetime of
     * the {@link Observable}.
     * <dl>
     * <dt><b>Scheduler:</b></dt>
     * <dd>Operates on {@link StorIOSQLite#defaultScheduler()} if not {@code null}.</dd>
     * </dl>
     * <p>
     * Please don't forget to unsubscribe from this {@link Observable} because
     * it's "Hot" and endless.
     *
     * @return non-null {@link Observable} which will emit non-null
     * list with mapped results and will be subscribed to changes of tables from query.
     */
@NonNull
@CheckResult
@Override
public Observable<Cursor> asRxObservable() {
    throwExceptionIfRxJavaIsNotAvailable("asRxObservable()");
    final Set<String> tables;
    if (query != null) {
        tables = new HashSet<String>(1);
        tables.add(query.table());
    } else if (rawQuery != null) {
        tables = rawQuery.observesTables();
    } else {
        throw new StorIOException("Please specify query");
    }
    final Observable<Cursor> observable;
    if (!tables.isEmpty()) {
        observable = storIOSQLite.observeChangesInTables(// each change triggers executeAsBlocking
        tables).map(MapSomethingToExecuteAsBlocking.newInstance(this)).startWith(// start stream with first query result
        Observable.create(OnSubscribeExecuteAsBlocking.newInstance(this))).onBackpressureLatest();
    } else {
        observable = Observable.create(OnSubscribeExecuteAsBlocking.newInstance(this));
    }
    return RxJavaUtils.subscribeOn(storIOSQLite, observable);
}
Also used : StorIOException(com.pushtorefresh.storio.StorIOException) Cursor(android.database.Cursor) NonNull(android.support.annotation.NonNull) CheckResult(android.support.annotation.CheckResult)

Example 50 with NonNull

use of android.support.annotation.NonNull in project storio by pushtorefresh.

the class PreparedGetListOfObjects method executeAsBlocking.

/**
     * Executes Get Operation immediately in current thread.
     * <p>
     * Notice: This is blocking I/O operation that should not be executed on the Main Thread,
     * it can cause ANR (Activity Not Responding dialog), block the UI and drop animations frames.
     * So please, call this method on some background thread. See {@link WorkerThread}.
     *
     * @return non-null, immutable {@link List} with mapped results, list can be empty.
     */
@WorkerThread
@SuppressWarnings({ "TryFinallyCanBeTryWithResources", "unchecked" })
// Min SDK :( unchecked for empty list
@NonNull
@Override
public List<T> executeAsBlocking() {
    try {
        final GetResolver<T> getResolver;
        if (explicitGetResolver != null) {
            getResolver = explicitGetResolver;
        } else {
            final SQLiteTypeMapping<T> typeMapping = storIOSQLite.lowLevel().typeMapping(type);
            if (typeMapping == null) {
                throw new IllegalStateException("This type does not have type mapping: " + "type = " + type + "," + "db was not touched by this operation, please add type mapping for this type");
            }
            getResolver = typeMapping.getResolver();
        }
        final Cursor cursor;
        if (query != null) {
            cursor = getResolver.performGet(storIOSQLite, query);
        } else if (rawQuery != null) {
            cursor = getResolver.performGet(storIOSQLite, rawQuery);
        } else {
            throw new IllegalStateException("Please specify query");
        }
        try {
            final int count = cursor.getCount();
            if (count == 0) {
                // it's immutable
                return EMPTY_LIST;
            }
            final List<T> list = new ArrayList<T>(count);
            while (cursor.moveToNext()) {
                list.add(getResolver.mapFromCursor(cursor));
            }
            return unmodifiableList(list);
        } finally {
            cursor.close();
        }
    } catch (Exception exception) {
        throw new StorIOException("Error has occurred during Get operation. query = " + (query != null ? query : rawQuery), exception);
    }
}
Also used : EMPTY_LIST(java.util.Collections.EMPTY_LIST) StorIOException(com.pushtorefresh.storio.StorIOException) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) StorIOException(com.pushtorefresh.storio.StorIOException) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)747 View (android.view.View)94 TextView (android.widget.TextView)90 ArrayList (java.util.ArrayList)83 Intent (android.content.Intent)53 ContentValues (android.content.ContentValues)46 Bundle (android.os.Bundle)46 Test (org.junit.Test)45 AlertDialog (android.support.v7.app.AlertDialog)41 Cursor (android.database.Cursor)38 List (java.util.List)34 IOException (java.io.IOException)32 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)31 LayoutInflater (android.view.LayoutInflater)29 RecyclerView (android.support.v7.widget.RecyclerView)28 ImageView (android.widget.ImageView)28 File (java.io.File)28 DialogAction (com.afollestad.materialdialogs.DialogAction)25 HashMap (java.util.HashMap)25 Bitmap (android.graphics.Bitmap)24