Created
May 23, 2018 11:33
-
-
Save bdarfler/708fd8584f92c6c25cdd64e3c017cb03 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 = buildUpdateParts( dbObj ); | |
if ( parts.isEmpty() ) { return; } | |
final String query = "UPDATE " + dbObj.getTableName() + " SET " + join( parts, ", " ) + " WHERE id = :id"; | |
simpleJdbcTemplate.update( query, new BeanPropertySqlParameterSource( dbObj ) ); | |
private static final Collection<String> buildUpdateParts( final LocaDbObj dbObj ) { | |
return transform( filter( dbObj.getFieldNames(), not( IS_ID ) ), new BuildPart( dbObj ) ); | |
} | |
private static final class BuildPart implements Function<String, String> { | |
private final LocaDbObj dbObj; | |
public BuildPart( final LocaDbObj dbObj ) { | |
this.dbObj = dbObj; | |
} | |
public String apply( final String propName ) { | |
return dbObj.getColumnName( propName ) + " = :" + propName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment