Example usage for org.apache.commons.dbutils BeanProcessor toBeanList

List of usage examples for org.apache.commons.dbutils BeanProcessor toBeanList

Introduction

In this page you can find the example usage for org.apache.commons.dbutils BeanProcessor toBeanList.

Prototype

public <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException 

Source Link

Document

Convert a ResultSet into a List of JavaBeans.

Usage

From source file:ke.co.tawi.babblesms.server.persistence.geolocation.CountryDAO.java

/**
 *
 *///from w  ww  . j  av a2  s  . co  m
@Override
public List<Country> getAllCountries() {
    List<Country> list = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Country;");
        rset = pstmt.executeQuery();

        list = b.toBeanList(rset, Country.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all networks");
        logger.error(ExceptionUtils.getStackTrace(e));

    }

    return list;
}

From source file:ke.co.tawi.babblesms.server.persistence.template.MessageTemplateDAO.java

/**
*
*//*from w w  w.  ja  v  a2s. c om*/
@Override
public List<MessageTemplate> getTemplates(Account account) {
    List<MessageTemplate> list = null;

    BeanProcessor b = new BeanProcessor();

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement(
                    "SELECT * FROM MessageTemplate WHERE accountuuid=? ORDER BY title ASC;");) {

        pstmt.setString(1, account.getUuid());
        try (ResultSet rset = pstmt.executeQuery();) {

            list = b.toBeanList(rset, MessageTemplate.class);

        }
    } catch (SQLException e) {
        logger.error("SQL Exception when getting all messageTemplates" + account.getUuid());
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return list;
}

From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java

/**
 *
 *//*from  w w w.  j a  v a 2s  .co m*/
