/** * スコアの登録. * * @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(); }
@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"); }
@DELETE @Path("{id}") @Consumes({MediaType.APPLICATION_JSON}) public void delete(@PathParam("id") Long id) { log.info("delete:" + id); Datastore.delete(Datastore.createKey(ShopModel.class, id)); }
public static String getDisplayName() { final User user = getUser(); if (user == null) { return null; } Key key = Datastore.createKey(JEUser.class, user.getEmail()); JEUser jeUser = Datastore.getOrNull(JEUser.class, key); return (jeUser == null) ? null : jeUser.getDisplayName(); }
/** * Send the Cared Person current Plan as XML. The method receciedCaredPersonStatus and this method * will be a synchronous call. Logic : * * <p>1. ReCalc the Rx State and send the updated Rx Snapshot to CaredPerson 2. Assess the * CaredPerson health status a. Alert CareGiver b. Alert Physician c. Send a message to * CaredPerson - something how they are doing on their progress. */ public StringBuffer sendCaredPersonCurrentRxPlan(Long caredPersonKey) throws Exception { ICareDAO _careDAO = getCareDAO(); Key _key = Datastore.createKey(CaredPerson.class, caredPersonKey); CaredPerson _caredPerson = _careDAO.loadCaredPerson(_key); IPrescriptionDAO _iRxDAO = getPrescriptionDAO(); List<Prescription> _prescriptionList = _iRxDAO.loadPrescriptionsByCaredPerson(_caredPerson.getKey()); ArrayList<Prescription> _updPrescriptionList = new ArrayList<Prescription>(); for (Iterator<Prescription> iterator = _prescriptionList.iterator(); iterator.hasNext(); ) { Prescription _prescriptionIn = (Prescription) iterator.next(); // Expire the Rx Lines before use _iRxDAO.expireRxLines(_prescriptionIn.getKey()); List<PrescriptionLines> _rxLines = _iRxDAO.loadPrescriptionLines(_prescriptionIn.getKey(), false); _prescriptionIn.setPrescriptionLines(_rxLines); _updPrescriptionList.add(_prescriptionIn); iterator.remove(); } _caredPerson.setPrescription(_updPrescriptionList); /** * Temp fix to show only default symptoms List<PreExistingCondition> _preExCondList = _careDAO * .loadAllPreExistingConditonsForCaredPerson(_caredPerson .getKey()); */ // @todo Temp fix start : Hard coded to show only default predcondition CommonPreExistingDiseases _defaultCommonDisease = _careDAO.loadDefaultCommonPreExistingDisease(); PreExistingCondition _preExCond = new PreExistingCondition(); // All the default condition to have a hard key of 999999 // It is not store in the database Key _preconditionkey = Datastore.createKey(PreExistingCondition.class, new Long(999999)); _preExCond.setKey(_preconditionkey); _preExCond.getPreExisitingDiseases().setModel(_defaultCommonDisease); _preExCond.getCaredPerson().setModel(_caredPerson); ArrayList<PreExistingCondition> _preExCondList = new ArrayList<PreExistingCondition>(); _preExCondList.add(_preExCond); // @todo Temp Fix End _caredPerson.setPreExistingCondition(_preExCondList); EmergencyResponse _emResponse = _careDAO.loadEmergemcyResponseForCaredPerson(_caredPerson.getKey()); _caredPerson.setEmergencyResponse(_emResponse); StringBuffer _xml = MobileDataExchangeHelper.fillCaredPersonData(_caredPerson); return _xml; }
@PUT @Path("{id}") @Consumes({MediaType.APPLICATION_JSON}) public void update(@PathParam("id") Long id, Shop shop) { log.info("put:" + id + " " + shop.getName()); Key key = Datastore.createKey(ShopModel.class, id); ShopModel shopModel = Datastore.get(ShopModel.class, key); shopModel.setName(shop.getName()); Datastore.put(shopModel); }
@GET @Path("{id}") @Produces("application/x-javascript") public JSONWithPadding get( @PathParam("id") Long id, @QueryParam("jsoncallback") @DefaultValue("fn") String callback) { log.info("get:" + id); Key key = Datastore.createKey(ShopModel.class, id); ShopModel shopModel = Datastore.get(ShopModel.class, key); Shop shop = new Shop(shopModel); return new JSONWithPadding(shop, callback); }
@Override public Navigation run() throws Exception { Employee employee = new Employee(); employee.setKey(Datastore.createKey(Employee.class, 9999)); employee.setName("ŽÐ’{Žl˜Y"); employee.setDeptId(1L); Key key = Datastore.put(employee); requestScope("key", key); return forward("create2.jsp"); }
/** * 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; }
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); } }
public CommentaryLog commentaryLog(Key gameKey, String commentary) { CommentaryLog cl = new CommentaryLog(); cl.setKey(Datastore.allocateId(CommentaryLog.class)); cl.setGameKey(gameKey); cl.setCommentary(commentary); cl.setDate(new Date()); GlobalTransaction tx = Datastore.beginGlobalTransaction(); tx.put(cl); tx.commit(); return null; }
public List<GameData> newGame() { return Datastore.query(GameData.class) .filter(GameDataMeta.get().accessLevel.equal(PUBLIC_GAME)) .sort(GameDataMeta.get().date.desc) .limit(5) .asList(); }
/** @inheritDoc */ @Override public List<AddressEntry> findAllAddressesForContact(String contactId) { return Datastore.query(AddressEntry.META) .filter(AddressEntry.META.identifier.equal(contactId)) .asList(); }
/** * 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; }
@Override public Navigation run() throws Exception { Integer id = asInteger("id"); if (id != null) { Key key = Datastore.createKey(PrizeRule.class, id); GlobalTransaction tx = Datastore.beginGlobalTransaction(); Datastore.delete(key); tx.commit(); } else { return redirect("prizeRules"); } return redirect("prizeRules"); }
/** @inheritDoc */ @Override public List<ContactEntry> findAllContacts() { return Datastore.query(ContactEntry.CONTACT) .sort(ContactEntry.CONTACT.name.asc) .limit(250) .asList(); }
/** * ユーザーリスト * * @return */ public SitePage getByName(User user, String name) { return Datastore.query(meta) .filter( meta.userRef.equal(user.getKey()), meta.name.equal(name), meta.template.equal(user.getTemplate())) .asSingle(); }
/** * インデックスページの取得 * * @return */ public SitePage getIndexPage(User user) { return Datastore.query(meta) .filter( meta.userRef.equal(user.getKey()), meta.template.equal(user.getTemplate()), meta.role.equal("index")) .asSingle(); }
/* * (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; } }
/* * (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; } }
/** * ユーザーリスト * * @return */ public List<SitePage> getList(User user) { return Datastore.query(meta) .filter( meta.userRef.equal(user.getKey()), meta.template.equal(user.getTemplate()), meta.published.equal(true)) .sort(meta.sortOrder.asc, meta.createDate.asc) .asList(); }
/** @inheritDoc */ @Override public List<AddressEntry> findAllAddressesInCityForContact(String name, String city) { return Datastore.query(AddressEntry.META) .filterInMemory(AddressEntry.META.name.contains(name)) .filterInMemory(AddressEntry.META.city.contains(city)) .limit(250) .asList(); }
@Override public void setUp() throws Exception { super.setUp(); account = new Account(); account.setKey(Datastore.createKey(Account.class, 1)); Datastore.put(account); discussions = new ArrayList<Submission>(); for (int i = 0; i < 10; i++) { Submission submission = new Submission(); submission.setTitle("title" + i); submission.setDescription("description" + i); submission.setAuthor(Datastore.createKey(Account.class, i + 1)); submission.setAuthorName("author" + i); discussions.add(submission); } Datastore.put(discussions); }
public EventTodoModel getEventTodoModelByTodoId(long eventId, long id) { EventTodoModelMeta meta = new EventTodoModelMeta(); EventTodoModel etm = (EventTodoModel) Datastore.query(meta) .filter("todoId", FilterOperator.EQUAL, id) .filter("eventID", FilterOperator.EQUAL, eventId) .asSingle(); return etm; }
@Test public void testSearchFromKey() throws Exception { Member m = memberSvc.searchFromId("test1"); Practice p = practiceSvc.searchFromStartDateTime( DateUtil.toDate("2010-10-01T10:00:00", DateUtil.ISO_DATE_TIME_PATTERN)); assertNotNull(service.searchFromKey(service.generateKey(m.getKey(), p.getKey()))); assertNull(service.searchFromKey(Datastore.createKey(Attendance.class, "XXX"))); assertNull(service.searchFromKey(null)); }
@POST @Consumes({MediaType.APPLICATION_JSON}) public Shop createShop(Shop shop) { log.info("post:" + shop.getName()); ShopModel shopModel = new ShopModel(); shopModel.setConversionRatio(shop.getConversionRatio()); shopModel.setName(shop.getName()); Datastore.put(shopModel); return shop; }
/** * 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; }
/** * 指定したuserModelとContentModel両方にマッチするリストを取得 * * @param userModel * @param contentModel * @return */ public List<TransmitHistoryModel> getListByUserAndCountent( UserModel userModel, ContentModel contentModel) { ModelRefAttributeMeta<TransmitHistoryModel, ModelRef<UserModel>, UserModel> userRefMeta = meta.userModelRef; ModelRefAttributeMeta<TransmitHistoryModel, ModelRef<ContentModel>, ContentModel> contentRefMeta = meta.contentModelRef; return Datastore.query(meta) .filter(userRefMeta.equal(userModel.getKey()), contentRefMeta.equal(contentModel.getKey())) .asList(); }
/* * (non-Javadoc) * * @see * yanitime4u.yanitime.logic.UserLogic#findByCondition(yanitime4u.yanitime.condition.UserCondition * ) */ @Override public List<Users> findByCondition(UserCondition condition) { AssertionUtil.assertNotNull(condition); ModelQuery<Users> query = Datastore.query(meta); FilterCriterion[] filters = createFilterByCondition(condition); if (filters.length > 0) { query = query.filter(filters); } return query.asList(); }
/* * (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; } }