@Test public void testExceptionsinBatchLifeCycleMethods() { LifeCycle lc0 = new LifeCycle(); lc0.foo = "bar"; lc0.bar = "order"; lc0.save(); LifeCycle lc1 = new LifeCycle(); lc1.foo = "foo"; lc1.bar = "order"; lc1.save(); MorphiaQuery q = LifeCycle.q("bar", "order"); LifeCycle.batchDeleteFail = true; try { q.delete(); } catch (Exception e) { // ignore } assertEquals(q.count(), 2); LifeCycle.batchDeleteFail = false; LifeCycle.batchDeletedFail = true; try { q.delete(); assertFalse(true); } catch (Exception e) { // ignore } assertEquals(q.count(), 0); LifeCycle.batchDeletedFail = false; }
static void onBatchLifeCycleEvent(MorphiaEvent event, MorphiaQuery query) { Class<? extends Model> c = query.getEntityClass(); List<IMorphiaEventHandler> l = modelEventHandlers_.get(c); if (null != l) { for (IMorphiaEventHandler h : l) { event.invokeOn(h, query); } } for (IMorphiaEventHandler h : globalEventHandlers_) { event.invokeOn(h, query); } }
public User getByName(String username) { MorphiaQuery query = filter("name", username); return query.first(); }
public static List<User> find( Long id, String name, String screenName, Long uid, String accessToken, int begin, int max) { if (max <= 0) { max = 50; } if (begin <= 1) { begin = 1; } MorphiaQuery query = createQuery(); query.offset((begin - 1) * max); query.limit(max); if (id != null && id > 0) { query.field("_id").equal(id); } if (!StringUtils.isEmpty(name)) { if (!StringUtils.contains(name, "*")) { query.field("name").contains(StringUtils.remove(name, "*")); } else { query.field("name").equal(name); } } if (!StringUtils.isEmpty(screenName)) { if (!StringUtils.contains(screenName, "*")) { query.field("screenName").contains(StringUtils.remove(screenName, "*")); } else { query.field("screenName").equal(screenName); } } if (uid != null && uid > 0) { query.field("uid").equal(uid); } if (!StringUtils.isEmpty(accessToken)) { query.field("accessToken").equal(accessToken); } return query.asList(); }