private void showSyncStats() {
    final SharedPreferences sharedPreferences =
        GroomApplication.getContext()
            .getSharedPreferences(getString(R.string.groom_sync), Context.MODE_PRIVATE);
    String lastSync =
        sharedPreferences.getString(getString(R.string.last_sync), getString(R.string.never_sync));
    String eventsNumber =
        String.valueOf(Realm.getInstance(this).where(RealmEvent.class).findAll().size());
    String productsNumber =
        String.valueOf(Realm.getInstance(this).where(RealmProduct.class).findAll().size());

    ((TextView) findViewById(R.id.lastSync)).setText(lastSync);
    ((TextView) findViewById(R.id.eventsNumber)).setText(eventsNumber);
    ((TextView) findViewById(R.id.productsNumber)).setText(productsNumber);
  }
  public void sum() {
    Log.i("DataStoreBenchmark", "Realm invoking sum");
    // super.intitalize();         Realm.deleteRealm(realmConfiguration);

    Realm realm;
    List<Long> values;
    long timeStart;
    values = new ArrayList<>();

    realm = Realm.getInstance(realmConfiguration);
    add(realm);
    check(realm);

    for (int i = 0; i < numberOfIterations; i++) {
      timeStart = Debug.threadCpuTimeNanos();
      System.gc();

      long sum = realm.where(Student.class).sumInt("points");
      long timeStop = Debug.threadCpuTimeNanos();
      long duration = timeStop - timeStart;
      values.add(duration);
    }

    realm.beginTransaction();
    realm.clear(Student.class);
    realm.commitTransaction();
    realm.close();

    finalvalues.put(SUM, values);

    System.gc();
  }
Beispiel #3
0
 public static void clearAllDatabaseCache() {
   // holder.timeOutMap.clear();
   Realm realm = Realm.getInstance(sContext);
   realm.clear(CacheInfo.class);
   realm.close();
   Log.d("aop-cache", "database cache has been cleared ");
 }
  /**
   * *********************************************************************************************
   * VOD시청
   */
  public void addWatchVod(Date watchDate, String assetId, String title) {
    // Realm Database **********************************************************************
    // Obtain a Realm instance
    Realm realm = Realm.getInstance(mContext);
    RealmResults<WatchVodObject> results = realm.where(WatchVodObject.class).findAll();
    long iSeq = 0;
    if (results == null) {
      //
    } else {
      if (results.size() == 0) {
        iSeq = 0;
      } else {
        iSeq = realm.where(WatchVodObject.class).maximumInt("iSeq") + 1;
      }
    }

    WatchVodObject obj = new WatchVodObject();
    obj.setiSeq((int) iSeq);
    obj.setdDate(watchDate);
    obj.setsAssetId(assetId);
    obj.setsTitle(title);
    realm.beginTransaction();
    WatchVodObject obj2 = realm.copyToRealm(obj);
    realm.commitTransaction();
    // Realm Database **********************************************************************
  }
  public void loadData() {
    SimpleDateFormat formatIn = new SimpleDateFormat("MMMM d, yyyy");
    SimpleDateFormat formatOut = new SimpleDateFormat("MM/d/yy");
    ObjectMapper objectMapper = new ObjectMapper();
    JsonFactory jsonFactory = new JsonFactory();
    Random random = new Random();
    try {
      JsonParser jsonParserBlog =
          jsonFactory.createParser(getResources().openRawResource(R.raw.blog));
      List<Blog> entries =
          objectMapper.readValue(jsonParserBlog, new TypeReference<List<Blog>>() {});
      JsonParser jsonParserEmoji =
          jsonFactory.createParser(getResources().openRawResource(R.raw.emoji));
      List<String> emojies =
          objectMapper.readValue(jsonParserEmoji, new TypeReference<List<String>>() {});

      int numEmoji = emojies.size();
      for (Blog blog : entries) {
        blog.setEmoji(emojies.get(random.nextInt(numEmoji)));
        try {
          blog.setDate(formatOut.format(formatIn.parse(blog.getDate())));
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
      Realm realm = Realm.getInstance(this);
      realm.beginTransaction();
      realm.copyToRealm(entries);
      realm.commitTransaction();
      realm.close();

    } catch (Exception e) {
      throw new IllegalStateException("Could not load blog data.");
    }
  }
  /**
   * 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 **********************************************************************
  }
  public void createOrUpdateQuests(
      int id,
      int type,
      String text,
      String answer,
      String other,
      String title,
      String icon,
      String color,
      int status) {
    Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    QuestModel quest = getQuest(id);

    if (quest == null) {
      quest = realm.createObject(QuestModel.class);
    }

    quest.setId(id);
    quest.setType(type);
    quest.setText(text);
    quest.setAnswer(answer);
    quest.setOther(other);
    quest.setTitle(title);
    quest.setIcon(icon);
    quest.setColor(color);
    /*quest.setStatus(status);*/

    realm.commitTransaction();
  }
 public void UpdateStatus(int id, int status) {
   Realm realm = Realm.getInstance(context);
   QuestModel toEdit = realm.where(QuestModel.class).equalTo("id", id).findFirst();
   realm.beginTransaction();
   toEdit.setStatus(status);
   realm.commitTransaction();
 }
 /** 카테고리(메인) */
 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 **********************************************************************
 }
