本文整理匯總了Java中io.realm.Realm.beginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.beginTransaction方法的具體用法?Java Realm.beginTransaction怎麽用?Java Realm.beginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.Realm
的用法示例。
在下文中一共展示了Realm.beginTransaction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertOrUpdate
import io.realm.Realm; //導入方法依賴的package包/類
/**
* Insert or update all
* @param items
* @return List of item copied from realm
*/
@Override
public Flowable<Optional<List<T>>> insertOrUpdate(List<T> items) {
final Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
items = realm.copyToRealmOrUpdate(items);
realm.commitTransaction();
List<T> copies = realm.copyFromRealm(items);
realm.close();
return Flowable.just(Optional.wrap(copies));
}
示例2: populateRealmIgnored
import io.realm.Realm; //導入方法依賴的package包/類
private void populateRealmIgnored() {
final Realm realm =
Realm.getInstance(new RealmConfiguration.Builder().name("realm.ignored").build());
final Author moses = new Author();
moses.name = "Moses";
final Book genesis = new Book();
genesis.index = 0;
genesis.name = "Genesis";
genesis.author = moses;
realm.beginTransaction();
realm.copyToRealmOrUpdate(genesis);
realm.commitTransaction();
realm.close();
}
示例3: parseRawData
import io.realm.Realm; //導入方法依賴的package包/類
static void parseRawData() {
Realm realmRawData = Realm.getInstance(realmConfigRawData);
Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
// if processed data realm is empty
if (realmProcessedData.isEmpty() && !realmRawData.isEmpty()) {
// parse data from raw realm into processed data realm
Log.i(LOG_ID, "Parsing data raw_data realm to processed_data realm.");
realmProcessedData.beginTransaction();
for (RawTagData rawTagData : realmRawData.where(RawTagData.class)
.findAllSorted(RawTagData.DATE, Sort.ASCENDING)) {
realmProcessedData.copyToRealmOrUpdate(new ReadingData(rawTagData));
}
realmProcessedData.commitTransaction();
}
realmProcessedData.close();
realmRawData.close();
}
示例4: fetchRandomMovieOrTvSeries
import io.realm.Realm; //導入方法依賴的package包/類
private Movie fetchRandomMovieOrTvSeries() {
Realm realm = Realm.getDefaultInstance();
//TODO: Add Random TV Series to fetch
RealmResults<Movie> movieRealmResults = realm.where(Movie.class).equalTo("isNotified", false).findAll();
Util.debugLog(TAG, "fetchRandomMovieOrTvSeries: Size of movies with isNotified false " + movieRealmResults.size());
if (movieRealmResults.size() != 0) {
Random r = new Random();
int randomNumber = r.nextInt(movieRealmResults.size());
Movie movie = movieRealmResults.get(randomNumber);
realm.beginTransaction();
movieRealmResults.get(randomNumber).setNotified(true);
realm.commitTransaction();
return movie;
} else {
return null;
}
}
示例5: logoutRealmUser
import io.realm.Realm; //導入方法依賴的package包/類
private void logoutRealmUser() {
//注冊成功寫數據庫
RealmConfiguration config = new RealmConfiguration.Builder().name("yyox.realm").build();
Realm objRealm = Realm.getInstance(config);
//查找
RealmUser realmUser = objRealm.where(RealmUser.class).findFirst();
if (realmUser != null) {
//先刪除
objRealm.beginTransaction();
RealmResults results = objRealm.where(RealmUser.class).findAll();
results.deleteAllFromRealm();
objRealm.commitTransaction();
//再添加
objRealm.beginTransaction();
RealmUser realmUserNew = objRealm.createObject(RealmUser.class);
realmUserNew.setName("");
objRealm.commitTransaction();
mRealmUser = null;
}
}
示例6: insert
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public boolean insert(Note note) {
Realm realm = Realm.getInstance(configuration);
final NoteDAO dao = RealmConverter.convert(note);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
示例7: updateDAB
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void updateDAB(Object object) {
JSONObject jsonObject = (JSONObject) object;
String username = "", password = "";
try {
username = jsonObject.getString("username");
password = jsonObject.getString("password");
} catch (Exception e) {
e.printStackTrace();
}
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
realm.delete(User.class);
User user = realm.createObject(User.class);
user.setUsername(username);
user.setPassword(password);
realm.commitTransaction();
mainController.updateResponse(user);
}
示例8: readFromRealmSync
import io.realm.Realm; //導入方法依賴的package包/類
protected <T> T readFromRealmSync(SyncCallable<T> callable) {
Realm realm = null;
try {
realm = Realm.getDefaultInstance();
realm.beginTransaction();
return callable.execute(realm);
} finally {
if (realm != null) {
realm.commitTransaction();
realm.close();
}
}
}
示例9: updateLastReadDate
import io.realm.Realm; //導入方法依賴的package包/類
public void updateLastReadDate(String id, String date) {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
BookDB result = realm.where(BookDB.class).equalTo("idBook", id).findFirst();
if (result != null)
result.setLastReadDate(date);
realm.commitTransaction();
}
示例10: delete
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void delete(Notification notification, Callbacks.IResultCallback<Notification> callback) {
Realm realm = Realm.getDefaultInstance();
try {
realm.beginTransaction();
notification.deleteFromRealm();
realm.commitTransaction();
} catch (Exception ex) {
ex.printStackTrace();
if (callback != null)
callback.onDataUnavailable();
}
}
示例11: delete
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public RealmObject delete(String cacheId, Class<? extends RealmObject> aClass) {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
RealmObject realmObject = realm.where(aClass).endsWith("cacheId", cacheId).findFirst();
realmObject.deleteFromRealm();
realm.commitTransaction();
return null;
}
示例12: writeSampleData
import io.realm.Realm; //導入方法依賴的package包/類
private void writeSampleData(Realm realm) {
realm.beginTransaction();
for (int i = 0; i < TEST_SIZE; i++) {
AllTypes obj = realm.createObject(AllTypes.class);
obj.setColumnString("Object " + i);
}
realm.commitTransaction();
}
示例13: resetInstance
import io.realm.Realm; //導入方法依賴的package包/類
public static void resetInstance() {
instance = null;
Realm realm = Realm.getInstance(configuration);
UserFactoryStore store = realm.where(UserFactoryStore.class).findFirst();
realm.beginTransaction();
if (store == null) {
store = realm.createObject(UserFactoryStore.class);
}
store.setUserName(UUID.randomUUID().toString());
realm.commitTransaction();
realm.close();
}
示例14: deleteAllFromDB
import io.realm.Realm; //導入方法依賴的package包/類
public void deleteAllFromDB() {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
RealmResults<BookDB> results = realm.where(BookDB.class).findAll();
results.deleteAllFromRealm();
realm.commitTransaction();
}
示例15: onReceive
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
String title = intent.getStringExtra("title");
String content = intent.getStringExtra("content");
String id = intent.getStringExtra("id");
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(content)
.setContentInfo("Alarm")
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_ALL)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setWhen(System.currentTimeMillis());
manager.notify(0, builder.build());
Realm realm = Realm.getDefaultInstance();
AlarmRealmData deleteData = realm.where(AlarmRealmData.class).equalTo("geofenceId", id).findFirst();
if (deleteData != null) {
realm.beginTransaction();
// FIXME: 2017/08/18 Error now
deleteData.deleteFromRealm();
realm.commitTransaction();
}
Log.d("onReceive", "はいったお!!!!!!!!");
}