/** * Generic object finder method, used by all other {@code findObject} methods. * Object finder methods are like EJB entity bean finders, in that it is * considered an error if they return more than one result. * @return the result object, or {@code null} if not found. Subclasses may * choose to treat this as an error and throw an exception. * @see org.springframework.dao.support.DataAccessUtils#singleResult */ @Nullable public T findObject(@Nullable Object[] params, @Nullable Map<?, ?> context) throws DataAccessException { List<T> results = execute(params, context); return DataAccessUtils.singleResult(results); }
/** * Generic object finder method for named parameters. * @param paramMap a Map of parameter name to parameter object, * matching named parameters specified in the SQL statement. * Ordering is not significant. * @param context contextual information passed to the {@code mapRow} * callback method. The JDBC operation itself doesn't rely on this parameter, * but it can be useful for creating the objects of the result list. * @return a List of objects, one per row of the ResultSet. Normally all these * will be of the same class, although it is possible to use different types. */ @Nullable public T findObjectByNamedParam(Map<String, ?> paramMap, @Nullable Map<?, ?> context) throws DataAccessException { List<T> results = executeByNamedParam(paramMap, context); return DataAccessUtils.singleResult(results); }
private Optional<String> selectForUpdate(String target) { return Optional.ofNullable(DataAccessUtils.singleResult(jdbcTemplate.query(selectFromSagaLockTableSql, (rs, rowNum) -> { return rs.getString("saga_id"); }, target))); }
private Optional<String> selectForUpdate(String target) { return Optional.ofNullable(DataAccessUtils.singleResult(jdbcTemplate.query(selectFromSagaLockTableSql, (rs, rowNum) -> { return rs.getString("saga_id"); }, target))); }
/** * Decide whether the owner ORI of the transaction with the transaction number has FBI subscription qualification. * @param transactionNumber * @return */ public Boolean getfbiSubscriptionQualification(String transactionNumber){ final String sql = "SELECT fbi_subscription_qualification FROM agency_profile " + "WHERE agency_ori = (SELECT owner_ori FROM identification_transaction t WHERE t.transaction_number= ?)"; List<Boolean> fbiSubscriptionQualifications = jdbcTemplate.queryForList(sql, Boolean.class, transactionNumber); return DataAccessUtils.singleResult(fbiSubscriptionQualifications); }
/** * Decide whether the owner ORI of the transaction with the subscription ID has FBI subscription qualification. * @param subscriptionId * @return */ public Boolean getfbiSubscriptionQualification(Integer subscriptionId){ final String sql = "SELECT fbi_subscription_qualification FROM agency_profile " + "WHERE agency_ori = (SELECT owner_ori FROM identification_transaction t WHERE t.subscription_id= ?)"; List<Boolean> fbiSubscriptionQualifications = jdbcTemplate.queryForList(sql, Boolean.class, subscriptionId); return DataAccessUtils.singleResult(fbiSubscriptionQualifications); }
@Override public Integer getPortalUserId(String userName) { final List<Integer> results = this.jdbcOperations.queryForList( "SELECT USER_ID FROM UP_USER WHERE USER_NAME=?", Integer.class, userName); return DataAccessUtils.singleResult(results); }
/** * Executes the given HiveQL using the list of arguments, that results in a single object. * The script is interpreted as a URL or if that fails, as a HiveQL statement. * * @param query HiveQL * @param arguments query arguments * @return query result * @throws DataAccessException exception */ @Override public String queryForString(String query, Map<?, ?> arguments) throws DataAccessException { return DataAccessUtils.singleResult(query(query, arguments)); }
@Override public Integer getPortalUserId(String userName) { final List<Integer> results = this.jdbcOperations.queryForList( "SELECT USER_ID FROM UP_USER WHERE USER_NAME=?", Integer.class, userName); return DataAccessUtils.singleResult(results); }
public FbiRapbackSubscription getFbiRapbackSubscription(String category, String ucn) { logger.info("\n\n\n Using category: " + category + ", and ucn: " + ucn + "\n\n\n"); if ( StringUtils.isEmpty(category) || StringUtils.isEmpty(ucn)){ throw new IllegalArgumentException("category and ucn cannot be null."); } List<FbiRapbackSubscription> fbiSubscriptions = jdbcTemplate.query(FBI_SUBSCRIPTION_SELECT, new FbiSubscriptionRowMapper(), category, ucn); return DataAccessUtils.singleResult(fbiSubscriptions); }
/** * Generic object finder method, used by all other {@code findObject} methods. * Object finder methods are like EJB entity bean finders, in that it is * considered an error if they return more than one result. * @return the result object, or {@code null} if not found. Subclasses may * choose to treat this as an error and throw an exception. * @see org.springframework.dao.support.DataAccessUtils#singleResult */ public T findObject(Object[] params, Map context) throws DataAccessException { List<T> results = execute(params, context); return DataAccessUtils.singleResult(results); }
@Override public String getPortalUserName(final int uPortalUID) { final List<String> results = this.jdbcOperations.queryForList( "SELECT USER_NAME FROM UP_USER WHERE USER_ID=?", String.class, uPortalUID); return DataAccessUtils.singleResult(results); }
@Override public String getPortalUserName(final int uPortalUID) { final List<String> results = this.jdbcOperations.queryForList( "SELECT USER_NAME FROM UP_USER WHERE USER_ID=?", String.class, uPortalUID); return DataAccessUtils.singleResult(results); }
@Override public final Map<String, List<Object>> getMultivaluedUserAttributes(final Map<String, List<Object>> seed) { final Set<IPersonAttributes> people = this.getPeopleWithMultivaluedAttributes(seed); //Get the first IPersonAttributes to return data for final IPersonAttributes person = DataAccessUtils.singleResult(people); //If null or no results return null if (person == null) { return null; } //Make a mutable copy of the person's attributes return new LinkedHashMap<>(person.getAttributes()); }
@Override public final Map<String, List<Object>> getMultivaluedUserAttributes(final Map<String, List<Object>> seed) { final Set<IPersonAttributes> people = this.getPeopleWithMultivaluedAttributes(seed); //Get the first IPersonAttributes to return data for final IPersonAttributes person = DataAccessUtils.singleResult(people); //If null or no results return null if (person == null) { return null; } //Make a mutable copy of the person's attributes return new LinkedHashMap<>(person.getAttributes()); }
@Cacheable( cacheName = "org.apereo.portal.EntityTypes.ID_BY_CLASS", keyGeneratorName = ListCacheKeyGenerator.DEFAULT_BEAN_NAME) public Integer getEntityIDFromType(Class<? extends IBasicEntity> type) { return DataAccessUtils.singleResult( this.jdbcOperations.queryForList( "SELECT ENTITY_TYPE_ID FROM UP_ENTITY_TYPE WHERE ENTITY_TYPE_NAME = ?", Integer.class, type.getName())); }
@Override public final Map<String, Object> getUserAttributes(final Map<String, Object> seed) { final Set<IPersonAttributes> people = this.getPeople(seed); //Get the first IPersonAttributes to return data for final IPersonAttributes person = DataAccessUtils.singleResult(people); //If null or no results return null if (person == null) { return null; } final Map<String, List<Object>> multivaluedUserAttributes = new LinkedHashMap<>(person.getAttributes()); return this.flattenResults(multivaluedUserAttributes); }
@SuppressWarnings("deprecation") public final Map<String, Object> getUserAttributes(Map<String, Object> seed) { final Set<IPersonAttributes> people = this.getPeople(seed); //Get the first IPersonAttributes to return data for final IPersonAttributes person = (IPersonAttributes)DataAccessUtils.singleResult(people); //If null or no results return null if (person == null) { return null; } final Map<String, List<Object>> multivaluedUserAttributes = new LinkedHashMap<String, List<Object>>(person.getAttributes()); return this.flattenResults(multivaluedUserAttributes); }
@Override public final Map<String, Object> getUserAttributes(final Map<String, Object> seed) { final Set<IPersonAttributes> people = this.getPeople(seed); //Get the first IPersonAttributes to return data for final IPersonAttributes person = DataAccessUtils.singleResult(people); //If null or no results return null if (person == null) { return null; } final Map<String, List<Object>> multivaluedUserAttributes = new LinkedHashMap<>(person.getAttributes()); return this.flattenResults(multivaluedUserAttributes); }
public <T> T querySingleResult(T entity) { BoundSql boundSql = Criteria.select(entity.getClass()).mappingHandler(getMappingHandler()).build(entity, true); //采用list方式查询,当记录不存在时返回null而不会抛出异常 List<T> list = (List<T>) jdbcTemplate.query(boundSql.getSql(), boundSql.getParameters().toArray(), this.getRowMapper(entity.getClass())); return DataAccessUtils.singleResult(list); }