Beispiel #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    ButterKnife.inject(this);

    realm = Realm.getInstance(this);

    getSupportActionBar().setTitle("Riwayat Wisata");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    locationModels = new ArrayList<>();
    adapterRoute = new ListRouteAdapter(this, locationModels);

    updateView();

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapterRoute);
    recyclerView.addOnItemTouchListener(
        new RecyclerItemClickListener(this, this) {
          @Override
          public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {}
        });
    readDataFromDb();

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
  }
Beispiel #11
0
 public void setUp() throws Exception {
   super.setUp();
   realm = Realm.getInstance(getContext());
   realmCache = getRealmCache();
   testSubscriber = new TestSubscriber<>();
   mockDataMapper = getMockDataMapper();
 }
  // 2016-03-29 시청예약시 데이타베이스 처리를 programId 로 하는데 서버에서 programId를 중복으로 보내고 있다
  // 그래서 시청시간을 추가함.
  public void removeWatchTvReserveAlarmWithProgramIdAndStartTime(
      String programId, String startTime) {
    int iSeq = 0;
    Realm realm = Realm.getInstance(mContext);
    realm.beginTransaction();
    RealmResults<WatchTvObject> results =
        mRealm
            .where(WatchTvObject.class)
            .equalTo("sProgramId", programId)
            .equalTo("sProgramBroadcastingStartTime", startTime)
            .findAll();
    if (results.size() > 0) {
      WatchTvObject obj = results.get(0);
      iSeq = obj.getiSeq();
      obj.removeFromRealm();
    } else {
      //
    }
    realm.commitTransaction();

    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(mContext, WatchTvAlarmBroadcastReceiver.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(mContext, iSeq, intent, PendingIntent.FLAG_NO_CREATE);
    if (pendingIntent != null) {
      alarmManager.cancel(pendingIntent);
      pendingIntent.cancel();
    }
  }
Beispiel #13
0
  @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?
  }
 /** when view is created * */
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   /** set realm instance * */
   realm = Realm.getInstance(getActivityFromBase());
   /** add change listener to realm * */
   realm.addChangeListener(this);
 }
Beispiel #15
0
 public static void removeDataBaseCache(String classMethodString) {
   Realm realm = Realm.getInstance(sContext);
   CacheInfo info = realm.where(CacheInfo.class).equalTo("key", classMethodString).findFirst();
   if (info != null) {
     info.removeFromRealm();
   }
   realm.close();
 }
 protected void createRealm() {
   RealmConfiguration.Builder configBuilder = new RealmConfiguration.Builder(getContext());
   if (inMemory) {
     configBuilder.name("inmemory.realm").inMemory();
   } else {
     configBuilder.name("ondisk.realm");
   }
   realm = Realm.getInstance(configBuilder.build());
 }
