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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.db;
import java.util.IdentityHashMap;
import java.util.Map;
import org.sonar.db.ce.CeActivityDao;
import org.sonar.db.ce.CeQueueDao;
import org.sonar.db.ce.CeScannerContextDao;
import org.sonar.db.ce.CeTaskInputDao;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentKeyUpdaterDao;
import org.sonar.db.component.ComponentLinkDao;
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.duplication.DuplicationDao;
import org.sonar.db.event.EventDao;
import org.sonar.db.issue.IssueChangeDao;
import org.sonar.db.issue.IssueDao;
import org.sonar.db.es.EsQueueDao;
import org.sonar.db.loadedtemplate.LoadedTemplateDao;
import org.sonar.db.measure.MeasureDao;
import org.sonar.db.measure.custom.CustomMeasureDao;
import org.sonar.db.metric.MetricDao;
import org.sonar.db.notification.NotificationQueueDao;
import org.sonar.db.organization.OrganizationDao;
import org.sonar.db.organization.OrganizationMemberDao;
import org.sonar.db.permission.AuthorizationDao;
import org.sonar.db.permission.GroupPermissionDao;
import org.sonar.db.permission.UserPermissionDao;
import org.sonar.db.permission.template.PermissionTemplateCharacteristicDao;
import org.sonar.db.permission.template.PermissionTemplateDao;
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.DefaultQProfileDao;
import org.sonar.db.qualityprofile.QProfileChangeDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleRepositoryDao;
import org.sonar.db.schemamigration.SchemaMigrationDao;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.user.GroupDao;
import org.sonar.db.user.GroupMembershipDao;
import org.sonar.db.user.RoleDao;
import org.sonar.db.user.UserDao;
import org.sonar.db.user.UserGroupDao;
import org.sonar.db.user.UserTokenDao;
import org.sonar.db.webhook.WebhookDeliveryDao;
public class DbClient {
private final Database database;
private final MyBatis myBatis;
private final DBSessions dbSessions;
private final SchemaMigrationDao schemaMigrationDao;
private final AuthorizationDao authorizationDao;
private final OrganizationDao organizationDao;
private final OrganizationMemberDao organizationMemberDao;
private final QualityProfileDao qualityProfileDao;
private final LoadedTemplateDao loadedTemplateDao;
private final PropertiesDao propertiesDao;
private final InternalPropertiesDao internalPropertiesDao;
private final SnapshotDao snapshotDao;
private final ComponentDao componentDao;
private final ResourceDao resourceDao;
private final ComponentKeyUpdaterDao componentKeyUpdaterDao;
private final MeasureDao measureDao;
private final UserDao userDao;
private final UserGroupDao userGroupDao;
private final UserTokenDao userTokenDao;
private final GroupMembershipDao groupMembershipDao;
private final RoleDao roleDao;
private final GroupPermissionDao groupPermissionDao;
private final PermissionTemplateDao permissionTemplateDao;
private final PermissionTemplateCharacteristicDao permissionTemplateCharacteristicDao;
private final IssueDao issueDao;
private final IssueChangeDao issueChangeDao;
private final CeActivityDao ceActivityDao;
private final CeQueueDao ceQueueDao;
private final CeTaskInputDao ceTaskInputDao;
private final CeScannerContextDao ceScannerContextDao;
private final FileSourceDao fileSourceDao;
private final ComponentLinkDao componentLinkDao;
private final EventDao eventDao;
private final PurgeDao purgeDao;
private final QualityGateDao qualityGateDao;
private final QualityGateConditionDao gateConditionDao;
private final ProjectQgateAssociationDao projectQgateAssociationDao;
private final DuplicationDao duplicationDao;
private final NotificationQueueDao notificationQueueDao;
private final CustomMeasureDao customMeasureDao;
private final MetricDao metricDao;
private final GroupDao groupDao;
private final RuleDao ruleDao;
private final RuleRepositoryDao ruleRepositoryDao;
private final ActiveRuleDao activeRuleDao;
private final QProfileChangeDao qProfileChangeDao;
private final UserPermissionDao userPermissionDao;
private final WebhookDeliveryDao webhookDeliveryDao;
private final DefaultQProfileDao defaultQProfileDao;
private final EsQueueDao esQueueDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
this.myBatis = myBatis;
this.dbSessions = dbSessions;
Map<Class, Dao> map = new IdentityHashMap<>();
for (Dao dao : daos) {
map.put(dao.getClass(), dao);
}
schemaMigrationDao = getDao(map, SchemaMigrationDao.class);
authorizationDao = getDao(map, AuthorizationDao.class);
organizationDao = getDao(map, OrganizationDao.class);
organizationMemberDao = getDao(map, OrganizationMemberDao.class);
qualityProfileDao = getDao(map, QualityProfileDao.class);
loadedTemplateDao = getDao(map, LoadedTemplateDao.class);
propertiesDao = getDao(map, PropertiesDao.class);
internalPropertiesDao = getDao(map, InternalPropertiesDao.class);
snapshotDao = getDao(map, SnapshotDao.class);
componentDao = getDao(map, ComponentDao.class);
resourceDao = getDao(map, ResourceDao.class);
componentKeyUpdaterDao = getDao(map, ComponentKeyUpdaterDao.class);
measureDao = getDao(map, MeasureDao.class);
userDao = getDao(map, UserDao.class);
userGroupDao = getDao(map, UserGroupDao.class);
userTokenDao = getDao(map, UserTokenDao.class);
groupMembershipDao = getDao(map, GroupMembershipDao.class);
roleDao = getDao(map, RoleDao.class);
groupPermissionDao = getDao(map, GroupPermissionDao.class);
permissionTemplateDao = getDao(map, PermissionTemplateDao.class);
permissionTemplateCharacteristicDao = getDao(map, PermissionTemplateCharacteristicDao.class);
issueDao = getDao(map, IssueDao.class);
issueChangeDao = getDao(map, IssueChangeDao.class);
ceActivityDao = getDao(map, CeActivityDao.class);
ceQueueDao = getDao(map, CeQueueDao.class);
ceTaskInputDao = getDao(map, CeTaskInputDao.class);
ceScannerContextDao = getDao(map, CeScannerContextDao.class);
fileSourceDao = getDao(map, FileSourceDao.class);
componentLinkDao = getDao(map, ComponentLinkDao.class);
eventDao = getDao(map, EventDao.class);
purgeDao = getDao(map, PurgeDao.class);
qualityGateDao = getDao(map, QualityGateDao.class);
gateConditionDao = getDao(map, QualityGateConditionDao.class);
projectQgateAssociationDao = getDao(map, ProjectQgateAssociationDao.class);
duplicationDao = getDao(map, DuplicationDao.class);
notificationQueueDao = getDao(map, NotificationQueueDao.class);
customMeasureDao = getDao(map, CustomMeasureDao.class);
metricDao = getDao(map, MetricDao.class);
groupDao = getDao(map, GroupDao.class);
ruleDao = getDao(map, RuleDao.class);
ruleRepositoryDao = getDao(map, RuleRepositoryDao.class);
activeRuleDao = getDao(map, ActiveRuleDao.class);
qProfileChangeDao = getDao(map, QProfileChangeDao.class);
userPermissionDao = getDao(map, UserPermissionDao.class);
webhookDeliveryDao = getDao(map, WebhookDeliveryDao.class);
defaultQProfileDao = getDao(map, DefaultQProfileDao.class);
esQueueDao = getDao(map, EsQueueDao.class);
}
public DbSession openSession(boolean batch) {
return dbSessions.openSession(batch);
}
public Database getDatabase() {
return database;
}
public SchemaMigrationDao schemaMigrationDao() {
return schemaMigrationDao;
}
public AuthorizationDao authorizationDao() {
return authorizationDao;
}
public OrganizationDao organizationDao() {
return organizationDao;
}
public OrganizationMemberDao organizationMemberDao() {
return organizationMemberDao;
}
public IssueDao issueDao() {
return issueDao;
}
public IssueChangeDao issueChangeDao() {
return issueChangeDao;
}
public QualityProfileDao qualityProfileDao() {
return qualityProfileDao;
}
public LoadedTemplateDao loadedTemplateDao() {
return loadedTemplateDao;
}
public PropertiesDao propertiesDao() {
return propertiesDao;
}
public InternalPropertiesDao internalPropertiesDao() {
return internalPropertiesDao;
}
public SnapshotDao snapshotDao() {
return snapshotDao;
}
public ComponentDao componentDao() {
return componentDao;
}
public ResourceDao resourceDao() {
return resourceDao;
}
public ComponentKeyUpdaterDao componentKeyUpdaterDao() {
return componentKeyUpdaterDao;
}
public MeasureDao measureDao() {
return measureDao;
}
public UserDao userDao() {
return userDao;
}
public UserGroupDao userGroupDao() {
return userGroupDao;
}
public UserTokenDao userTokenDao() {
return userTokenDao;
}
public GroupMembershipDao groupMembershipDao() {
return groupMembershipDao;
}
public RoleDao roleDao() {
return roleDao;
}
public GroupPermissionDao groupPermissionDao() {
return groupPermissionDao;
}
public PermissionTemplateDao permissionTemplateDao() {
return permissionTemplateDao;
}
public PermissionTemplateCharacteristicDao permissionTemplateCharacteristicDao() {
return permissionTemplateCharacteristicDao;
}
public CeActivityDao ceActivityDao() {
return ceActivityDao;
}
public CeQueueDao ceQueueDao() {
return ceQueueDao;
}
public CeTaskInputDao ceTaskInputDao() {
return ceTaskInputDao;
}
public CeScannerContextDao ceScannerContextDao() {
return ceScannerContextDao;
}
public FileSourceDao fileSourceDao() {
return fileSourceDao;
}
public ComponentLinkDao componentLinkDao() {
return componentLinkDao;
}
public EventDao eventDao() {
return eventDao;
}
public PurgeDao purgeDao() {
return purgeDao;
}
public QualityGateDao qualityGateDao() {
return qualityGateDao;
}
public QualityGateConditionDao gateConditionDao() {
return gateConditionDao;
}
public ProjectQgateAssociationDao projectQgateAssociationDao() {
return projectQgateAssociationDao;
}
public DuplicationDao duplicationDao() {
return duplicationDao;
}
public NotificationQueueDao notificationQueueDao() {
return notificationQueueDao;
}
public CustomMeasureDao customMeasureDao() {
return customMeasureDao;
}
public MetricDao metricDao() {
return metricDao;
}
public GroupDao groupDao() {
return groupDao;
}
public RuleDao ruleDao() {
return ruleDao;
}
public RuleRepositoryDao ruleRepositoryDao() {
return ruleRepositoryDao;
}
public ActiveRuleDao activeRuleDao() {
return activeRuleDao;
}
public QProfileChangeDao qProfileChangeDao() {
return qProfileChangeDao;
}
public UserPermissionDao userPermissionDao() {
return userPermissionDao;
}
public WebhookDeliveryDao webhookDeliveryDao() {
return webhookDeliveryDao;
}
public DefaultQProfileDao defaultQProfileDao() {
return defaultQProfileDao;
}
public EsQueueDao esQueueDao() {
return esQueueDao;
}
protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
return (K) map.get(clazz);
}
// should be removed. Still used by some old DAO in sonar-server
public MyBatis getMyBatis() {
return myBatis;
}
}
|