當前位置: 首頁>>代碼示例>>Java>>正文


Java Realm.createObject方法代碼示例

本文整理匯總了Java中io.realm.Realm.createObject方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.createObject方法的具體用法?Java Realm.createObject怎麽用?Java Realm.createObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.realm.Realm的用法示例。


在下文中一共展示了Realm.createObject方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import io.realm.Realm; //導入方法依賴的package包/類
@Override
protected void run() {
    user = UserFactory.getInstance().loginWithDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;

    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl)
            .directory(getService().getRoot())
            .build();
    getService().setRealm(Realm.getInstance(syncConfig));
    Realm realm = getService().getRealm();

    realm.beginTransaction();
    ProcessInfo processInfo = realm.createObject(ProcessInfo.class);
    processInfo.setName("Background_Process1");
    processInfo.setPid(android.os.Process.myPid());
    processInfo.setThreadId(Thread.currentThread().getId());
    realm.commitTransaction();
    // FIXME: If we close the Realm here, the data won't be able to synced to the main process. Is it a bug
    // in sync client which stops too early?
    // Realm is currently configured with stop_immediately. This means the sync session is closed as soon as
    // the last realm instance is closed. Not doing this would make the Realm lifecycle really
    // unpredictable. We should have an easy way to wait for all changes to be uploaded though.
    // Perhaps SyncSession.uploadAllLocalChanges() or something similar to
    // SyncSesson.downloadAllServerChanges()
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:ProcessCommitTests.java

示例2: addMovieItemInUserList

import io.realm.Realm; //導入方法依賴的package包/類
private MovieItem addMovieItemInUserList(Realm realm, GenericMovieDataWrapper wrapper) {

        MovieItem movieItem = findInRealmMovieItem(realm, wrapper.getMovieId());

        if (movieItem == null) {
            movieItem = realm.createObject(MovieItem.class, wrapper.getMovieId());
            movieItem.setTitle(wrapper.getTitle());
            movieItem.setPosterPath(wrapper.getPosterPath());
            movieItem.setOverview(wrapper.getOverview());
            movieItem.setVoteCount(wrapper.getVoteCount());
            movieItem.setVoteAverage(wrapper.getVoteAverage());
            movieItem.setReleaseDate(wrapper.getReleaseDate());
            movieItem.setBackdropPath(wrapper.getBackdropPath());
        }

        return movieItem;
    }
 
開發者ID:prakh25,項目名稱:MovieApp,代碼行數:18,代碼來源:MovieDetailPresenter.java

示例3: addMovieItemInRealm

import io.realm.Realm; //導入方法依賴的package包/類
private void addMovieItemInRealm(Realm realm, GenericMovieDataWrapper wrapper) {

        MovieItem movieItemRealm = findInRealmMovieItem(realm, wrapper.getMovieId());

        if (movieItemRealm == null) {

            movieItemRealm = realm.createObject(MovieItem.class, wrapper.getMovieId());

            movieItemRealm.setTitle(wrapper.getTitle());
            movieItemRealm.setPosterPath(wrapper.getPosterPath());
            movieItemRealm.setOverview(wrapper.getOverview());
            movieItemRealm.setVoteCount(wrapper.getVoteCount());
            movieItemRealm.setVoteAverage(wrapper.getVoteAverage());
            movieItemRealm.setReleaseDate(wrapper.getReleaseDate());
            movieItemRealm.setBackdropPath(wrapper.getBackdropPath());
        } else {
            Timber.i(wrapper.getTitle() + "Already present in MovieItem");
        }
    }
 
開發者ID:prakh25,項目名稱:MovieApp,代碼行數:20,代碼來源:MovieDetailPresenter.java

示例4: 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;
    }
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:23,代碼來源:WEApplication.java

示例5: 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);
}
 
開發者ID:attiqrehman1991,項目名稱:AndroidRepositoryWithOfflineMode,代碼行數:24,代碼來源:LoginDAB.java

示例6: writeBookToDataBase

import io.realm.Realm; //導入方法依賴的package包/類
public void writeBookToDataBase(String bookId, Book.BookData book) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    BookDB data = realm.createObject(BookDB.class, bookId);
    data.setIdServerBook(book.getIdServerBook());
    data.setBookName(book.getBookName());
    data.setIdAuthor(book.getIdAuthor());
    data.setIdCategory(book.getIdCategory());
    data.setDescription(book.getDescription());
    data.setLanguage(book.getLanguage());
    data.setPhoto(book.getPhoto());
    data.setWhoAdded(book.getWhoAdded());
    data.setUploadDate(book.getUploadDate());
    data.setOfflineBook(false);
    realm.commitTransaction();
}
 
