@Test @SuppressWarnings("unchecked") public void testExecute() { final Long ford1 = 42L; final Long ford2 = 142L; final Long sagan = 4507L; final Long smithers = 98L; List<String> adminAccountIds = new ArrayList<String>(); adminAccountIds.add("fordp"); adminAccountIds.add("fordp2"); adminAccountIds.add("csagan"); sut.execute(adminAccountIds); List<Long> peopleIds = getEntityManager().createQuery("SELECT id FROM Person WHERE isAdministrator=true") .getResultList(); Assert.assertEquals(3, peopleIds.size()); Assert.assertTrue(peopleIds.contains(ford1)); Assert.assertTrue(peopleIds.contains(ford2)); Assert.assertTrue(peopleIds.contains(sagan)); adminAccountIds = new ArrayList<String>(); adminAccountIds.add("fordp"); adminAccountIds.add("smithers"); sut.execute(adminAccountIds); peopleIds = getEntityManager().createQuery("SELECT id FROM Person WHERE isAdministrator=true").getResultList(); Assert.assertEquals(2, peopleIds.size()); Assert.assertTrue(peopleIds.contains(ford1)); Assert.assertTrue(peopleIds.contains(smithers)); }
@Override public Boolean execute(final List<String> inAccountIds) { getEntityManager().createQuery( "UPDATE Person SET isAdministrator=false WHERE isAdministrator=true " + "AND accountId NOT IN (:accountIds)").setParameter("accountIds", inAccountIds) .executeUpdate(); getEntityManager().createQuery( "UPDATE Person SET isAdministrator=true WHERE isAdministrator=false AND accountId IN (:accountIds)") .setParameter("accountIds", inAccountIds).executeUpdate(); return true; }
SetSystemAdminsDbMapper extends BaseArgDomainMapper<List<String>, Boolean> { @Override public Boolean execute(final List<String> inAccountIds) { getEntityManager().createQuery( "UPDATE Person SET isAdministrator=false WHERE isAdministrator=true " + "AND accountId NOT IN (:accountIds)").setParameter("accountIds", inAccountIds) .executeUpdate(); getEntityManager().createQuery( "UPDATE Person SET isAdministrator=true WHERE isAdministrator=false AND accountId IN (:accountIds)") .setParameter("accountIds", inAccountIds).executeUpdate(); return true; } }
SetSystemAdminsDbMapper extends BaseArgDomainMapper<List<String>, Boolean> { @Override public Boolean execute(final List<String> inAccountIds) { getEntityManager().createQuery( "UPDATE Person SET isAdministrator=false WHERE isAdministrator=true " + "AND accountId NOT IN (:accountIds)").setParameter("accountIds", inAccountIds) .executeUpdate(); getEntityManager().createQuery( "UPDATE Person SET isAdministrator=true WHERE isAdministrator=false AND accountId IN (:accountIds)") .setParameter("accountIds", inAccountIds).executeUpdate(); return true; }  }
SetSystemAdminsDbMapper extends BaseArgDomainMapper<List<String>, Boolean> { @Override public Boolean execute(final List<String> inAccountIds) { getEntityManager().createQuery( "UPDATE Person SET isAdministrator=false WHERE isAdministrator=true " + "AND accountId NOT IN (:accountIds)").setParameter("accountIds", inAccountIds) .executeUpdate(); getEntityManager().createQuery( "UPDATE Person SET isAdministrator=true WHERE isAdministrator=false AND accountId IN (:accountIds)") .setParameter("accountIds", inAccountIds).executeUpdate(); return true; }  @Override Boolean execute(final List<String> inAccountIds); }
SetSystemAdminsDbMapper extends BaseArgDomainMapper<List<String>, Boolean> { @Override public Boolean execute(final List<String> inAccountIds) { getEntityManager().createQuery( "UPDATE Person SET isAdministrator=false WHERE isAdministrator=true " + "AND accountId NOT IN (:accountIds)").setParameter("accountIds", inAccountIds) .executeUpdate(); getEntityManager().createQuery( "UPDATE Person SET isAdministrator=true WHERE isAdministrator=false AND accountId IN (:accountIds)") .setParameter("accountIds", inAccountIds).executeUpdate(); return true; }  @Override Boolean execute(final List<String> inAccountIds);  }