@Override
public List<MessageTemplate> getAllMessageTemplates() {
    List<MessageTemplate> list = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate;");
        rset = pstmt.executeQuery();

        list = b.toBeanList(rset, MessageTemplate.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all messageTemplates");
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return list;
}

From source file:ke.co.tawi.babblesms.server.persistence.notification.NotificationDAO.java

/**
 *
 *//*from ww w .j  av  a2 s. c o  m*/
@Override
public List<Notification> getAllNotifications() {
    List<Notification> list = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;

    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Notification ORDER BY NotificationDate DESC;");

        rset = pstmt.executeQuery();

        list = b.toBeanList(rset, Notification.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all notifications.");
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return list;
}

From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java

/**
 *
 *//*from  w  w  w  . j  a va2  s  .co m*/
@Override
public List<MessageTemplate> getAllMessageTemplatesbyuuid(String accuuid) {
    List<MessageTemplate> list = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE accountuuid=? ORDER BY title ASC;");
        pstmt.setString(1, accuuid);
        rset = pstmt.executeQuery();

        list = b.toBeanList(rset, MessageTemplate.class);

    } catch (SQLException e) {
        logger.error("SQL Exception when getting all messageTemplates" + accuuid);
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return list;
}

From source file:ke.co.tawi.babblesms.server.persistence.notification.NotificationDAO.java

/**
 * // w w  w  .  j  ava 2 s  . c om
 * @param origin
 * @return 
 */
@Override
public List<Notification> getNotificationbyOrigin(String origin) {
    List<Notification> notification = null;

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;

    BeanProcessor b = new BeanProcessor();

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Notification WHERE origin = ?;");
        pstmt.setString(1, origin);

        rset = pstmt.executeQuery();

        if (rset.next()) {
            notification = b.toBeanList(rset, Notification.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when trying to get Notification with Uuid: " + origin);
        logger.error(ExceptionUtils.getStackTrace(e));
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return notification;
}

From source file:ke.co.tawi.babblesms.server.persistence.contacts.ContactDAO.java

/**
 * Method to fetch contacts that match the search string
 * // w w w .j av  a2 s. com
 * @param account 
 * @param contMatcher
 * @return a list of contacts
 */
public List<Contact> getContactListMatch(Account account, String contMatcher) {
    List<Contact> contactList = new ArrayList<Contact>();

    BeanProcessor b = new BeanProcessor();

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement psmt = conn
                    .prepareStatement("SELECT * FROM contact WHERE accountuuid=? AND name ILIKE ? "
                            + "ORDER BY NAME ASC LIMIT ? OFFSET ?;");) {

        psmt.setString(1, account.getUuid());
        psmt.setString(2, "%" + contMatcher + "%");
        psmt.setInt(3, 15);
        psmt.setInt(4, 0);

        ResultSet rset = psmt.executeQuery();

        contactList = b.toBeanList(rset, Contact.class);

        rset.close();
    }

    catch (SQLException e) {
        logger.error("SQL Exception when getting contacts from table contact that match the " + " string : "
                + contMatcher);
        logger.error(ExceptionUtils.getStackTrace(e));
    }

    return contactList;
}

From source file:org.biblionum.authentification.modele.UtilisateurModele.java

/**
 * get utilisateur par le login/*from  ww w.j  av a  2s  .c  om*/
 */
public Utilisateur getUtilisateurConnecter(DataSource ds, String pseudo, String pwd) {
    Utilisateur u = null;
    ArrayList<Utilisateur> list = new ArrayList<Utilisateur>();

    try {
        con = ds.getConnection();
        stm = con.prepareStatement("SELECT * FROM utilisateur WHERE pseudo=? AND password=?");
        stm.setString(1, pseudo);//type user prof 1
        stm.setString(2, pwd);
        rs = stm.executeQuery();

        BeanProcessor bp = new BeanProcessor();
        list = (ArrayList) bp.toBeanList(rs, Utilisateur.class);
        System.out.println("taille list utilisateur modele " + list.size());
        if (list.size() > 0) {
            u = list.get(0);
        }
        con.close();
        rs.close();

    } catch (SQLException ex) {
        Logger.getLogger(UtilisateurModele.class.getName()).log(Level.SEVERE, null, ex);
    }

    return u;
}

From source file:org.biblionum.ouvrage.modele.CategorieOuvrageModele.java

/**
 * get all categorie/*from ww  w  .jav  a 2 s. c  o  m*/
 */
public static ArrayList<CategorieOuvrage> getCategorieOuvrage(DataSource ds) {

    ArrayList<CategorieOuvrage> list = new ArrayList<CategorieOuvrage>();

    try {
        con = ds.getConnection();
        stm = con.prepareStatement("SELECT * FROM categorieouvrage");

        rs = stm.executeQuery();

        BeanProcessor bp = new BeanProcessor();
        list = (ArrayList) bp.toBeanList(rs, CategorieOuvrage.class);

        con.close();
        rs.close();

    } catch (SQLException ex) {
        Logger.getLogger(UtilisateurModele.class.getName()).log(Level.SEVERE, null, ex);
    }

    return list;
}

From source file:org.biblionum.ouvrage.modele.OuvrageModele.java

/**
 * get utilisatuer par type et categorie
 *///from ww w  .j a v  a2  s  . co m

public ArrayList<Ouvrage> getOuvrage(DataSource ds, int type, int categorie) {

    ArrayList<Ouvrage> list = new ArrayList<Ouvrage>();

    try {
        con = ds.getConnection();
        stm = con.prepareStatement("SELECT * FROM ouvrage WHERE CategorieOuvrageid=? AND OuvrageTypeid=?");
        stm.setInt(1, categorie);//type user prof 1
        stm.setInt(2, type);
        rs = stm.executeQuery();

        BeanProcessor bp = new BeanProcessor();
        list = (ArrayList) bp.toBeanList(rs, Ouvrage.class);

        con.close();
        rs.close();

    } catch (SQLException ex) {
        Logger.getLogger(UtilisateurModele.class.getName()).log(Level.SEVERE, null, ex);
    }

    return list;
}