1 19 20 21 package org.apache.cayenne.jpa.conf; 22 23 import java.lang.reflect.AnnotatedElement ; 24 import java.lang.reflect.Method ; 25 26 import org.apache.cayenne.jpa.map.JpaAbstractEntity; 27 import org.apache.cayenne.jpa.map.JpaLifecycleCallback; 28 29 class EntityCallbackAnnotationProcessorFactory extends AnnotationProcessorFactory { 30 31 static abstract class AbstractCallbackAnnotationProcessor implements 32 AnnotationProcessor { 33 34 public void onStartElement( 35 AnnotatedElement element, 36 AnnotationProcessorStack context) { 37 38 Method m = (Method ) element; 39 updateEntity((JpaAbstractEntity) context.peek(), new JpaLifecycleCallback(m 40 .getName())); 41 } 42 43 public void onFinishElement( 44 AnnotatedElement element, 45 AnnotationProcessorStack context) { 46 } 48 49 abstract void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback); 50 } 51 52 static final class PrePersistProcessor extends AbstractCallbackAnnotationProcessor { 53 54 @Override 55 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 56 entity.setPrePersist(callback); 57 } 58 } 59 60 static final class PostPersistProcessor extends AbstractCallbackAnnotationProcessor { 61 62 @Override 63 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 64 entity.setPostPersist(callback); 65 } 66 } 67 68 static final class PreRemoveProcessor extends AbstractCallbackAnnotationProcessor { 69 70 @Override 71 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 72 entity.setPreRemove(callback); 73 } 74 } 75 76 static final class PostRemoveProcessor extends AbstractCallbackAnnotationProcessor { 77 78 @Override 79 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 80 entity.setPostRemove(callback); 81 } 82 } 83 84 static final class PreUpdateProcessor extends AbstractCallbackAnnotationProcessor { 85 86 @Override 87 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 88 entity.setPreUpdate(callback); 89 } 90 } 91 92 static final class PostUpdateProcessor extends AbstractCallbackAnnotationProcessor { 93 94 @Override 95 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 96 entity.setPostUpdate(callback); 97 } 98 } 99 100 static final class PostLoadProcessor extends AbstractCallbackAnnotationProcessor { 101 102 @Override 103 void updateEntity(JpaAbstractEntity entity, JpaLifecycleCallback callback) { 104 entity.setPostLoad(callback); 105 } 106 } 107 } 108 | Popular Tags |