本文整理汇总了Java中io.realm.Realm.close方法的典型用法代码示例。如果您正苦于以下问题:Java Realm.close方法的具体用法?Java Realm.close怎么用?Java Realm.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.Realm
的用法示例。
在下文中一共展示了Realm.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateRealm2
import io.realm.Realm; //导入方法依赖的package包/类
private void populateRealm2() {
final Realm realm = Realm.getInstance(
new RealmConfiguration.Builder().directory(new File(getFilesDir(), "custom"))
.name("random.realm")
.build());
final Author moses = new Author();
moses.name = "Moses";
final Book genesis = new Book();
genesis.index = 0;
genesis.name = "Genesis";
genesis.author = moses;
final Verse verse =
Verse.create(genesis, 0, 0, "In the beginning God created the heaven and the earth.");
realm.beginTransaction();
realm.copyToRealmOrUpdate(verse);
realm.commitTransaction();
realm.close();
}
示例2: onCreate
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
handler = new Handler(Looper.myLooper());
final Runnable runnable = new Runnable() {
@Override
public void run() {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
realm.copyToRealmOrUpdate(Utils.createStandaloneProcessInfo(AnotherProcessService.this));
realm.commitTransaction();
realm.close();
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(runnable, 1000);
}
示例3: onHandleIntent
import io.realm.Realm; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (intent.getExtras() != null) {
String personId = intent.getStringExtra("person_id");
Realm realm = Realm.getDefaultInstance();
Person person = realm.where(Person.class).equalTo("id", personId).findFirst();
final String output = person.toString();
new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Loaded Person from intent service: " + output, Toast.LENGTH_LONG).show();
}
});
realm.close();
}
}
示例4: insert
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public boolean insert(TodoList todoList) {
Realm realm = Realm.getInstance(configuration);
final TodoListDAO dao = RealmConverter.convert(todoList);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
示例5: getHeaderById
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Optional<TodoListHeader> getHeaderById(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("uuid", uuid).findFirst());
Optional<TodoListHeader> header = headerDAO.transform(new TodoListHeaderDAOConverter());
realm.close();
return header;
}
示例6: delete
import io.realm.Realm; //导入方法依赖的package包/类
public static <O extends RealmObject> void delete(Realm realmInstance, QueryFilters filters, Class<O> clazz){
Realm realm = realmInstance;
realm.beginTransaction();
RealmQuery<O> query = realm.where(clazz);
query = filters.copyToRealmQuery(query);
final RealmResults<O> results = query.findAll();
results.deleteAllFromRealm();
realm.commitTransaction();
realm.close();
}
示例7: usingConfigurationWithInvalidUserShouldThrow
import io.realm.Realm; //导入方法依赖的package包/类
@Test
public void usingConfigurationWithInvalidUserShouldThrow() {
String username = UUID.randomUUID().toString();
String password = "password";
SyncCredentials credentials = SyncCredentials.usernamePassword(username, password, true);
SyncUser user = SyncUser.login(credentials, Constants.AUTH_URL);
RealmConfiguration configuration = new SyncConfiguration.Builder(user, Constants.USER_REALM).build();
user.logout();
assertFalse(user.isValid());
Realm instance = Realm.getInstance(configuration);
instance.close();
}
示例8: savePackage
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Save a package to database.
* @param pack The package to save. See {@link Package}
*/
@Override
public void savePackage(@NonNull Package pack) {
Realm rlm = RealmHelper.newRealmInstance();
// DO NOT forget begin and commit the transaction.
rlm.beginTransaction();
rlm.copyToRealmOrUpdate(pack);
rlm.commitTransaction();
rlm.close();
}
示例9: getTodoListById
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Optional<TodoList> getTodoListById(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<TodoListDAO> todoListDAO = Optional.fromNullable(realm.where(TodoListDAO.class).equalTo("uuid", uuid).findFirst());
Optional<TodoList> todoList = todoListDAO.transform(new TodoListDAOConverter());
realm.close();
return todoList;
}
示例10: clearInstance
import io.realm.Realm; //导入方法依赖的package包/类
public static void clearInstance() {
Realm realm = Realm.getInstance(configuration);
realm.beginTransaction();
realm.delete(UserFactoryStore.class);
realm.commitTransaction();
realm.close();
}
示例11: getItemById
import io.realm.Realm; //导入方法依赖的package包/类
@Override
public Optional<TodoListItem> getItemById(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<TodoListItemDAO> itemDAO = Optional.fromNullable(realm.where(TodoListItemDAO.class).equalTo("uuid", uuid).findFirst());
Optional<TodoListItem> item = itemDAO.transform(new TodoListItemDAOConverter());
realm.close();
return item;
}
示例12: sendReport
import io.realm.Realm; //导入方法依赖的package包/类
private void sendReport(@Nullable Station correctStation) {
// build report
Map<String, Object> map = new HashMap<>();
if (incorrectStation == null) {
map.put("incorrectStation", "none");
} else {
map.put("incorrectStation", incorrectStation.getId());
}
if (correctStation == null) {
map.put("correctStation", "none");
} else {
map.put("correctStation", correctStation.getId());
}
map.put("wiFiScanResults", scanResults);
ObjectMapper mapper = new ObjectMapper();
try {
String jsonResult = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(map);
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
Feedback feedback = realm.createObject(Feedback.class, UUID.randomUUID().toString());
feedback.setSynced(false);
feedback.setTimestamp(new Date());
feedback.setType("s2ls-incorrect-detection");
feedback.setContents(jsonResult);
realm.copyToRealm(feedback);
realm.commitTransaction();
realm.close();
Intent intent = new Intent(ACTION_FEEDBACK_PROVIDED);
intent.putExtra(EXTRA_FEEDBACK_PROVIDED_DELAYED, !Connectivity.isConnected(context));
LocalBroadcastManager bm = LocalBroadcastManager.getInstance(context);
bm.sendBroadcast(intent);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
示例13: closeTestRealms
import io.realm.Realm; //导入方法依赖的package包/类
/**
* Explicitly close all held realms.
* <p>
* 'testRealms' is accessed from both test and main threads.
* 'testRealms' is valid after {@code before}.
*/
public void closeTestRealms() {
List<Realm> realms = new ArrayList<>();
synchronized (lock) {
List<Realm> tmp = testRealms;
testRealms = realms;
realms = tmp;
}
for (Realm testRealm : realms) {
testRealm.close();
}
}
示例14: exportRepository
import io.realm.Realm; //导入方法依赖的package包/类
public static boolean exportRepository(File destination, String activeRealm) {
if(!destination.exists()) {
RealmConfiguration configuration = createConfiguration(activeRealm);
Realm realm = Realm.getInstance(configuration);
realm.writeEncryptedCopyTo(destination, letMeReadImLegit());
realm.close();
return true;
}
return false;
}
示例15: complexQuery
import io.realm.Realm; //导入方法依赖的package包/类
private String complexQuery() {
String status = "\n\nPerforming complex Query operation...";
Realm realm = Realm.getDefaultInstance();
status += "\nNumber of persons: " + realm.where(Person.class).count();
// Find all persons where age between 7 and 9 and name begins with "Person".
RealmResults<Person> results = realm.where(Person.class)
.between("age", 7, 9) // Notice implicit "and" operation
.beginsWith("name", "Person").findAll();
status += "\nSize of result set: " + results.size();
realm.close();
return status;
}