当前位置: 首页>>代码示例>>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;未经允许,请勿转载。