Package com.github.zhangkaitao.shiro.chapter21.entity

Examples of com.github.zhangkaitao.shiro.chapter21.entity.User


   
    @Test
    public void testDeleteUsersWithPrimaryKey(){
        em.getTransaction().begin();        
        // primary key
        User s1 = em.find(User.class, 11);    
        em.remove(s1);       
        em.getTransaction().commit();               
    }
View Full Code Here


        Assert.assertTrue(cnt > 0);
    }
   
    @Test
    public void testUserPasswordInvalidLength() {
        User user = new User();
        user.setPassword("xxaa1");
        Assert.fail("User password must be at least 6 characters in length");
    }
View Full Code Here

        }
    } 

    @Test
    public void testUserEnrollment() throws ParseException {
         tempUser = new User("anakin", "anakin@skywalker.net", "24ewRTtr", 'S', 500, new SimpleDateFormat("MM/dd/yy").parse("05/18/05"));
         List<Enrollment> enrollList = new ArrayList<Enrollment>();
        
         // create courses and add to enroll list of temp user;                      
         Courses tempCourse = new Courses("testClass with john lennon", 'A', "How to play guitar without pick", new SimpleDateFormat("MM/dd/yy").parse("05/18/05"));      
         tempCourse.setCreaterUserId(tempUser);
View Full Code Here

    // tempUser's primaryId will be needed to delete user and it's associative entities; enrollment and courses entities.       
    private void removeTestData() {
        primaryId = Integer.parseInt(emf.getPersistenceUnitUtil().getIdentifier(tempUser).toString());            
        em.getTransaction().begin();    
        User user = em.find(User.class, primaryId);
        if (user != null) {
            em.remove(user);
        }
        em.getTransaction().commit();
    }
View Full Code Here

            Courserates courserates = enrollment.getCourserates();
            if (courserates != null) {
                courserates = em.getReference(courserates.getClass(), courserates.getId());
                enrollment.setCourserates(courserates);
            }
            User userId = enrollment.getUserId();
            if (userId != null) {
                userId = em.getReference(userId.getClass(), userId.getId());
                enrollment.setUserId(userId);
            }
            Courses courseId = enrollment.getCourseId();
            if (courseId != null) {
                courseId = em.getReference(courseId.getClass(), courseId.getCourseId());
                enrollment.setCourseId(courseId);
            }
            List<Comments> attachedCommentsList = new ArrayList<Comments>();
            for (Comments commentsListCommentsToAttach : enrollment.getCommentsList()) {
                commentsListCommentsToAttach = em.getReference(commentsListCommentsToAttach.getClass(), commentsListCommentsToAttach.getId());
                attachedCommentsList.add(commentsListCommentsToAttach);
            }
            enrollment.setCommentsList(attachedCommentsList);
            em.persist(enrollment);
            if (courserates != null) {
                Enrollment oldEnrollmentOfCourserates = courserates.getEnrollment();
                if (oldEnrollmentOfCourserates != null) {
                    oldEnrollmentOfCourserates.setCourserates(null);
                    oldEnrollmentOfCourserates = em.merge(oldEnrollmentOfCourserates);
                }
                courserates.setEnrollment(enrollment);
                courserates = em.merge(courserates);
            }
            if (userId != null) {
                userId.getEnrollmentList().add(enrollment);
                userId = em.merge(userId);
            }
            if (courseId != null) {
                courseId.getEnrollmentList().add(enrollment);
                courseId = em.merge(courseId);
View Full Code Here

            em = getEntityManager();
            em.getTransaction().begin();
            Enrollment persistentEnrollment = em.find(Enrollment.class, enrollment.getId());
            Courserates courseratesOld = persistentEnrollment.getCourserates();
            Courserates courseratesNew = enrollment.getCourserates();
            User userIdOld = persistentEnrollment.getUserId();
            User userIdNew = enrollment.getUserId();
            Courses courseIdOld = persistentEnrollment.getCourseId();
            Courses courseIdNew = enrollment.getCourseId();
            List<Comments> commentsListOld = persistentEnrollment.getCommentsList();
            List<Comments> commentsListNew = enrollment.getCommentsList();
            List<String> illegalOrphanMessages = null;
            if (courseratesOld != null && !courseratesOld.equals(courseratesNew)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain Courserates " + courseratesOld + " since its enrollment field is not nullable.");
            }
            for (Comments commentsListOldComments : commentsListOld) {
                if (!commentsListNew.contains(commentsListOldComments)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Comments " + commentsListOldComments + " since its enrollmentId field is not nullable.");
                }
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            if (courseratesNew != null) {
                courseratesNew = em.getReference(courseratesNew.getClass(), courseratesNew.getId());
                enrollment.setCourserates(courseratesNew);
            }
            if (userIdNew != null) {
                userIdNew = em.getReference(userIdNew.getClass(), userIdNew.getId());
                enrollment.setUserId(userIdNew);
            }
            if (courseIdNew != null) {
                courseIdNew = em.getReference(courseIdNew.getClass(), courseIdNew.getCourseId());
                enrollment.setCourseId(courseIdNew);
            }
            List<Comments> attachedCommentsListNew = new ArrayList<Comments>();
            for (Comments commentsListNewCommentsToAttach : commentsListNew) {
                commentsListNewCommentsToAttach = em.getReference(commentsListNewCommentsToAttach.getClass(), commentsListNewCommentsToAttach.getId());
                attachedCommentsListNew.add(commentsListNewCommentsToAttach);
            }
            commentsListNew = attachedCommentsListNew;
            enrollment.setCommentsList(commentsListNew);
            enrollment = em.merge(enrollment);
            if (courseratesNew != null && !courseratesNew.equals(courseratesOld)) {
                Enrollment oldEnrollmentOfCourserates = courseratesNew.getEnrollment();
                if (oldEnrollmentOfCourserates != null) {
                    oldEnrollmentOfCourserates.setCourserates(null);
                    oldEnrollmentOfCourserates = em.merge(oldEnrollmentOfCourserates);
                }
                courseratesNew.setEnrollment(enrollment);
                courseratesNew = em.merge(courseratesNew);
            }
            if (userIdOld != null && !userIdOld.equals(userIdNew)) {
                userIdOld.getEnrollmentList().remove(enrollment);
                userIdOld = em.merge(userIdOld);
            }
            if (userIdNew != null && !userIdNew.equals(userIdOld)) {
                userIdNew.getEnrollmentList().add(enrollment);
                userIdNew = em.merge(userIdNew);
            }
            if (courseIdOld != null && !courseIdOld.equals(courseIdNew)) {
                courseIdOld.getEnrollmentList().remove(enrollment);
                courseIdOld = em.merge(courseIdOld);
View Full Code Here

                illegalOrphanMessages.add("This Enrollment (" + enrollment + ") cannot be destroyed since the Comments " + commentsListOrphanCheckComments + " in its commentsList field has a non-nullable enrollmentId field.");
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            User userId = enrollment.getUserId();
            if (userId != null) {
                userId.getEnrollmentList().remove(enrollment);
                userId = em.merge(userId);
            }
            Courses courseId = enrollment.getCourseId();
            if (courseId != null) {
                courseId.getEnrollmentList().remove(enrollment);
View Full Code Here

                attachedEnrollmentList.add(enrollmentListEnrollmentToAttach);
            }
            user.setEnrollmentList(attachedEnrollmentList);
            em.persist(user);
            for (Courses coursesListCourses : user.getCoursesList()) {
                User oldCreaterUserIdOfCoursesListCourses = coursesListCourses.getCreaterUserId();
                coursesListCourses.setCreaterUserId(user);
                coursesListCourses = em.merge(coursesListCourses);
                if (oldCreaterUserIdOfCoursesListCourses != null) {
                    oldCreaterUserIdOfCoursesListCourses.getCoursesList().remove(coursesListCourses);
                    oldCreaterUserIdOfCoursesListCourses = em.merge(oldCreaterUserIdOfCoursesListCourses);
                }
            }
            for (Enrollment enrollmentListEnrollment : user.getEnrollmentList()) {
                User oldUserIdOfEnrollmentListEnrollment = enrollmentListEnrollment.getUserId();
                enrollmentListEnrollment.setUserId(user);
                enrollmentListEnrollment = em.merge(enrollmentListEnrollment);
                if (oldUserIdOfEnrollmentListEnrollment != null) {
                    oldUserIdOfEnrollmentListEnrollment.getEnrollmentList().remove(enrollmentListEnrollment);
                    oldUserIdOfEnrollmentListEnrollment = em.merge(oldUserIdOfEnrollmentListEnrollment);
                }
            }
            em.getTransaction().commit();
        } finally {
View Full Code Here

    public void edit(User user) throws IllegalOrphanException, NonexistentEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            User persistentUser = em.find(User.class, user.getId());
            List<Courses> coursesListOld = persistentUser.getCoursesList();
            List<Courses> coursesListNew = user.getCoursesList();
            List<Enrollment> enrollmentListOld = persistentUser.getEnrollmentList();
            List<Enrollment> enrollmentListNew = user.getEnrollmentList();
            List<String> illegalOrphanMessages = null;
            for (Courses coursesListOldCourses : coursesListOld) {
                if (!coursesListNew.contains(coursesListOldCourses)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Courses " + coursesListOldCourses + " since its createrUserId field is not nullable.");
                }
            }
            for (Enrollment enrollmentListOldEnrollment : enrollmentListOld) {
                if (!enrollmentListNew.contains(enrollmentListOldEnrollment)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Enrollment " + enrollmentListOldEnrollment + " since its userId field is not nullable.");
                }
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            List<Courses> attachedCoursesListNew = new ArrayList<Courses>();
            for (Courses coursesListNewCoursesToAttach : coursesListNew) {
                coursesListNewCoursesToAttach = em.getReference(coursesListNewCoursesToAttach.getClass(), coursesListNewCoursesToAttach.getCourseId());
                attachedCoursesListNew.add(coursesListNewCoursesToAttach);
            }
            coursesListNew = attachedCoursesListNew;
            user.setCoursesList(coursesListNew);
            List<Enrollment> attachedEnrollmentListNew = new ArrayList<Enrollment>();
            for (Enrollment enrollmentListNewEnrollmentToAttach : enrollmentListNew) {
                enrollmentListNewEnrollmentToAttach = em.getReference(enrollmentListNewEnrollmentToAttach.getClass(), enrollmentListNewEnrollmentToAttach.getId());
                attachedEnrollmentListNew.add(enrollmentListNewEnrollmentToAttach);
            }
            enrollmentListNew = attachedEnrollmentListNew;
            user.setEnrollmentList(enrollmentListNew);
            user = em.merge(user);
            for (Courses coursesListNewCourses : coursesListNew) {
                if (!coursesListOld.contains(coursesListNewCourses)) {
                    User oldCreaterUserIdOfCoursesListNewCourses = coursesListNewCourses.getCreaterUserId();
                    coursesListNewCourses.setCreaterUserId(user);
                    coursesListNewCourses = em.merge(coursesListNewCourses);
                    if (oldCreaterUserIdOfCoursesListNewCourses != null && !oldCreaterUserIdOfCoursesListNewCourses.equals(user)) {
                        oldCreaterUserIdOfCoursesListNewCourses.getCoursesList().remove(coursesListNewCourses);
                        oldCreaterUserIdOfCoursesListNewCourses = em.merge(oldCreaterUserIdOfCoursesListNewCourses);
                    }
                }
            }
            for (Enrollment enrollmentListNewEnrollment : enrollmentListNew) {
                if (!enrollmentListOld.contains(enrollmentListNewEnrollment)) {
                    User oldUserIdOfEnrollmentListNewEnrollment = enrollmentListNewEnrollment.getUserId();
                    enrollmentListNewEnrollment.setUserId(user);
                    enrollmentListNewEnrollment = em.merge(enrollmentListNewEnrollment);
                    if (oldUserIdOfEnrollmentListNewEnrollment != null && !oldUserIdOfEnrollmentListNewEnrollment.equals(user)) {
                        oldUserIdOfEnrollmentListNewEnrollment.getEnrollmentList().remove(enrollmentListNewEnrollment);
                        oldUserIdOfEnrollmentListNewEnrollment = em.merge(oldUserIdOfEnrollmentListNewEnrollment);
                    }
                }
            }
            em.getTransaction().commit();
View Full Code Here

    public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            User user;
            try {
                user = em.getReference(User.class, id);
                user.getId();
            } catch (EntityNotFoundException enfe) {
                throw new NonexistentEntityException("The user with id " + id + " no longer exists.", enfe);
            }
            List<String> illegalOrphanMessages = null;
            List<Courses> coursesListOrphanCheck = user.getCoursesList();
            for (Courses coursesListOrphanCheckCourses : coursesListOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This User (" + user + ") cannot be destroyed since the Courses " + coursesListOrphanCheckCourses + " in its coursesList field has a non-nullable createrUserId field.");
            }
            List<Enrollment> enrollmentListOrphanCheck = user.getEnrollmentList();
            for (Enrollment enrollmentListOrphanCheckEnrollment : enrollmentListOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This User (" + user + ") cannot be destroyed since the Enrollment " + enrollmentListOrphanCheckEnrollment + " in its enrollmentList field has a non-nullable userId field.");
View Full Code Here

TOP

Related Classes of com.github.zhangkaitao.shiro.chapter21.entity.User

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.