開發者ID:OlegKlimenko,項目名稱:Plamber-Android,代碼行數:17,代碼來源:BookUtilsDB.java

示例7: 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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:ProgressListenerTests.java

示例8: 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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:UserFactory.java

示例9: saveSyncableObject

import io.realm.Realm; //導入方法依賴的package包/類
/**
 * Stores a {@link SyncableObject} created from some user input, to be stored for
 * synchronization on the next connection to a LDLN Base Station or other LDLN-sync
 * enabled device.
 * 
 * @param callback          The callback that implements {@link SaveSyncableObjectListener} and will handle the result
 * @param schemaKey    		The key for the {@link Schema} of the {@link SyncableObject} to be saved.
 * @param keyValuePairs		The key value pairs of the {@link SyncableObject} to be saved.
 * @return                  void, results are returned via the {@link SaveSyncableObjectListener}
 */
public static void saveSyncableObject(Context context, SaveSyncableObjectListener callback, String schemaKey, String keyValuePairs)
{
	try {
		// Generate one uuid for use in both the plaintext and encrypted objects
		String uuid = UUID.randomUUID().toString();

		// Save the encrypted version of the object
		Realm realm = Realm.getInstance(getRealmConfig(context, RealmLevel.GLOBAL));
		realm.beginTransaction();
		SyncableObject syncableObject = realm.createObject(SyncableObject.class, uuid);
		syncableObject.setSchema(realm.where(Schema.class).equalTo("key", schemaKey).findFirst());
		syncableObject.setKeyValuePairs(keyValuePairs, DEK, encryptionIsEnabled);
		realm.commitTransaction();

		// Save the plaintext "cached" version of the object
		PlaintextObject plaintextObject = new PlaintextObject(syncableObject, DEK, encryptionIsEnabled);
		realm = Realm.getInstance(getRealmConfig(context, RealmLevel.USER));
		realm.beginTransaction();
		realm.insert(plaintextObject);
		realm.commitTransaction();

		// Sync with server
		LDLN.initializeWebSocketSync(context);

		// Call back to the implementor of the interface
		callback.onSaveSyncableObjectResult(true);
		return;
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}

	callback.onSaveSyncableObjectResult(false);
}
 
開發者ID:LDLN,項目名稱:Responder-Android,代碼行數:44,代碼來源:LDLN.java

示例10: saveBookOffline

import io.realm.Realm; //導入方法依賴的package包/類
public void saveBookOffline(String bookId, String bookName) {
    Realm realm = Realm.getDefaultInstance();
    realm.beginTransaction();
    BookDB data = realm.createObject(BookDB.class, bookId);
    data.setBookName(bookName);
    data.setOfflineBook(true);
    realm.commitTransaction();
}
 
開發者ID:OlegKlimenko,項目名稱:Plamber-Android,代碼行數:9,代碼來源:BookUtilsDB.java

示例11: 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();
    }
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:39,代碼來源:FeedbackUtil.java

示例12: execute

import io.realm.Realm; //導入方法依賴的package包/類
@Override
public void execute(Realm realm) {
    Log.d("realm", "now insert [" + date + " ," + num + "]");

    StepModel stepModel =realm.where(StepModel.class).equalTo("date",date).findFirst();

    if (stepModel == null)
        stepModel = realm.createObject(StepModel.class);
    stepModel.setDate(date);
    stepModel.setNumSteps(num);
}
 
開發者ID:gojuukaze,項目名稱:healthgo,代碼行數:12,代碼來源:StepTransaction.java

示例13: create

import io.realm.Realm; //導入方法依賴的package包/類
@Override public Named create(Realm realm) {
    return realm.createObject(Category.class, UUID.randomUUID().toString());
}
 
開發者ID:SeriousBug,項目名稱:Kutuk,代碼行數:4,代碼來源:Category.java

示例14: create

import io.realm.Realm; //導入方法依賴的package包/類
@Override public Named create(Realm realm) {
    GameObject object = realm.createObject(GameObject.class, UUID.randomUUID().toString());
    object.setCategory(category);
    return object;
}
 
開發者ID:SeriousBug,項目名稱:Kutuk,代碼行數:6,代碼來源:GameObject.java


注:本文中的io.realm.Realm.createObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。