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