当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseException类代码示例

本文整理汇总了Java中com.google.firebase.database.DatabaseException的典型用法代码示例。如果您正苦于以下问题:Java DatabaseException类的具体用法?Java DatabaseException怎么用?Java DatabaseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DatabaseException类属于com.google.firebase.database包,在下文中一共展示了DatabaseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertInteger

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
private static Integer convertInteger(Object obj) {
  if (obj instanceof Integer) {
    return (Integer) obj;
  } else if (obj instanceof Long || obj instanceof Double) {
    double value = ((Number) obj).doubleValue();
    if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
      return ((Number) obj).intValue();
    } else {
      throw new DatabaseException(
          "Numeric value out of 32-bit integer range: "
              + value
              + ". Did you mean to use a long or double instead of an int?");
    }
  } else {
    throw new DatabaseException(
        "Failed to convert a value of type " + obj.getClass().getName() + " to int");
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:19,代码来源:CustomClassMapper.java

示例2: convertToCustomClass

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
/**
 * Converts a standard library Java representation of JSON data to an object of the class provided
 * through the GenericTypeIndicator
 *
 * @param object The representation of the JSON data
 * @param typeIndicator The indicator providing class of the object to convert to
 * @return The POJO object.
 */
public static <T> T convertToCustomClass(Object object, GenericTypeIndicator<T> typeIndicator) {
  Class<?> clazz = typeIndicator.getClass();
  Type genericTypeIndicatorType = clazz.getGenericSuperclass();
  if (genericTypeIndicatorType instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) genericTypeIndicatorType;
    if (!parameterizedType.getRawType().equals(GenericTypeIndicator.class)) {
      throw new DatabaseException(
          "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
    }
    // We are guaranteed to have exactly one type parameter
    Type type = parameterizedType.getActualTypeArguments()[0];
    return deserializeToType(object, type);
  } else {
    throw new DatabaseException(
        "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:CustomClassMapper.java

示例3: deserializeToType

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
private static <T> T deserializeToType(Object obj, Type type) {
  if (obj == null) {
    return null;
  } else if (type instanceof ParameterizedType) {
    return deserializeToParameterizedType(obj, (ParameterizedType) type);
  } else if (type instanceof Class) {
    return deserializeToClass(obj, (Class<T>) type);
  } else if (type instanceof WildcardType) {
    throw new DatabaseException("Generic wildcard types are not supported");
  } else if (type instanceof GenericArrayType) {
    throw new DatabaseException(
        "Generic Arrays are not supported, please use Lists " + "instead");
  } else {
    throw new IllegalStateException("Unknown type encountered: " + type);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:18,代码来源:CustomClassMapper.java

示例4: deserializeToPrimitive

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T deserializeToPrimitive(Object obj, Class<T> clazz) {
  if (Integer.class.isAssignableFrom(clazz) || int.class.isAssignableFrom(clazz)) {
    return (T) convertInteger(obj);
  } else if (Boolean.class.isAssignableFrom(clazz) || boolean.class.isAssignableFrom(clazz)) {
    return (T) convertBoolean(obj);
  } else if (Double.class.isAssignableFrom(clazz) || double.class.isAssignableFrom(clazz)) {
    return (T) convertDouble(obj);
  } else if (Long.class.isAssignableFrom(clazz) || long.class.isAssignableFrom(clazz)) {
    return (T) convertLong(obj);
  } else if (Float.class.isAssignableFrom(clazz) || float.class.isAssignableFrom(clazz)) {
    return (T) (Float) convertDouble(obj).floatValue();
  } else if (Short.class.isAssignableFrom(clazz) || short.class.isAssignableFrom(clazz)) {
    throw new DatabaseException("Deserializing to shorts is not supported");
  } else if (Byte.class.isAssignableFrom(clazz) || byte.class.isAssignableFrom(clazz)) {
    throw new DatabaseException("Deserializing to bytes is not supported");
  } else if (Character.class.isAssignableFrom(clazz) || char.class.isAssignableFrom(clazz)) {
    throw new DatabaseException("Deserializing to char is not supported");
  } else {
    throw new IllegalArgumentException("Unknown primitive type: " + clazz);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:23,代码来源:CustomClassMapper.java

示例5: deserializeToEnum

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T deserializeToEnum(Object object, Class<T> clazz) {
  if (object instanceof String) {
    String value = (String) object;
    // We cast to Class without generics here since we can't prove the bound
    // T extends Enum<T> statically
    try {
      return (T) Enum.valueOf((Class) clazz, value);
    } catch (IllegalArgumentException e) {
      throw new DatabaseException(
          "Could not find enum value of " + clazz.getName() + " for value \"" + value + "\"");
    }
  } else {
    throw new DatabaseException(
        "Expected a String while deserializing to enum "
            + clazz
            + " but got a "
            + object.getClass());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:CustomClassMapper.java

示例6: convertLong

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
private static Long convertLong(Object obj) {
  if (obj instanceof Integer) {
    return ((Integer) obj).longValue();
  } else if (obj instanceof Long) {
    return (Long) obj;
  } else if (obj instanceof Double) {
    Double value = (Double) obj;
    if (value >= Long.MIN_VALUE && value <= Long.MAX_VALUE) {
      return value.longValue();
    } else {
      throw new DatabaseException(
          "Numeric value out of 64-bit long range: "
              + value
              + ". Did you mean to use a double instead of a long?");
    }
  } else {
    throw new DatabaseException(
        "Failed to convert a value of type " + obj.getClass().getName() + " to long");
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:CustomClassMapper.java

示例7: messageForException

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public static String messageForException(Throwable t) {
  if (t instanceof OutOfMemoryError) {
    return "Firebase Database encountered an OutOfMemoryError. You may need to reduce the"
        + " amount of data you are syncing to the client (e.g. by using queries or syncing"
        + " a deeper path). See "
        + "https://firebase.google"
        + ".com/docs/database/ios/structure-data#best_practices_for_data_structure"
        + " and "
        + "https://firebase.google.com/docs/database/android/retrieve-data#filtering_data";
  } else if (t instanceof DatabaseException) {
    // Exception should be self-explanatory and they shouldn't contact support.
    return "";
  } else {
    return "Uncaught exception in Firebase Database runloop ("
        + FirebaseDatabase.getSdkVersion()
        + "). Please report to [email protected]";
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:19,代码来源:DefaultRunLoop.java

示例8: checkValid

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
private void checkValid() throws DatabaseException {
  if (byteLength > MAX_PATH_LENGTH_BYTES) {
    throw new DatabaseException(
        "Data has a key path longer than "
            + MAX_PATH_LENGTH_BYTES
            + " bytes ("
            + byteLength
            + ").");
  }
  if (parts.size() > MAX_PATH_DEPTH) {
    throw new DatabaseException(
        "Path specified exceeds the maximum depth that can be written ("
            + MAX_PATH_DEPTH
            + ") or object contains a cycle "
            + toErrorString());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:18,代码来源:ValidationPath.java

示例9: testInvalidPathsToOrderBy

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Test
public void testInvalidPathsToOrderBy() {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);

  List<String> badKeys = ImmutableList.<String>builder()
      .add("$child/foo", "$childfoo", "$/foo", "$child/foo/bar", "$child/.foo", ".priority",
          "$priority", "$key", ".key", "$child/.priority")
      .build();
  for (String key : badKeys) {
    try {
      ref.orderByChild(key);
      fail("Should throw");
    } catch (DatabaseException | IllegalArgumentException e) { // ignore
    }
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:QueryTestIT.java

示例10: testInvalidUpdate

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Test
public void testInvalidUpdate() {
  Map[] invalidUpdates = new Map[]{
      ImmutableMap.of(".sv", "foo"),
      ImmutableMap.of(".value", "foo"),
      ImmutableMap.of(".priority", ImmutableMap.of("a", "b")),
      ImmutableMap.of("foo", "value", "foo/bar", "value"),
      ImmutableMap.of("foo", Double.POSITIVE_INFINITY),
      ImmutableMap.of("foo", Double.NEGATIVE_INFINITY),
      ImmutableMap.of("foo", Double.NaN),
  };
  Path path = new Path("path");
  for (Map map : invalidUpdates) {
    try {
      Validation.parseAndValidateUpdate(path, map);
      fail("No error thrown for invalid update: " + map);
    } catch (DatabaseException expected) {
      // expected
    }
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:22,代码来源:ValidationTest.java

示例11: onDataChange

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    mFollowRequestArray.clear();

    for(DataSnapshot snapshot : dataSnapshot.getChildren()) {
        FollowRequest request;
        try {
            request = snapshot.getValue(FollowRequest.class);
        }
        catch (DatabaseException e) {
            return;
        }

        if (onlyShowUnaccepted && request.getAccepted()) continue;
        if (onlyShowAccepted && !request.getAccepted()) continue;
        mFollowRequestArray.add(request);
    }

    datasetChanged();
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:21,代码来源:FollowRequestDataSource.java

示例12: save

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public Boolean save(HighScore spacecraft)
{
    if(spacecraft==null)
    {
        saved=false;
    }else {

        try
        {
            db.child("Spacecraft").push().setValue(spacecraft);
            saved=true;
        }catch (DatabaseException e)
        {
            e.printStackTrace();
            saved=false;
        }

    }

    return saved;
}
 
开发者ID:mrprona92,项目名称:SecretBrand,代码行数:22,代码来源:HighScoreHelper.java

示例13: testDataChanges_DataReference_onCancelled

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Test
public void testDataChanges_DataReference_onCancelled() {
    TestObserver<DataSnapshot> sub = TestObserver.create();

    RxFirebaseDatabase.dataChanges(mockDatabaseReference)
            .subscribe(sub);

    verifyDataReferenceAddValueEventListener();
    callValueEventOnCancelled(new DatabaseException("foo"));

    sub.assertError(DatabaseException.class);
    sub.assertNoValues();

    sub.dispose();

    callValueEventOnCancelled(new DatabaseException("foo"));

    // Ensure no more values are emitted after unsubscribe
    assertThat(sub.errorCount())
            .isEqualTo(1);
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:22,代码来源:RxFirebaseDatabaseTest.java

示例14: testDataChanges_Query_onCancelled

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Test
public void testDataChanges_Query_onCancelled() {
    TestObserver<DataSnapshot> sub = TestObserver.create();

    RxFirebaseDatabase.dataChanges(mockQuery)
            .subscribe(sub);

    verifyQueryAddValueEventListener();
    callValueEventOnCancelled(new DatabaseException("foo"));

    sub.assertError(DatabaseException.class);
    sub.assertNoValues();

    sub.dispose();

    callValueEventOnCancelled(new DatabaseException("foo"));

    // Ensure no more values are emitted after unsubscribe
    assertThat(sub.errorCount())
            .isEqualTo(1);
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:22,代码来源:RxFirebaseDatabaseTest.java

示例15: testRunTransaction_onError

import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@Test
public void testRunTransaction_onError() {
    TestObserver sub = TestObserver.create();

    RxFirebaseDatabase
            .runTransaction(mockDatabaseReference, mockTransactionTask)
            .subscribe(sub);

    verifyRunTransaction();

    callTransactionOnCompleteWithError(new DatabaseException("Foo"));

    sub.assertNotComplete();
    sub.assertError(DatabaseException.class);

    sub.dispose();
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:18,代码来源:RxFirebaseDatabaseTest.java


注:本文中的com.google.firebase.database.DatabaseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。