List of usage examples for org.apache.commons.dbutils.handlers ScalarHandler ScalarHandler
public ScalarHandler(String columnName)
From source file:com.che.software.testato.domain.dao.jdbc.impl.HierarchyDAO.java
/** * Checks if a hierarchy is already existing for a given version id. * /* w w w. j a v a 2 s .c o m*/ * @author Clement HELIOU (clement.heliou@che-software.com). * @param versionId the version id to check * @return true if a hierarchy is already existing, else false. * @since July, 2011. * @throws HierarchySearchDAOException if an error occurs during the search. */ @Override public boolean isHierarchyExistingFromVersionId(int versionId) throws HierarchySearchDAOException { LOGGER.debug("isHierarchyExistingFromVersionId(" + versionId + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Boolean) getQueryRunner().query(connection, "SELECT EXISTS ( SELECT hierarchy_id FROM hierarchy_version WHERE version_id = ? ) AS result ", new ScalarHandler("result"), new Object[] { versionId }); } catch (SQLException e) { throw new HierarchySearchDAOException(e); } finally { if (null != connection) { try { connection.close(); } catch (SQLException e) { throw new HierarchySearchDAOException(e); } } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ScriptDAO.java
/** * Recursive method. Creates the items for a given script. Then, for each * item, makes a recursive call to create their children items. The stop * condition is reached when variants are discovered in an item. * /*w w w . ja va2 s . co m*/ * @param connection the connection to use. * @param items the items to create. * @param scriptId the parent script. Will be the same for all items. * @param depth the level of the items to create. Default is one and it's * incremented at each iteration. * @param hierarchyId the related hierarchy id. * @throws SQLException if an SQLException occurs during the creations. */ private void createItems(Connection connection, List<MapArrow> items, int scriptId, int depth, int hierarchyId) throws SQLException { LOGGER.debug("createItems(" + items.size() + " items," + scriptId + "," + depth + ")."); for (int i = 1; i <= items.size(); i++) { MapArrow item = items.get(i - 1); getQueryRunner().update(connection, "INSERT INTO script_item(script_item_id, script_id, \"ORDER\", label) VALUES(nextval('script_item_seq'),?,?,?) ", new Object[] { scriptId, i, "[" + item.getSourceLabel() + "," + item.getLabel() + "," + item.getTargetLabel() + "]" }); Integer createdItem = (Integer) getQueryRunner().query(connection, "SELECT MAX(script_item_id)::int AS scriptItemId FROM script_item ", new ScalarHandler("scriptItemId")); if (null != item.getScripts() && !item.getScripts().isEmpty()) { for (ScriptCreation itemScripts : item.getScripts()) { getQueryRunner().update(connection, "INSERT INTO script(script_id, hierarchy_id, label, depth, parent_script_item) VALUES(nextval('script_seq'), ?, '', ?, ?) ", new Object[] { hierarchyId, (depth + 1), createdItem }); Integer createdScript = (Integer) getQueryRunner().query(connection, "SELECT MAX(script_id)::int AS scriptId FROM script ", new ScalarHandler("scriptId")); createItems(connection, itemScripts.getScriptArrows(), createdScript, (depth + 1), hierarchyId); } } else { // Stop condition. for (int j = 1; j <= item.getVariants().size(); j++) { getQueryRunner().update(connection, "INSERT INTO script(script_id, hierarchy_id, label, depth, parent_script_item) VALUES(nextval('script_seq'), ?, '', ?, ?) ", new Object[] { hierarchyId, (depth + 1), createdItem }); Integer createdScript = (Integer) getQueryRunner().query(connection, "SELECT MAX(script_id)::int AS scriptId FROM script ", new ScalarHandler("scriptId")); Variant variant = item.getVariants().get(j - 1); getQueryRunner().update(connection, "INSERT INTO script_item(script_item_id, script_id, \"ORDER\", label) VALUES(nextval('script_item_seq'),?,?,?) ", new Object[] { createdScript, j, variant.getLabel() }); } } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.VariantDAO.java
/** * Variant search from a bean of criterions. * /*from w w w. ja v a 2 s . com*/ * @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 VariantSearchDAOException if an error occurs during the search. */ @Override public List<Variant> searchVariant(VariantSearch searchBean) throws VariantSearchDAOException { LOGGER.debug("searchVariant()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); List<Variant> variants = getQueryRunner().query(connection, getVariantSearchQueryFromCriterion(searchBean, params), new BeanListHandler<Variant>(Variant.class), params.toArray()); for (Variant variant : variants) { variant.setVariantType(VariantTypes.valueOf((String) getQueryRunner().query(connection, "SELECT variant_type AS variantTypeAsString FROM variant WHERE variant_id = ? ", new ScalarHandler("variantTypeAsString"), new Object[] { variant.getVariantId() }))); } return variants; } catch (SQLException e) { throw new VariantSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlTagService.java
private TagItem findOrCreateTagItemByName(final String name, final Connection conn) throws SQLException { TagItem result = get(name);//w ww . j a v a2 s . c o m if (result == null) { final Object[] params = { name, config.getTagServiceUserAdmin(), config.getTagServiceUserAdmin() }; final Long id = new QueryRunner().insert(conn, SQL_INSERT_TAG_ITEM, new ScalarHandler<>(1), params); result = new TagItem(); result.setName(name); result.setId(id); } return result; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ElementDAO.java
/** * Checks if some element have been setted for a given case test. In other * words, is able to say if a procedural diagram has already been setted or * not./*w w w . j av a 2s. com*/ * * @author Clement HELIOU (clement.heliou@che-software.com). * @param caseTestId the case test id. * @return true if the procedural diagram has already been setted, else * false. * @since July, 2011. * @throws ElementSearchDAOException if an error occurs during the search. */ @Override public boolean isElementExistingFromCaseTestId(int testCaseId) throws ElementSearchDAOException { LOGGER.debug("isElementExistingFromCaseTestId(" + testCaseId + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Boolean) getQueryRunner().query(connection, "SELECT EXISTS ( SELECT element_id FROM element WHERE test_case_id = ? ) AS result ", new ScalarHandler("result"), new Object[] { testCaseId }); } catch (SQLException e) { throw new ElementSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.IterationDAO.java
/** * Retrieves the current iteration to process for a given prioritization. * //from w w w . j a v a 2 s .co m * @author Clement HELIOU (clement.heliou@che-software.com). * @param prioritization the given prioritization. * @return the current iteration to process id. * @since July, 2011. * @throws IterationSearchDAOException if an error occurs during the search. */ @Override public int getCurrentIterationFromPrioritization(Prioritization prioritization) throws IterationSearchDAOException { LOGGER.debug("getCurrentIterationFromPrioritization(" + prioritization + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Integer) getQueryRunner().query(connection, "SELECT COALESCE(MAX(iteration_id),0)::int AS iterationId FROM iteration WHERE prioritization_id = ? ", new ScalarHandler("iterationId"), new Object[] { prioritization.getPrioritizationId() }); } catch (SQLException e) { throw new IterationSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ActionDAO.java
/** * Checks if some action have been setted for a given action plan. In other * words, is able to say if a map has already been setted or not. * // ww w . ja v a 2 s . c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param actionPlanId the action plan id. * @return true if the map has already been setted, else false. * @since July, 2011. * @throws ActionSearchDAOException if an error occurs during the search. */ @Override public boolean isActionExistingFromActionPlanId(int actionPlanId) throws ActionSearchDAOException { LOGGER.debug("isActionExistingFromActionPlanId(" + actionPlanId + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Boolean) getQueryRunner().query(connection, "SELECT EXISTS( SELECT action_id FROM action WHERE action_plan_id = ? ) AS result ", new ScalarHandler("result"), new Object[] { actionPlanId }); } catch (SQLException e) { throw new ActionSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.netflix.metacat.usermetadata.mysql.MySqlLookupService.java
private Lookup findOrCreateLookupByName(final String name, final Connection conn) throws SQLException { Lookup lookup = get(name);//from w w w. j a v a 2 s.c om if (lookup == null) { final Object[] params = { name, STRING_TYPE, config.getLookupServiceUserAdmin(), config.getLookupServiceUserAdmin(), }; final Long lookupId = new QueryRunner().insert(conn, SQL_INSERT_LOOKUP, new ScalarHandler<>(1), params); lookup = new Lookup(); lookup.setName(name); lookup.setId(lookupId); } return lookup; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.IterationDAO.java
/** * Retrieves the remaining scripts count for a given prioritization. * //from w w w . j av a 2s .com * @author Clement HELIOU (clement.heliou@che-software.com). * @param prioritization the given prioritization. * @return the resulting count. * @since July, 2011. * @throws IterationSearchDAOException if an error occurs during the search. */ @Override public int getRemainingScriptsCountFromPrioritization(Prioritization prioritization) throws IterationSearchDAOException { LOGGER.debug("getRemainingScriptsCountFromPrioritization(" + prioritization.getPrioritizationId() + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Integer) getQueryRunner().query(connection, "SELECT COALESCE(((MAX(depth)-MIN(depth))+1),0)::int AS result FROM script WHERE hierarchy_id = ? AND NOT EXISTS( SELECT iteration_assignment_id FROM comparisonMatrixItem WHERE first_script = script_id ) ", new ScalarHandler("result"), new Object[] { prioritization.getHierarchyId() }); } catch (SQLException e) { throw new IterationSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.IterationDAO.java
/** * Retrieves the scripts count for a given iteration. * //from w w w. ja va2 s .co m * @author Clement HELIOU (clement.heliou@che-software.com). * @param iterationId the given iteration id. * @return the resulting scripts count. * @since July, 2011. * @throws IterationSearchDAOException if an error occurs during a search. */ @Override public int getScriptsCountFromIteration(int iterationId) throws IterationSearchDAOException { LOGGER.debug("getScriptsCountFromIteration(" + iterationId + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Integer) getQueryRunner().query(connection, "SELECT COUNT(DISTINCT(script_id))::int AS result FROM script JOIN comparisonMatrixItem ON(first_script = script_id) JOIN iteration_assignment USING(iteration_assignment_id) WHERE iteration_id = ? ", new ScalarHandler("result"), new Object[] { iterationId }); } catch (SQLException e) { throw new IterationSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }