本文整理汇总了Java中io.realm.RealmModel类的典型用法代码示例。如果您正苦于以下问题:Java RealmModel类的具体用法?Java RealmModel怎么用?Java RealmModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealmModel类属于io.realm包,在下文中一共展示了RealmModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FilterableMediator
import io.realm.RealmModel; //导入依赖的package包/类
/**
* Creates a filterable {@link RealmProxyMediator}.
*
* @param originalMediator the original auto generated mediator.
* @param allowedClasses the subset of classes from original mediator to allow.
*/
public FilterableMediator(RealmProxyMediator originalMediator, Collection<Class<? extends RealmModel>> allowedClasses) {
this.originalMediator = originalMediator;
Set<Class<? extends RealmModel>> tempAllowedClasses = new HashSet<>();
//noinspection ConstantConditions
if (originalMediator != null) {
Set<Class<? extends RealmModel>> originalClasses = originalMediator.getModelClasses();
for (Class<? extends RealmModel> clazz : allowedClasses) {
if (originalClasses.contains(clazz)) {
tempAllowedClasses.add(clazz);
}
}
}
this.allowedClasses = Collections.unmodifiableSet(tempAllowedClasses);
}
示例2: getColumnInfo
import io.realm.RealmModel; //导入依赖的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;
}
示例3: init
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public void init() {
RealmResults<TodoList> listResults = todoRepository.queryList(listId);
list = listResults.get(0);
view.initViews(list.getTitle());
bindData();
list.addChangeListener(new RealmChangeListener<RealmModel>() {
@Override
public void onChange(RealmModel element) {
if (view != null) {
bindData();
view.notifyDataChanged(list.getTitle());
}
}
});
}
示例4: init
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public void init(long taskId) {
RealmResults<Task> taskResults = repository.queryTask(taskId);
if (taskResults.size() > 0) {
task = taskResults.get(0);
}
task.addChangeListener(new RealmChangeListener<RealmModel>() {
@Override
public void onChange(RealmModel element) {
task.getId();
view.updateViews(task);
}
});
view.initViews();
view.updateViews(task);
}
示例5: deleteAndInsert
import io.realm.RealmModel; //导入依赖的package包/类
public static <T extends RealmModel & TreeItem & Insertable> void deleteAndInsert(Realm realm, final Class<T> clazz, final List<T> elements) {
Collections.sort(elements, TreeItem.COMPARATOR);
realm.executeTransaction(realm1 -> {
final RealmResults<T> databaseItems = realm1.where(clazz).findAllSorted(TreeItem.ID, Sort.ASCENDING);
final Iterator<T> databaseIterator = databaseItems.iterator();
for (T element : elements) {
T currentDatabaseItem;
// The lists are sorted by id, so if currentDatabaseItem.getId() < element.getId() we can remove it from the database
while (databaseIterator.hasNext() && (currentDatabaseItem = databaseIterator.next()).getId() < element.getId()) {
currentDatabaseItem.delete(realm1);
}
element.insert(realm1);
}
// Remove remaining items from the database
while (databaseIterator.hasNext()) {
databaseIterator.next().delete(realm1);
}
});
}
示例6: createOrUpdate
import io.realm.RealmModel; //导入依赖的package包/类
/**
* 增加或更新
*/
public static <E extends RealmModel> E createOrUpdate(final E realmModel) {
sRealm = Realm.getDefaultInstance();
sRealm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
E person = sRealm.copyToRealmOrUpdate(realmModel);
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
// Transaction was a success.
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
// Transaction failed and was automatically canceled.
}
});
sRealm.close();
return null;
}
示例7: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.DATE == fieldType) return realmQuery.lessThan(field, (Date) args[0]);
else if (FieldType.DOUBLE == fieldType) return realmQuery.lessThan(field, (Double) args[0]);
else if (FieldType.FLOAT == fieldType) return realmQuery.lessThan(field, (Float) args[0]);
else if (FieldType.INTEGER == fieldType) return realmQuery.lessThan(field, (Integer) args[0]);
else if (FieldType.LONG == fieldType) return realmQuery.lessThan(field, (Long) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例8: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.STRING == fieldType) return realmQuery.contains(field, (String) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例9: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.DATE == fieldType)
return realmQuery.lessThanOrEqualTo(field, (Date) args[0]);
else if (FieldType.DOUBLE == fieldType)
return realmQuery.lessThanOrEqualTo(field, (Double) args[0]);
else if (FieldType.FLOAT == fieldType)
return realmQuery.lessThanOrEqualTo(field, (Float) args[0]);
else if (FieldType.INTEGER == fieldType)
return realmQuery.lessThanOrEqualTo(field, (Integer) args[0]);
else if (FieldType.LONG == fieldType)
return realmQuery.lessThanOrEqualTo(field, (Long) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例10: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
if (FieldType.STRING == fieldType) return realmQuery.beginsWith(field, (String) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例11: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.DATE == fieldType)
return realmQuery.between(field, (Date) args[0], (Date) args[1]);
else if (FieldType.DOUBLE == fieldType)
return realmQuery.between(field, (Double) args[0], (Double) args[1]);
else if (FieldType.FLOAT == fieldType)
return realmQuery.between(field, (Float) args[0], (Float) args[1]);
else if (FieldType.INTEGER == fieldType)
return realmQuery.between(field, (Integer) args[0], (Integer) args[1]);
else if (FieldType.LONG == fieldType)
return realmQuery.between(field, (Long) args[0], (Long) args[1]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例12: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.BOOLEAN == fieldType) return realmQuery.equalTo(field, (Boolean) args[0]);
else if (FieldType.DATE == fieldType) return realmQuery.equalTo(field, (Date) args[0]);
else if (FieldType.DOUBLE == fieldType) return realmQuery.equalTo(field, (Double) args[0]);
else if (FieldType.FLOAT == fieldType) return realmQuery.equalTo(field, (Float) args[0]);
else if (FieldType.INTEGER == fieldType) return realmQuery.equalTo(field, (Integer) args[0]);
else if (FieldType.LONG == fieldType) return realmQuery.equalTo(field, (Long) args[0]);
else if (FieldType.SHORT == fieldType) return realmQuery.equalTo(field, (Short) args[0]);
else if (FieldType.STRING == fieldType) return realmQuery.equalTo(field, (String) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例13: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
if (FieldType.STRING == fieldType) return realmQuery.endsWith(field, (String) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例14: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.BOOLEAN == fieldType) return realmQuery.notEqualTo(field, (Boolean) args[0]);
else if (FieldType.DATE == fieldType) return realmQuery.notEqualTo(field, (Date) args[0]);
else if (FieldType.DOUBLE == fieldType) return realmQuery.notEqualTo(field, (Double) args[0]);
else if (FieldType.FLOAT == fieldType) return realmQuery.notEqualTo(field, (Float) args[0]);
else if (FieldType.INTEGER == fieldType) return realmQuery.notEqualTo(field, (Integer) args[0]);
else if (FieldType.LONG == fieldType) return realmQuery.notEqualTo(field, (Long) args[0]);
else if (FieldType.SHORT == fieldType) return realmQuery.notEqualTo(field, (Short) args[0]);
else if (FieldType.STRING == fieldType) return realmQuery.notEqualTo(field, (String) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}
示例15: transform
import io.realm.RealmModel; //导入依赖的package包/类
@Override
public <T extends RealmModel> RealmQuery<T> transform(RealmQuery<T> realmQuery, Condition condition) {
// Checks.
if (!condition.isValid()) throw new IllegalArgumentException("Condition isn't valid.");
if (condition.getType() != Condition.Type.NORMAL)
throw new IllegalArgumentException("Condition type is not NORMAL.");
// Get data from Conditions.
String field = condition.getField();
FieldType fieldType = condition.getFieldType();
Object[] args = condition.getArgs();
// Use different methods based on field type.
if (FieldType.DATE == fieldType)
return realmQuery.greaterThan(field, (Date) args[0]);
else if (FieldType.DOUBLE == fieldType)
return realmQuery.greaterThan(field, (Double) args[0]);
else if (FieldType.FLOAT == fieldType)
return realmQuery.greaterThan(field, (Float) args[0]);
else if (FieldType.INTEGER == fieldType)
return realmQuery.greaterThan(field, (Integer) args[0]);
else if (FieldType.LONG == fieldType)
return realmQuery.greaterThan(field, (Long) args[0]);
else
throw new IllegalArgumentException(String.format("Illegal argument type \"%s\".", fieldType.getTypeName()));
}