001/*002 * Copyright 2017 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.batch.item.data.builder;018019020import java.lang.reflect.Method;021import java.util.ArrayList;022import java.util.Arrays;023import java.util.List;024025import org.springframework.batch.item.data.RepositoryItemWriter;026import org.springframework.cglib.proxy.Enhancer;027import org.springframework.cglib.proxy.MethodInterceptor;028import org.springframework.cglib.proxy.MethodProxy;029import org.springframework.data.repository.CrudRepository;030import org.springframework.util.Assert;031032/**033 * A builder implementation for the {@link RepositoryItemWriter}.034 *035 * @author Glenn Renfro036 * @since 4.0037 * @see RepositoryItemWriter038 */039public class RepositoryItemWriterBuilder<T> {040041 private CrudRepository<T, ?> repository;042043 private String methodName;044045 private RepositoryMethodReference repositoryMethodReference;046047 /**048 * Specifies what method on the repository to call. This method must have the type of049 * object passed to this writer as the <em>sole</em> argument.050 *051 * @param methodName the name of the method to be used for saving the item.052 * @return The current instance of the builder.053 * @see RepositoryItemWriter#setMethodName(String)054 */055 public RepositoryItemWriterBuilder<T> methodName(String methodName) {056 this.methodName = methodName;057058 return this;059 }060061 /**062 * Set the {@link org.springframework.data.repository.CrudRepository} implementation063 * for persistence064 *065 * @param repository the Spring Data repository to be set066 * @return The current instance of the builder.067 * @see RepositoryItemWriter#setRepository(CrudRepository)068 */069 public RepositoryItemWriterBuilder<T> repository(CrudRepository<T, ?> repository) {070 this.repository = repository;071072 return this;073 }074075 /**076 * Specifies a repository and the type-safe method to call for the writer. The method077 * configured via this mechanism must take