Skip to content

Package: DeviceEventDAO

DeviceEventDAO

nameinstructionbranchcomplexitylinemethod
DeviceEventDAO()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
count(EntityManager, KapuaQuery)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(EntityManager, DeviceEventCreator)
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
delete(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
find(EntityManager, KapuaId, KapuaId)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
query(EntityManager, KapuaQuery)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.device.registry.event.internal;
14:
15: import org.eclipse.kapua.KapuaEntityNotFoundException;
16: import org.eclipse.kapua.KapuaException;
17: import org.eclipse.kapua.commons.jpa.EntityManager;
18: import org.eclipse.kapua.commons.service.internal.ServiceDAO;
19: import org.eclipse.kapua.model.id.KapuaId;
20: import org.eclipse.kapua.model.query.KapuaQuery;
21: import org.eclipse.kapua.service.device.registry.event.DeviceEvent;
22: import org.eclipse.kapua.service.device.registry.event.DeviceEventCreator;
23: import org.eclipse.kapua.service.device.registry.event.DeviceEventListResult;
24:
25: /**
26: * Device event DAO
27: *
28: * @since 1.0.0
29: */
30: public class DeviceEventDAO extends ServiceDAO {
31:
32: /**
33: * Create a new {@link DeviceEvent}
34: *
35: * @param em
36: * @param deviceEventCreator
37: * @return
38: */
39: public static DeviceEvent create(EntityManager em, DeviceEventCreator deviceEventCreator) {
40: DeviceEvent deviceEvent = new DeviceEventImpl(deviceEventCreator.getScopeId());
41: deviceEvent.setDeviceId(deviceEventCreator.getDeviceId());
42: deviceEvent.setReceivedOn(deviceEventCreator.getReceivedOn());
43: deviceEvent.setSentOn(deviceEventCreator.getSentOn());
44: deviceEvent.setResource(deviceEventCreator.getResource());
45: deviceEvent.setAction(deviceEventCreator.getAction());
46: deviceEvent.setResponseCode(deviceEventCreator.getResponseCode());
47: deviceEvent.setEventMessage(deviceEventCreator.getEventMessage());
48: deviceEvent.setPosition(deviceEventCreator.getPosition());
49:
50: return ServiceDAO.create(em, deviceEvent);
51: }
52:
53: /**
54: * Find the device event by device event identifier
55: *
56: * @param em
57: * @param scopeId
58: * @param deviceEventId
59: * @return
60: */
61: public static DeviceEvent find(EntityManager em, KapuaId scopeId, KapuaId deviceEventId) {
62: return ServiceDAO.find(em, DeviceEventImpl.class, scopeId, deviceEventId);
63: }
64:
65: /**
66: * Return the device event list matching the provided query
67: *
68: * @param em
69: * @param query
70: * @return
71: * @throws KapuaException
72: */
73: public static DeviceEventListResult query(EntityManager em, KapuaQuery query)
74: throws KapuaException {
75: return ServiceDAO.query(em, DeviceEvent.class, DeviceEventImpl.class, new DeviceEventListResultImpl(), query);
76: }
77:
78: /**
79: * Return the device event count matching the provided query
80: *
81: * @param em
82: * @param query
83: * @return
84: * @throws KapuaException
85: */
86: public static long count(EntityManager em, KapuaQuery query)
87: throws KapuaException {
88: return ServiceDAO.count(em, DeviceEvent.class, DeviceEventImpl.class, query);
89: }
90:
91: /**
92: * Delete the device event by device event identifier
93: *
94: * @param em
95: * @param scopeId
96: * @param deviceEventId
97: * @return deleted entity
98: * @throws KapuaEntityNotFoundException If the {@link DeviceEvent} is not found.
99: */
100: public static DeviceEvent delete(EntityManager em, KapuaId scopeId, KapuaId deviceEventId)
101: throws KapuaEntityNotFoundException {
102: return ServiceDAO.delete(em, DeviceEventImpl.class, scopeId, deviceEventId);
103: }
104:
105: }