Examples of TWithPreInsert


Examples of com.avaje.tests.model.basic.TWithPreInsert

  }

  @Override
  public boolean preInsert(BeanPersistRequest<?> request) {

    TWithPreInsert e = (TWithPreInsert) request.getBean();
    if (e.getName() == null) {
      e.setName("set on preInsert");
    }
    return true;
  }
View Full Code Here

Examples of com.avaje.tests.model.basic.TWithPreInsert

  }

  @Override
  public boolean preUpdate(BeanPersistRequest<?> request) {

    TWithPreInsert b = (TWithPreInsert) request.getBean();
    System.out.println("preUpdate - title is: " + b.getTitle());
    if (b.getTitle() == null) {
      b.setTitle("set on preUpdate");
    }
    // request.getEbeanServer().refresh(b);
    // System.out.println("title is Mister:"+b.getTitle());

    return super.preUpdate(request);
View Full Code Here

Examples of com.avaje.tests.model.basic.TWithPreInsert

    final Object myUserObject = new Object();

    Transaction tx = Ebean.beginTransaction();
    tx.putUserObject("myUserObject", myUserObject);

    TWithPreInsert e = new TWithPreInsert();
    e.setTitle("Mister Transaction1");
    Ebean.save(e);

    tx.commit();

    assertNotNull(MyTestTransactionEventListener.getLastCommitted());
    assertSame(MyTestTransactionEventListener.getLastCommitted(), tx);
    assertNotNull(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"));
    assertSame(MyTestTransactionEventListener.getLastCommitted().getUserObject("myUserObject"), myUserObject);
    assertNull(MyTestTransactionEventListener.getLastRollbacked());

    Transaction tx2 = Ebean.beginTransaction();
    tx2.putUserObject("myUserObject2", myUserObject);

    TWithPreInsert e2 = new TWithPreInsert();
    e2.setTitle("Mister Transaction2");
    Ebean.save(e2);

    tx2.rollback();

    assertNotNull(MyTestTransactionEventListener.getLastCommitted());
View Full Code Here

Examples of com.avaje.tests.model.basic.TWithPreInsert

public class TestPreInsertValidation extends BaseTestCase {

  @Test
  public void test() {
   
    TWithPreInsert e = new TWithPreInsert();
    e.setTitle("Mister");
    // the perInsert should populate the
    // name with should not be null
    Ebean.save(e);
   
    // the save worked and name set in preInsert
    Assert.assertNotNull(e.getId());
    Assert.assertNotNull(e.getName());
   
    TWithPreInsert e1 = Ebean.find(TWithPreInsert.class, e.getId());
   
    e1.setTitle("Missus");
    Ebean.save(e1);
  }
View Full Code Here

Examples of com.avaje.tests.model.basic.TWithPreInsert

  }
 
  @Test
  public void testStatelessUpdate() {
   
    TWithPreInsert e = new TWithPreInsert();
    e.setName("BeanForUpdateTest");
    Ebean.save(e);
   
    TWithPreInsert bean2 = new TWithPreInsert();
    bean2.setId(e.getId());
    bean2.setName("stateless-update-name");
    bean2.setTitle(null);
   
    Ebean.update(bean2);
   
    // title set on preUpdate
    Assert.assertNotNull(bean2.getTitle());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.