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


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

Logging database statement duration in a DRY way

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Logging database statement duration in a DRY way
Date 2016-08-19 14:32 +0200
Organization Decebal Computing
Message-ID <87wpjdhrbm.fsf@Equus.decebal.nl> (permalink)

Show all headers | View raw


I like to log the time it takes for certain database actions. At the
moment I do this like this:
    startTime = System.nanoTime();
    ps = conn.prepareStatement(insertLine);
    ps.setString(1, className);
    ps.setLong(  2, pid);
    ps.setLong(  3, free);
    ps.setLong(  4, rt.maxMemory() / divideValue);
    ps.setLong(  5, total);
    ps.executeUpdate();
    ps.close();
    stopTime = System.nanoTime();
    logMessage(String.format("preparedStatement saveMemoryLineNoGC took %f milliseconds",
                             (stopTime - startTime) * 1E-6));

This works, but I need to copy the first and last two statements and
edit the last one, so I was wondering if this could be done more DRY
(Do not Repeat Yourself). In C(++) you would use a macro, but as far
as I know this is not possible with Java.

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

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


Thread

Logging database statement duration in a DRY way Cecil Westerhof <Cecil@decebal.nl> - 2016-08-19 14:32 +0200
  Re: Logging database statement duration in a DRY way Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-19 09:05 -0400
    Re: Logging database statement duration in a DRY way Cecil Westerhof <Cecil@decebal.nl> - 2016-08-19 20:54 +0200
  Re: Logging database statement duration in a DRY way Cecil Westerhof <Cecil@decebal.nl> - 2016-08-19 15:12 +0200
    Re: Logging database statement duration in a DRY way Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-19 10:01 -0400
    Re: Logging database statement duration in a DRY way Arne Vajhøj <arne@vajhoej.dk> - 2016-08-19 22:17 -0400
      Re: Logging database statement duration in a DRY way Arne Vajhøj <arne@vajhoej.dk> - 2016-08-19 22:37 -0400
  Re: Logging database statement duration in a DRY way Martin Gregorie <martin@address-in-sig.invalid> - 2016-08-19 16:05 +0000
    Re: Logging database statement duration in a DRY way Eric Douglas <e.d.programmer@gmail.com> - 2016-08-19 10:06 -0700
  Re: Logging database statement duration in a DRY way Steven Simpson <ss@my.domain.invalid> - 2016-08-19 22:34 +0100

csiph-web