List of usage examples for org.apache.commons.lang3 ExtendedStringUtils safeCompare
public static final int safeCompare(String s1, String s2, boolean caseSensitive)
null
's From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override @Transactional(readOnly = true)/* w w w .jav a2 s . c o m*/ public List<String> findEntities(final String propName, final Predicate<? super Serializable> predicate) { if (StringUtils.isEmpty(propName)) { throw new IllegalArgumentException( "findEntities(" + getEntityClass().getSimpleName() + ") no property specified"); } if (predicate == null) { throw new IllegalArgumentException( "findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "] no predicate"); } final Set<String> internalIdsSet = new HashSet<String>(); final Set<String> matchingSet = jdbcAccessor.query("SELECT " + PROPS_TABLE_ALIAS + "." + PROP_OWNER_COL + " AS " + PROP_OWNER_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_NAME_COL + " AS " + PROP_NAME_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_TYPE_COL + " AS " + PROP_TYPE_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_VALUE_COL + " AS " + PROP_VALUE_COL + " ," + ENTITIES_TABLE_ALIAS + "." + ENTITY_ID_COL + " AS " + ENTITY_ID_COL + " FROM " + ENTITY_PROPERTIES_TABLE + " AS " + PROPS_TABLE_ALIAS + " INNER JOIN " + IDENTIFIED_ENTITIES_TABLE + " AS " + ENTITIES_TABLE_ALIAS + " ON " + ENTITIES_TABLE_ALIAS + "." + INTERNAL_ID_COL + " = " + PROPS_TABLE_ALIAS + "." + PROP_OWNER_COL + " AND " + ENTITIES_TABLE_ALIAS + "." + ENTITY_TYPE_COL + " = :" + ENTITY_TYPE_COL + " AND " + PROPS_TABLE_ALIAS + "." + PROP_NAME_COL + " = :" + PROP_NAME_COL, new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; { put(ENTITY_TYPE_COL, getEntityClass().getSimpleName()); put(PROP_NAME_COL, propName); } }, new ResultSetExtractor<Set<String>>() { @Override @SuppressWarnings("synthetic-access") public Set<String> extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { int rowNum = rs.getRow(); Pair<String, Serializable> rowValue = valueMapper.mapRow(rs, rowNum); String rowName = rowValue.getLeft(); String ownerId = rs.getString(ENTITY_ID_COL); // just for safety if (ExtendedStringUtils.safeCompare(propName, rowName, false) != 0) { logger.warn("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " mismatched property name at row " + rowNum + " for owner=" + ownerId + ": " + rowName); continue; } Serializable propValue = rowValue.getRight(); if (!predicate.evaluate(propValue)) { if (logger.isTraceEnabled()) { logger.trace("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " skip row " + rowNum + " value=" + propValue + " for owner=" + ownerId); } continue; } if (StringUtils.isEmpty(ownerId)) { throw new SQLException("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " no owner for row " + rowNum + " on matching value=" + propValue); } if (logger.isTraceEnabled()) { logger.trace("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " matched row " + rowNum + " value=" + propValue + " for owner=" + ownerId); } if (!internalIdsSet.add(ownerId)) { continue; // debug breakpoint } } return internalIdsSet; } }); if (ExtendedCollectionUtils.isEmpty(matchingSet)) { return Collections.emptyList(); } else { return new ArrayList<String>(matchingSet); } }