本文整理匯總了Java中io.realm.Realm.getDefaultInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.getDefaultInstance方法的具體用法?Java Realm.getDefaultInstance怎麽用?Java Realm.getDefaultInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.Realm
的用法示例。
在下文中一共展示了Realm.getDefaultInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertOrUpdateElephant
import io.realm.Realm; //導入方法依賴的package包/類
static public void insertOrUpdateElephant(final Elephant elephant, final List<Document> documents) {
Realm realm = Realm.getDefaultInstance();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
if (elephant.id == -1) {
elephant.id = getNextId(bgRealm, Elephant.class, Elephant.ID);
}
bgRealm.insertOrUpdate(elephant);
for (Document document : documents) {
if (document.id == -1) {
document.id = getNextId(bgRealm, Document.class, Document.ID);
}
document.elephant_id = elephant.id;
bgRealm.insertOrUpdate(document);
}
}
});
}
示例2: delete
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void delete(Post post, Callbacks.IRequestCallback callback) {
Realm realm = Realm.getDefaultInstance();
try {
realm.beginTransaction(); // open a transation
post.deleteFromRealm(); // delete the data
realm.commitTransaction(); // close the transation
if (callback != null)
callback.onSuccess();
} catch (Exception ex) {
ex.printStackTrace();
if (callback != null)
callback.onError();
}
}
示例3: getUsers
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void getUsers(Callbacks.IResultsCallback<Usuario> callback) {
Realm realm = Realm.getDefaultInstance();
try {
//realm.beginTransaction();
List<Usuario> tempList = realm.where(Usuario.class).findAll();
// if there is not data, notify empty data source
if (tempList == null || tempList.isEmpty()) {
callback.onDataUnavailable();
return;
}
// Return the result to Repository
callback.onSuccess(tempList);
} catch (Exception e) {
//print error
e.printStackTrace();
// notify error
callback.onDataUnavailable();
}
}
示例4: 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 broadcast-receiver->intent-service: " + output, Toast.LENGTH_LONG).show();
}
});
realm.close();
}
// All the work is done, release the wake locks/etc
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
示例5: updateOfflineBook
import io.realm.Realm; //導入方法依賴的package包/類
public void updateOfflineBook(String id, Book.BookData bookData) {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
BookDB result = realm.where(BookDB.class).equalTo("idBook", id).findFirst();
if (result != null) {
result.setIdServerBook(bookData.getIdServerBook());
result.setBookName(bookData.getBookName());
result.setIdAuthor(bookData.getIdAuthor());
result.setIdCategory(bookData.getIdCategory());
result.setDescription(bookData.getDescription());
result.setLanguage(bookData.getLanguage());
result.setPhoto(bookData.getPhoto());
result.setWhoAdded(bookData.getWhoAdded());
result.setUploadDate(bookData.getUploadDate());
result.setOfflineBook(false);
}
realm.commitTransaction();
}
示例6: shouldBeAbleToVerifyTransactionCalls
import io.realm.Realm; //導入方法依賴的package包/類
/**
* Have to verify the transaction execution in a different test because
* of a problem with Powermock: https://github.com/jayway/powermock/issues/649
*/
@Test
public void shouldBeAbleToVerifyTransactionCalls() {
// Create activity
ExampleActivity activity = Robolectric.buildActivity(ExampleActivity.class).create().start().resume().visible().get();
assertThat(activity.getTitle().toString(), is("Unit Test Example"));
// Verify that two Realm.getInstance() calls took place.
verifyStatic(times(2));
Realm.getDefaultInstance();
// verify that we have four begin and commit transaction calls
// Do not verify partial mock invocation count: https://github.com/jayway/powermock/issues/649
verify(mockRealm, times(4)).executeTransaction(Mockito.any(Realm.Transaction.class));
// Click the clean up button
activity.findViewById(R.id.clean_up).performClick();
// Verify that begin and commit transaction were called (been called a total of 5 times now)
// Do not verify partial mock invocation count: https://github.com/jayway/powermock/issues/649
verify(mockRealm, times(5)).executeTransaction(Mockito.any(Realm.Transaction.class));
// Call the destroy method so we can verify that the .close() method was called (below)
activity.onDestroy();
// Verify that the realm got closed 2 separate times. Once in the AsyncTask, once
// in onDestroy
verify(mockRealm, times(2)).close();
}
示例7: onCreate
import io.realm.Realm; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
realm=Realm.getDefaultInstance();
navigation= (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigation.setSelectedItemId(R.id.navigation_dashboard);
}
示例8: getBookPrimaryKey
import io.realm.Realm; //導入方法依賴的package包/類
public String getBookPrimaryKey(long id) {
String primaryKey = null;
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
BookDB result = realm.where(BookDB.class).equalTo("idServerBook", id).findFirst();
if (result != null)
primaryKey = result.getIdBook();
realm.commitTransaction();
return primaryKey;
}
示例9: getListBookFromDB
import io.realm.Realm; //導入方法依賴的package包/類
public List<Book.BookData> getListBookFromDB() {
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
List<BookDB> offlineBooks = new ArrayList<>();
offlineBooks.addAll(realm.where(BookDB.class).findAll());
realm.commitTransaction();
return convertBookListForDB(offlineBooks);
}
示例10: onItemDismissed
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void onItemDismissed(final int position)
{
final Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(realm1 ->
{
final Task task = getData().get(position);
task.deleteFromRealm();
});
realm.close();
}
示例11: getDeviceId
import io.realm.Realm; //導入方法依賴的package包/類
public String getDeviceId() {
try (Realm realm = Realm.getDefaultInstance()) {
DeviceModel model = realm.where(DeviceModel.class)
.equalTo(DeviceModel.ID,
DeviceModel.DEFAULT_ID).findFirst();
if (model == null) {
return null;
} else {
return model.getDeviceId();
}
}
}
示例12: setMother
import io.realm.Realm; //導入方法依賴的package包/類
public void setMother(final String id) {
Realm realm = Realm.getDefaultInstance();
elephant.mother = realm.where(Elephant.class).equalTo(ID, id).findFirst();
elephant.mother = realm.copyFromRealm(elephant.mother);
motherButton.setVisibility(View.GONE);
motherPreview.setElephant(elephant.mother);
motherPreview.setVisibility(View.VISIBLE);
realm.close();
}
示例13: bindData
import io.realm.Realm; //導入方法依賴的package包/類
public void bindData(InfoBean bean) {
typeIdentifier = bean.type().name();
super.bindData(bean);
String title = bean.valueOfUi("title_main");
String subtitle = bean.valueOfUi("subtitle");
String data = bean.valueOfUi("data");
String dataSecond = bean.valueOfUi("data_second");
SubViewSetter dataSetter = new SubViewSetter(tvsData);
dataSetter.set(new SubViewSetter.Value(true, data));
dataSetter.set(new SubViewSetter.Value(false, dataSecond));
SubViewSetter titleSetter = new SubViewSetter(tvsTitle);
titleSetter.set(new SubViewSetter.Value(true, title));
titleSetter.set(new SubViewSetter.Value(false, subtitle));
String identifier = bean.valueOfUi("identifier");
Realm realm = Realm.getDefaultInstance();
Synonyms synonyms = realm.where(Synonyms.class)
.contains(Synonyms.FILED_CANDIDATES, identifier)
.findFirst();
if (synonyms != null) {
setColorIcon(synonyms.identifier());
} else {
setColorIcon(typeIdentifier);
}
realm.close();
List<ConceptValue> conceptValues = bean.valuesOfUi("meta");
for (ConceptValue conceptValue : conceptValues) {
addMeta(conceptValue);
}
}
示例14: saveContacts
import io.realm.Realm; //導入方法依賴的package包/類
/**
* save contacts data into local storage
* @param contacts
*/
public static void saveContacts(final RealmList<RealmContact> contacts ){
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
final RealmResults<RealmContact> results = realm.where(RealmContact.class).findAll();
results.deleteAllFromRealm();
realm.copyToRealmOrUpdate(contacts);
realm.commitTransaction();
}
示例15: set
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void set(StripViewHolder holder, String value) {
holder.tvDetailTitle.setText(value);
Realm realm = Realm.getDefaultInstance();
Synonyms synonyms = realm.where(Synonyms.class)
.contains(Synonyms.FILED_CANDIDATES, value)
.findFirst();
if (synonyms != null) {
holder.setColorIcon(synonyms.identifier());
} else {
holder.setColorIcon(holder.typeIdentifier);
}
}