Skip to content

Package: TriggerDAO

TriggerDAO

nameinstructionbranchcomplexitylinemethod
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, TriggerCreator)
M: 31 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 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, Trigger)
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) 2017, 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.scheduler.trigger.quartz;
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.scheduler.trigger.Trigger;
22: import org.eclipse.kapua.service.scheduler.trigger.TriggerCreator;
23: import org.eclipse.kapua.service.scheduler.trigger.TriggerListResult;
24:
25: /**
26: * {@link Trigger} DAO.
27: *
28: * @since 1.0.0
29: */
30: public class TriggerDAO {
31:
32: private TriggerDAO() {
33: }
34:
35: /**
36: * Creates and return new {@link Trigger}
37: *
38: * @param em The {@link EntityManager} that owns the transaction.
39: * @param triggerCreator The {@link TriggerCreator} to persist.
40: * @return The newly created {@link Trigger}.
41: * @since 1.0.0
42: */
43: public static Trigger create(EntityManager em, TriggerCreator triggerCreator) {
44: TriggerImpl triggerImpl = new TriggerImpl(triggerCreator.getScopeId());
45: triggerImpl.setName(triggerCreator.getName());
46: triggerImpl.setStartsOn(triggerCreator.getStartsOn());
47: triggerImpl.setEndsOn(triggerCreator.getEndsOn());
48: triggerImpl.setTriggerDefinitionId(triggerCreator.getTriggerDefinitionId());
49: triggerImpl.setTriggerProperties(triggerCreator.getTriggerProperties());
50:
51: return ServiceDAO.create(em, triggerImpl);
52: }
53:
54: /**
55: * Updates the provided {@link Trigger}
56: *
57: * @param em The {@link EntityManager} that owns the transaction.
58: * @param trigger The {@link Trigger} to update.
59: * @return The updated {@link Trigger}.
60: * @throws KapuaException if error occurs while updating.
61: * @since 1.0.0
62: */
63: public static Trigger update(EntityManager em, Trigger trigger) throws KapuaException {
64: //
65: // Update trigger
66: TriggerImpl triggerImpl = (TriggerImpl) trigger;
67:
68: return ServiceDAO.update(em, TriggerImpl.class, triggerImpl);
69: }
70:
71: /**
72: * Finds the trigger by trigger identifier
73: *
74: * @param em The {@link EntityManager} that owns the transaction
75: * @param scopeId The {@link Trigger#getScopeId()}.
76: * @param triggerId The {@link Trigger#getId()}.
77: * @return The found {@link Trigger} or {@code null}.
78: * @since 1.0.0
79: */
80: public static Trigger find(EntityManager em, KapuaId scopeId, KapuaId triggerId) {
81: return ServiceDAO.find(em, TriggerImpl.class, scopeId, triggerId);
82: }
83:
84: /**
85: * Returns the trigger list matching the provided query
86: *
87: * @param em The {@link EntityManager} that owns the transaction.
88: * @param triggerQuery The {@link org.eclipse.kapua.service.scheduler.trigger.TriggerQuery} to perform
89: * @return The {@link TriggerListResult} matching the given query.
90: * @throws KapuaException if error occurs while quering.
91: * @since 1.0.0
92: */
93: public static TriggerListResult query(EntityManager em, KapuaQuery triggerQuery)
94: throws KapuaException {
95: return ServiceDAO.query(em, Trigger.class, TriggerImpl.class, new TriggerListResultImpl(), triggerQuery);
96: }
97:
98: /**
99: * Returns the trigger count matching the provided query
100: *
101: * @param em The {@link EntityManager} that owns the transaction.
102: * @param triggerQuery The {@link org.eclipse.kapua.service.scheduler.trigger.TriggerQuery} to perform
103: * @return The {@link TriggerListResult} matching the given query.
104: * @throws KapuaException if error occurs while counting.
105: * @since 1.0.0
106: */
107: public static long count(EntityManager em, KapuaQuery triggerQuery)
108: throws KapuaException {
109: return ServiceDAO.count(em, Trigger.class, TriggerImpl.class, triggerQuery);
110: }
111:
112: /**
113: * Deletes the trigger by trigger identifier
114: *
115: * @param em The {@link EntityManager} that owns the transaction.
116: * @param scopeId The {@link Trigger#getScopeId()}.
117: * @param triggerId The {@link Trigger#getId()}
118: * @return deleted entity
119: * @throws KapuaEntityNotFoundException If the {@link Trigger} is not found
120: * @since 1.0.0
121: */
122: public static Trigger delete(EntityManager em, KapuaId scopeId, KapuaId triggerId) throws KapuaEntityNotFoundException {
123: return ServiceDAO.delete(em, TriggerImpl.class, scopeId, triggerId);
124: }
125:
126: }