Package com.tmm.enterprise.microblog.util

Source Code of com.tmm.enterprise.microblog.util.BatchService

package com.tmm.enterprise.microblog.util;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tmm.enterprise.microblog.domain.Person;
import com.tmm.enterprise.microblog.domain.Team;
import com.tmm.enterprise.microblog.service.ContactableService;

@Service("batchService")
@Repository
@Transactional
public class BatchService {
  private EntityManager entityManager;

  @Autowired
  private ContactableService contactableService;

  @PersistenceContext
  public void setEntityManager(EntityManager em) {
    this.entityManager = em;
  }

  public EntityManager getEntityManager() {
    return entityManager;
  }

  public void setContactableService(ContactableService contactableService) {
    this.contactableService = contactableService;
  }

  @Transactional
  public void setAllTeams(String teamName) {
    List<Person> peeps = contactableService.loadAllPersons();
    Team t = new Team();
    t.setName(teamName);
    for (Person p : peeps) {
      if (p.getTeam() != null) {
        continue;
      }
      System.out.println("Person assigned to team! " + teamName);
      t.addMember(p);
      p.setTeam(t);
    }
    contactableService.createTeam(t);
  }
}
TOP

Related Classes of com.tmm.enterprise.microblog.util.BatchService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.