當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseReference.CompletionListener方法代碼示例

本文整理匯總了Java中com.google.firebase.database.DatabaseReference.CompletionListener方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.CompletionListener方法的具體用法?Java DatabaseReference.CompletionListener怎麽用?Java DatabaseReference.CompletionListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.firebase.database.DatabaseReference的用法示例。


在下文中一共展示了DatabaseReference.CompletionListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrapOnComplete

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public static Pair<Task<Void>, DatabaseReference.CompletionListener> wrapOnComplete(
    DatabaseReference.CompletionListener optListener) {
  if (optListener == null) {
    final TaskCompletionSource<Void> source = new TaskCompletionSource<>();
    DatabaseReference.CompletionListener listener =
        new DatabaseReference.CompletionListener() {
          @Override
          public void onComplete(DatabaseError error, DatabaseReference ref) {
            if (error != null) {
              source.setException(error.toException());
            } else {
              source.setResult(null);
            }
          }
        };
    return new Pair<>(source.getTask(), listener);
  } else {
    // If a listener is supplied we do not want to create a Task
    return new Pair<>(null, optListener);
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:22,代碼來源:Utilities.java

示例2: callOnComplete

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
void callOnComplete(
    final DatabaseReference.CompletionListener onComplete,
    final DatabaseError error,
    final Path path) {
  if (onComplete != null) {
    final DatabaseReference ref;
    ChildKey last = path.getBack();
    if (last != null && last.isPriorityChildName()) {
      ref = InternalHelpers.createReference(this, path.getParent());
    } else {
      ref = InternalHelpers.createReference(this, path);
    }
    postEvent(
        new Runnable() {
          @Override
          public void run() {
            onComplete.onComplete(error, ref);
          }
        });
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:22,代碼來源:Repo.java

示例3: onDisconnectSetValue

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void onDisconnectSetValue(
    final Path path, final Node newValue, final DatabaseReference.CompletionListener onComplete) {
  connection.onDisconnectPut(
      path.asList(),
      newValue.getValue(true),
      new RequestResultCallback() {
        @Override
        public void onRequestResult(String optErrorCode, String optErrorMessage) {
          DatabaseError error = fromErrorCode(optErrorCode, optErrorMessage);
          warnIfWriteFailed("onDisconnect().setValue", path, error);
          if (error == null) {
            onDisconnect.remember(path, newValue);
          }
          callOnComplete(onComplete, error, path);
        }
      });
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:18,代碼來源:Repo.java

示例4: onDisconnectUpdate

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void onDisconnectUpdate(
    final Path path,
    final Map<Path, Node> newChildren,
    final DatabaseReference.CompletionListener listener,
    Map<String, Object> unParsedUpdates) {
  connection.onDisconnectMerge(
      path.asList(),
      unParsedUpdates,
      new RequestResultCallback() {
        @Override
        public void onRequestResult(String optErrorCode, String optErrorMessage) {
          DatabaseError error = fromErrorCode(optErrorCode, optErrorMessage);
          warnIfWriteFailed("onDisconnect().updateChildren", path, error);
          if (error == null) {
            for (Map.Entry<Path, Node> entry : newChildren.entrySet()) {
              onDisconnect.remember(path.child(entry.getKey()), entry.getValue());
            }
          }
          callOnComplete(listener, error, path);
        }
      });
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:23,代碼來源:Repo.java

示例5: testWrapOnComplete

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testWrapOnComplete() {
  Pair<Task<Void>, DatabaseReference.CompletionListener> result =
      Utilities.wrapOnComplete(null);
  assertNotNull(result.getFirst());
  assertNotNull(result.getSecond());
  try {
    result.getFirst().getResult();
    fail("No error thrown for pending task");
  } catch (Exception e) {
    // expected
  }

  result.getSecond().onComplete(null, null);
  result.getFirst().getResult();
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:17,代碼來源:UtilitiesTest.java

示例6: testWrapOnCompleteErrorResult

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testWrapOnCompleteErrorResult() {
  Pair<Task<Void>, DatabaseReference.CompletionListener> result =
      Utilities.wrapOnComplete(null);
  assertNotNull(result.getFirst());
  assertNotNull(result.getSecond());
  try {
    result.getFirst().getResult();
    fail("No error thrown for pending task");
  } catch (Exception e) {
    // expected
  }

  result.getSecond().onComplete(DatabaseError.fromStatus("test error"), null);
  assertNotNull(result.getFirst().getException());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:17,代碼來源:UtilitiesTest.java

示例7: testCallOnComplete

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testCallOnComplete() {
  final Repo repo = newRepo();
  final AtomicReference<DatabaseError> errorResult = new AtomicReference<>();
  final AtomicReference<DatabaseReference> refResult = new AtomicReference<>();
  DatabaseReference.CompletionListener listener = new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError error, DatabaseReference ref) {
      errorResult.set(error);
      refResult.set(ref);
    }
  };
  repo.callOnComplete(listener, null, new Path("/foo"));
  assertNull(errorResult.get());
  assertEquals("foo", refResult.get().getKey());

  DatabaseError ex = DatabaseError.fromCode(DatabaseError.WRITE_CANCELED);
  repo.callOnComplete(listener, ex, new Path("/bar"));
  assertEquals(ex, errorResult.get());
  assertEquals("bar", refResult.get().getKey());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:22,代碼來源:RepoTest.java

示例8: setValue

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void setValue(
    final Path path,
    Node newValueUnresolved,
    final DatabaseReference.CompletionListener onComplete) {
  if (operationLogger.logsDebug()) {
    operationLogger.debug("set: " + path);
  }
  if (dataLogger.logsDebug()) {
    dataLogger.debug("set: " + path + " " + newValueUnresolved);
  }

  Map<String, Object> serverValues = ServerValues.generateServerValues(serverClock);
  Node newValue = ServerValues.resolveDeferredValueSnapshot(newValueUnresolved, serverValues);

  final long writeId = this.getNextWriteId();
  List<? extends Event> events =
      this.serverSyncTree.applyUserOverwrite(
          path, newValueUnresolved, newValue, writeId, /*visible=*/ true, /*persist=*/ true);
  this.postEvents(events);

  connection.put(
      path.asList(),
      newValueUnresolved.getValue(true),
      new RequestResultCallback() {
        @Override
        public void onRequestResult(String optErrorCode, String optErrorMessage) {
          DatabaseError error = fromErrorCode(optErrorCode, optErrorMessage);
          warnIfWriteFailed("setValue", path, error);
          ackWriteAndRerunTransactions(writeId, path, error);
          callOnComplete(onComplete, error, path);
        }
      });

  Path affectedPath = abortTransactions(path, DatabaseError.OVERRIDDEN_BY_SET);
  this.rerunTransactions(affectedPath);
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:37,代碼來源:Repo.java

示例9: onDisconnectCancel

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void onDisconnectCancel(
    final Path path, final DatabaseReference.CompletionListener onComplete) {
  connection.onDisconnectCancel(
      path.asList(),
      new RequestResultCallback() {
        @Override
        public void onRequestResult(String optErrorCode, String optErrorMessage) {
          DatabaseError error = fromErrorCode(optErrorCode, optErrorMessage);
          if (error == null) {
            onDisconnect.forget(path);
          }
          callOnComplete(onComplete, error, path);
        }
      });
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:16,代碼來源:Repo.java

示例10: testWrapOnCompleteExplicit

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testWrapOnCompleteExplicit() {
  CompletionListener listener = new CompletionListener() {
    @Override
    public void onComplete(DatabaseError error, DatabaseReference ref) {

    }
  };
  Pair<Task<Void>, DatabaseReference.CompletionListener> result =
      Utilities.wrapOnComplete(listener);
  assertNull(result.getFirst());
  assertSame(listener, result.getSecond());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:14,代碼來源:UtilitiesTest.java

示例11: testOnDisconnectSetValue

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testOnDisconnectSetValue() throws InterruptedException {
  final Repo repo = newRepo();
  final AtomicReference<DatabaseError> errorResult = new AtomicReference<>();
  final AtomicReference<DatabaseReference> refResult = new AtomicReference<>();
  final Semaphore semaphore = new Semaphore(0);
  final DatabaseReference.CompletionListener listener = newCompletionListener(
      errorResult, refResult);

  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectSetValue(new Path(SUCCESS), NodeUtilities.NodeFromJSON("test"), listener);
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNull(errorResult.get());
  assertEquals("success", refResult.get().getKey());

  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectSetValue(new Path(FAILURE), NodeUtilities.NodeFromJSON("test"), listener);
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNotNull(errorResult.get());
  assertEquals(DatabaseError.DATA_STALE, errorResult.get().getCode());
  assertEquals("failure", refResult.get().getKey());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:33,代碼來源:RepoTest.java

示例12: testOnDisconnectUpdate

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testOnDisconnectUpdate() throws InterruptedException {
  final Repo repo = newRepo();
  final AtomicReference<DatabaseError> errorResult = new AtomicReference<>();
  final AtomicReference<DatabaseReference> refResult = new AtomicReference<>();
  final Semaphore semaphore = new Semaphore(0);
  final DatabaseReference.CompletionListener listener = newCompletionListener(
      errorResult, refResult);

  final Map<Path, Node> update = ImmutableMap.of(
      new Path("/child"), NodeUtilities.NodeFromJSON("foo"));
  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectUpdate(new Path(SUCCESS), update, listener,
          ImmutableMap.<String, Object>of("child", "foo"));
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNull(errorResult.get());
  assertEquals("success", refResult.get().getKey());

  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectUpdate(new Path(FAILURE), update, listener,
          ImmutableMap.<String, Object>of("child", "foo"));
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNotNull(errorResult.get());
  assertEquals(DatabaseError.DATA_STALE, errorResult.get().getCode());
  assertEquals("failure", refResult.get().getKey());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:37,代碼來源:RepoTest.java

示例13: testOnDisconnectCancel

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Test
public void testOnDisconnectCancel() throws InterruptedException {
  final Repo repo = newRepo();
  final AtomicReference<DatabaseError> errorResult = new AtomicReference<>();
  final AtomicReference<DatabaseReference> refResult = new AtomicReference<>();
  final Semaphore semaphore = new Semaphore(0);
  final DatabaseReference.CompletionListener listener = newCompletionListener(
      errorResult, refResult);

  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectCancel(new Path(SUCCESS), listener);
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNull(errorResult.get());
  assertEquals("success", refResult.get().getKey());

  repo.scheduleNow(new Runnable() {
    @Override
    public void run() {
      repo.onDisconnectCancel(new Path(FAILURE), listener);
      semaphore.release();
    }
  });
  waitFor(semaphore);
  assertNotNull(errorResult.get());
  assertEquals(DatabaseError.DATA_STALE, errorResult.get().getCode());
  assertEquals("failure", refResult.get().getKey());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:33,代碼來源:RepoTest.java

示例14: newCompletionListener

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private DatabaseReference.CompletionListener newCompletionListener(
    final AtomicReference<DatabaseError> errorResult,
    final AtomicReference<DatabaseReference> refResult) {
  return new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError error, DatabaseReference ref) {
      errorResult.set(error);
      refResult.set(ref);
    }
  };
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:12,代碼來源:RepoTest.java

示例15: setResults

import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void setResults() {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = simpleDateFormat.format(new Date());

        Results result = new Results(chronometer.getText().toString(), date);
        DatabaseReference.CompletionListener completeListener = new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                Log.d("saved", "onComplete: ");
            }
        };
        myRefResults.child(String.valueOf(position)).push().setValue(result, completeListener);
        Log.d("result", "setResults: ");
    }
 
開發者ID:RobIsr,項目名稱:OneMoreRepFitness,代碼行數:16,代碼來源:MainActivity.java


注:本文中的com.google.firebase.database.DatabaseReference.CompletionListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。