@Override
	public int update(final SqlContext sqlContext) throws SQLException {
		// パラメータログを出力する
		MDC.put(SUPPRESS_PARAMETER_LOG_OUTPUT, Boolean.FALSE.toString());

		// コンテキスト変換
		transformContext(sqlContext, false);

		StopWatch watch = null;

		try (PreparedStatement stmt = getPreparedStatement(sqlContext)) {

			// INパラメータ設定
			sqlContext.bindParams(stmt);

			if (LOG.isDebugEnabled()) {
				LOG.debug("Execute update SQL.");
				watch = new StopWatch();
				watch.start();
			}

			// 前処理
			beforeUpdate(sqlContext);

			// デフォルト最大リトライ回数を取得し、個別指定（SqlContextの値）があれば上書き
			int maxRetryCount = getMaxRetryCount();
			if (sqlContext.getMaxRetryCount() > 0) {
				maxRetryCount = sqlContext.getMaxRetryCount();
			}

			// デフォルトリトライ待機時間を取得し、個別指定（SqlContextの値）があれば上書き
			int retryWaitTime = getRetryWaitTime();
			if (sqlContext.getRetryWaitTime() > 0) {
				retryWaitTime = sqlContext.getRetryWaitTime();
			}
			int loopCount = 0;
			do {
				try {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						setSavepoint(RETRY_SAVEPOINT_NAME);
					}
					int count = getSqlFilterManager().doUpdate(sqlContext, stmt, stmt.executeUpdate());
					if ((SqlKind.INSERT.equals(sqlContext.getSqlKind()) ||
							SqlKind.BULK_INSERT.equals(sqlContext.getSqlKind()))
							&& sqlContext.hasGeneratedKeyColumns()) {
						try (ResultSet rs = stmt.getGeneratedKeys()) {
							List<BigDecimal> generatedKeyValues = new ArrayList<>();
							while (rs.next()) {
								for (int i = 0; i < sqlContext.getGeneratedKeyColumns().length; i++) {
									generatedKeyValues.add(rs.getBigDecimal(i + 1));
								}
							}
							sqlContext.setGeneratedKeyValues(
									generatedKeyValues.toArray(new BigDecimal[generatedKeyValues.size()]));
						}
					}
					return count;
				} catch (SQLException ex) {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						rollback(RETRY_SAVEPOINT_NAME);
					}
					if (maxRetryCount > loopCount) {
						String errorCode = String.valueOf(ex.getErrorCode());
						String sqlState = ex.getSQLState();
						if (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState)) {
							if (LOG.isDebugEnabled()) {
								LOG.debug(String.format(
										"Caught the error code to be retried.(%d times). Retry after %,3d ms.",
										loopCount + 1, retryWaitTime));
							}
							if (retryWaitTime > 0) {
								try {
									Thread.sleep(retryWaitTime);
								} catch (InterruptedException ie) {
									// do nothing
								}
							}
						} else {
							throw ex;
						}
					} else {
						throw ex;
					}
				} finally {
					if (maxRetryCount > 0 && getSqlConfig().getDialect().isRollbackToSavepointBeforeRetry()) {
						releaseSavepoint(RETRY_SAVEPOINT_NAME);
					}
					sqlContext.contextAttrs().put(CTX_ATTR_KEY_RETRY_COUNT, loopCount);
				}
			} while (maxRetryCount > loopCount++);
			return 0;
		} catch (SQLException ex) {
			handleException(sqlContext, ex);
			return 0;
		} finally {
			afterUpdate(sqlContext);
			if (LOG.isDebugEnabled() && watch != null) {
				watch.stop();
				LOG.debug("SQL execution time [{}] : [{}]", sqlContext.getSqlName(), watch.toString());
			}
			MDC.remove(SUPPRESS_PARAMETER_LOG_OUTPUT);
		}
	}
