}
tx.begin();
// TODO: RAGE-71 - Migrate to InstructorDAO
query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
query.setParameter("webid", ins.getWebID());
Instructor insRes;
try
{
insRes = (Instructor)query.getSingleResult();
}
catch (NoResultException ex)
{
// Instructor not found in DB
insRes = null;
}
if (insRes == null) // The instructor is not in the database
{
em.persist(ins);
}
else
{
ins.setId(insRes.getId());
}
query = em.createQuery("select c FROM Course c WHERE name = :name");
query.setParameter("name", c.getName());
Course crsRes;
try
{
crsRes = (Course)query.getSingleResult();
}
catch (NoResultException ex)
{
// Instructor not found in DB
crsRes = null;
}
if (crsRes == null) // The instructor is not in the database
{
em.persist(c);
}
else
{
c.setId(crsRes.getId());
}
//s.setStudents(students);
s.setInstructor(ins);
s.setCourse(c);
query = em.createQuery("select s FROM Section s WHERE s.name = :name");
query.setParameter("name", s.getName());
Section res;
try
{
res = (Section)query.getSingleResult();
}
catch (NoResultException ex)
{
// Section not found in DB
res = null;
}
if (res == null) // The section is not in the database
{
em.persist(s);
}
else
{
s.setId(res.getId());
}
tx.commit();
}
}
try
{
ins.setSections(sections);
}
catch (IllegalArgumentException e)
{
System.out.println("ERROR Setting Sections. Size of Section list: " + sections.size());
}
tx.begin();
query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
query.setParameter("webid", ins.getWebID());
Instructor res;
try
{
res = (Instructor)query.getSingleResult();
}
catch (NoResultException ex)
{
// Instructor not found in DB
res = null;
}
if (res == null) // The instructor is not in the database
{
em.persist(ins);
}
else
{
ins.setId(res.getId());
}
tx.commit();
}
}
try