use of cn.edu.zju.acm.onlinejudge.persistence.PersistenceCreationException 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