Guest User

Untitled

a guest
May 27th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. final Collection<String> parts = buildUpdateParts( dbObj );
  2. if ( parts.isEmpty() ) { return; }
  3. final String query = "UPDATE " + dbObj.getTableName() + " SET " + join( parts, ", " ) + " WHERE id = :id";
  4. simpleJdbcTemplate.update( query, new BeanPropertySqlParameterSource( dbObj ) );
  5. private static final Collection<String> buildUpdateParts( final LocaDbObj dbObj ) {
  6.  return transform( filter( dbObj.getFieldNames(), not( IS_ID ) ), new BuildPart( dbObj ) );
  7. }
  8. private static final class BuildPart implements Function<String, String> {
  9.  private final LocaDbObj dbObj;
  10.  public BuildPart( final LocaDbObj dbObj ) {
  11.  this.dbObj = dbObj;
  12.  }
  13.  public String apply( final String propName ) {
  14.  return dbObj.getColumnName( propName ) + " = :" + propName;
  15.  }
  16. }
Add Comment
Please, Sign In to add comment