1 package liquibase.ext.spatial.sqlgenerator;
2
3 import java.util.Map.Entry;
4
5 import liquibase.database.Database;
6 import liquibase.exception.ValidationErrors;
7 import liquibase.sql.Sql;
8 import liquibase.sqlgenerator.SqlGeneratorChain;
9 import liquibase.sqlgenerator.core.InsertGenerator;
10 import liquibase.statement.core.InsertStatement;
11
12
13
14
15
16
17
18 public abstract class AbstractSpatialInsertGenerator extends InsertGenerator implements
19 WktInsertOrUpdateGenerator {
20 @Override
21 public int getPriority() {
22 return super.getPriority() + 1;
23 }
24
25 @Override
26 public ValidationErrors validate(final InsertStatement statement, final Database database,
27 final SqlGeneratorChain sqlGeneratorChain) {
28 return sqlGeneratorChain.validate(statement, database);
29 }
30
31
32
33
34 @Override
35 public Sql[] generateSql(final InsertStatement statement, final Database database,
36 final SqlGeneratorChain sqlGeneratorChain) {
37 for (final Entry<String, Object> entry : statement.getColumnValues().entrySet()) {
38 entry.setValue(handleColumnValue(entry.getValue(), database));
39 }
40 return super.generateSql(statement, database, sqlGeneratorChain);
41 }
42
43
44
45
46
47 @Override
48 public boolean looksLikeFunctionCall(final String value, final Database database) {
49 final boolean result;
50 if (value.trim().toUpperCase().startsWith(getGeomFromWktFunction().trim().toUpperCase())) {
51 result = true;
52 } else {
53 result = super.looksLikeFunctionCall(value, database);
54 }
55 return result;
56 }
57
58
59
60
61
62
63
64
65
66
67 @Override
68 public boolean isSridRequiredInFunction(final Database database) {
69 return false;
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83 protected Object handleColumnValue(final Object oldValue, final Database database) {
84 final Object newValue = WktConversionUtils.handleColumnValue(oldValue, database, this);
85 return newValue;
86 }
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public String convertToFunction(final String wkt, final String srid, final Database database) {
99 final String function = WktConversionUtils.convertToFunction(wkt, srid, database, this);
100 return function;
101 }
102 }