@ Override public int update ( final SqlContext sqlContext ) throws SQLException { MDC . put ( SUPPRESS_PARAMETER_LOG_OUTPUT , Boolean . FALSE . toString ( ) ) ; transformContext ( sqlContext , false ) ; StopWatch watch = null ; try ( PreparedStatement stmt = getPreparedStatement ( sqlContext ) ) { sqlContext . bindParams ( stmt ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Execute update SQL." ) ; watch = new StopWatch ( ) ; watch . start ( ) ; } beforeUpdate ( sqlContext ) ; int maxRetryCount = getMaxRetryCount ( ) ; if ( sqlContext . getMaxRetryCount ( ) > 0 ) { maxRetryCount = sqlContext . getMaxRetryCount ( ) ; } int retryWaitTime = getRetryWaitTime ( ) ; if ( sqlContext . getRetryWaitTime ( ) > 0 ) { retryWaitTime = sqlContext . getRetryWaitTime ( ) ; } int loopCount = 0 ; do { try { if ( maxRetryCount > 0 && getSqlConfig ( ) . getDialect ( ) . isRollbackToSavepointBeforeRetry ( ) ) { setSavepoint ( RETRY_SAVEPOINT_NAME ) ; } int count = getSqlFilterManager ( ) . doUpdate ( sqlContext , stmt , stmt . executeUpdate ( ) ) ; if ( ( SqlKind . INSERT . equals ( sqlContext . getSqlKind ( ) ) || SqlKind . BULK_INSERT . equals ( sqlContext . getSqlKind ( ) ) ) && sqlContext . hasGeneratedKeyColumns ( ) ) { try ( ResultSet rs = stmt . getGeneratedKeys ( ) ) { List < BigDecimal > generatedKeyValues = new ArrayList < > ( ) ; while ( rs . next ( ) ) { for ( int i = 0 ; i < sqlContext . getGeneratedKeyColumns ( ) . length ; i ++ ) { generatedKeyValues . add ( rs . getBigDecimal ( i + 1 ) ) ; } } sqlContext . setGeneratedKeyValues ( generatedKeyValues . toArray ( new BigDecimal [ generatedKeyValues . size ( ) ] ) ) ; } } return count ; } catch ( SQLException ex ) { if ( maxRetryCount > 0 && getSqlConfig ( ) . getDialect ( ) . isRollbackToSavepointBeforeRetry ( ) ) { rollback ( RETRY_SAVEPOINT_NAME ) ; } if ( maxRetryCount > loopCount ) { String errorCode = String . valueOf ( ex . getErrorCode ( ) ) ; String sqlState = ex . getSQLState ( ) ; if ( getSqlRetryCodes ( ) . contains ( errorCode ) || getSqlRetryCodes ( ) . contains ( sqlState ) ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( String . format ( "Caught the error code to be retried.(%d times). Retry after %,3d ms." , loopCount + 1 , retryWaitTime ) ) ; } if ( retryWaitTime > 0 ) { try { Thread . sleep ( retryWaitTime ) ; } catch ( InterruptedException ie ) { } } } else { throw ex ; } } else { throw ex ; } } finally { if ( maxRetryCount > 0 && getSqlConfig ( ) . getDialect ( ) . isRollbackToSavepointBeforeRetry ( ) ) { releaseSavepoint ( RETRY_SAVEPOINT_NAME ) ; } sqlContext . contextAttrs ( ) . put ( CTX_ATTR_KEY_RETRY_COUNT , loopCount ) ; } } while ( maxRetryCount > loopCount ++ ) ; return 0 ; } catch ( SQLException ex ) { handleException ( sqlContext , ex ) ; return 0 ; } finally { afterUpdate ( sqlContext ) ; if ( LOG . isDebugEnabled ( ) && watch != null ) { watch . stop ( ) ; LOG . debug ( "SQL execution time [{}] : [{}]" , sqlContext . getSqlName ( ) , watch . toString ( ) ) ; } MDC . remove ( SUPPRESS_PARAMETER_LOG_OUTPUT ) ; } }
@see jp.co.future.uroborosql.SqlAgent#update(jp.co.future.uroborosql.context.SqlContext)