Created
May 23, 2018 11:34
-
-
Save bdarfler/aee1b11956babd8887c99360100ad73f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Collection<String> parts = buildQueryParts( dbObj ); | |
if ( parts.isEmpty() ) { return ImmutableList.of(); } | |
final String query = "SELECT " + columnNames + " FROM " + dbObj.getTableName() + " WHERE " + join( parts, " AND " ); | |
return result = simpleJdbcTemplate.query( query, new BeanPropertyRowMapper<DbObj>( dbObj.getClass() ), new BeanPropertySqlParameterSource( dbObj ) ); | |
private static final Collection<String> buildQueryParts( final LocaDbObj dbObj ) { | |
return transform( filter( dbObj.getFieldNames(), new HasValue( dbObj.toMap() ) ), new BuildPart( dbObj ) ); | |
} | |
private static final class HasValue implements Predicate<String> { | |
private final Map<String, Object> map; | |
public HasValue( final Map<String, Object> map ) { | |
this.map = map; | |
} | |
public boolean apply( final String propName ) { | |
return map.get( propName ) != null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment