1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.efaps.update;
23
24 import java.sql.SQLException;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.efaps.ci.CIAdminCommon;
29 import org.efaps.db.Context;
30 import org.efaps.db.InstanceQuery;
31 import org.efaps.db.QueryBuilder;
32 import org.efaps.update.util.InstallationException;
33 import org.efaps.util.EFapsException;
34
35
36
37
38
39
40
41
42 public final class AppDependency
43 {
44
45
46
47
48 private static final Map<String, AppDependency> NAME2APPDEPENDENCY = new HashMap<String, AppDependency>();
49
50
51
52
53 private final String name;
54
55
56
57
58 private Boolean met;
59
60
61
62
63 private AppDependency(final String _name)
64 {
65 this.name = _name;
66 }
67
68
69
70
71
72 public boolean isMet()
73 throws InstallationException
74 {
75 if (this.met == null) {
76 try {
77 if (Context.getDbType().existsView(Context.getThreadContext().getConnection(), "V_ADMINTYPE")
78 && CIAdminCommon.Version.getType() != null) {
79 final QueryBuilder queryBldr = new QueryBuilder(CIAdminCommon.Version);
80 queryBldr.addWhereAttrEqValue(CIAdminCommon.Version.Name, this.name);
81 final InstanceQuery query = queryBldr.getQuery();
82 this.met = query.executeWithoutAccessCheck().size() > 0;
83 } else {
84 this.met = true;
85 }
86 } catch (final EFapsException e) {
87 throw new InstallationException("Latest version could not be found", e);
88 } catch (final SQLException e) {
89 throw new InstallationException("Latest version could not be found", e);
90 } finally {
91 if (this.met == null) {
92 this.met = true;
93 }
94 }
95 }
96 return this.met;
97 }
98
99
100
101
102
103 public String getName()
104 {
105 return this.name;
106 }
107
108 @Override
109 public String toString()
110 {
111 return this.name;
112 }
113
114 @Override
115 public int hashCode()
116 {
117 return this.name.hashCode();
118 }
119
120 @Override
121 public boolean equals(final Object _object)
122 {
123 boolean ret;
124 if (_object instanceof AppDependency) {
125 ret = this.name.equals(((AppDependency) _object).getName());
126 } else {
127 ret = false;
128 }
129 return ret;
130 }
131
132
133
134
135
136 public static AppDependency getAppDependency(final String _name)
137 {
138 final AppDependency ret;
139 if (AppDependency.NAME2APPDEPENDENCY.containsKey(_name)) {
140 ret = AppDependency.NAME2APPDEPENDENCY.get(_name);
141 } else {
142 ret = new AppDependency(_name);
143 AppDependency.NAME2APPDEPENDENCY.put(_name, ret);
144 }
145 return ret;
146 }
147
148
149
150
151 public static void initialise()
152 {
153 AppDependency.NAME2APPDEPENDENCY.clear();
154 }
155 }