本文整理汇总了Java中io.realm.exceptions.RealmException类的典型用法代码示例。如果您正苦于以下问题:Java RealmException类的具体用法?Java RealmException怎么用?Java RealmException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RealmException类属于io.realm.exceptions包,在下文中一共展示了RealmException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createAllFromJson
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Creates a Realm object for each object in a JSON array. This must be done within a transaction.
* <p>
* JSON properties with unknown properties will be ignored. If a {@link RealmObject} field is not present in the
* JSON object the {@link RealmObject} field will be set to the default value for that type.
*
* <p>
* This method currently does not support value list field.
*
* @param clazz type of Realm objects to create.
* @param json an array where each JSONObject must map to the specified class.
* @throws RealmException if mapping from JSON fails.
* @throws IllegalArgumentException if the JSON object doesn't have a primary key property but the corresponding
* {@link RealmObjectSchema} has a {@link io.realm.annotations.PrimaryKey} defined.
*/
public <E extends RealmModel> void createAllFromJson(Class<E> clazz, JSONArray json) {
//noinspection ConstantConditions
if (clazz == null || json == null) {
return;
}
checkIfValid();
for (int i = 0; i < json.length(); i++) {
try {
configuration.getSchemaMediator().createOrUpdateUsingJsonObject(clazz, this, json.getJSONObject(i), false);
} catch (JSONException e) {
throw new RealmException("Could not map JSON", e);
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:Realm.java
示例2: createOrUpdateObjectFromJson
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Tries to update an existing object defined by its primary key with new JSON data. If no existing object could be
* found a new object will be saved in the Realm. This must happen within a transaction. If updating a
* {@link RealmObject} and a field is not found in the JSON object, that field will not be updated. If a new
* {@link RealmObject} is created and a field is not found in the JSON object, that field will be assigned the
* default value for the field type.
* <p>
* This API is only available in API level 11 or later.
*
* <p>
* This method currently does not support value list field.
*
* @param clazz type of {@link io.realm.RealmObject} to create or update. It must have a primary key defined.
* @param in the {@link InputStream} with object data in JSON format.
* @return created or updated {@link io.realm.RealmObject}.
* @throws IllegalArgumentException if trying to update a class without a {@link io.realm.annotations.PrimaryKey}.
* @throws IllegalArgumentException if the JSON object doesn't have a primary key property but the corresponding
* {@link RealmObjectSchema} has a {@link io.realm.annotations.PrimaryKey} defined.
* @throws RealmException if failure to read JSON.
* @see #createObjectFromJson(Class, java.io.InputStream)
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public <E extends RealmModel> E createOrUpdateObjectFromJson(Class<E> clazz, InputStream in) {
//noinspection ConstantConditions
if (clazz == null || in == null) {
return null;
}
checkIfValid();
checkHasPrimaryKey(clazz);
// As we need the primary key value we have to first parse the entire input stream as in the general
// case that value might be the last property. :(
Scanner scanner = null;
try {
scanner = getFullStringScanner(in);
JSONObject json = new JSONObject(scanner.next());
return createOrUpdateObjectFromJson(clazz, json);
} catch (JSONException e) {
throw new RealmException("Failed to read JSON", e);
} finally {
if (scanner != null) {
scanner.close();
}
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:Realm.java
示例3: createObjectInternal
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Same as {@link #createObject(Class)} but this does not check the thread.
*
* @param clazz the Class of the object to create.
* @param acceptDefaultValue if {@code true}, default value of the object will be applied and
* if {@code false}, it will be ignored.
* @return the new object.
* @throws RealmException if the primary key is defined in the model class or an object cannot be created.
*/
// Called from proxy classes.
<E extends RealmModel> E createObjectInternal(
Class<E> clazz,
boolean acceptDefaultValue,
List<String> excludeFields) {
Table table = schema.getTable(clazz);
// Checks and throws the exception earlier for a better exception message.
if (OsObjectStore.getPrimaryKeyForObject(
sharedRealm, configuration.getSchemaMediator().getSimpleClassName(clazz)) != null) {
throw new RealmException(String.format(Locale.US, "'%s' has a primary key, use" +
" 'createObject(Class<E>, Object)' instead.", table.getClassName()));
}
return configuration.getSchemaMediator().newInstance(clazz, this,
OsObject.create(table),
schema.getColumnInfo(clazz),
acceptDefaultValue, excludeFields);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Realm.java
示例4: subscribeToObjects
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* If the Realm is a partially synchronized Realm, fetch and synchronize the objects of a given
* object type that match the given query (in string format).
*
* The results will be returned asynchronously in the callback.
*
* @param clazz the class to query.
* @param query string query.
* @param callback A callback used to vend the results of a partial sync fetch.
* @throws IllegalStateException if it is called from a non-Looper or {@link IntentService} thread.
* @throws IllegalStateException if called from a non-synchronized (Realm Object Server) Realm.
*/
@Beta
public <E extends RealmModel> void subscribeToObjects(final Class<E> clazz, String query, final PartialSyncCallback<E> callback) {
checkIfValid();
if (!configuration.isSyncConfiguration()) {
throw new IllegalStateException("Partial sync is only available for synchronized Realm (Realm Object Server)");
}
sharedRealm.capabilities.checkCanDeliverNotification(BaseRealm.LISTENER_NOT_ALLOWED_MESSAGE);
String className = configuration.getSchemaMediator().getSimpleClassName(clazz);
OsSharedRealm.PartialSyncCallback internalCallback = new OsSharedRealm.PartialSyncCallback(className) {
@Override
public void onSuccess(OsResults osResults) {
RealmResults<E> results = new RealmResults<>(Realm.this, osResults, clazz);
callback.onSuccess(results);
}
@Override
public void onError(RealmException error) {
callback.onError(error);
}
};
sharedRealm.registerPartialSyncQuery(query, internalCallback);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:Realm.java
示例5: createWithPrimaryKey
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Create an object in the given table which has a primary key column defined, and set the primary key with given
* value.
*
* @param table the table where the object is created. This table must be atached to {@link OsSharedRealm}.
* @return a newly created {@code UncheckedRow}.
*/
public static UncheckedRow createWithPrimaryKey(Table table, @Nullable Object primaryKeyValue) {
long primaryKeyColumnIndex = getAndVerifyPrimaryKeyColumnIndex(table);
RealmFieldType type = table.getColumnType(primaryKeyColumnIndex);
final OsSharedRealm sharedRealm = table.getSharedRealm();
if (type == RealmFieldType.STRING) {
if (primaryKeyValue != null && !(primaryKeyValue instanceof String)) {
throw new IllegalArgumentException("Primary key value is not a String: " + primaryKeyValue);
}
return new UncheckedRow(sharedRealm.context, table,
nativeCreateNewObjectWithStringPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
primaryKeyColumnIndex, (String) primaryKeyValue));
} else if (type == RealmFieldType.INTEGER) {
long value = primaryKeyValue == null ? 0 : Long.parseLong(primaryKeyValue.toString());
return new UncheckedRow(sharedRealm.context, table,
nativeCreateNewObjectWithLongPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
primaryKeyColumnIndex, value, primaryKeyValue == null));
} else {
throw new RealmException("Cannot check for duplicate rows for unsupported primary key type: " + type);
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:OsObject.java
示例6: createRowWithPrimaryKey
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Create an object in the given table which has a primary key column defined, and set the primary key with given
* value.
* This is used for the fast bulk insertion.
*
* @param table the table where the object is created.
* @param primaryKeyColumnIndex the column index of primary key field.
* @param primaryKeyValue the primary key value.
* @return a newly created {@code UncheckedRow}.
*/
// FIXME: Proxy could just pass the pk index here which is much faster.
public static long createRowWithPrimaryKey(Table table, long primaryKeyColumnIndex, Object primaryKeyValue) {
RealmFieldType type = table.getColumnType(primaryKeyColumnIndex);
final OsSharedRealm sharedRealm = table.getSharedRealm();
if (type == RealmFieldType.STRING) {
if (primaryKeyValue != null && !(primaryKeyValue instanceof String)) {
throw new IllegalArgumentException("Primary key value is not a String: " + primaryKeyValue);
}
return nativeCreateRowWithStringPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
primaryKeyColumnIndex, (String) primaryKeyValue);
} else if (type == RealmFieldType.INTEGER) {
long value = primaryKeyValue == null ? 0 : Long.parseLong(primaryKeyValue.toString());
return nativeCreateRowWithLongPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
primaryKeyColumnIndex, value, primaryKeyValue == null);
} else {
throw new RealmException("Cannot check for duplicate rows for unsupported primary key type: " + type);
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:OsObject.java
示例7: getColumnInfo
import io.realm.exceptions.RealmException; //导入依赖的package包/类
/**
* Returns the {@link ColumnInfo} for the passed class name.
*
* @param simpleClassName the simple name of the class for which to get the ColumnInfo.
* @return the corresponding {@link ColumnInfo} object.
* @throws io.realm.exceptions.RealmException if the class cannot be found in the schema.
*/
@Nonnull
public ColumnInfo getColumnInfo(String simpleClassName) {
ColumnInfo columnInfo = simpleClassNameToColumnInfoMap.get(simpleClassName);
if (columnInfo == null) {
Set<Class<? extends RealmModel>> modelClasses = mediator.getModelClasses();
for (Class<? extends RealmModel> modelClass : modelClasses) {
if (mediator.getSimpleClassName(modelClass).equals(simpleClassName)) {
columnInfo = getColumnInfo(modelClass);
simpleClassNameToColumnInfoMap.put(simpleClassName, columnInfo);
break;
}
}
}
if (columnInfo == null) {
throw new RealmException(
String.format(Locale.US, "'%s' doesn't exist in current schema.", simpleClassName));
}
return columnInfo;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:ColumnIndices.java
示例8: createObjectFromJson_jsonException
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Test
public void createObjectFromJson_jsonException() throws JSONException {
JSONObject json = new JSONObject();
json.put("columnString", "Foo");
json.put("columnDate", "Boom");
realm.beginTransaction();
try {
realm.createObjectFromJson(AllTypes.class, json);
fail();
} catch (RealmException ignored) {
} finally {
realm.commitTransaction();
}
AllTypes obj = realm.where(AllTypes.class).findFirst();
assertEquals("Foo", obj.getColumnString());
assertEquals(new Date(0), obj.getColumnDate());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:RealmJsonTests.java
示例9: createOrUpdateObjectFromJson_streamInvalidJson
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Test
public void createOrUpdateObjectFromJson_streamInvalidJson() throws IOException {
assumeThat(Build.VERSION.SDK_INT, greaterThanOrEqualTo(Build.VERSION_CODES.HONEYCOMB));
AllTypesPrimaryKey obj = new AllTypesPrimaryKey();
obj.setColumnLong(1);
realm.beginTransaction();
realm.copyToRealm(obj);
realm.commitTransaction();
InputStream in = TestHelper.loadJsonFromAssets(context, "all_types_invalid.json");
realm.beginTransaction();
try {
realm.createOrUpdateObjectFromJson(AllTypesPrimaryKey.class, in);
fail();
} catch (RealmException ignored) {
} finally {
realm.commitTransaction();
in.close();
}
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:RealmJsonTests.java
示例10: createOrUpdateObjectFromJson_invalidJsonObject
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Test
public void createOrUpdateObjectFromJson_invalidJsonObject() throws JSONException {
TestHelper.populateSimpleAllTypesPrimaryKey(realm);
realm.beginTransaction();
JSONObject json = new JSONObject();
json.put("columnLong", "A");
try {
realm.createOrUpdateObjectFromJson(AllTypesPrimaryKey.class, json);
fail();
} catch (RealmException ignored) {
} finally {
realm.commitTransaction();
}
AllTypesPrimaryKey obj2 = realm.where(AllTypesPrimaryKey.class).findFirst();
assertEquals("Foo", obj2.getColumnString());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:RealmJsonTests.java
示例11: json_updateObject
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Test
public void json_updateObject() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.setFieldObject(child);
realm.commitTransaction();
RealmResults<AllJavaTypes> parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
realm.beginTransaction();
try {
realm.createOrUpdateAllFromJson(AllJavaTypes.class, "[{ \"fieldId\" : 1, \"objectParents\" : null }]");
} catch (RealmException e) {
fail("Failed loading JSON" + e);
}
realm.commitTransaction();
parents = child.getObjectParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:LinkingObjectsManagedTests.java
示例12: json_updateList
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Test
public void json_updateList() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.getFieldList().add(child);
realm.commitTransaction();
RealmResults<AllJavaTypes> parents = child.getListParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
realm.beginTransaction();
try {
realm.createOrUpdateAllFromJson(AllJavaTypes.class, "[{ \"fieldId\" : 1, \"listParents\" : null }]");
} catch (RealmException e) {
fail("Failed loading JSON" + e);
}
realm.commitTransaction();
parents = child.getListParents();
assertNotNull(parents);
assertEquals(1, parents.size());
assertTrue(parents.contains(parent));
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:LinkingObjectsManagedTests.java
示例13: setItemsUnread
import io.realm.exceptions.RealmException; //导入依赖的package包/类
public static void setItemsUnread(Realm realm, final boolean newUnread, final Item... items) {
realm.executeTransaction(realm1 -> {
try {
for (Item item : items) {
/* If the item has a fingerprint, mark all items with the same fingerprint
as read
*/
if(item.getFingerprint() == null) {
item.setUnread(newUnread);
} else {
RealmResults<Item> sameItems = realm1.where(Item.class)
.equalTo(Item.FINGERPRINT, item.getFingerprint())
.equalTo(Item.UNREAD, !newUnread)
.findAll();
for(Item sameItem: sameItems) {
sameItem.setUnread(newUnread);
}
}
}
} catch (RealmException e) {
Log.e(TAG, "Failed to set item as unread", e);
} finally {
checkAlarm(realm1);
}
});
}
开发者ID:schaal,项目名称:ocreader,代码行数:27,代码来源:Queries.java
示例14: saveStatus
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public BusinessObject<OrchextraStatus> saveStatus(OrchextraStatus orchextraStatus) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
OrchextraStatus result = null;
try {
realm.beginTransaction();
result = orchextraStatusUpdater.saveStatus(realm, orchextraStatus);
//TODO Store crm and session
} catch (RealmException re) {
return new BusinessObject<>(null, BusinessError.createKoInstance(re.getMessage()));
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return new BusinessObject<>(result, BusinessError.createOKInstance());
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:OrchextraStatusDBDataSourceImpl.java
示例15: loadStatus
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public BusinessObject<OrchextraStatus> loadStatus() {
Realm realm = realmDefaultInstance.createRealmInstance(context);
OrchextraStatus result = null;
try {
result = orchextraStatusReader.readStatus(realm);
//TODO retrieve crm and session
} catch (NotFountRealmObjectException exception) {
orchextraLogger.log(
"orchextraStatus info not present, new data will be created: " + exception.getMessage(),
OrchextraSDKLogLevel.WARN);
return new BusinessObject<>(OrchextraStatus.getInstance(), BusinessError.createOKInstance());
} catch (RealmException re) {
return new BusinessObject<>(null, BusinessError.createKoInstance(re.getMessage()));
} finally {
if (realm != null) {
realm.close();
}
}
return new BusinessObject<>(result, BusinessError.createOKInstance());
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:21,代码来源:OrchextraStatusDBDataSourceImpl.java
示例16: saveSdkAuthCredentials
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public boolean saveSdkAuthCredentials(SdkAuthCredentials sdkAuthCredentials) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
try {
realm.beginTransaction();
sessionUpdater.updateSdkAuthCredentials(realm, sdkAuthCredentials);
} catch (RealmException re) {
return false;
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return true;
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:SessionDBDataSourceImpl.java
示例17: saveSdkAuthResponse
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public boolean saveSdkAuthResponse(SdkAuthData sdkAuthData) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
try {
realm.beginTransaction();
sessionUpdater.updateSdkAuthResponse(realm, sdkAuthData);
} catch (RealmException re) {
return false;
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return true;
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:SessionDBDataSourceImpl.java
示例18: saveClientAuthCredentials
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public boolean saveClientAuthCredentials(ClientAuthCredentials clientAuthCredentials) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
try {
realm.beginTransaction();
sessionUpdater.updateClientAuthCredentials(realm, clientAuthCredentials);
} catch (RealmException re) {
return false;
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return true;
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:SessionDBDataSourceImpl.java
示例19: saveClientAuthResponse
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public boolean saveClientAuthResponse(ClientAuthData clientAuthData) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
try {
realm.beginTransaction();
sessionUpdater.updateClientAuthResponse(realm, clientAuthData);
} catch (RealmException re) {
return false;
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return true;
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:SessionDBDataSourceImpl.java
示例20: saveUser
import io.realm.exceptions.RealmException; //导入依赖的package包/类
@Override public boolean saveUser(CrmUser crmUser) {
Realm realm = realmDefaultInstance.createRealmInstance(context);
try {
realm.beginTransaction();
sessionUpdater.updateCrm(realm, crmUser);
} catch (RealmException re) {
return false;
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
return true;
}
开发者ID:Orchextra,项目名称:orchextra-android-sdk,代码行数:18,代码来源:SessionDBDataSourceImpl.java
注:本文中的io.realm.exceptions.RealmException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论