Example #1
0
 /**
  * Save words into database. This words should be loaded from database before (should contain id).
  */
 public void updateWords(Word word1, Word word2) {
   if (word1.getId() != -1) {
     dataBaseManager.update(dao.setPersistable(word1));
   }
   if (word2.getId() != -1) {
     dataBaseManager.update(dao.setPersistable(word2));
   }
 }
Example #2
0
  /**
   * Save new words into database. Words should contain different language. Link will be created and
   * saved into database and cache.
   */
  public void addWords(Word word1, Word word2) {
    Link link = new Link();
    Dao<Link> linkDao = DaoFactory.createDao(Link.class);

    link.setWord(dataBaseManager.insert(dao.setPersistable(word1)));
    link.setWord(dataBaseManager.insert(dao.setPersistable(word2)));
    link = dataBaseManager.insert(linkDao.setPersistable(link));

    links.add(link);
  }
Example #3
0
  /**
   * Remove link and words from cache and database.
   *
   * @param link link to be removed from cache and database
   * @param word1 word to be removed from database
   * @param word2 word to be removed from database
   */
  public void removeWords(Link link, Word word1, Word word2) {
    links.remove(link);

    Dao<Link> linkDao = DaoFactory.createDao(Link.class);
    Dao<Word> wordDao = DaoFactory.createDao(Word.class);

    dataBaseManager.delete(linkDao.setPersistable(link));
    dataBaseManager.delete(wordDao.setPersistable(word1));
    dataBaseManager.delete(wordDao.setPersistable(word2));
  }
Example #4
0
 /**
  * Save link into database. This link should be loaded from database before (should contain id).
  */
 public void updateLink(Link link) {
   Dao<Link> linkDao = DaoFactory.createDao(Link.class);
   dataBaseManager.update(linkDao.setPersistable(link));
 }
Example #5
0
 private Word loadWord(Link link, Language language) {
   Word target = new Word();
   target.setId(link.getWordId(language));
   target.setLanguage(language);
   return dataBaseManager.retrieve(dao.setPersistable(target));
 }