Package: BeanListenerAspect
BeanListenerAspect
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BeanListenerAspect() |
|
|
|
|
|
||||||||||||||||||||
ajc$afterReturning$cz_cvut_kbss_jopa_model_BeanListenerAspect$2$5580f1c0(JoinPoint) |
|
|
|
|
|
||||||||||||||||||||
ajc$before$cz_cvut_kbss_jopa_model_BeanListenerAspect$1$5580f1c0(JoinPoint) |
|
|
|
|
|
||||||||||||||||||||
ajc$before$cz_cvut_kbss_jopa_model_BeanListenerAspect$3$76f2d74c(JoinPoint) |
|
|
|
|
|
||||||||||||||||||||
aspectOf() |
|
|
|
|
|
||||||||||||||||||||
hasAspect() |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1:•/**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model;
16:
17: import java.lang.reflect.Field;
18:
19: import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
20: import cz.cvut.kbss.jopa.model.annotations.OWLClass;
21: import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
22: import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
23: import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty;
24: import cz.cvut.kbss.jopa.model.annotations.Properties;
25: import cz.cvut.kbss.jopa.model.annotations.Types;
26: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
27: import org.slf4j.Logger;
28: import org.slf4j.LoggerFactory;
29:
30: public aspect BeanListenerAspect {
31:
32: private static final Logger LOG = LoggerFactory.getLogger(BeanListenerAspect.class);
33:
34: pointcut getter(): get( @(OWLObjectProperty || OWLDataProperty || OWLAnnotationProperty || Types || Properties ) * * ) && within(@OWLClass *);
35:
36: pointcut setter(): set( @(OWLObjectProperty || OWLDataProperty || OWLAnnotationProperty || Types || Properties ) * * ) && within(@OWLClass *);
37:
38: before(): setter() {
39: // Check for inferred field modification
40: final Object object = thisJoinPoint.getTarget();
41: Class<?> cls = object.getClass();
42: Field field = null;
43: final String fieldName = thisJoinPoint.getSignature().getName();
44: try {
45: field = cls.getDeclaredField(fieldName);
46: } catch (NoSuchFieldException e) {
47: Class<?> superCls = cls;
48:• while ((superCls = superCls.getSuperclass()) != null) {
49: try {
50: field = superCls.getDeclaredField(fieldName);
51: break;
52: } catch (NoSuchFieldException ex) {
53: // Do nothing, keep trying
54: }
55: }
56:• if (field == null) {
57: throw new OWLPersistenceException(e.getMessage());
58: }
59: } catch (SecurityException e) {
60: LOG.error(e.getMessage(), e);
61: throw new OWLPersistenceException(e.getMessage());
62: }
63: JOPAPersistenceProvider.verifyInferredAttributeNotModified(object, field);
64: }
65:
66: after() returning : setter() {
67: // Persist changes done during transaction
68: final Object entity = thisJoinPoint.getTarget();
69: Field f;
70: try {
71: f = entity.getClass().getDeclaredField(thisJoinPoint.getSignature().getName());
72:• if (EntityPropertiesUtils.isFieldTransient(f)) {
73: return;
74: }
75: JOPAPersistenceProvider.persistEntityChanges(entity, f);
76: } catch (NoSuchFieldException | SecurityException e) {
77: LOG.error(e.getMessage(), e);
78: throw new OWLPersistenceException(e.getMessage());
79: }
80: }
81:
82: before(): getter() {
83: // Load lazy loaded entity field
84: try {
85: final Object object = thisJoinPoint.getTarget();
86: final Field field = object.getClass().getDeclaredField(
87: thisJoinPoint.getSignature().getName());
88:• if (EntityPropertiesUtils.isFieldTransient(field)) {
89: return;
90: }
91:
92: field.setAccessible(true);
93:
94: LOG.trace("*** Fetching {} of {}: {}", field.getName(), object.getClass(), System.identityHashCode(object));
95:
96: JOPAPersistenceProvider.loadReference(object, field);
97: } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
98: LOG.error(e.getMessage(), e);
99: throw new OWLPersistenceException();
100: }
101: }
102: }