spring-batch Neo4jItemWriterBuilder 源码

  • 2022-08-16
  • 浏览 (411)

spring-batch Neo4jItemWriterBuilder 代码

文件路径:/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilder.java

/*
 * Copyright 2017-2021 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          https://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.springframework.batch.item.data.builder;

import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;

import org.springframework.batch.item.data.Neo4jItemWriter;
import org.springframework.util.Assert;

/**
 * A builder implementation for the {@link Neo4jItemWriter}
 *
 * @author Glenn Renfro
 * @author Mahmoud Ben Hassine
 * @since 4.0
 * @see Neo4jItemWriter
 * @deprecated since 5.0 in favor of the item writer builder from
 * https://github.com/spring-projects/spring-batch-extensions/blob/main/spring-batch-neo4j
 */
@Deprecated
public class Neo4jItemWriterBuilder<T> {

	private boolean delete = false;

	private SessionFactory sessionFactory;

	/**
	 * Boolean flag indicating whether the writer should save or delete the item at write
	 * time.
	 * @param delete true if write should delete item, false if item should be saved.
	 * Default is false.
	 * @return The current instance of the builder
	 * @see Neo4jItemWriter#setDelete(boolean)
	 */
	public Neo4jItemWriterBuilder<T> delete(boolean delete) {
		this.delete = delete;

		return this;
	}

	/**
	 * Establish the session factory that will be used to create {@link Session} instances
	 * for interacting with Neo4j.
	 * @param sessionFactory sessionFactory to be used.
	 * @return The current instance of the builder
	 * @see Neo4jItemWriter#setSessionFactory(SessionFactory)
	 */
	public Neo4jItemWriterBuilder<T> sessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;

		return this;
	}

	/**
	 * Validates and builds a {@link org.springframework.batch.item.data.Neo4jItemWriter}.
	 * @return a {@link Neo4jItemWriter}
	 */
	public Neo4jItemWriter<T> build() {
		Assert.notNull(sessionFactory, "sessionFactory is required.");
		Neo4jItemWriter<T> writer = new Neo4jItemWriter<>();
		writer.setDelete(this.delete);
		writer.setSessionFactory(this.sessionFactory);
		return writer;
	}

}

相关信息

spring-batch 源码目录

相关文章

spring-batch GemfireItemWriterBuilder 源码

spring-batch MongoItemReaderBuilder 源码

spring-batch MongoItemWriterBuilder 源码

spring-batch Neo4jItemReaderBuilder 源码

spring-batch RepositoryItemReaderBuilder 源码

spring-batch RepositoryItemWriterBuilder 源码

spring-batch package-info 源码

0  赞