3 * Copyright (C) 2010 Guillaume Cottenceau and MNC S.A.
5 * This file is part of sdbl4j, and is licensed under the Apache 2.0 license.
11 import org.apache.log4j.Logger;
13 import java.sql.PreparedStatement;
14 import java.sql.SQLException;
16 public abstract class DBUpdateService {
18 private static Logger log = Logger.getLogger( DBUpdateService.class );
20 protected static int executeUpdate( PreparedStatement ps )
22 // synchronize for autocommit and rollback stuff of batched update running on the same connection
23 synchronized ( ps.getConnection() ) {
24 if ( log.isDebugEnabled() ) {
25 long begin = System.currentTimeMillis();
26 int result = ps.executeUpdate();
27 log.debug( ( System.currentTimeMillis() - begin ) + " ms for: " + ps.toString().replaceAll( "\\s+", " " )
28 + "[" + DBUtils.getStackTrace()[2].getClassName() + "]" );
31 return ps.executeUpdate();