Exemplo n.º 1
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));
  }
Exemplo n.º 2
0
  /** Load links from database and cache them. Sort by priority. */
  private void loadLinks() {
    links = new LinkedList<Link>();
    Dao<Link> linkDao = DaoFactory.createDao(Link.class);
    Iterator<Link> it = dataBaseManager.retrieveIterator(linkDao);

    while (it.hasNext()) links.add(it.next());

    Collections.sort(links, new PrioritySorter());
  }
Exemplo n.º 3
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);
  }
Exemplo n.º 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));
 }
Exemplo n.º 5
0
 /**
  * Create data source.
  *
  * @param language default language. Used in methods {@link
  *     #loadOriginalWord(dmax.plua.domain.Link)} and {@link
  *     #loadTranslationWord(dmax.plua.domain.Link)}
  */
 public DataSource(DataBaseManager dataBaseManager, Language language) {
   this.dataBaseManager = dataBaseManager;
   this.language = language;
   this.dao = DaoFactory.createDao(Word.class);
 }