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);
}
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);
}
}
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;
}
Aggregations