Repository navigation
Expand file tree
/
Copy pathNicDetailDaoImpl.java
More file actions
108 lines (92 loc) · 3.62 KB
/
Copy pathNicDetailDaoImpl.java
File metadata and controls
108 lines (92 loc) · 3.62 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
// 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.vm.dao;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.vm.NicDetailVO;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
import java.util.List;
import java.util.Map;
@Component
@Local (value={NicDetailDao.class})
public class NicDetailDaoImpl extends GenericDaoBase<NicDetailVO, Long> implements NicDetailDao {
protected final SearchBuilder<NicDetailVO> NicSearch;
protected final SearchBuilder<NicDetailVO> DetailSearch;
public NicDetailDaoImpl() {
NicSearch = createSearchBuilder();
NicSearch.and("nicId", NicSearch.entity().getNicId(), SearchCriteria.Op.EQ);
NicSearch.done();
DetailSearch = createSearchBuilder();
DetailSearch.and("nicId", DetailSearch.entity().getNicId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
DetailSearch.done();
}
@Override
public void deleteDetails(long nicId) {
SearchCriteria<NicDetailVO> sc = NicSearch.create();
sc.setParameters("nicId", nicId);
List<NicDetailVO> results = search(sc, null);
for (NicDetailVO result : results) {
remove(result.getId());
}
}
@Override
public NicDetailVO findDetail(long nicId, String name) {
SearchCriteria<NicDetailVO> sc = DetailSearch.create();
sc.setParameters("nicId", nicId);
sc.setParameters("name", name);
return findOneBy(sc);
}
@Override
public List<NicDetailVO> findDetails(long nicId) {
SearchCriteria<NicDetailVO> sc = NicSearch.create();
sc.setParameters("nicId", nicId);
List<NicDetailVO> results = search(sc, null);
/*Map<String, String> details = new HashMap<String, String>(results.size());
for (NicDetailVO result : results) {
details.put(result.getName(), result.getValue());
} */
return results;
}
@Override
public void persist(long nicId, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<NicDetailVO> sc = NicSearch.create();
sc.setParameters("nicId", nicId);
expunge(sc);
for (Map.Entry<String, String> detail : details.entrySet()) {
NicDetailVO vo = new NicDetailVO(nicId, detail.getKey(), detail.getValue());
persist(vo);
}
txn.commit();
}
@Override
public void removeDetails(long nicId, String key) {
if(key != null){
NicDetailVO detail = findDetail(nicId, key);
if(detail != null){
remove(detail.getId());
}
}else {
deleteDetails(nicId);
}
}
}