本文整理汇总了Java中io.realm.RealmObject类的典型用法代码示例。如果您正苦于以下问题:Java RealmObject类的具体用法?Java RealmObject怎么用?Java RealmObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealmObject类属于io.realm包,在下文中一共展示了RealmObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscribeDataChange
import io.realm.RealmObject; //导入依赖的package包/类
@Override
public void subscribeDataChange(Object dataIdentity, final DataChangeListener listener) {
if (dataIdentity instanceof RealmResults) {
RealmResults<RealmObject> realmResults = (RealmResults<RealmObject>) dataIdentity;
realmResults.addChangeListener(new RealmChangeListener<RealmResults<RealmObject>>() {
@Override
public void onChange(RealmResults<RealmObject> element) {
if (listener != null) {
listener.onChange();
}
}
});
}
}
示例2: makeGsonForRealm
import io.realm.RealmObject; //导入依赖的package包/类
/**
* Make gson which {@link DateDeserializer} and compatible with {@link RealmObject}
* @return {@link Gson} object
*/
public static Gson makeGsonForRealm() {
return makeDefaultGsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.create();
}
示例3: deleteAllIn
import io.realm.RealmObject; //导入依赖的package包/类
public <E extends RealmObject> void deleteAllIn(Class<E> classType, String classField,
String[] fieldsIn) {
Realm realm = get();
try {
realm.beginTransaction();
realm.where(classType)
.in(classField, fieldsIn)
.findAll()
.deleteAllFromRealm();
realm.commitTransaction();
} finally {
if (realm != null) {
realm.close();
}
}
}
示例4: onClick
import io.realm.RealmObject; //导入依赖的package包/类
@Override
public void onClick(View v) {
Context c = RealmBrowserSampleActivity.this;
RealmConfiguration firstConfig = new RealmConfiguration.Builder().build();
Realm realm = Realm.getInstance(firstConfig);
RealmConfiguration secondRealmConfig = new RealmConfiguration.Builder()
.name(SECOND_REALM_NAME)
.build();
Realm realmSecond = Realm.getInstance(secondRealmConfig);
List<Class<? extends RealmObject>> classes = new ArrayList<>();
classes.add(Cat.class);
classes.add(Dog.class);
classes.add(Person.class);
classes.add(DataTypeTest.class);
new RealmBrowser.Builder(c)
.add(realm, classes)
.add(realmSecond, DifferentFileObject.class)
.show();
}
示例5: getApiObservable
import io.realm.RealmObject; //导入依赖的package包/类
@Override
public <Item extends RealmObject> Observable<List<Item>> getApiObservable(Observable<List<Item>> api, Class<Item> realmClass, String sortedField, List<Integer> ids) {
if (getStorage() != null) {
RealmResults<Item> realmResults;
if (sortedField != null)
realmResults = (ids == null) ? getItems(realmClass, sortedField) : getItems(realmClass, sortedField, ids);
else
realmResults = getItems(realmClass);
Observable<List<Item>> realmObserver = realmResults.asObservable()
.filter(RealmResults::isLoaded)
.compose(getLifecycle())
.switchMap(Observable::just);
Observable<List<Item>> retrofitObserver = api
.compose(applySchedulers())
.compose(getLifecycle());
return Observable.<List<Item>>create(subscriber -> {
realmObserver.take(2).subscribe(subscriber::onNext, subscriber::onError, subscriber::onCompleted);
retrofitObserver.subscribe(this::setItems, subscriber::onError);
}).compose(getLifecycle());
} else
return api;
}
示例6: put
import io.realm.RealmObject; //导入依赖的package包/类
/**
* Puts and element into the DB.
*
* @param jsonObject Element to insert in the DB.
* @param dataClass Class type of the items to be put.
*/
@NonNull
@Override
public Single<Boolean> put(@Nullable JSONObject jsonObject, @Nullable String idColumnName,
Class itemIdType, @NonNull Class dataClass) {
return Single.fromCallable(() -> {
if (jsonObject == null) {
throw new IllegalArgumentException("JSONObject is invalid");
} else {
updateJsonObjectWithIdValue(jsonObject, idColumnName, itemIdType, dataClass);
return getRealm(Realm.getDefaultInstance()).map(realm1 ->
RealmObject.isValid(executeWriteOperationInRealm(realm1,
() -> realm1.createOrUpdateObjectFromJson(dataClass, jsonObject))))
.blockingFirst();
}
});
}
示例7: onClick
import io.realm.RealmObject; //导入依赖的package包/类
@Override
public void onClick(View v) {
Context c = MainActivity.this;
RealmConfiguration firstConfig = new RealmConfiguration.Builder().build();
RealmConfiguration secondRealmConfig = new RealmConfiguration.Builder()
.name(SECOND_REALM_NAME)
.schemaVersion(5)
.migration(mMigration)
.build();
List<Class<? extends RealmObject>> classes = new ArrayList<>();
classes.add(Cat.class);
classes.add(Dog.class);
classes.add(Person.class);
classes.add(DataTypeTest.class);
new RealmBrowser.Builder(c)
.add(firstConfig, classes)
.add(secondRealmConfig, DifferentFileObject.class)
.show();
}
示例8: convert
import io.realm.RealmObject; //导入依赖的package包/类
@Override
public RealmObject convert(Cursor cursor, PackageManager packageManager, Context context) {
cm.aptoide.pt.database.realm.Update realmObject = new cm.aptoide.pt.database.realm.Update();
realmObject.setPackageName(cursor.getString(cursor.getColumnIndex(COLUMN_PACKAGE_NAME)));
realmObject.setLabel(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
realmObject.setVersionCode(cursor.getInt(cursor.getColumnIndex(COLUMN_VERCODE)));
realmObject.setUpdateVersionName(cursor.getString(cursor.getColumnIndex(COLUMN_VERNAME)));
realmObject.setExcluded(true);
String cleanIconPath = AptoideUtils.IconSizeU.cleanImageUrl(
cursor.getString(cursor.getColumnIndex(COLUMN_ICONPATH)));
realmObject.setIcon(cleanIconPath);
// are this columns to remove?
// COLUMN_NAME
return realmObject;
}
示例9: deleteAllExcluding
import io.realm.RealmObject; //导入依赖的package包/类
public <E extends RealmObject> void deleteAllExcluding(Class<E> classType, String classField,
List<String> fieldsIn) {
Realm realm = get();
try {
realm.beginTransaction();
RealmQuery<E> query = realm.where(classType);
for (String field : fieldsIn) {
query.notEqualTo(classField, field);
}
query.findAll()
.deleteAllFromRealm();
realm.commitTransaction();
} finally {
if (realm != null) {
realm.close();
}
}
}
示例10: provideGson
import io.realm.RealmObject; //导入依赖的package包/类
/**
* Custom Gson to make Retrofit Gson adapter work with Realm objects
*/
@NonNull
@Provides
@Singleton
public static Gson provideGson(@NonNull ListTypeAdapterFactory jsonArrayTypeAdapterFactory,
@NonNull HtmlAdapter htmlAdapter,
@NonNull StringCapitalizerAdapter stringCapitalizerAdapter) {
return new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.registerTypeAdapterFactory(jsonArrayTypeAdapterFactory)
.registerTypeAdapter(String.class, htmlAdapter)
.registerTypeAdapter(String.class, stringCapitalizerAdapter)
.create();
}
示例11: getFieldDisplayedName
import io.realm.RealmObject; //导入依赖的package包/类
static String getFieldDisplayedName(@NonNull RealmObject obj, @NonNull Field field) {
if (isFieldRealmList(field)) {
return getRealmListFieldDisplayingName(obj, field);
} else if (isFieldRealmObject(field)) {
Object value = getRealmObjectFieldValue(obj, field);
return value == null ? "null" : getRealmObjectFieldDisplayingName(field);
} else {
Object result = getNotParamFieldValue(obj, field);
if (result != null) {
if (field.getType() == byte[].class || field.getType() == Byte[].class) {
byte[] array = (byte[]) result;
StringBuilder builder = new StringBuilder();
for (byte b : array) {
builder.append(String.format("0x%02X", b));
builder.append(" ");
}
return builder.toString();
}
}
return result == null ? "null" : result.toString();
}
}
示例12: getRealmListFieldDisplayingName
import io.realm.RealmObject; //导入依赖的package包/类
private static String getRealmListFieldDisplayingName(@NonNull RealmObject obj,
@NonNull Field field) {
ParameterizedType pType = (ParameterizedType) field.getGenericType();
String rawType = pType.getRawType().toString();
int rawTypeIndex = rawType.lastIndexOf(".");
if (rawTypeIndex > 0) {
rawType = rawType.substring(rawTypeIndex + 1);
}
String argument = pType.getActualTypeArguments()[0].toString();
int argumentIndex = argument.lastIndexOf(".");
if (argumentIndex > 0) {
argument = argument.substring(argumentIndex + 1);
}
int objNumber = RealmUtils.getRealmListFieldValue(obj, field).size();
return String.format("%s<%s> (%d)", rawType, argument, objNumber);
}
示例13: getDisplayedRealmObjects
import io.realm.RealmObject; //导入依赖的package包/类
List<Class<? extends RealmObject>> getDisplayedRealmObjects(RealmConfiguration realm) {
List<Class<? extends RealmObject>> result = new ArrayList<>();
for (Class<? extends RealmObject> clazz : displayedRealmConfigs.keySet()) {
RealmConfiguration config = displayedRealmConfigs.get(clazz);
if (config.getPath().equals(realm.getPath())) {
result.add(clazz);
}
}
Collections.sort(result, new Comparator<Class<? extends RealmObject>>() {
@Override
public int compare(Class<? extends RealmObject> lhs, Class<? extends RealmObject> rhs) {
return lhs.getSimpleName().compareTo(rhs.getSimpleName());
}
});
return result;
}
示例14: fillTable
import io.realm.RealmObject; //导入依赖的package包/类
private void fillTable(RealmObject realmObj, Field field) {
if (RealmUtils.isFieldRealmList(field)) {
ParameterizedType pType = (ParameterizedType) field.getGenericType();
//noinspection unchecked
mClazz = (Class<? extends RealmObject>) pType.getActualTypeArguments()[0];
mOriginalData = RealmUtils.getRealmListFieldValue(realmObj, field);
} else if (RealmUtils.isFieldRealmObject(field)) {
//noinspection unchecked
mClazz = (Class<? extends RealmObject>) field.getType();
mOriginalData = new ArrayList<>(1);
mOriginalData.add(RealmUtils.getRealmObjectFieldValue(realmObj, field));
} else {
throw new IllegalArgumentException("Unsupported field type: " + field);
}
updateData(mOriginalData);
}
示例15: getGsonInstance
import io.realm.RealmObject; //导入依赖的package包/类
public static Gson getGsonInstance(){
return new GsonBuilder()
.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
return f.getDeclaringClass().equals(RealmObject.class);
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
})
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
}