本文整理汇总了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");
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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");
}
}
示例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]";
}
}
示例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());
}
}
示例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
}
}
}
示例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
}
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}