Search in sources :

Example 6 with Configuration

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

the class ConfigurationPersistenceImpl method getConfigurations.

/**
     * <p>
     * Returns a list of Configuration instances retrieved from persistence layer.
     * </p>
     * 
     * @return a list of Configuration instances retrieved from persistence layer.
     * @throws PersistenceException
     *             wrapping a persistence implementation specific exception
     */
public List<Configuration> getConfigurations() throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(ConfigurationPersistenceImpl.GET_ALL_CONFIGURATIONS);
            ResultSet rs = ps.executeQuery();
            List<Configuration> configurations = new ArrayList<Configuration>();
            while (rs.next()) {
                Configuration configuration = new Configuration();
                configuration.setName(rs.getString(DatabaseConstants.CONFIGURATION_NAME));
                configuration.setValue(rs.getString(DatabaseConstants.CONFIGURATION_VALUE));
                configuration.setDescription(rs.getString(DatabaseConstants.CONFIGURATION_DESCRIPTION));
                configurations.add(configuration);
            }
            return configurations;
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Error.", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : Configuration(cn.edu.zju.acm.onlinejudge.bean.Configuration) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Configuration (cn.edu.zju.acm.onlinejudge.bean.Configuration)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Iterator (java.util.Iterator)3 Set (java.util.Set)3 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1