Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Section


                                            {
                                                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
View Full Code Here


        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section();
        section.setCourse(course);
        section.setId(5L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        Long newId = instance.create(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section("T1A");
        section.setCourse(course);
        section.setId(5L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        instance.closeConnection();
        assertFalse(instance.isOpen());
        Long newId = instance.create(section);
View Full Code Here

    @Test
    public void testUpdate()
    {
        System.out.println("update");
        assertTrue(instance.isOpen());
        Section section = instance.find(4L);
        assertNotNull(section);
        assertEquals("T6A", section.getName());
        assertEquals(3, section.getStudents().size());
        section.setName("T6H");
        section = instance.update(section);
        assertNotNull(section);
        assertTrue(instance.isOpen());
        Section expectedResult = instance.find(4L);
        assertNotNull(expectedResult);
        assertEquals("T6H", expectedResult.getName());
        assertEquals(expectedResult.getName(), section.getName());
        assertEquals(3, expectedResult.getStudents().size());
        assertEquals(expectedResult.getStudents().size(), section.getStudents().size());
    }
View Full Code Here

    @Test(expected=NullPointerException.class)
    public void testUpdateNullSection()
    {
        System.out.println("updateNullSection");
        Section section = null;
        assertTrue(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section("T6A");
        section.setId(4L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

    {
        System.out.println("updateNullInstructor");
        Course course = new Course("CS364");
        course.setId(2L);

        Section section = new Section("T6A");
        section.setId(4L);
        section.setCourse(course);

        assertTrue(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section();
        section.setId(4L);
        section.setCourse(course);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

    @Test(expected=IllegalStateException.class)
    public void testUpdateClosedConnection()
    {
        System.out.println("updateClosedConnection");
        assertTrue(instance.isOpen());
        Section section = instance.find(4L);
        assertNotNull(section);
        assertEquals("T6A", section.getName());
        assertEquals(3, section.getStudents().size());
        section.setName("T6H");
        assertTrue(instance.isOpen());
        instance.closeConnection();
        assertFalse(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section("T1A");
        section.setCourse(course);
        section.setId(5L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        section = instance.update(section);
    }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.Section

Copyright © 2018 www.massapicom. 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.