Beispiel #17
0
  public static void removeFavorite(Context context, MashableNewsItem newsItem) {
    Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    RealmResults<Favorites> result =
        realm.where(Favorites.class).equalTo("link", newsItem.link).findAll();

    result.clear();
    realm.commitTransaction();
  }
  /**
   * @param programId "S321387639"
   * @param seriesId ""
   * @param programTitle "국악무대"
   * @param programBroadcastingStartTime 2015-11-10 16:02:00"
   *     <p>mPref.addWatchTvAlarm("S321387639", "", "국악무대1", "2015-11-10 18:50:00");
   *     mPref.addWatchTvAlarm("S321387640", "", "국악무대2", "2015-11-10 18:51:00");
   *     mPref.addWatchTvAlarm("S321387641", "", "국악무대3", "2015-11-10 18:52:00");
   *     mPref.addWatchTvAlarm("S321387642", "", "국악무대4", "2015-11-10 18:53:00");
   *     mPref.addWatchTvAlarm("S321387643", "", "국악무대5", "2015-11-10 18:54:00");
   */
  public void addWatchTvReserveAlarm(
      String programId, String seriesId, String programTitle, String programBroadcastingStartTime) {

    // Realm Database **********************************************************************
    // Obtain a Realm instance
    Realm realm = Realm.getInstance(mContext);

    // remove all
    realm.beginTransaction();
    WatchTvObject obj = realm.createObject(WatchTvObject.class); // Create a new object
    long iSeq = realm.where(WatchTvObject.class).maximumInt("iSeq") + 1;
    obj.setiSeq((int) iSeq);
    obj.setsScheduleSeq("");
    obj.setsBroadcastingDate("");
    obj.setsProgramId(programId);
    obj.setsSeriesId(seriesId);
    obj.setsProgramTitle(programTitle);
    obj.setsProgramContent("");
    obj.setsProgramBroadcastingStartTime(programBroadcastingStartTime);
    obj.setsProgramBroadcastingEndTime("");
    obj.setsProgramHD("");
    obj.setsProgramGrade("");
    obj.setsProgramPVR("");
    // 트랜잭션 종료
    realm.commitTransaction();
    // Realm Database **********************************************************************

    Date startDate = null;
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
      startDate = formatter.parse(programBroadcastingStartTime);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    calendar.setTime(startDate);

    Intent intent = new Intent(mContext, WatchTvAlarmBroadcastReceiver.class);
    intent.putExtra("programId", programId);
    intent.putExtra("seriesId", seriesId);
    intent.putExtra("programTitle", programTitle);
    intent.putExtra("programBroadcastingStartTime", programBroadcastingStartTime);
    intent.putExtra("iSeq", String.valueOf(iSeq));

    //        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, (int)iSeq, intent,
    // PendingIntent.FLAG_NO_CREATE);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(mContext, (int) iSeq, intent, PendingIntent.FLAG_ONE_SHOT);
    //        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, (int)iSeq, intent,
    // PendingIntent.FLAG_UPDATE_CURRENT );

    AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    //        alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
  }
  @Override
  public void call(final Subscriber<? super T> subscriber) {
    final Realm realm = Realm.getInstance(context);
    thread = Thread.currentThread();
    subscriber.add(
        Subscriptions.create(
            new Action0() {
              @Override
              public void call() {
                if (thread != null && !thread.isInterrupted()) {
                  thread.interrupt();
                }
              }
            }));

    boolean interrupted = false;
    boolean withError = false;

    T object = null;
    try {
      realm.beginTransaction();
      object = get(realm);
      interrupted = thread.isInterrupted();
      if (object != null && !interrupted) {
        realm.commitTransaction();
      } else {
        realm.cancelTransaction();
      }
    } catch (RuntimeException e) {
      realm.cancelTransaction();
      subscriber.onError(new RealmException("Error during transaction.", e));
      withError = true;
    } catch (Error e) {
      realm.cancelTransaction();
      subscriber.onError(e);
      withError = true;
    }
    if (!interrupted && !withError) {
      subscriber.onNext(object);
    }

    try {
      realm.close();
    } catch (RealmException ex) {
      subscriber.onError(ex);
      withError = true;
    }
    thread = null;
    if (!withError) {
      subscriber.onCompleted();
    }
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
 public void removeWWishAsset(String assetId) {
   Realm realm = Realm.getInstance(mContext);
   realm.beginTransaction();
   RealmResults<WishObject> results =
       mRealm.where(WishObject.class).equalTo("sAssetId", assetId).findAll();
   if (results.size() > 0) {
     WishObject obj = results.get(0);
     obj.removeFromRealm();
   }
   realm.commitTransaction();
 }
Beispiel #21
0
  private void fillList() {

    Realm realm = Realm.getInstance(getActivity());

    noteList.clear();
    noteList.addAll(realm.where(Note.class).findAll());

    Collections.reverse(noteList);
    notesAdapter.notifyDataSetChanged();

    list.setAdapter(notesAdapter);
  }
Beispiel #22
0
  public static boolean isFavorite(Context context, MashableNewsItem newsItem) {

    Realm realm = Realm.getInstance(context);

    RealmResults<Favorites> result =
        realm.where(Favorites.class).equalTo("link", newsItem.link).findAll();
    if (result.size() > 0) {
      return true;
    } else {
      return false;
    }
  }
 public void removeAllWatchVod() {
   // Realm Database **********************************************************************
   // Obtain a Realm instance
   Realm realm = Realm.getInstance(mContext);
   realm.beginTransaction();
   RealmResults<WatchVodObject> results = mRealm.where(WatchVodObject.class).findAll();
   if (results.size() > 0) {
     results.clear();
   }
   realm.commitTransaction();
   // Realm Database **********************************************************************
 }
Beispiel #24
0
  public static void addFavorite(Context context, MashableNewsItem newsItem) {

    Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    Favorites favorite = realm.createObject(Favorites.class); // Create a new object
    favorite.setAuthor(newsItem.author);
    favorite.setImage(newsItem.image);
    favorite.setLink(newsItem.link);
    favorite.setTitle(newsItem.title);

    realm.commitTransaction();
  }
 @Override
 protected void onResume() {
   super.onResume();
   invalidateOptionsMenu();
   setUpMapIfNeeded();
   realm = Realm.getInstance(this);
   RealmQuery<OrgEvent> query = realm.where(OrgEvent.class);
   RealmResults<OrgEvent> result1 = query.findAll();
   if (result1.size() > 0) {
     // Toast.makeText(getApplicationContext(), result1.toString(),
     //      Toast.LENGTH_LONG).show();
   }
 }
 /** 선호채널 */
 public void addBookmarkChannel(String channelId, String channelNumber, String channelName) {
   // Realm Database **********************************************************************
   // Obtain a Realm instance
   Realm realm = Realm.getInstance(mContext);
   realm.beginTransaction();
   BookmarkChannelObject bm =
       realm.createObject(BookmarkChannelObject.class); // Create a new object
   bm.setsChannelId(channelId);
   bm.setsChannelNumber(channelNumber);
   bm.setsChannelName(channelName);
   realm.commitTransaction();
   // Realm Database **********************************************************************
 }
  public void addQuest(
      final int id, final int type, final String text, final String answer, final String other) {
    final Realm realm = Realm.getInstance(context);
    realm.beginTransaction();

    final QuestModel qm = realm.createObject(QuestModel.class);

    qm.setId(id);
    qm.setType(type);
    qm.setText(text);
    qm.setAnswer(answer);
    qm.setOther(other);

    realm.commitTransaction();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    realmSearchView = (RealmSearchView) findViewById(R.id.main_realmSearch);
    floatingActionButton = (FloatingActionButton) findViewById(R.id.main_floating_refresh);

    resetRealm();
    loadData();

    realm = Realm.getInstance(this);
    bRecyclerViewAdapter = new BRecyclerViewAdapter(this, realm, "title");
    realmSearchView.setAdapter(bRecyclerViewAdapter);
  }
  @Override
  public void call(final Subscriber<? super RealmResults<T>> subscriber) {
    final Realm realm =
        dbName != null ? Realm.getInstance(context, dbName) : Realm.getInstance(context);
    subscriber.add(
        Subscriptions.create(
            new Action0() {
              @Override
              public void call() {
                try {
                  realm.close();
                } catch (RealmException ex) {
                  subscriber.onError(ex);
                }
              }
            }));

    RealmResults<T> object;
    realm.beginTransaction();
    try {
      object = get(realm);
      realm.commitTransaction();
    } catch (RuntimeException e) {
      realm.cancelTransaction();
      subscriber.onError(new RealmException("Error during transaction.", e));
      return;
    } catch (Error e) {
      realm.cancelTransaction();
      subscriber.onError(e);
      return;
    }
    if (object != null) {
      subscriber.onNext(object);
    }
    subscriber.onCompleted();
  }
 public void removeCategory(String channelId) {
   // Realm Database **********************************************************************
   // Obtain a Realm instance
   Realm realm = Realm.getInstance(mContext);
   realm.beginTransaction();
   RealmResults<BookmarkChannelObject> results =
       mRealm.where(BookmarkChannelObject.class).equalTo("sChannelId", channelId).findAll();
   if (results.size() > 0) {
     BookmarkChannelObject obj = results.get(0);
     obj.removeFromRealm();
   } else {
     //
   }
   realm.commitTransaction();
   // Realm Database **********************************************************************
 }