1 | |
package org.jtheque.core.managers.schema; |
2 | |
|
3 | |
import org.jtheque.core.managers.Managers; |
4 | |
import org.jtheque.core.managers.properties.IPropertiesManager; |
5 | |
import org.jtheque.core.utils.CoreUtils; |
6 | |
import org.jtheque.utils.Constants; |
7 | |
import org.jtheque.utils.StringUtils; |
8 | |
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public abstract class AbstractSchema implements Schema { |
33 | |
private SimpleJdbcTemplate jdbcTemplate; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public SimpleJdbcTemplate getJdbcTemplate(){ |
41 | 0 | if(jdbcTemplate == null){ |
42 | 0 | jdbcTemplate = CoreUtils.getBean("jdbcTemplate"); |
43 | |
} |
44 | |
|
45 | 0 | return jdbcTemplate; |
46 | |
} |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public void update(String request, Object... args){ |
55 | 0 | getJdbcTemplate().update(request, args); |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public final int compareTo(Schema other) { |
60 | 0 | boolean hasDependency = StringUtils.isNotEmpty(getDependencies()); |
61 | 0 | boolean hasOtherDependency = StringUtils.isNotEmpty(other.getDependencies()); |
62 | |
|
63 | 0 | if (hasDependency && !hasOtherDependency) { |
64 | 0 | return 1; |
65 | 0 | } else if (!hasDependency && hasOtherDependency) { |
66 | 0 | return -1; |
67 | 0 | } else if(hasDependency && hasOtherDependency){ |
68 | 0 | for (String dependency : other.getDependencies()) { |
69 | 0 | if (dependency.equals(getId())) { |
70 | 0 | return -1; |
71 | |
} |
72 | |
} |
73 | |
|
74 | 0 | for (String dependency : getDependencies()) { |
75 | 0 | if (dependency.equals(other.getId())) { |
76 | 0 | return 1; |
77 | |
} |
78 | |
} |
79 | |
} |
80 | |
|
81 | 0 | return 0; |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public int hashCode() { |
86 | 0 | int hash = Constants.HASH_CODE_START; |
87 | |
|
88 | 0 | hash = Constants.HASH_CODE_PRIME * hash + getVersion().hashCode(); |
89 | 0 | hash = Constants.HASH_CODE_PRIME * hash + getId().hashCode(); |
90 | |
|
91 | 0 | for(String dependency : getDependencies()){ |
92 | 0 | hash = Constants.HASH_CODE_PRIME * hash + dependency.hashCode(); |
93 | |
} |
94 | |
|
95 | 0 | return hash; |
96 | |
} |
97 | |
|
98 | |
@Override |
99 | |
public boolean equals(Object obj) { |
100 | 0 | return Managers.getManager(IPropertiesManager.class).areEquals(this, obj, "id", "version"); |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public final String toString() { |
105 | 0 | return getId() + ':' + getVersion(); |
106 | |
} |
107 | |
} |