本文整理汇总了Java中com.google.firebase.database.DatabaseException类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseException类的具体用法?Java DatabaseException怎么用?Java DatabaseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseException类属于com.google.firebase.database包,在下文中一共展示了DatabaseException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: parsePriority
import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public static Node parsePriority(Path nodePath, Object value) {
Node priority = NodeUtilities.NodeFromJSON(value);
if (priority instanceof LongNode) {
priority =
new DoubleNode(
Double.valueOf((Long) priority.getValue()), PriorityUtilities.NullPriority());
}
if (!isValidPriority(priority)) {
throw new DatabaseException(
(nodePath != null ? "Path '" + nodePath + "'" : "Node")
+ " contains invalid priority: Must be a string, double, ServerValue, or null");
}
return priority;
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:15,代码来源:PriorityUtilities.java
示例17: validatePathString
import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public static void validatePathString(String pathString) throws DatabaseException {
if (!isValidPathString(pathString)) {
throw new DatabaseException(
"Invalid Firebase Database path: "
+ pathString
+ ". Firebase Database paths must not contain '.', '#', '$', '[', or ']'");
}
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:9,代码来源:Validation.java
示例18: validateRootPathString
import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public static void validateRootPathString(String pathString) throws DatabaseException {
if (pathString.startsWith(".info")) {
validatePathString(pathString.substring(5));
} else if (pathString.startsWith("/.info")) {
validatePathString(pathString.substring(6));
} else {
validatePathString(pathString);
}
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:10,代码来源:Validation.java
示例19: parseAndValidateUpdate
import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
public static Map<Path, Node> parseAndValidateUpdate(Path path, Map<String, Object> update)
throws DatabaseException {
final SortedMap<Path, Node> parsedUpdate = new TreeMap<>();
for (Map.Entry<String, Object> entry : update.entrySet()) {
Path updatePath = new Path(entry.getKey());
Object newValue = entry.getValue();
ValidationPath.validateWithObject(path.child(updatePath), newValue);
String childName = !updatePath.isEmpty() ? updatePath.getBack().asString() : "";
if (childName.equals(ServerValues.NAME_SUBKEY_SERVERVALUE)
|| childName.equals("" + ".value")) {
throw new DatabaseException(
"Path '" + updatePath + "' contains disallowed child name: " + childName);
}
Node parsedValue;
if (childName.equals(".priority")) {
parsedValue = PriorityUtilities.parsePriority(updatePath, newValue);
} else {
parsedValue = NodeUtilities.NodeFromJSON(newValue);
}
Validation.validateWritableObject(newValue);
parsedUpdate.put(updatePath, parsedValue);
}
// Check that update keys are not ancestors of each other.
Path prevPath = null;
for (Path curPath : parsedUpdate.keySet()) {
// We rely on the property that sorting guarantees that ancestors come right before
// descendants.
hardAssert(prevPath == null || prevPath.compareTo(curPath) < 0);
if (prevPath != null && prevPath.contains(curPath)) {
throw new DatabaseException(
"Path '" + prevPath + "' is an ancestor of '" + curPath + "' in an update.");
}
prevPath = curPath;
}
return parsedUpdate;
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:37,代码来源:Validation.java
示例20: deserializeToClass
import com.google.firebase.database.DatabaseException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> T deserializeToClass(Object obj, Class<T> clazz) {
if (obj == null) {
return null;
} else if (clazz.isPrimitive()
|| Number.class.isAssignableFrom(clazz)
|| Boolean.class.isAssignableFrom(clazz)
|| Character.class.isAssignableFrom(clazz)) {
return deserializeToPrimitive(obj, clazz);
} else if (String.class.isAssignableFrom(clazz)) {
return (T) convertString(obj);
} else if (clazz.isArray()) {
throw new DatabaseException(
"Converting to Arrays is not supported, please use Lists" + "instead");
} else if (clazz.getTypeParameters().length > 0) {
throw new DatabaseException(
"Class "
+ clazz.getName()
+ " has generic type "
+ "parameters, please use GenericTypeIndicator instead");
} else if (clazz.equals(Object.class)) {
return (T) obj;
} else if (clazz.isEnum()) {
return deserializeToEnum(obj, clazz);
} else {
return convertBean(obj, clazz);
}
}
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:29,代码来源:CustomClassMapper.java
注:本文中的com.google.firebase.database.DatabaseException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论