public static Address randomAddress() { Address a = create(Address.class); a.setAddressee(randomize(ADDRESSEE)); if (rand.nextBoolean()) { a.setAddressLine1(randomize(ADDRESS)); a.setAddressLine2(""); } else { a.setAddressLine1(""); a.setAddressLine2(randomize(ADDRESS)); } a.setCity(randomize(CITY)); a.setPostalCode(generateKey(5)); a.setState(randomize(STATE)); return (a); }
public User getUser(MySqlHelper helper, String userName, String password) { User user = new User(); String query = "select * " + "from login u inner join address a on u.UserId = a.UserId " + "inner join personalinfo p on a.AddressId = p.AddressId " + "where Email=? and Password= ?"; System.out.println(query); System.out.println("u=" + userName + " p=" + password); try { java.sql.PreparedStatement loginPreparedStatement = helper.conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); loginPreparedStatement.setString(1, userName); loginPreparedStatement.setString(2, password); ResultSet rs = loginPreparedStatement.executeQuery(); while (rs.next()) { user.setFirstName(rs.getString("FirstName")); user.setLastName(rs.getString("LastName")); user.setUserType(Integer.toString(rs.getInt("UserTypeId"))); user.setEmail(rs.getString("Email")); Address address = new Address(); address.setAddressLine1(rs.getString("AddressLine1")); address.setAddressLine2(rs.getString("AddressLine2")); address.setCity(rs.getString("City")); address.setState(rs.getString("State")); address.setZipCode(rs.getString("ZipCode")); address.setLattitude(rs.getString("Lattitude")); address.setLongitude(rs.getString("Longitude")); user.setAddress(address); user.setPhoneNumber(rs.getString("PhoneNumber")); } } catch (Exception ex) { ex.printStackTrace(); } return user; }
public static void main(String[] args) { Student student = new Student(); student.setName("Jeff"); Address homeAddress = new Address(); homeAddress.setAddressType(AddressType.HOME); homeAddress.setAddressLine1("101 Fifth St."); homeAddress.setAddressLine2("Suite 3a"); homeAddress.setCity("St. Charles"); homeAddress.setState("MO"); homeAddress.setPostalCode("63303"); Set addresses = new HashSet(); addresses.add(homeAddress); student.setAddresses(addresses); Instructor instructor = new Instructor(); instructor.setFirstName("John"); instructor.setLastName("Smith"); instructor.setInstructorName(instructor.getFirstName(), instructor.getLastName()); Instructor instructor2 = new Instructor(); instructor2.setFirstName("Ron"); instructor2.setLastName("Regan"); instructor2.setInstructorName(instructor.getFirstName(), instructor.getLastName()); Course java = new Course(); java.setCourseName("CSP 443 Advanced Java"); java.setCreditHours(3.0f); java.setInstructor(instructor); Course cSharp = new Course(); cSharp.setCourseName("CSP 233 Beginning C#"); cSharp.setCreditHours(5.0f); java.setInstructor(instructor2); Course algebra = new Course(); algebra.setCourseName("Beginners Algebra"); algebra.setCreditHours(3.0f); algebra.setInstructor(instructor2); Course computer = new Course(); computer.setCourseName("Intro to Computer Science"); computer.setCreditHours(4.5f); computer.setInstructor(instructor); Rating rate = new Rating(); rate.setCourse(java, 8.5d); Rating rate2 = new Rating(); rate2.setCourse(cSharp, 9.0d); Rating rate3 = new Rating(); rate3.setCourse(algebra, 7.0); Rating rate4 = new Rating(); rate4.setCourse(computer, 8.0); Set courses = new HashSet(); courses.add(java); courses.add(cSharp); courses.add(computer); courses.add(algebra); student.setCourses(courses); Set instructors = new HashSet(); instructors.add(instructor); instructors.add(instructor2); instructor.setInstructors(instructors); Grade javaGrade = new Grade(student, java, 3.459f); Grade cSharpGrade = new Grade(student, cSharp, 3.975f); Grade algebraGrade = new Grade(student, algebra, 3.5f); Grade computerGrade = new Grade(student, computer, 3.0f); Session session = HibernateUtilities.getSessionFactory().openSession(); session.beginTransaction(); session.save(student); session.save(javaGrade); session.save(cSharpGrade); session.save(algebraGrade); session.save(computerGrade); session.getTransaction().commit(); session.close(); double result = GradebookBusinessLogic.calculateCumulativeGPA(student); System.out.println(student.getName() + " Cumulative Grade: " + result); System.out.println(instructor.getInstructorName() + ":" + rate4.getRate()); System.out.println(instructor2.getInstructorName() + ";" + rate3.getRate()); }