Code example for AtomicInteger

Methods: incrementAndGet

0
    private EntityManager entityManager;
 
    @Override 
    public void addEmployee(final String name) {
        Employee e = new Employee();
        e.setId(idGenerator.incrementAndGet());
        e.setName(name);
        entityManager.persist(e);
    } 
 
    @Override 
    public Set<String> getEmployees() {
        final List<Employee> emps = entityManager.createQuery("from Employee").getResultList();
        final Set<String> ret = new HashSet<String>();
        for (Employee e : emps) {
            ret.add(e.getName());
        } 
        return ret;
    } 
}