{
SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
// TODO: Need to add query for name...but Sections are not equal by name...RAGE-94
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
{
tx.begin();
em.persist(s);
tx.commit();
//stu.setSection(s);
}
else
{
tx.begin();
em.persist(res);
tx.commit();
//stu.setSection(res);
}
// TODO: RAGE-34 - Migrate to StudentDAO
query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
query.setParameter("webid", stu.getWebID());
Student stuRes;
try
{
stuRes = (Student)query.getSingleResult();
}
catch (NoResultException ex)
{
// Student not found in DB
stuRes = null;
}
if (stuRes == null) // The student is not in the database
{
tx.begin();
em.persist(stu);
tx.commit();
}
sectionDAO.closeConnection();
}
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