/** 카테고리(메인) */ public void addMainCategory( MainCategoryObject obj1, MainCategoryObject obj2, MainCategoryObject obj3) { // Realm Database ********************************************************************** // Obtain a Realm instance Realm realm = Realm.getInstance(mContext); realm.beginTransaction(); realm.allObjects(MainCategoryObject.class).clear(); MainCategoryObject newObj1 = realm.createObject(MainCategoryObject.class); // Create a new object newObj1.setsSortNo(obj1.getsSortNo()); newObj1.setsCategoryId(obj1.getsCategoryId()); newObj1.setsCategoryType(obj1.getsCategoryType()); newObj1.setsCategoryTitle(obj1.getsCategoryTitle()); MainCategoryObject newObj2 = realm.createObject(MainCategoryObject.class); // Create a new object newObj2.setsSortNo(obj2.getsSortNo()); newObj2.setsCategoryId(obj2.getsCategoryId()); newObj2.setsCategoryType(obj2.getsCategoryType()); newObj2.setsCategoryTitle(obj2.getsCategoryTitle()); MainCategoryObject newObj3 = realm.createObject(MainCategoryObject.class); // Create a new object newObj3.setsSortNo(obj3.getsSortNo()); newObj3.setsCategoryId(obj3.getsCategoryId()); newObj3.setsCategoryType(obj3.getsCategoryType()); newObj3.setsCategoryTitle(obj3.getsCategoryTitle()); realm.commitTransaction(); // Realm Database ********************************************************************** }
/** * getWishList로 전체 찜 목록을 가져왔을때 호출되는 함수. 기존의 Wish들을 삭제하고, 파라메터의 어레이로 다시 채운다. * * @param arr */ public void setAllWishList(JSONArray arr) { // Realm Database ********************************************************************** // Obtain a Realm instance Realm realm = Realm.getInstance(mContext); // remove all realm.beginTransaction(); realm.allObjects(WishObject.class).clear(); for (int i = 0; i < arr.length(); i++) { try { JSONObject jo = arr.getJSONObject(i); JSONObject asset = jo.getJSONObject("asset"); String assetId = asset.getString("assetId"); RealmResults<WishObject> results = mRealm.where(WishObject.class).equalTo("sAssetId", assetId).findAll(); if (results.size() > 0) { // skip } else { // 객체를 생성하거나 데이터를 수정하는 작업을 수행한다. WishObject wish = realm.createObject(WishObject.class); // Create a new object wish.setsAssetId(assetId); wish.setsPhoneNumber(jo.getString("phoneNumber")); wish.setsUserId(jo.getString("userId")); } } catch (JSONException e) { e.printStackTrace(); } } // 트랜잭션 종료 realm.commitTransaction(); // Realm Database ********************************************************************** }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ImageLoaderConfiguration conf = new ImageLoaderConfiguration.Builder(getActivity()).build(); ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(conf); adapter = new FriendsArrayAdapter(getActivity(), R.layout.row_friends, imageLoader, this); setListAdapter(adapter); realm = Realm.getInstance(getActivity()); RealmResults<Friend> results = realm.allObjects(Friend.class); // TODO: Run async if (results.size() > 0) { if (!compact) { getListView().setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); } adapter.update(results); } refreshFriends(); // TODO: Timeout on the refresh rate? }
private void check(Realm realm) { RealmResults<Student> realmResults = realm.allObjects(Student.class); if (realmResults.size() != numberOfObjects) { throw new RuntimeException( String.format("Error in number of objectss.", realmResults.size(), numberOfObjects)); } }
// Todoデータの件数を取得 public int selectTodoCount() { return realm.allObjects(Todo.class).size(); }
@Override public RealmQuery<Chapter> getQuery(Realm realm) { return realm.allObjects(Chapter.class).where().equalTo("tags.id", tagId); }