Search in sources :

Example 6 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class UserPersistenceImplTest method setUp.

/**
	 * Setup.
	 * @throws Exception to JUnit
	 */
protected void setUp() throws Exception {
    DatabaseHelper.resetAllTables(false);
    persistence = new UserPersistenceImpl();
    profile.setHandle("myHandle");
    profile.setPassword("myPassword");
    profile.setEmail("myEmail");
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    perference.setPlan("my plan");
    perference.setPostPaging(1);
    perference.setProblemPaging(2);
    perference.setStatusPaging(3);
    perference.setSubmissionPaging(4);
    perference.setThreadPaging(5);
    perference.setUserPaging(6);
}
Also used : Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 7 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class AuthorizationPersistenceImplTest method setUp.

/**
	 * Setup.
	 * @throws Exception to JUnit
	 */
protected void setUp() throws Exception {
    DatabaseHelper.resetAllTables(false);
    profile.setHandle("myHandle");
    profile.setPassword("myPassword");
    profile.setEmail("myEmail");
    profile.setRegDate(new Date());
    profile.setFirstName("myFirstName");
    profile.setLastName("myLastName");
    profile.setAddressLine1("myAddressLine1");
    profile.setAddressLine2("myAddressLine2");
    profile.setCity("myCity");
    profile.setState("myState");
    profile.setCountry(new Country(1, "foo"));
    profile.setZipCode("myZipCode");
    profile.setPhoneNumber("myPhoneNumber");
    profile.setBirthDate(DateFormat.getDateInstance(DateFormat.SHORT, Locale.US).parse("1/1/1980"));
    profile.setGender('M');
    profile.setSchool("mySchool");
    profile.setMajor("myMajor");
    profile.setGraduateStudent(true);
    profile.setGraduationYear(2005);
    profile.setStudentNumber("myStudentNumber");
    profile.setConfirmed(false);
    new UserPersistenceImpl().createUserProfile(profile, 1);
    forum1 = newForum(1);
    forum2 = newForum(2);
    forum3 = newForum(3);
    persistence.createForum(forum1, 1);
    persistence.createForum(forum2, 1);
    persistence.createForum(forum3, 1);
    thread1 = newThread(1, forum1.getId(), profile.getId());
    thread2 = newThread(2, forum1.getId(), profile.getId());
    thread3 = newThread(3, forum2.getId(), profile.getId());
    persistence.createThread(thread1, 1);
    persistence.createThread(thread2, 1);
    persistence.createThread(thread3, 1);
    post1 = newPost(1, thread1.getId(), profile.getId());
    post2 = newPost(2, thread1.getId(), profile.getId());
    post3 = newPost(3, thread2.getId(), profile.getId());
    persistence.createPost(post1, 1);
    persistence.createPost(post2, 1);
    persistence.createPost(post3, 1);
    thread3Posts = new ArrayList();
    for (int i = 1; i <= 10; ++i) {
        Post post = newPost(i, thread3.getId(), profile.getId());
        thread3Posts.add(post);
        persistence.createPost(post, 1);
    }
}
Also used : Post(cn.edu.zju.acm.onlinejudge.bean.Post) ArrayList(java.util.ArrayList) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) Date(java.util.Date)

Example 8 with Country

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.Country in project zoj by licheng.

the class UserPersistenceImpl method getAllCountries.

/**
     * <p>
     * Gets all countries from the persistence layer.
     * </p>
     * 
     * @return a list containing all country names
     */
public List<Country> getAllCountries() throws PersistenceException {
    if (this.allCountries == null) {
        synchronized (this) {
            if (this.allCountries == null) {
                Connection conn = null;
                try {
                    conn = Database.createConnection();
                    PreparedStatement ps = null;
                    try {
                        ps = conn.prepareStatement(UserPersistenceImpl.GET_ALL_COUNTRIES);
                        ResultSet rs = ps.executeQuery();
                        List<Country> countries = new ArrayList<Country>();
                        while (rs.next()) {
                            countries.add(new Country(rs.getLong(DatabaseConstants.COUNTRY_COUNTRY_ID), rs.getString(DatabaseConstants.COUNTRY_NAME)));
                        }
                        this.allCountries = Collections.unmodifiableList(countries);
                    } finally {
                        Database.dispose(ps);
                    }
                } catch (Exception e) {
                    throw new PersistenceCreationException("Failed to get all countries", e);
                } finally {
                    Database.dispose(conn);
                }
            }
        }
    }
    return this.allCountries;
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Country(cn.edu.zju.acm.onlinejudge.bean.enumeration.Country) PreparedStatement(java.sql.PreparedStatement) PersistenceCreationException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceCreationException) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) SQLException(java.sql.SQLException) PersistenceCreationException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceCreationException)

Aggregations

Country (cn.edu.zju.acm.onlinejudge.bean.enumeration.Country)8 Date (java.util.Date)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)3 ArrayList (java.util.ArrayList)3 Post (cn.edu.zju.acm.onlinejudge.bean.Post)2 PersistenceCreationException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceCreationException)1 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 List (java.util.List)1