List of usage examples for org.apache.commons.dbutils.handlers BeanHandler BeanHandler
public BeanHandler(Class<T> type)
From source file:com.pinterest.arcee.db.DBHealthCheckDAOImpl.java
@Override public HealthCheckBean getHealthCheckById(String id) throws Exception { ResultSetHandler<HealthCheckBean> h = new BeanHandler<HealthCheckBean>(HealthCheckBean.class); return new QueryRunner(dataSource).query(GET_HEALTH_CHECK_BY_ID, h, id); }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * /*w ww .j av a 2 s.co m*/ * * @param sql * @param clazz * @return */ public Object get(String sql, Class clazz) { Object obj = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); obj = qRunner.query(conn, sql, new BeanHandler(clazz)); } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return obj; }
From source file:com.pinterest.deployservice.db.DBTagDAOImpl.java
@Override public TagBean getLatestByTargetId(String targetId) throws Exception { return new QueryRunner(basicDataSource).query(GET_LATEST_TAG_BY_TARGET_ID, new BeanHandler<>(TagBean.class), targetId);/* ww w. ja v a2s. co m*/ }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlLookupService.java
/** * Returns the lookup for the given <code>name</code>. * @param name lookup name//from www . j ava 2s. c o m * @return lookup */ @Override public Lookup get(final String name) { Lookup result = null; final Connection connection = DBUtil.getReadConnection(getDataSource()); try { final ResultSetHandler<Lookup> handler = new BeanHandler<>(Lookup.class); result = new QueryRunner().query(connection, SQL_GET_LOOKUP, handler, name); if (result != null) { result.setValues(getValues(result.getId())); } } catch (Exception e) { final String message = String.format("Failed to get the lookup for name %s", name); log.error(message, e); throw new UserMetadataServiceException(message, e); } finally { DBUtil.closeReadConnection(connection); } return result; }
From source file:com.pinterest.arcee.db.DBGroupInfoDAOImpl.java
@Override public GroupBean getGroupInfo(String groupName) throws Exception { ResultSetHandler<GroupBean> h = new BeanHandler<GroupBean>(GroupBean.class); return new QueryRunner(dataSource).query(GET_GROUP_INFO_BY_NAME, h, groupName); }
From source file:com.pinterest.deployservice.db.DBHostTagDAOImpl.java
@Override public HostTagBean get(String hostId, String tagName) throws Exception { ResultSetHandler<HostTagBean> h = new BeanHandler<HostTagBean>(HostTagBean.class); return new QueryRunner(dataSource).query(GET_HOST_TAG_BY_HOST_ID_AND_TAG_NAME, h, hostId, tagName); }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * ??/*from w w w . j av a2 s. c o m*/ * * @param sql * @param clazz * @return */ public Object get(String sql, Class clazz, Object[] params) { Object obj = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); obj = qRunner.query(conn, sql, new BeanHandler(clazz), params); } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return obj; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.VersionDAO.java
/** * Retrieves the last version of a specific project. * //from www. j ava 2 s . c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param projectId the project id. * @return the resulting object id. * @since July, 2011. * @throws VersionSearchDAOException if an error occurs during the search. */ @Override public Version getLastVersionFromProjectId(int projectId) throws VersionSearchDAOException { LOGGER.debug("getLastVersionFromProjectId(" + projectId + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return getQueryRunner().query(connection, "SELECT version_id AS versionId, \"name\" FROM version WHERE project_id = ? AND version_id = (SELECT MAX(version_id) FROM version) ", new BeanHandler<Version>(Version.class), new Object[] { projectId }); } catch (SQLException e) { throw new VersionSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java
@Override public BuildBean getById(String buildId) throws Exception { ResultSetHandler<BuildBean> h = new BeanHandler<>(BuildBean.class); return new QueryRunner(dataSource).query(GET_BUILD_BY_ID, h, buildId); }
From source file:com.versatus.jwebshield.securitylock.SecurityLockService.java
private SecurityLock checkSecurityLock(int userId, String ip) throws SQLException { logger.debug("checkAccountLock: userid=" + userId); logger.debug("checkAccountLock: ip=" + ip); SecurityLock res;//w ww . j a v a 2 s. co m Object[] params = new Object[] { userId, ip }; QueryRunner run = new QueryRunner(); Connection conn = dbHelper.getConnection(); BeanHandler<SecurityLock> rsh = new BeanHandler(SecurityLock.class) { @Override public SecurityLock handle(ResultSet rs) throws SQLException { SecurityLock brp = null; if (rs.first()) { brp = new BasicRowProcessor().toBean(rs, SecurityLock.class); } return brp; } }; try { res = run.query(conn, lockCheckSql, rsh, params); logger.debug("checkAccountLock: response=" + res); if (res != null) { if (res.isLock()) { logger.debug("checkAccountLock: Calendar.getInstance()=" + Calendar.getInstance().getTime()); logger.debug("checkAccountLock: TimeWhenUnlock()=" + res.getTimeWhenUnlock()); logger.debug("checkAccountLock: is time to ulock=" + Calendar.getInstance().getTime().after(res.getTimeWhenUnlock())); if (Calendar.getInstance().getTime().after(res.getTimeWhenUnlock())) { logger.info("unlocking IP " + res.getIp()); int r = run.update(conn, resetLockSql, new Object[] { ip }); logger.debug("checkAccountLock: reset response=" + r); res = run.query(conn, lockCheckSql, rsh, params); logger.debug("checkAccountLock: after reset response=" + res); } } } else { res = new SecurityLock(); res.setLock(false); } } finally { try { DbUtils.close(conn); } catch (SQLException e) { // ignore } } return res; }