Skip to content

Package: DeviceConnectionDAO

DeviceConnectionDAO

nameinstructionbranchcomplexitylinemethod
DeviceConnectionDAO()
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, DeviceConnectionCreator)
M: 47 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 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%
update(EntityManager, DeviceConnection)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 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.connection.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.connection.DeviceConnection;
22: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionCreator;
23: import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionListResult;
24:
25: /**
26: * Device connection DAO
27: *
28: * @since 1.0
29: */
30: public class DeviceConnectionDAO extends ServiceDAO {
31:
32: /**
33: * Create a new device connection
34: *
35: * @param em
36: * @param deviceConnectionCreator
37: * @return
38: */
39: public static DeviceConnection create(EntityManager em, DeviceConnectionCreator deviceConnectionCreator) {
40: DeviceConnection deviceConnection = new DeviceConnectionImpl(deviceConnectionCreator.getScopeId());
41: deviceConnection.setStatus(deviceConnectionCreator.getStatus());
42: deviceConnection.setClientId(deviceConnectionCreator.getClientId());
43: deviceConnection.setUserId(deviceConnectionCreator.getUserId());
44: deviceConnection.setUserCouplingMode(deviceConnectionCreator.getUserCouplingMode());
45: deviceConnection.setReservedUserId(deviceConnectionCreator.getReservedUserId());
46: deviceConnection.setAllowUserChange(deviceConnectionCreator.getAllowUserChange());
47: deviceConnection.setProtocol(deviceConnectionCreator.getProtocol());
48: deviceConnection.setClientIp(deviceConnectionCreator.getClientIp());
49: deviceConnection.setServerIp(deviceConnectionCreator.getServerIp());
50:
51: return ServiceDAO.create(em, deviceConnection);
52: }
53:
54: /**
55: * Update the provided device connection
56: *
57: * @param em
58: * @param deviceConnection
59: * @return
60: * @throws KapuaEntityNotFoundException If the {@link DeviceConnection} is not found.
61: */
62: public static DeviceConnection update(EntityManager em, DeviceConnection deviceConnection)
63: throws KapuaException {
64: DeviceConnectionImpl deviceConnectionImpl = (DeviceConnectionImpl) deviceConnection;
65: return ServiceDAO.update(em, DeviceConnectionImpl.class, deviceConnectionImpl);
66: }
67:
68: /**
69: * Find the device connection by device connection identifier
70: *
71: * @param em
72: * @param scopeId
73: * @param deviceConnectionId
74: * @return
75: */
76: public static DeviceConnection find(EntityManager em, KapuaId scopeId, KapuaId deviceConnectionId) {
77: return ServiceDAO.find(em, DeviceConnectionImpl.class, scopeId, deviceConnectionId);
78: }
79:
80: /**
81: * Return the device connection list matching the provided query
82: *
83: * @param em
84: * @param query
85: * @return
86: * @throws KapuaException
87: */
88: public static DeviceConnectionListResult query(EntityManager em, KapuaQuery query)
89: throws KapuaException {
90: return ServiceDAO.query(em, DeviceConnection.class, DeviceConnectionImpl.class, new DeviceConnectionListResultImpl(), query);
91: }
92:
93: /**
94: * Return the device connection count matching the provided query
95: *
96: * @param em
97: * @param query
98: * @return
99: * @throws KapuaException
100: */
101: public static long count(EntityManager em, KapuaQuery query)
102: throws KapuaException {
103: return ServiceDAO.count(em, DeviceConnection.class, DeviceConnectionImpl.class, query);
104: }
105:
106: /**
107: * Delete the device connection by device connection identifier
108: *
109: * @param em
110: * @param scopeId
111: * @param deviceConnectionId
112: * @return the deleted {@link DeviceConnection}
113: * @throws KapuaEntityNotFoundException If the {@link DeviceConnection} is not found.
114: */
115: public static DeviceConnection delete(EntityManager em, KapuaId scopeId, KapuaId deviceConnectionId) throws KapuaEntityNotFoundException {
116: return ServiceDAO.delete(em, DeviceConnectionImpl.class, scopeId, deviceConnectionId);
117: }
118:
119: }