List of usage examples for org.apache.commons.dbutils BeanProcessor BeanProcessor
public BeanProcessor()
From source file:ke.co.tawi.babblesms.server.persistence.items.messageTemplate.MessageTemplateDAO.java
/** * *///from www . ja v a 2 s .com @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.contacts.ContactDAO.java
/** * Method to fetch contacts that match the search string * //w w w. jav a 2 s. c o m * @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:ke.co.tawi.babblesms.server.persistence.notification.NotificationDAO.java
/** */*from w ww . j a va 2 s . c o m*/ */ @Override public Notification getNotification(String uuid) { 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 Uuid = ?;"); pstmt.setString(1, uuid); rset = pstmt.executeQuery(); if (rset.next()) { notification = b.toBean(rset, Notification.class); } } catch (SQLException e) { logger.error("SQL Exception when getting network with uuid: " + uuid); 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:org.biblionum.authentification.modele.UtilisateurModele.java
/** * get utilisateur par le login/*from w ww. ja v a2 s. c o m*/ */ 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 w w w . ja va 2 s . c om*/ */ 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 w ww. jav a 2 s. c o 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; }
From source file:org.biblionum.ouvrage.modele.OuvrageTypeModele.java
public static ArrayList<OuvrageType> getTypeOuvrage(DataSource ds) { ArrayList<OuvrageType> list = new ArrayList<OuvrageType>(); PreparedStatement stm;/*from w w w. j a v a 2 s. c om*/ String requete; ResultSet rs; try { con = ds.getConnection(); stm = con.prepareStatement("SELECT * FROM ouvragetype"); rs = stm.executeQuery(); BeanProcessor bp = new BeanProcessor(); list = (ArrayList) bp.toBeanList(rs, OuvrageType.class); con.close(); rs.close(); } catch (SQLException ex) { Logger.getLogger(UtilisateurModele.class.getName()).log(Level.SEVERE, null, ex); } return list; }
From source file:wzw.sql.ResultSetConverter.java
/** * Convert a ResultSet Object to Bean.// w ww . j a va2s. c o m * @param rs * @param type * @return * @throws SQLException */ public static Object toBean(ResultSet rs, Class<?> type) throws SQLException { BeanProcessor bp = new BeanProcessor(); return bp.toBean(rs, type); }
From source file:wzw.sql.ResultSetConverter.java
/** * <p>//from w w w . j a v a 2 s . com * Convert a ResultSet Object to List. * ??ResultSet?? rs.beforeFirst() * </p>. * @param rs * @param type * @return * @throws SQLException */ @SuppressWarnings("unchecked") public static List<Object> toBeanList(ResultSet rs, Class<?> type) throws SQLException { BeanProcessor bp = new BeanProcessor(); return bp.toBeanList(rs, type); }