-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Neo4jItemWriterBuilder.java
82 lines (71 loc) · 2.51 KB
/
Neo4jItemWriterBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* 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;
}
}