Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37098

Re: Is this the way to work with try with resources

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Re: Is this the way to work with try with resources
Date 2017-08-09 07:01 +0200
Organization Decebal Computing
Message-ID <8760dxwd0j.fsf@munus.decebal.nl> (permalink)
References <87poc6wb9n.fsf@munus.decebal.nl> <refactor-20170808133822@ram.dialup.fu-berlin.de> <omcsep$org$1@newsreader4.netcologne.de> <refactor-20170808190144@ram.dialup.fu-berlin.de>

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Patrick Roemer <sangamon@netcologne.de> writes:
>>I'd rather move towards something like this:
>>String format = runQueryFun(stmt, COUNT_TOTAL_PROV,
>>    rs -> totalStats(rs.getInt("no")));
>>runQueryProc(stmt, COUNT_UNUSED_PROV,
>>    rs -> unusedStats(format, rs.getInt("no")));
> ...
>>- runQuery[Fun|Proc] and associated interfaces could go to a reusable
>>toolbox
>>- all JDBC jazz is confined to this method; all methods called from here
>>are JDBC agnostic
>
>   Excellent idea! I always like to separate parts of a library
>   according to the system (like JDBC) they deal with. I think
>   that this is also an important aspect of MVC, where the VC
>   contains GUI stuff, while the M contains non-GUI stuff.
>
>   I think you might mean something along the lines of (untested):
>
> private static void 
> runQueryProc 
> ( final java.sql.Statement statement,
>   final java.lang.String query,
>   final java.util.function.Consumer< java.sql.ResultSet >consumer )
> throws java.sql.SQLException
> { try( final java.sql.ResultSet set = statement.executeQuery( query )) 
>   { consumer.accept( set ); }}
>
> private static< T >T 
> runQueryFun 
> ( final java.sql.Statement statement,
>   final java.lang.String query,
>   final java.util.function.Function< java.sql.ResultSet, T > function )
> throws java.sql.SQLException
> { T result = null;
>   try( final java.sql.ResultSet set = statement.executeQuery( query )) 
>   { result = function.apply( set ); }
>   return result; }

Looks interesting. For the moment I found a solution. But this is
certainly something to look at.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-08 13:26 +0200
  Re: Is this the way to work with try with resources Martin Gregorie <martin@address-in-sig.invalid> - 2017-08-08 12:51 +0000
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:10 +0200
  Re: Is this the way to work with try with resources Patrick Roemer <sangamon@netcologne.de> - 2017-08-08 18:29 +0200
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:20 +0200
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:16 +0200
  Re: Is this the way to work with try with resources Patrick Roemer <sangamon@netcologne.de> - 2017-08-08 19:30 +0200
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 06:49 +0200
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:01 +0200
    Re: Is this the way to work with try with resources Patrick Roemer <sangamon@netcologne.de> - 2017-08-09 15:39 +0200
  Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-08 21:25 -0400
    Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-08 21:36 -0400
      Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:29 +0200
        Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-09 20:53 -0400
          Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-09 23:03 -0400
    Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-08 21:48 -0400
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 07:24 +0200
  Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 06:26 +0200
    Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 08:30 +0200
    Re: Is this the way to work with try with resources Andreas Leitgeb <avl@logic.at> - 2017-08-09 09:40 +0000
      Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 12:56 +0200
        Re: Is this the way to work with try with resources Andreas Leitgeb <avl@logic.at> - 2017-08-09 16:51 +0000
          Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 19:37 +0200
            Re: Is this the way to work with try with resources Andreas Leitgeb <avl@logic.at> - 2017-08-09 19:51 +0000
              Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 22:20 +0200
                Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 23:17 +0200
          Re: Is this the way to work with try with resources Patrick Roemer <sangamon@netcologne.de> - 2017-08-09 22:08 +0200
        Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-09 18:07 -0400
    Re: Is this the way to work with try with resources Arne Vajhøj <arne@vajhoej.dk> - 2017-08-09 18:05 -0400
  Re: Is this the way to work with try with resources Cecil Westerhof <Cecil@decebal.nl> - 2017-08-09 06:39 +0200

csiph-web