forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDomainDetailsDaoImpl.java
More file actions
135 lines (121 loc) · 5.03 KB
/
Copy pathDomainDetailsDaoImpl.java
File metadata and controls
135 lines (121 loc) · 5.03 KB
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.domain.dao;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import com.cloud.domain.DomainDetailVO;
import com.cloud.domain.DomainVO;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
public class DomainDetailsDaoImpl extends ResourceDetailsDaoBase<DomainDetailVO> implements DomainDetailsDao, ScopedConfigStorage {
protected final SearchBuilder<DomainDetailVO> domainSearch;
@Inject
protected DomainDao _domainDao;
@Inject
private ConfigurationDao _configDao;
protected DomainDetailsDaoImpl() {
domainSearch = createSearchBuilder();
domainSearch.and("domainId", domainSearch.entity().getResourceId(), Op.EQ);
domainSearch.done();
}
@Override
public Map<String, String> findDetails(long domainId) {
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
sc.and(sc.entity().getResourceId(), Op.EQ, domainId);
List<DomainDetailVO> results = sc.list();
Map<String, String> details = new HashMap<String, String>(results.size());
for (DomainDetailVO r : results) {
details.put(r.getName(), r.getValue());
}
return details;
}
@Override
public void persist(long domainId, Map<String, String> details) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SearchCriteria<DomainDetailVO> sc = domainSearch.create();
sc.setParameters("domainId", domainId);
expunge(sc);
for (Map.Entry<String, String> detail : details.entrySet()) {
DomainDetailVO vo = new DomainDetailVO(domainId, detail.getKey(), detail.getValue());
persist(vo);
}
txn.commit();
}
@Override
public DomainDetailVO findDetail(long domainId, String name) {
QueryBuilder<DomainDetailVO> sc = QueryBuilder.create(DomainDetailVO.class);
sc.and(sc.entity().getResourceId(), Op.EQ, domainId);
sc.and(sc.entity().getName(), Op.EQ, name);
return sc.find();
}
@Override
public void addDetail(long resourceId, String key, String value, boolean display) {
super.addDetail(new DomainDetailVO(resourceId, key, value));
}
@Override
public void deleteDetails(long domainId) {
SearchCriteria<DomainDetailVO> sc = domainSearch.create();
sc.setParameters("domainId", domainId);
List<DomainDetailVO> results = search(sc, null);
for (DomainDetailVO result : results) {
remove(result.getId());
}
}
@Override
public void update(long domainId, Map<String, String> details) {
Map<String, String> oldDetails = findDetails(domainId);
oldDetails.putAll(details);
persist(domainId, oldDetails);
}
@Override
public Scope getScope() {
return Scope.Domain;
}
@Override
public String getConfigValue(long id, ConfigKey<?> key) {
DomainDetailVO vo = null;
String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain");
if (!Boolean.parseBoolean(enableDomainSettingsForChildDomain)) {
vo = findDetail(id, key.key());
return vo == null ? null : getActualValue(vo);
}
DomainVO domain = _domainDao.findById(id);
// if value is not configured in domain then check its parent domain till ROOT
while (domain != null) {
vo = findDetail(domain.getId(), key.key());
if (vo != null) {
break;
} else if (domain.getParent() != null) {
domain = _domainDao.findById(domain.getParent());
} else {
break;
}
}
return vo == null ? null : getActualValue(vo);
}
}