Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd3dd9d
Adding the sync APIs for FirebaseAuth
hiranya911 Feb 22, 2018
ac3453b
Added more tests; Added sync APIs for FirebaseMessaging
hiranya911 Feb 22, 2018
ded167e
Removing Task references from database, iid and fcm APIs
hiranya911 Feb 22, 2018
765f209
Fixing a typo
hiranya911 Feb 26, 2018
01ce79e
Minor code clean up
hiranya911 Mar 1, 2018
3913688
Merged with master (auth unit test improvements)
hiranya911 Mar 2, 2018
d5ec1c3
Updated javadocs; Renamed internal helpers of FirebaseMessaging for c…
hiranya911 Mar 8, 2018
f8f33b4
Removed the deprecated FirebaseCredential API (#149)
hiranya911 Mar 9, 2018
27eddb6
Removing the Task API (#152)
hiranya911 Mar 12, 2018
edd825e
Dropping Support for App Engine Java 7 Runtime (#153)
hiranya911 Mar 20, 2018
559ce44
Removing Deprecated LogWrapper API (#154)
hiranya911 Mar 23, 2018
3979c02
Merged with master
hiranya911 Mar 29, 2018
ef036bb
merged with master
hiranya911 Apr 14, 2018
0523bf3
Initial code for the importUsers() API
hiranya911 Apr 18, 2018
0db88c5
Added documentation and more tests
hiranya911 Apr 19, 2018
fe3cc03
Added integration tests; Scrypt hash; more documentation
hiranya911 Apr 19, 2018
46e51ab
Added more tests
hiranya911 Apr 19, 2018
5ede505
Merge branch 'master' into v6
hiranya911 Apr 19, 2018
efc9016
updated test
hiranya911 Apr 24, 2018
dbc1492
Merged with master
hiranya911 May 3, 2018
0633d37
Merged with v6
hiranya911 May 4, 2018
2514703
Adding other hash types
hiranya911 May 4, 2018
ebe905c
Added the remaining hash algorithms
hiranya911 May 4, 2018
1182576
Renamed to ImportUserRecord
hiranya911 May 4, 2018
421a86c
Updated documentation
hiranya911 May 5, 2018
7b085df
Merged with master
hiranya911 May 8, 2018
501faf8
Some minor cleanup
hiranya911 May 8, 2018
dccc454
Updated documentation
hiranya911 May 11, 2018
a4cf116
Updated documentation; Made hash required in UserImportOptions; Other…
hiranya911 May 17, 2018
9130ab2
Renamed BasicHash to RepeatableHash; Made rounds range test configurable
hiranya911 May 22, 2018
3f30183
Added javadoc comment
hiranya911 May 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removing Task references from database, iid and fcm APIs
  • Loading branch information
hiranya911 committed Feb 22, 2018
commit ded167e5cd4830f46c206eaa21ce0180b99bd009
74 changes: 9 additions & 65 deletions src/main/java/com/google/firebase/database/DatabaseReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import com.google.firebase.database.utilities.Utilities;
import com.google.firebase.database.utilities.Validation;
import com.google.firebase.database.utilities.encoding.CustomClassMapper;
import com.google.firebase.internal.TaskToApiFuture;
import com.google.firebase.tasks.Task;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Expand Down Expand Up @@ -177,7 +175,7 @@ public DatabaseReference push() {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setValueAsync(Object value) {
return new TaskToApiFuture<>(setValue(value));
return setValueInternal(value, PriorityUtilities.parsePriority(this.path, null), null);
}

/**
Expand Down Expand Up @@ -215,29 +213,6 @@ public ApiFuture<Void> setValueAsync(Object value) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setValueAsync(Object value, Object priority) {
return new TaskToApiFuture<>(setValue(value, priority));
}

/**
* Similar to {@link #setValueAsync(Object)} but returns a Task.
*
* @param value The value to set at this location
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setValueAsync(Object)}
*/
public Task<Void> setValue(Object value) {
return setValueInternal(value, PriorityUtilities.parsePriority(this.path, null), null);
}

/**
* Similar to {@link #setValueAsync(Object, Object)} but returns a Task.
*
* @param value The value to set at this location
* @param priority The priority to set at this location
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setValueAsync(Object, Object)}
*/
public Task<Void> setValue(Object value, Object priority) {
return setValueInternal(value, PriorityUtilities.parsePriority(this.path, priority), null);
}

Expand Down Expand Up @@ -315,13 +290,14 @@ public void setValue(Object value, Object priority, CompletionListener listener)
setValueInternal(value, PriorityUtilities.parsePriority(this.path, priority), listener);
}

private Task<Void> setValueInternal(Object value, Node priority, CompletionListener optListener) {
private ApiFuture<Void> setValueInternal(Object value, Node priority, CompletionListener
optListener) {
Validation.validateWritablePath(getPath());
ValidationPath.validateWithObject(getPath(), value);
Object bouncedValue = CustomClassMapper.convertToPlainJavaTypes(value);
Validation.validateWritableObject(bouncedValue);
final Node node = NodeUtilities.NodeFromJSON(bouncedValue, priority);
final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand Down Expand Up @@ -364,17 +340,6 @@ public void run() {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setPriorityAsync(Object priority) {
return new TaskToApiFuture<>(setPriority(priority));
}

/**
* Similar to {@link #setPriorityAsync(Object)} but returns a Task.
*
* @param priority The priority to set at the specified location.
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setPriorityAsync(Object)}
*/
public Task<Void> setPriority(Object priority) {
return setPriorityInternal(PriorityUtilities.parsePriority(this.path, priority), null);
}

Expand Down Expand Up @@ -413,10 +378,10 @@ public void setPriority(Object priority, CompletionListener listener) {

// Remove

private Task<Void> setPriorityInternal(final Node priority, CompletionListener optListener) {
private ApiFuture<Void> setPriorityInternal(final Node priority, CompletionListener optListener) {
Validation.validateWritablePath(getPath());

final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand All @@ -438,17 +403,6 @@ public void run() {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> updateChildrenAsync(Map<String, Object> update) {
return new TaskToApiFuture<>(updateChildren(update));
}

/**
* Similar to {@link #updateChildrenAsync(Map)} but returns a Task.
*
* @param update The paths to update and their new values
* @return The {@link Task} for this operation.
* @deprecated Use {@link #updateChildrenAsync(Map)}
*/
public Task<Void> updateChildren(Map<String, Object> update) {
return updateChildrenInternal(update, null);
}

Expand All @@ -467,7 +421,7 @@ public void updateChildren(final Map<String, Object> update, final CompletionLis

// Transactions

private Task<Void> updateChildrenInternal(
private ApiFuture<Void> updateChildrenInternal(
final Map<String, Object> update, final CompletionListener optListener) {
if (update == null) {
throw new NullPointerException("Can't pass null for argument 'update' in updateChildren()");
Expand All @@ -477,7 +431,7 @@ private Task<Void> updateChildrenInternal(
Validation.parseAndValidateUpdate(getPath(), bouncedUpdate);
final CompoundWrite merge = CompoundWrite.fromPathMerge(parsedUpdate);

final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand All @@ -494,17 +448,7 @@ public void run() {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> removeValueAsync() {
return new TaskToApiFuture<>(removeValue());
}

/**
* Similar to {@link #removeValueAsync()} but returns a Task.
*
* @return The Task for this operation.
* @deprecated Use {@link #removeValueAsync()}
*/
public Task<Void> removeValue() {
return setValue(null);
return setValueAsync(null);
}

// Manual Connection Management
Expand Down
92 changes: 12 additions & 80 deletions src/main/java/com/google/firebase/database/OnDisconnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import com.google.firebase.database.utilities.Utilities;
import com.google.firebase.database.utilities.Validation;
import com.google.firebase.database.utilities.encoding.CustomClassMapper;
import com.google.firebase.internal.TaskToApiFuture;
import com.google.firebase.tasks.Task;

import java.util.Map;

Expand All @@ -52,41 +50,6 @@ public class OnDisconnect {
this.path = path;
}

/**
* Similar to {@link #setValueAsync(Object)}, but returns a Task.
*
* @param value The value to be set when a disconnect occurs
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setValueAsync(Object)}
*/
public Task<Void> setValue(Object value) {
return onDisconnectSetInternal(value, PriorityUtilities.NullPriority(), null);
}

/**
* Similar to {@link #setValueAsync(Object, String)}, but returns a Task.
*
* @param value The value to be set when a disconnect occurs
* @param priority The priority to be set when a disconnect occurs
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setValueAsync(Object, String)}
*/
public Task<Void> setValue(Object value, String priority) {
return onDisconnectSetInternal(value, PriorityUtilities.parsePriority(path, priority), null);
}

/**
* Similar to {@link #setValueAsync(Object, double)}, but returns a Task.
*
* @param value The value to be set when a disconnect occurs
* @param priority The priority to be set when a disconnect occurs
* @return The {@link Task} for this operation.
* @deprecated Use {@link #setValueAsync(Object, double)}
*/
public Task<Void> setValue(Object value, double priority) {
return onDisconnectSetInternal(value, PriorityUtilities.parsePriority(path, priority), null);
}

/**
* Ensure the data at this location is set to the specified value when the client is disconnected
* (due to closing the browser, navigating to a new page, or network issues). <br>
Expand Down Expand Up @@ -157,7 +120,7 @@ public void setValue(Object value, Map priority, CompletionListener listener) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setValueAsync(Object value) {
return new TaskToApiFuture<>(setValue(value));
return onDisconnectSetInternal(value, PriorityUtilities.NullPriority(), null);
}

/**
Expand All @@ -172,7 +135,7 @@ public ApiFuture<Void> setValueAsync(Object value) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setValueAsync(Object value, String priority) {
return new TaskToApiFuture<>(setValue(value, priority));
return onDisconnectSetInternal(value, PriorityUtilities.parsePriority(path, priority), null);
}

/**
Expand All @@ -187,17 +150,17 @@ public ApiFuture<Void> setValueAsync(Object value, String priority) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> setValueAsync(Object value, double priority) {
return new TaskToApiFuture<>(setValue(value, priority));
return onDisconnectSetInternal(value, PriorityUtilities.parsePriority(path, priority), null);
}

private Task<Void> onDisconnectSetInternal(
private ApiFuture<Void> onDisconnectSetInternal(
Object value, Node priority, final CompletionListener optListener) {
Validation.validateWritablePath(path);
ValidationPath.validateWithObject(path, value);
Object bouncedValue = CustomClassMapper.convertToPlainJavaTypes(value);
Validation.validateWritableObject(bouncedValue);
final Node node = NodeUtilities.NodeFromJSON(bouncedValue, priority);
final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand All @@ -210,17 +173,6 @@ public void run() {

// Update

/**
* Similar to {@link #updateChildrenAsync(Map)}, but returns a Task.
*
* @param update The paths to update, along with their desired values
* @return The {@link Task} for this operation.
* @deprecated Use {@link #updateChildrenAsync(Map)}
*/
public Task<Void> updateChildren(Map<String, Object> update) {
return updateChildrenInternal(update, null);
}

/**
* Ensure the data has the specified child values updated when the client is disconnected
*
Expand All @@ -238,13 +190,13 @@ public void updateChildren(final Map<String, Object> update, final CompletionLis
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> updateChildrenAsync(Map<String, Object> update) {
return new TaskToApiFuture<>(updateChildren(update));
return updateChildrenInternal(update, null);
}

private Task<Void> updateChildrenInternal(
private ApiFuture<Void> updateChildrenInternal(
final Map<String, Object> update, final CompletionListener optListener) {
final Map<Path, Node> parsedUpdate = Validation.parseAndValidateUpdate(path, update);
final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand All @@ -257,16 +209,6 @@ public void run() {

// Remove

/**
* Similar to {@link #removeValueAsync()}, but returns a Task.
*
* @return The {@link Task} for this operation.
* @deprecated Use {@link #removeValueAsync()}
*/
public Task<Void> removeValue() {
return setValue(null);
}

/**
* Remove the value at this location when the client disconnects
*
Expand All @@ -282,21 +224,11 @@ public void removeValue(CompletionListener listener) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> removeValueAsync() {
return new TaskToApiFuture<>(removeValue());
return setValueAsync(null);
}

// Cancel the operation

/**
* Similar to {@link #cancelAsync()} ()}, but returns a Task.
*
* @return The {@link Task} for this operation.
* @deprecated Use {@link #cancelAsync()}.
*/
public Task<Void> cancel() {
return cancelInternal(null);
}

/**
* Cancel any disconnect operations that are queued up at this location
*
Expand All @@ -312,11 +244,11 @@ public void cancel(final CompletionListener listener) {
* @return The ApiFuture for this operation.
*/
public ApiFuture<Void> cancelAsync() {
return new TaskToApiFuture<>(cancel());
return cancelInternal(null);
}

private Task<Void> cancelInternal(final CompletionListener optListener) {
final Pair<Task<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
private ApiFuture<Void> cancelInternal(final CompletionListener optListener) {
final Pair<ApiFuture<Void>, CompletionListener> wrapped = Utilities.wrapOnComplete(optListener);
repo.scheduleNow(
new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.firebase.database.utilities;

import com.google.api.core.ApiFuture;
import com.google.api.core.SettableApiFuture;
import com.google.common.io.BaseEncoding;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseException;
Expand Down Expand Up @@ -237,22 +239,22 @@ public static void hardAssert(boolean condition, String message) {
}
}

public static Pair<Task<Void>, DatabaseReference.CompletionListener> wrapOnComplete(
public static Pair<ApiFuture<Void>, DatabaseReference.CompletionListener> wrapOnComplete(
DatabaseReference.CompletionListener optListener) {
if (optListener == null) {
final TaskCompletionSource<Void> source = new TaskCompletionSource<>();
final SettableApiFuture<Void> future = SettableApiFuture.create();
DatabaseReference.CompletionListener listener =
new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference ref) {
if (error != null) {
source.setException(error.toException());
future.setException(error.toException());
} else {
source.setResult(null);
future.set(null);
}
}
};
return new Pair<>(source.getTask(), listener);
return new Pair<ApiFuture<Void>, DatabaseReference.CompletionListener>(future, listener);
} else {
// If a listener is supplied we do not want to create a Task
return new Pair<>(null, optListener);
Expand Down
Loading