Esempio n. 1
0
 @Transactional
 public static boolean revokeAccount(String email) {
   if (((List) OrderTire.findByUserAndNotInInitiated(email)).size() == 0) {
     Ebean.delete(OrderTire.findByUser(email));
     Ebean.delete(User.findByEmail(email));
     return true;
   } else {
     return false;
   }
 }
  @Test
  public void testInsert() {

    SomePeriodBean bean = new SomePeriodBean();
    bean.setPeriod(Period.of(3, 4, 5));
    bean.setAnniversary(MonthDay.of(4, 29));
    Ebean.save(bean);

    SomePeriodBean bean1 = Ebean.find(SomePeriodBean.class, bean.getId());
    assertEquals(bean.getPeriod(), bean1.getPeriod());
    assertEquals(bean.getAnniversary(), bean1.getAnniversary());

    // insert fetch null value
    SomePeriodBean bean2 = new SomePeriodBean();
    Ebean.save(bean2);

    SomePeriodBean bean3 = Ebean.find(SomePeriodBean.class, bean2.getId());
    assertNull(bean3.getPeriod());
    assertNull(bean3.getAnniversary());

    List<SomePeriodBean> anniversaryList =
        Ebean.find(SomePeriodBean.class)
            .where()
            .eq("anniversary", MonthDay.of(4, 29))
            .eq("period_years", 3)
            .eq("period_months", 4)
            .findList();

    assertEquals(1, anniversaryList.size());

    // must use year 2000 for range predicates
    // ... using 2001 here so not finding anything
    anniversaryList =
        Ebean.find(SomePeriodBean.class)
            .where()
            .gt("anniversary", Date.valueOf(LocalDate.of(2001, 4, 29)))
            .findList();

    assertEquals(0, anniversaryList.size());

    // can use year 2000 for range predicates
    // ... and can use LocalDate to bind
    anniversaryList =
        Ebean.find(SomePeriodBean.class)
            .where()
            .gt("anniversary", LocalDate.of(2000, 4, 22))
            .findList();

    assertEquals(1, anniversaryList.size());

    Ebean.delete(bean);
    Ebean.delete(bean2);
  }
Esempio n. 3
0
 @AccessLevel(level = 2)
 public Result delete(String id) {
   try {
     Ebean.delete(ShakeRecord.class, id);
     return ok();
   } catch (Throwable e) {
     return status(ErrDefinition.E_SHAKE_RECORD_DELETE_ERROR, Messages.get("shakerecord.failure"));
   }
 }
  @Test
  public void test_deleteCascading() {

    Permission p1 = new Permission("p1");
    Permission p2 = new Permission("p2");
    Ebean.save(p1);
    Ebean.save(p2);

    Role role1 = new Role("role");

    Set<Permission> permissions = new HashSet<Permission>();
    permissions.add(p2);
    role1.setPermissions(permissions);
    Ebean.save(role1);

    // only deletes as not associated
    Ebean.delete(p1);
    // delete cascades
    Ebean.delete(role1);
  }
  @AccessLevel(level = 2)
  public Result delete(String id) {
    try {
      Ebean.delete(ActivityChoice.class, id);
    } catch (Throwable e) {
      return status(
          ErrDefinition.E_ACTIVITY_CHOICE_DELETE_FAILED, Messages.get("activitychoice.failure"));
    }

    return ok();
  }
  @Test
  public void test() {

    Ebean.createUpdate(Permission.class, "delete from Permission").execute();
    Ebean.createUpdate(Tenant.class, "delete from Tenant").execute();
    Ebean.createUpdate(Role.class, "delete from Role").execute();

    Tenant t = new Tenant("tenant");

    Ebean.save(t);

    Permission p1 = new Permission("p1");
    Permission p2 = new Permission("p2");

    Ebean.save(p1);
    Ebean.save(p2);

    Role role1 = new Role("role");
    role1.setTenant(t);

    Set<Permission> permissions = new HashSet<Permission>();
    List<Permission> permsList = Ebean.find(Permission.class).findList();
    permissions.addAll(permsList);

    role1.setPermissions(permissions);

    Ebean.save(role1);

    List<Tenant> tenantList = Ebean.find(Tenant.class).fetch("roles").findList();
    List<Role> roleList = Ebean.find(Role.class).fetch("permissions").findList();
    List<Permission> permissionList = Ebean.find(Permission.class).fetch("roles").findList();

    Assert.assertEquals(1, tenantList.size());
    Assert.assertEquals(2, permissionList.size());
    Assert.assertEquals(1, roleList.size());

    Ebean.delete(role1);

    List<Tenant> tenantList2 = Ebean.find(Tenant.class).fetch("roles").findList();
    List<Role> roleList2 = Ebean.find(Role.class).fetch("permissions").findList();
    List<Permission> permissionList2 = Ebean.find(Permission.class).fetch("roles").findList();

    Assert.assertEquals(0, roleList2.size());
    Assert.assertEquals(1, tenantList2.size());
    Assert.assertEquals(2, permissionList2.size());
  }
  @Test
  public void test() {

    PFile persistentFile = new PFile("test.txt", new PFileContent("test".getBytes()));

    Ebean.save(persistentFile);
    Integer id = persistentFile.getId();
    Integer contentId = persistentFile.getFileContent().getId();

    PFile partialPfile =
        Ebean.find(PFile.class).select("id").where().idEq(persistentFile.getId()).findUnique();

    // should delete file and fileContent
    Ebean.delete(partialPfile);
    System.out.println("finished delete");

    PFile file1 = Ebean.find(PFile.class, id);
    PFileContent content1 = Ebean.find(PFileContent.class, contentId);

    Assert.assertNull(file1);
    Assert.assertNull(content1);
  }
Esempio n. 8
0
 /**
  * 删除图片
  *
  * @param img_code
  */
 public static void deleteImage(String img_code) {
   // TODO 删除图片文件
   Ebean.delete(find.where().eq("img_code", img_code).findList());
 }
Esempio n. 9
0
 @After
 public void afterEachTest() {
   Ebean.delete(fixturesToUnload());
 }
Esempio n. 10
0
 public static Result delete(Long id) {
   FastSubject fastSubject = FastSubject.find.byId(id);
   Ebean.delete(fastSubject);
   FlashMessage.updateSuccess.send();
   return redirect(routes.FastSubjects.list(0, "name", "asc", ""));
 }