List of usage examples for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler
public BeanListHandler(Class<T> type)
From source file:com.che.software.testato.domain.dao.jdbc.impl.ActionDAO.java
/** * Creates a map from an action plan id, a list of intentions and a list of * sections./*from w ww .ja va2s . co m*/ * * @author Clement HELIOU (clement.heliou@che-software.com). * @param actionPlanId the action plan id to be linked to the created * actions. * @param intentions the intentions to add in the map. * @param sections the sections to add in the map. * @since July, 2011. * @throws ActionCreationDAOException if an error occurs during the * creation. */ @Override public void createMap(int actionPlanId, List<Intention> intentions, List<Section> sections) throws ActionCreationDAOException { LOGGER.debug("createMap(" + actionPlanId + "," + intentions.size() + " intentions," + sections.size() + " sections)."); Connection connection = null; try { connection = getDataSource().getConnection(); connection.setAutoCommit(false); List<Integer> createdIntentionsId = new ArrayList<Integer>(); for (Intention intention : intentions) { getQueryRunner().update(connection, "INSERT INTO intention(intention_id, label) VALUES(nextval('intention_seq'), ?) ", new Object[] { intention.getLabel() }); createdIntentionsId.add((Integer) getQueryRunner().query(connection, "SELECT MAX(intention_id)::int AS intentionId FROM intention ", new ScalarHandler("intentionId"))); } List<Intention> createdIntentions = getQueryRunner().query(connection, "SELECT intention_id AS intentionId, label FROM intention WHERE intention_id IN(" + getInClauseFromIntentionsIds(createdIntentionsId) + ") ", new BeanListHandler<Intention>(Intention.class)); LOGGER.debug(createdIntentions.size() + " intentions created with success..."); for (Section section : sections) { boolean source = false, target = false; for (Intention intention : createdIntentions) { if (!source && intention.getLabel().equalsIgnoreCase(section.getSourceIntention())) { section.setSourceIntentionId(intention.getIntentionId()); source = true; } if (!target && intention.getLabel().equalsIgnoreCase(section.getTargetIntention())) { section.setTargetIntentionId(intention.getIntentionId()); target = true; } if (target && source) { break; } } Integer actionId = (Integer) getQueryRunner().query(connection, "SELECT action_id::int AS actionId FROM action WHERE action_plan_id = ? AND source_intention = ? AND target_intention = ? ", new ScalarHandler("actionId"), new Object[] { actionPlanId, section.getSourceIntentionId(), section.getTargetIntentionId() }); if (null == actionId) { LOGGER.debug("Action creation..."); getQueryRunner().update(connection, "INSERT INTO action(action_id, target_intention, source_intention, action_plan_id) VALUES(nextval('action_seq'),?,?,?) ", new Object[] { section.getTargetIntentionId(), section.getSourceIntentionId(), actionPlanId }); actionId = (Integer) getQueryRunner().query(connection, "SELECT action_id::int AS actionId FROM action WHERE action_plan_id = ? AND source_intention = ? AND target_intention = ? ", new ScalarHandler("actionId"), new Object[] { actionPlanId, section.getSourceIntentionId(), section.getTargetIntentionId() }); } getQueryRunner().update(connection, "INSERT INTO item(item_id, label, iteration_max_number) VALUES(nextval('item_seq'), ?, ?) ", new Object[] { section.getStrategyLabel(), section.getMaxIterationNumber() }); Integer createdItemId = (Integer) getQueryRunner().query(connection, "SELECT MAX(item_id)::int AS itemId FROM item ", new ScalarHandler("itemId")); getQueryRunner().update(connection, (section.isExclusive()) ? "INSERT INTO action_exclusive_item(action_id, item_id) VALUES(?,?) " : "INSERT INTO action_inclusive_item(action_id, item_id) VALUES(?,?) ", new Object[] { actionId, createdItemId }); } connection.commit(); } catch (SQLException e) { try { connection.rollback(); } catch (SQLException e1) { throw new ActionCreationDAOException(e1); } throw new ActionCreationDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.MatrixItemDAO.java
/** * Matrix item search from a bean of criterions. * //from w w w. j a va 2 s. co m * @author Clement HELIOU (clement.heliou@che-software.com). * @param searchBean the criterions to use for the search. * @return the resulting object list. * @since July, 2011. * @throws MatrixItemSearchDAOException if an error occurs during the * search. */ @Override public List<MatrixItem> searchMatrixItem(MatrixItemSearch searchBean) throws MatrixItemSearchDAOException { LOGGER.debug("searchMatrixItem()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); return getQueryRunner().query(connection, getMatrixItemSearchQueryFromCriterion(searchBean, params), new BeanListHandler<MatrixItem>(MatrixItem.class), params.toArray()); } catch (SQLException e) { throw new MatrixItemSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2PostDeployAction.java
@VisibleForTesting MutableList<ReorgQueryResult> getInvalidObjects(Connection conn, RichIterable<PhysicalSchema> physicalSchemas) { LOG.info("Checking for invalid objects"); String schemaInClause = physicalSchemas.collect(PhysicalSchema.TO_PHYSICAL_NAME).makeString("('", "','", "')"); try {/*from ww w .ja v a 2 s . com*/ String sql = "SELECT OBJECTSCHEMA schema, OBJECTNAME name FROM SYSCAT.INVALIDOBJECTS WHERE OBJECTSCHEMA IN " + schemaInClause; return ListAdapter.adapt(this.stmtExecutor.getJdbcTemplate().query(conn, sql, new BeanListHandler<ReorgQueryResult>(ReorgQueryResult.class))); } catch (DataAccessException e) { LOG.debug("Failed to execute new invalid objects SQL; falling back to old query"); deployMetricsCollector.addMetric("oldInvalidObjectQueryRequired", true); String sql = "SELECT CREATOR schema, NAME name FROM SYSIBM.SYSTABLES WHERE TYPE = 'V' AND STATUS = 'X' AND CREATOR IN " + schemaInClause; return ListAdapter.adapt(this.stmtExecutor.getJdbcTemplate().query(conn, sql, new BeanListHandler<ReorgQueryResult>(ReorgQueryResult.class))); } }
From source file:com.pinterest.arcee.db.DBHealthCheckDAOImpl.java
@Override public List<HealthCheckBean> getOngoingRegularHealthChecksByGroup(String groupName) throws Exception { ResultSetHandler<List<HealthCheckBean>> h = new BeanListHandler<HealthCheckBean>(HealthCheckBean.class); return new QueryRunner(dataSource).query(GET_ONGOING_HEALTHCHECKS_BY_GROUP, h, groupName, HealthCheckType.TIME_TRIGGERED.toString(), HealthCheckState.COMPLETED.toString()); }
From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java
@Override public List<BuildBean> getByCommit7(String scmCommit7, int pageIndex, int pageSize) throws Exception { ResultSetHandler<List<BuildBean>> h = new BeanListHandler<>(BuildBean.class); return new QueryRunner(dataSource).query(GET_BUILDS_BY_COMMIT_7, h, scmCommit7, (pageIndex - 1) * pageSize, pageSize);//www. j a va 2 s .com }
From source file:com.erikw.libraryloan.DatabaseBookDataAccessObject.java
@Override public List<Book> findBookByProperty(BookSearchType searchType, Object value) { String whereClause = ""; String valueClause = ""; switch (searchType) { case AUTHOR:// w w w.j av a2 s .c o m whereClause = "authors LIKE ?"; valueClause = "%" + value.toString() + "%"; break; case AVAILABLE: whereClause = "available = ?"; valueClause = value.toString(); break; case ID: whereClause = "uniqueID = ?"; valueClause = value.toString(); break; case NAME: whereClause = "name LIKE ?"; // if the particular name or column contains part of string // when searching valueClause = "%" + value.toString() + "%"; break; case PUBLISHED_YEAR: whereClause = "publishedYear = ?"; valueClause = value.toString(); break; default: System.out.println("Unknown search type"); break; } try { // BeanListHandler allows us to automatically parse fields of Book dbAccess.query(myConn, "SELECT * FROM Books WHERE " + whereClause, new BeanListHandler<Book>(Book.class), valueClause); } catch (Exception ex) { ex.printStackTrace(); } return EMPTY; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.PrioritizationDAO.java
/** * Prioritization search from a bean of criterions. * /*w w w . j av a2s.co m*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param searchBean the criterions to use for the search. * @return the resulting object list. * @since July, 2011. * @throws PrioritizationSearchDAOException if an error occurs during the * search. */ @Override public List<Prioritization> searchPrioritization(PrioritizationSearch searchBean) throws PrioritizationSearchDAOException { LOGGER.debug("searchPrioritization()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); return getQueryRunner().query(connection, getPrioritizationSearchQueryFromCriterion(searchBean, params), new BeanListHandler<Prioritization>(Prioritization.class), params.toArray()); } catch (SQLException e) { throw new PrioritizationSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.ruihu.easyshop.order.dao.OrderDao.java
private PageBean<Order> findByCriteria(List<Expression> exprList, int pc) throws SQLException { int ps = PageConstants.ORDER_PAGE_SIZE;//get records in a page /*/* w w w. j a va2s . co m*/ * 2. where by using exprList */ StringBuilder whereSql = new StringBuilder(" where 1=1"); List<Object> params = new ArrayList<Object>(); for (Expression expr : exprList) { whereSql.append(" and ").append(expr.getName()).append(" ").append(expr.getOperator()).append(" "); // where 1=1 and bid = ? if (!expr.getOperator().equals("is null")) { whereSql.append("?"); params.add(expr.getValue()); } } /* * 3. totally records */ String sql = "select count(*) from t_order" + whereSql; Number number = (Number) qr.query(sql, new ScalarHandler(), params.toArray()); int tr = number.intValue();//get all totally records /* * 4.get current records through beanlist */ sql = "select * from t_order" + whereSql + " order by ordertime desc limit ?,?"; params.add((pc - 1) * ps);// index of current page params.add(ps);//search how many records in a page List<Order> beanList = qr.query(sql, new BeanListHandler<Order>(Order.class), params.toArray()); // load every items in each order list for (Order order : beanList) { loadOrderItem(order); } /* * 5. create PageBean */ PageBean<Order> pb = new PageBean<Order>(); pb.setBeanList(beanList); pb.setPc(pc); pb.setPs(ps); pb.setTr(tr); return pb; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ProjectDAO.java
/** * Project search from a bean of criterions. * //from ww w.j a v a 2 s . c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param searchBean the criterions to use for the search. * @return the resulting object list. * @since July, 2011. * @throws ProjectSearchDAOException if an error occurs during the search. */ @Override public List<Project> searchProject(ProjectSearch searchBean) throws ProjectSearchDAOException { LOGGER.debug("searchProject()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); return getQueryRunner().query(connection, getProjectSearchQueryFromCriterion(searchBean, params), new BeanListHandler<Project>(Project.class), params.toArray()); } catch (SQLException e) { throw new ProjectSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.pinterest.arcee.db.DBHealthCheckDAOImpl.java
@Override public List<HealthCheckBean> getRegularHealthChecksByGroupAndTime(String groupName, long time) throws Exception { ResultSetHandler<List<HealthCheckBean>> h = new BeanListHandler<HealthCheckBean>(HealthCheckBean.class); return new QueryRunner(dataSource).query(GET_REGULAR_HEALTH_CHECK_BY_GROUP_AND_TIME, h, groupName, HealthCheckType.TIME_TRIGGERED.toString(), time); }