1 package org.neo4j.talend;
2
3 import java.lang.reflect.Field;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8
9
10
11
12 abstract class Neo4jBatchInserterAbstract {
13
14
15
16
17 protected Neo4jBatchDatabase batchDb;
18
19
20
21
22
23
24 public Neo4jBatchInserterAbstract(Neo4jBatchDatabase batchDb) {
25 this.batchDb = batchDb;
26 }
27
28
29
30
31
32
33
34 public abstract void create(Object incoming, List<String> columnList) throws IllegalAccessException;
35
36
37
38
39 public abstract void finish();
40
41
42
43
44
45
46
47
48 protected Object getObjectProperty(Object obj, String property) throws IllegalAccessException {
49 Object value = null;
50
51 Class<?> cls = obj.getClass();
52 Field[] fields = cls.getFields();
53
54 for (Field field : fields) {
55 if (field.getName().equals(property)) {
56 value = field.get(obj);
57 }
58 }
59
60 return value;
61 }
62
63
64
65
66
67
68
69
70
71 protected Map<String, Object> constructMapFromObject(Object obj, List<String> columnList) throws IllegalAccessException {
72
73 Map<String, Object> properties = new HashMap<>();
74 for (String column : columnList) {
75 Object value = this.getObjectProperty(obj, column);
76
77
78 Object transValue = null;
79 if (value != null) {
80
81 if (value instanceof java.sql.Date) {
82 transValue = ((java.sql.Date) value).getTime();
83 }
84
85 if (value instanceof java.sql.Timestamp) {
86 transValue = ((java.sql.Timestamp) value).getTime();
87 }
88
89 if (value instanceof java.util.Date) {
90 transValue = ((java.util.Date) value).getTime();
91 }
92
93 if (transValue == null) {
94 transValue = value;
95 }
96
97 properties.put(column, transValue);
98 }
99 }
100 return properties;
101 }
102
103 }