@Override
  public Navigation run() throws Exception {

    Validators v = new Validators(request);
    v.add("id", v.longType());
    v.add("salary", v.required(), v.integerType());
    if (!v.validate()) {
      System.out.println("validation error: " + errors);
      return null;
    }

    long id = asLong("id");
    int salary = asInteger("salary");

    Key key = Datastore.createKey(Employee.class, id);
    Transaction tx = Datastore.beginTransaction();
    try {
      Employee e = Datastore.get(tx, Employee.class, key);
      e.setSalary(salary);
      Datastore.put(tx, e);
      tx.commit();
    } finally {
      if (tx.isActive()) {
        tx.rollback();
      }
    }

    return forward("updateSalary.jsp");
  }
Ejemplo n.º 2
0
  public static void putDisplayName(String displayName) throws JEDuplicateException {
    final String UNIQUE_KEY_DISPLAY_NAME = "UniqueKeyDisplayName";
    final User user = getUser();
    final Key key = Datastore.createKey(JEUser.class, user.getEmail());
    if (Datastore.putUniqueValue(UNIQUE_KEY_DISPLAY_NAME, displayName) == false) {
      throw new JEDuplicateException("the display name is already used");
    }
    Transaction tx = Datastore.beginTransaction();
    try {
      JEUser jeUser = Datastore.getOrNull(tx, JEUser.class, key);
      final long now = new Date().getTime();
      if (jeUser == null) {
        jeUser = new JEUser();
        jeUser.setKey(key);
        jeUser.setCreatedAt(now);
      }
      jeUser.setDisplayName(displayName);
      jeUser.setUpdatedAt(now);
      Datastore.put(tx, jeUser);

      // TODO: Run TQ to update past's memos.

      Datastore.commit(tx);

    } catch (Exception e) {
      Datastore.rollback(tx);
      Datastore.deleteUniqueValue(UNIQUE_KEY_DISPLAY_NAME, displayName);
    }
  }
Ejemplo n.º 3
0
 /**
  * スコアの登録.
  *
  * @param input スコア情報
  */
 public void register(Map<String, Object> input) {
   Score score = new Score();
   BeanUtil.copy(input, score);
   Transaction tx = Datastore.beginTransaction();
   Datastore.put(score);
   tx.commit();
 }
 /**
  * Adds an Event todo in the Datastore
  *
  * @param et the event todo added
  * @return whether transaction is successful
  */
 public boolean addEventTodo(EventTodoModel et) {
   boolean ok = false;
   if (getEventTodoModelByTodoId(et.getEventID(), et.getTodoId()) == null) {
     Key key = Datastore.allocateId(parentKey, "EventTodoModel");
     Transaction trans = Datastore.beginTransaction();
     et.setKey(key);
     et.setId(key.getId());
     Datastore.put(et);
     trans.commit();
     ok = true;
   }
   return ok;
 }
Ejemplo n.º 5
0
  @Override
  protected Map<String, Object> handle() throws Exception {
    Map<String, Object> result = new HashMap<String, Object>();
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String category = request.getParameter("category");

    Joshi joshi = service.findJoshi(id);
    if (joshi != null) {
      Transaction tx = Datastore.beginTransaction();
      if (!Utils.isNull(name)) {
        joshi.setName(name);
      }
      if (!Utils.isNull(category)) {
        joshi.setCategory(category);
      }
      Datastore.put(joshi);
      tx.commit();
    } else {
      Transaction tx = Datastore.beginTransaction();
      joshi = new Joshi();
      Key key = Datastore.createKey(Joshi.class, id);
      joshi.setKey(key);
      joshi.setKawaii(0);
      if (!Utils.isNull(name)) {
        joshi.setName(name);
      }
      if (!Utils.isNull(category)) {
        joshi.setCategory(category);
      }
      Datastore.put(joshi);
      tx.commit();
    }

    result.put("result", "true");
    return result;
  }
  /**
   * Removes an Event todo in the the Datastore
   *
   * @param key the key of the event to be removed
   * @return whether the transaction is successful
   */
  public boolean removeEventTodo(EventTodoModel et) {
    boolean ok = true;

    try {
      EventTodoModel etm = getEventTodoModelById(et.getId());
      if (etm != null) {
        Transaction trans = Datastore.beginTransaction();
        Datastore.delete(etm.getKey());
        trans.commit();
      }
    } catch (Exception e) {
      ok = false;
    }

    return ok;
  }
Ejemplo n.º 7
0
  /*
   * (non-Javadoc)
   *
   * @see yanitime4u.yanitime.logic.UserLogic#delete(com.google.appengine.api.datastore.Key,
   * java.lang.Long)
   */
  @Override
  public void delete(Key key, Long version) {
    AssertionUtil.assertNotNull(key);
    AssertionUtil.assertNotNull(version);

    Transaction tx = Datastore.beginTransaction();
    try {
      Users latest = Datastore.get(meta, key, version);
      Datastore.delete(latest.getKey());
      tx.commit();
    } catch (ConcurrentModificationException e) {
      if (tx.isActive()) {
        tx.rollback();
      }
      throw e;
    }
  }
Ejemplo n.º 8
0
 /*
  * (non-Javadoc)
  *
  * @see yanitime4u.yanitime.logic.UserLogic#create(yanitime4u.yanitime.model.Users)
  */
 @Override
 public Users create(Users users) {
   AssertionUtil.assertNotNull(users);
   Transaction tx = Datastore.beginTransaction();
   try {
     Users register = new Users();
     BeanUtil.copy(users, register);
     Datastore.put(register);
     tx.commit();
     return register;
   } catch (ConcurrentModificationException e) {
     if (tx.isActive()) {
       tx.rollback();
     }
     throw e;
   }
 }
Ejemplo n.º 9
0
  /*
   * (non-Javadoc)
   *
   * @see yanitime4u.yanitime.logic.UserLogic#update(com.google.appengine.api.datastore.Key,
   * java.lang.Long, java.util.Map)
   */
  @Override
  public Users update(Key key, Long version, Map<String, Object> input) {
    AssertionUtil.assertNotNull(key);
    AssertionUtil.assertNotNull(version);
    AssertionUtil.assertNotNull(input);

    Transaction tx = Datastore.beginTransaction();
    try {
      Users latest = Datastore.get(meta, key, version);
      BeanUtil.copy(input, latest);
      Datastore.put(tx, latest);
      tx.commit();
      return latest;
    } catch (ConcurrentModificationException e) {
      if (tx.isActive()) {
        tx.rollback();
      }
      throw e;
    }
  }
  /**
   * Updates an Event todo in the Datastore
   *
   * @param et the Event todo to be updated
   * @return whether the transaction is successful
   */
  public boolean updateEventTodo(EventTodoModel et) {
    boolean ok = true;

    try {
      EventTodoModel etm = getEventTodoModelById(et.getId());

      if (etm != null) {
        Transaction trans = Datastore.beginTransaction();
        etm.setEventTitle(et.getEventTitle());
        etm.setTodoDescription(et.getTodoDescription());
        etm.setTodoFinished_quantity(et.getTodoFinished_quantity());
        etm.setTodoTitle(et.getTodoTitle());
        Datastore.put(etm);
        trans.commit();
      }
    } catch (Exception e) {
      ok = false;
    }
    return ok;
  }
Ejemplo n.º 11
0
 public void deleteProductSpecialOffer(Key key) {
   Transaction tx = Datastore.beginTransaction();
   Datastore.delete(tx, key);
   tx.commit();
 }