Skip to content

Package: TagDAO

TagDAO

nameinstructionbranchcomplexitylinemethod
TagDAO()
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, TagCreator)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 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, Tag)
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, 2020 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.service.tag.internal;
13:
14: import org.eclipse.kapua.KapuaEntityNotFoundException;
15: import org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.commons.jpa.EntityManager;
17: import org.eclipse.kapua.commons.service.internal.ServiceDAO;
18: import org.eclipse.kapua.model.id.KapuaId;
19: import org.eclipse.kapua.model.query.KapuaQuery;
20: import org.eclipse.kapua.service.tag.Tag;
21: import org.eclipse.kapua.service.tag.TagCreator;
22: import org.eclipse.kapua.service.tag.TagListResult;
23: import org.eclipse.kapua.service.tag.TagQuery;
24:
25: /**
26: * {@link Tag} DAO
27: *
28: * @since 1.0.0
29: */
30: public class TagDAO extends ServiceDAO {
31:
32: /**
33: * Creates and returns new {@link Tag}
34: *
35: * @param em
36: * The {@link EntityManager} that holds the transaction.
37: * @param creator
38: * The {@link TagCreator} object from which create the new {@link Tag}.
39: * @return The newly created {@link Tag}.
40: * @throws KapuaException
41: * On create error.
42: * @since 1.0.0
43: */
44: public static Tag create(EntityManager em, TagCreator creator)
45: throws KapuaException {
46: Tag tag = new TagImpl(creator.getScopeId());
47: tag.setName(creator.getName());
48: tag.setDescription(creator.getDescription());
49:
50: return ServiceDAO.create(em, tag);
51: }
52:
53: /**
54: * Updates and returns the updated {@link Tag}
55: *
56: * @param em
57: * The {@link EntityManager} that holds the transaction.
58: * @param tag
59: * The {@link Tag} to update
60: * @return The updated {@link Tag}.
61: * @throws KapuaEntityNotFoundException
62: * If {@link Tag} is not found.
63: */
64: public static Tag update(EntityManager em, Tag tag) throws KapuaEntityNotFoundException {
65: TagImpl tagImpl = (TagImpl) tag;
66: return ServiceDAO.update(em, TagImpl.class, tagImpl);
67: }
68:
69: /**
70: * Finds the {@link Tag} by {@link Tag} identifier
71: *
72: * @param em
73: * The {@link EntityManager} that holds the transaction.
74: * @param scopeId
75: * @param tagId
76: * The {@link Tag} id to search.
77: * @return The found {@link Tag} or {@code null} if not found.
78: * @since 1.0.0
79: */
80: public static Tag find(EntityManager em, KapuaId scopeId, KapuaId tagId) {
81: return ServiceDAO.find(em,TagImpl.class, scopeId, tagId);
82: }
83:
84: /**
85: * Returns the {@link Tag} list matching the provided query.
86: *
87: * @param em
88: * The {@link EntityManager} that holds the transaction.
89: * @param tagQuery
90: * The {@link TagQuery} used to filter results.
91: * @return The list of {@link Tag}s that matches the given query.
92: * @throws KapuaException
93: * On query error.
94: * @since 1.0.0
95: */
96: public static TagListResult query(EntityManager em, KapuaQuery tagQuery)
97: throws KapuaException {
98: return ServiceDAO.query(em, Tag.class, TagImpl.class, new TagListResultImpl(), tagQuery);
99: }
100:
101: /**
102: * Return the {@link Tag} count matching the provided query
103: *
104: * @param em
105: * The {@link EntityManager} that holds the transaction.
106: * @param tagQuery
107: * The {@link TagQuery} used to filter results
108: * @return The count of {@link Tag}s that matches the given query.
109: * @throws KapuaException
110: * @since 1.0.0
111: */
112: public static long count(EntityManager em, KapuaQuery tagQuery)
113: throws KapuaException {
114: return ServiceDAO.count(em, Tag.class, TagImpl.class, tagQuery);
115: }
116:
117: /**
118: * Deletes the {@link Tag} by {@link Tag} identifier
119: *
120: * @param em
121: * The {@link EntityManager} that holds the transaction.
122: * @param scopeId
123: * @param tagId
124: * The {@link Tag} id to delete.
125: * @return deleted entity
126: * @throws KapuaEntityNotFoundException
127: * If {@link Tag} is not found.
128: * @since 1.0.0
129: */
130: public static Tag delete(EntityManager em, KapuaId scopeId, KapuaId tagId) throws KapuaEntityNotFoundException {
131: return ServiceDAO.delete(em, TagImpl.class, scopeId, tagId);
132: }
133: }