예제 #1
0
  public Email parse(final Map<String, String> keyVals) {
    if (_parsed) {
      return _email;
    }

    _email = new Email();

    if (null == keyVals) {
      return _email;
    }

    keyVals.putAll(parseScript(keyVals));

    Iterator<String> i = keyVals.keySet().iterator();
    while (i.hasNext()) {
      String key = i.next();
      String token = "@" + key + "@";
      String val = keyVals.get(key);
      val = Matcher.quoteReplacement(val);

      _addressee = _addressee.replaceAll(token, val);
      _subject = _subject.replaceAll(token, val);
      _template = _template.replaceAll(token, val);
    }

    _email.setSubject(_subject);

    _email.setTo(_addressee.split(","));
    _email.setBody(_template);

    _parsed = true;

    return _email;
  }
예제 #2
0
  public void testTransactional() throws Exception {
    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();
    final int loop = 4;
    for (int i = 0; i < loop; i++) {
      Email email = new Email();
      email.setId((long) i + 1);
      email.setTitle("JBoss World Berlin");
      email.setBody("Meet the guys who wrote the software");
      s.persist(email);
    }
    tx.commit();
    s.close();

    // check non created object does get found!!1
    s = Search.getFullTextSession(openSession());
    tx = s.beginTransaction();
    QueryParser parser =
        new QueryParser(TestConstants.getTargetLuceneVersion(), "id", TestConstants.stopAnalyzer);
    List result = s.createFullTextQuery(parser.parse("body:create")).list();
    assertEquals(0, result.size());
    tx.commit();
    s.close();

    s = Search.getFullTextSession(openSession());
    s.getTransaction().begin();
    s.doWork(
        new Work() {
          @Override
          public void execute(Connection connection) throws SQLException {
            Statement stmt = connection.createStatement();
            stmt.executeUpdate("update Email set body='Meet the guys who write the software'");
            stmt.close();
          }
        });
    s.doWork(
        new Work() {
          @Override
          public void execute(Connection connection) throws SQLException {
            // insert an object never indexed
            Statement stmt = connection.createStatement();
            stmt.executeUpdate(
                "insert into Email(id, title, body, header) values( + "
                    + (loop + 1)
                    + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')");
            stmt.close();
          }
        });

    s.getTransaction().commit();
    s.close();

    s = Search.getFullTextSession(openSession());
    tx = s.beginTransaction();
    parser =
        new QueryParser(TestConstants.getTargetLuceneVersion(), "id", TestConstants.stopAnalyzer);
    result = s.createFullTextQuery(parser.parse("body:write")).list();
    assertEquals(0, result.size());
    result = s.createCriteria(Email.class).list();
    for (int i = 0; i < loop / 2; i++) {
      s.index(result.get(i));
    }
    tx.commit(); // do the process
    s.index(result.get(loop / 2)); // do the process out of tx
    tx = s.beginTransaction();
    for (int i = loop / 2 + 1; i < loop; i++) {
      s.index(result.get(i));
    }
    tx.commit(); // do the process
    s.close();

    s = Search.getFullTextSession(openSession());
    tx = s.beginTransaction();
    // object never indexed
    Email email = (Email) s.get(Email.class, Long.valueOf(loop + 1));
    s.index(email);
    tx.commit();
    s.close();

    // check non indexed object get indexed by s.index
    s = Search.getFullTextSession(openSession());
    tx = s.beginTransaction();
    result = s.createFullTextQuery(parser.parse("body:create")).list();
    assertEquals(1, result.size());
    tx.commit();
    s.close();
  }