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

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

Introduction

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

Prototype

public BeanProcessor() 

Source Link

Document

Constructor for BeanProcessor.

Usage

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

/**
 *
 * @param name//from ww  w . j a v  a  2 s.  co  m
 * @return network
 * Returns 
 *
 */
@Override
public Country getCountryByName(String name) {
    Country network = null;

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

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Country WHERE LOWER(name) like LOWER(?);");
        pstmt.setString(1, "%" + name + "%");
        rset = pstmt.executeQuery();

        if (rset.next()) {
            network = b.toBean(rset, Country.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting network with uuid: " + name);
        logger.error(ExceptionUtils.getStackTrace(e));

    }

    return network;
}

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

/**
 *
 *//*from  w  w  w .  j a  v a2  s  .c o m*/
@Override
public Country getCountry(String uuid) {
    Country network = null;

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

    try {
        conn = dbCredentials.getConnection();
        pstmt = conn.prepareStatement("SELECT * FROM Country WHERE Uuid = ?;");
        pstmt.setString(1, uuid);
        rset = pstmt.executeQuery();

        if (rset.next()) {
            network = b.toBean(rset, Country.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting network with uuid: " + uuid);
        logger.error(ExceptionUtils.getStackTrace(e));

    }

    return network;
}

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

/**
*
*///from  ww w  . ja  v a 2  s. c o  m
@Override
public MessageTemplate getTemplate(String uuid) {
    MessageTemplate messageTemplate = null;

    BeanProcessor b = new BeanProcessor();

    try (Connection conn = dbCredentials.getConnection();
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM MessageTemplate WHERE Uuid = ?;");) {
        pstmt.setString(1, uuid);

        try (ResultSet rset = pstmt.executeQuery();) {
            if (rset.next()) {
                messageTemplate = b.toBean(rset, MessageTemplate.class);
            }

        }
    } catch (SQLException e) {
        logger.error("SQL Exception when getting messageTemplate with uuid: " + uuid);
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return messageTemplate;
}

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

/**
 *
 *//*from w  ww .j  ava  2s .  c o m*/
@Override
public MessageTemplate getMessageTemplate(String uuid) {
    MessageTemplate messageTemplate = 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 Uuid = ?;");
        pstmt.setString(1, uuid);
        rset = pstmt.executeQuery();

        if (rset.next()) {
            messageTemplate = b.toBean(rset, MessageTemplate.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting messageTemplate 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 messageTemplate;
}

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

/**
 *
 *//*from   ww  w.j  a v  a2 s  .c  o 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.notification.NotificationDAO.java

/**
 * /*www . j av a 2  s.c o m*/
 * @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.template.MessageTemplateDAO.java

/**
*
*///  w  w  w  .j  a va 2s .c  o m
@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 av  a 2  s .  c  o m
@Override
public MessageTemplate titleexists(String title) {
    MessageTemplate messageTemplate = 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 title = ?;");
        pstmt.setString(1, title);
        rset = pstmt.executeQuery();

        if (rset.next()) {
            messageTemplate = b.toBean(rset, MessageTemplate.class);
        }

    } catch (SQLException e) {
        logger.error("SQL Exception when getting messageTemplate with uuid: " + title);
        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 messageTemplate;
}

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

/**
 *
 *//*from w w w.  ja v a  2s.  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

/**
 *
 */// w ww  .j a v a 2s  .  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;
}