List of usage examples for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler
public BeanListHandler(Class<T> type)
From source file:com.pinterest.deployservice.db.DBHostTagDAOImpl.java
@Override public List<HostTagBean> getAllByEnvIdAndTagName(String envId, String tagName) throws Exception { ResultSetHandler<List<HostTagBean>> h = new BeanListHandler<>(HostTagBean.class); return new QueryRunner(dataSource).query(GET_ALL_BY_ENV_ID_AND_TAG_NAME, h, envId, tagName); }
From source file:com.pinterest.deployservice.db.DBAgentDAOImpl.java
@Override public List<AgentBean> getByHost(String hostName) throws Exception { ResultSetHandler<List<AgentBean>> h = new BeanListHandler<>(AgentBean.class); return new QueryRunner(dataSource).query(GET_AGENT_BY_HOST, h, hostName); }
From source file:com.erikw.libraryloan.DatabaseBookDataAccessObject.java
public List<Book> findAll() { try {// w w w. j av a 2 s . com // BeanListHandler allows us to automatically parse fields of Book return dbAccess.query(myConn, "SELECT * FROM Books", new BeanListHandler<Book>(Book.class)); } catch (Exception ex) { ex.printStackTrace(); } return EMPTY; }
From source file:com.pinterest.arcee.db.DBGroupInfoDAOImpl.java
@Override public List<GroupBean> getGroupInfoByAppName(String appName) throws Exception { ResultSetHandler<List<GroupBean>> h = new BeanListHandler<GroupBean>(GroupBean.class); return new QueryRunner(dataSource).query(GET_GROUP_INFO_BY_APP_NAME, h, appName); }
From source file:com.pinterest.deployservice.db.DBAgentDAOImpl.java
@Override public List<AgentBean> getByHostId(String hostId) throws Exception { ResultSetHandler<List<AgentBean>> h = new BeanListHandler<>(AgentBean.class); return new QueryRunner(dataSource).query(GET_AGENT_BY_HOSTID, h, hostId); }
From source file:com.che.software.testato.domain.dao.jdbc.impl.MatrixResultDAO.java
/** * Matrix result search from a bean of criterions. * /*from w w w. j a v a 2 s. c om*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param searchBean the criterions to use for the search. * @return the resulting object list. * @since August, 2011. * @throws MatrixResultSearchDAOException if an error occurs during the * search. */ @Override public List<MatrixResult> searchMatrixResult(MatrixResultSearch searchBean) throws MatrixResultSearchDAOException { LOGGER.debug("searchMatrixResult()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); return getQueryRunner().query(connection, getMatrixResultSearchQueryFromCriterion(searchBean, params), new BeanListHandler<MatrixResult>(MatrixResult.class), params.toArray()); } catch (SQLException e) { throw new MatrixResultSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ActivityDAO.java
/** * Activities to describe search./*ww w . j a v a 2s . c o m*/ * * @author Clement HELIOU (clement.heliou@che-software.com). * @return the resulting object list. * @since July, 2011. * @throws ActivitySearchDAOException if an error occurs during the search. */ @Override public List<Activity> searchActivitiesToDescribe() throws ActivitySearchDAOException { LOGGER.debug("searchActivitiesToDescribe()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); return getQueryRunner().query(connection, getActivitiesToDescribeQuery(null, params), new BeanListHandler<Activity>(Activity.class), params.toArray()); } catch (SQLException e) { throw new ActivitySearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.pinterest.deployservice.db.DBAgentDAOImpl.java
@Override public List<AgentBean> getAllByEnv(String envId) throws Exception { ResultSetHandler<List<AgentBean>> h = new BeanListHandler<>(AgentBean.class); return new QueryRunner(dataSource).query(GET_ALL_AGENT_BY_ENV, h, envId); }
From source file:com.pinterest.arcee.db.DBHealthCheckDAOImpl.java
@Override public List<HealthCheckBean> getHealthChecksByUnterminatedHosts() throws Exception { ResultSetHandler<List<HealthCheckBean>> h = new BeanListHandler<HealthCheckBean>(HealthCheckBean.class); return new QueryRunner(dataSource).query(GET_HEALTH_CHECK_BY_UNTERMINATED_HOSTS, h, HealthCheckState.COMPLETED.toString()); }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ElementDAO.java
/** * Creates a procedural diagram from a testCaseId, a set of elements and a * set of transitions. If activities have been reused or not to create this * diagram.//from w ww .ja v a2 s . c om * * @param testCaseId the test case id. * @param elements the set of elements. * @param transitions the set of transitions. * @throws ElementCreationDAOException if an error occurs during the * creation. */ @Override public void createDiagram(int testCaseId, List<ElementCreation> elements, List<TransitionCreation> transitions) throws ElementCreationDAOException { LOGGER.debug("createDiagram(" + testCaseId + ", " + elements.size() + " elements, " + transitions.size() + " transitions)."); Connection connection = null; try { connection = getDataSource().getConnection(); connection.setAutoCommit(false); for (ElementCreation element : elements) { Integer activityId = null, pointId = null; if (element.getType().equals(ElementCreationTypes.ACTIVITY)) { activityId = (Integer) getQueryRunner().query(connection, "SELECT activity_id::int AS activityId FROM activity WHERE label = ? ", new ScalarHandler("activityId"), new Object[] { element.getLabel() }); if (null == activityId) { getQueryRunner().update(connection, "INSERT INTO activity(activity_id, global_description, label) VALUES(nextval('activity_id_seq'), NULL, ?) ", new Object[] { element.getLabel() }); activityId = (Integer) getQueryRunner().query(connection, "SELECT activity_id::int AS activityId FROM activity WHERE label = ? ", new ScalarHandler("activityId"), new Object[] { element.getLabel() }); } } else { getQueryRunner().update(connection, "INSERT INTO point(point_id, point_type, label) VALUES(nextval('point_id_seq'), ?, ?) ", new Object[] { element.getType().name(), element.getLabel() }); pointId = (Integer) getQueryRunner().query(connection, "SELECT MAX(point_id)::int AS pointId FROM point ", new ScalarHandler("pointId")); } getQueryRunner().update(connection, "INSERT INTO element(element_id, point_id, activity_id, test_case_id) VALUES(nextval('element_id_seq')," + ((null != activityId) ? "NULL" : "?") + "," + ((null != pointId) ? "NULL" : "?") + ",?) ", (null != activityId) ? new Object[] { activityId, testCaseId } : new Object[] { pointId, testCaseId }); } List<Element> createdElements = getQueryRunner().query(connection, "SELECT element_id AS elementId, point_id AS pointId, activity_id AS activityId, test_case_id AS testCaseId, COALESCE(activity.label, point.label) AS label FROM element LEFT JOIN activity USING(activity_id) LEFT JOIN point USING(point_id) WHERE test_case_id = ? ", new BeanListHandler<Element>(Element.class), new Object[] { testCaseId }); for (TransitionCreation transition : transitions) { boolean source = false, target = false; for (Element element : createdElements) { if (element.getLabel().equalsIgnoreCase(transition.getSource())) { transition.setSourceId(element.getElementId()); source = true; } if (element.getLabel().equalsIgnoreCase(transition.getTarget())) { transition.setTargetId(element.getElementId()); target = true; } if (source && target) { break; } } getQueryRunner().update(connection, "INSERT INTO transition(transition_id, target_element, source_element, test_case_id, label) VALUES(nextval('transition_id_seq'), ?, ?, ?, ?) ", new Object[] { transition.getTargetId(), transition.getSourceId(), testCaseId, (null != transition.getLabel()) ? transition.getLabel() : "" }); } connection.commit(); } catch (SQLException e) { try { connection.rollback(); } catch (SQLException e1) { throw new ElementCreationDAOException(e1); } throw new ElementCreationDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }