/**
  * Updates or adds an agent to the database.
  *
  * @param agent The Agent you wish to modify or add in the database.
  */
 protected void updateAgentInDatabase(AgentImpl agent) {
   EntityManager em = null;
   EntityTransaction tx = null;
   try {
     em = emf.createEntityManager();
     tx = em.getTransaction();
     tx.begin();
     AgentImpl existing = getAgent(agent.getName(), agent.getOrganization(), em);
     if (existing == null) {
       em.persist(agent);
     } else {
       existing.setConfiguration(agent.getConfiguration());
       existing.setLastHeardFrom(agent.getLastHeardFrom());
       existing.setState(agent.getState());
       existing.setSchedulerRoles(agent.getSchedulerRoles());
       existing.setUrl(agent.getUrl());
       em.merge(existing);
     }
     tx.commit();
   } catch (RollbackException e) {
     logger.warn("Unable to commit to DB in updateAgent.");
     throw e;
   } finally {
     if (em != null) em.close();
   }
 }
 public boolean setAgentUrl(String agentName, String agentUrl) {
   AgentImpl agent = getAgent(agentName);
   if (agent == null) {
     return false;
   } else {
     agent.setUrl(agentUrl);
     updateAgentInDatabase(agent);
   }
   return true;
 }