/** Function to be called before delete */
  private void onPreDelete() {
    List<Association> associations = AssociationFinder.findAssociations(this.getClass());
    for (Association assoc : associations) {

      // Ignore if the class has the ignore on the field
      if (assoc.clazz.getAnnotation(CascadeIgnore.class) == null
          && assoc.field.getAnnotation(CascadeIgnore.class) == null) {

        List<? extends Model> childModels =
            Ebean.createQuery(assoc.clazz)
                .where()
                .eq(assoc.field.getName() + ".id", getId())
                .findList();
        for (Model child : childModels) {
          // If it is required, delete it, otherwise set it to null
          if (assoc.required) {
            child.delete();
          } else {
            try {
              assoc.field.set(child, null);
              Set<String> set = new HashSet<String>();
              set.add(assoc.field.getName());
              Ebean.update(child, set);
            } catch (IllegalAccessException e) {
              e
                  .printStackTrace(); // To change body of catch statement use File | Settings |
                                      // File Templates.
            }
          }
        }
      }
    }
  }
Beispiel #2
0
 public static Result save() {
   Form<FastSubject> fastSubjectForm = Form.form(FastSubject.class).bindFromRequest();
   FastSubject fastSubject = fastSubjectForm.get();
   if (fastSubject.id == null) Ebean.save(fastSubject);
   else Ebean.update(fastSubject);
   FlashMessage.updateSuccess.send();
   return redirect(routes.FastSubjects.edit(fastSubject.id));
 }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    log("new received ack message");

    // start connection if it did not
    DB.instance().connectToDB();

    // read sessionId
    String sessionId = request.getParameter("sessionId");

    // find user with this sessionId
    List<ChatUser> chatUsers =
        Ebean.find(ChatUser.class).where().eq("sessionId", sessionId).findList();

    // define the response message
    String responseMessage = "{}";

    // this user has a sessionId
    if (chatUsers.size() == 1) {

      // current chat user
      ChatUser chatUser = chatUsers.get(0);

      log("found user for this sessionId, chatUser: "******"messageId");

      List<ChatMessage> chatMessages =
          Ebean.find(ChatMessage.class).where().eq("messageId", messageId).findList();
      if (chatMessages.size() == 1) {
        ChatMessage chatMessage = chatMessages.get(0);
        log("received message found, chatMessage: " + chatMessage);
        // update the status to message's last status, this message is send, received and
        // acknowledged, notified and acknowledged
        chatMessage.setStatus(ChatMessage.SOURCE_SAID_IT_KNOWS_THIS_MESSAGE_IS_DELIVERED);
        Ebean.update(chatMessage);
        log("received message updated, chatMessage: " + chatMessage);
      }
      responseMessage = "{\"status\":\"acknowledged\", \"messageId\":\"" + messageId + "\"}";
    }

    // send response
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    out.print(responseMessage);
    out.flush();
    out.close();

    log("done");
  }
  @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());
  }
  @AccessLevel(level = 2)
  public Result update() {
    Form<ShakeRecord> shakeForm = Form.form(ShakeRecord.class).bindFromRequest();

    if (shakeForm.hasErrors()) {
      return status(ErrDefinition.E_SHAKE_RECORD_FORM_ERROR, Messages.get("shakerecord.failure"));
    }

    try {
      ShakeRecord shakeRecord = shakeForm.get();

      shakeRecord.shop = Shop.find.byId(shakeRecord.shop_id);
      shakeRecord.account = Account.find.byId(shakeRecord.user_id);

      Ebean.update(shakeRecord);

      return ok(Json.toJson(shakeRecord));
    } catch (Throwable e) {
      return status(ErrDefinition.E_SHAKE_RECORD_UPDATE_ERROR, Messages.get("shakerecord.failure"));
    }
  }
  @AccessLevel(level = 2)
  public Result update() {
    Form<ActivityChoice> choiceForm = Form.form(ActivityChoice.class).bindFromRequest();

    if (choiceForm.hasErrors()) {
      return status(
          ErrDefinition.E_ACTIVITY_CHOICE_FORM_HASERROR, Messages.get("activitychoice.failure"));
    }

    try {
      ActivityChoice choice = choiceForm.get();

      choice.content = new ActivityContent();
      choice.content.id = choice.id;

      Ebean.update(choice);

      return ok(Json.toJson(choice));
    } catch (Throwable e) {
      return status(
          ErrDefinition.E_ACTIVITY_CHOICE_UPDATE_FAILED, Messages.get("activitychoice.failure"));
    }
  }