Skip to content

Package: AbstractKapuaService

AbstractKapuaService

nameinstructionbranchcomplexitylinemethod
AbstractKapuaService(EntityManagerFactory)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
AbstractKapuaService(EntityManagerFactory, AbstractEntityCacheFactory)
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getEntityManagerSession()
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%
registerEventListener(ServiceEventBusListener, String, Class)
M: 7 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.commons.service.internal;
14:
15: import org.eclipse.kapua.commons.event.ServiceEventBusManager;
16: import org.eclipse.kapua.commons.jpa.AbstractEntityCacheFactory;
17: import org.eclipse.kapua.commons.jpa.EntityManagerFactory;
18: import org.eclipse.kapua.commons.jpa.EntityManagerSession;
19: import org.eclipse.kapua.commons.service.internal.cache.EntityCache;
20: import org.eclipse.kapua.event.ServiceEventBusException;
21: import org.eclipse.kapua.event.ServiceEventBusListener;
22: import org.eclipse.kapua.service.KapuaService;
23:
24: /**
25: * Abstract Kapua service.<br>
26: * It handles the {@link EntityManagerFactory} and {@link EntityManagerSession} to avoid to redefine each time in the subclasses.
27: *
28: * @since 1.0
29: */
30: public class AbstractKapuaService implements KapuaService {
31:
32: protected EntityManagerFactory entityManagerFactory;
33: protected EntityManagerSession entityManagerSession;
34: protected EntityCache entityCache;
35:
36: /**
37: * @param entityManagerFactory
38: * @deprecated this constructor will be removed in a next release (may be)
39: */
40: @Deprecated
41: protected AbstractKapuaService(EntityManagerFactory entityManagerFactory) {
42: this(entityManagerFactory, null);
43: }
44:
45: /**
46: * Constructor.
47: *
48: * @param entityManagerFactory the EntityManager factory.
49: * @param abstractCacheFactory the service cache factory.
50: */
51: protected AbstractKapuaService(EntityManagerFactory entityManagerFactory, AbstractEntityCacheFactory abstractCacheFactory) {
52: this.entityManagerFactory = entityManagerFactory;
53: this.entityManagerSession = new EntityManagerSession(entityManagerFactory);
54:• if (abstractCacheFactory != null) {
55: this.entityCache = abstractCacheFactory.createCache();
56: }
57: }
58:
59: public EntityManagerSession getEntityManagerSession() {
60: return entityManagerSession;
61: }
62:
63: protected void registerEventListener(ServiceEventBusListener listener, String address, Class<? extends KapuaService> clazz) throws ServiceEventBusException {
64: ServiceEventBusManager.getInstance().subscribe(address, clazz.getName(), listener);
65: }
66: }