1 19 20 package org.netbeans.modules.j2ee.persistence.spi.entitymanagergenerator; 21 22 import org.netbeans.modules.j2ee.persistence.spi.entitymanagergenerator.EntityManagerGenerationStrategySupport; 23 import com.sun.source.tree.AnnotationTree; 24 import com.sun.source.tree.ClassTree; 25 import com.sun.source.tree.ExpressionTree; 26 import com.sun.source.tree.MethodTree; 27 import com.sun.source.tree.ModifiersTree; 28 import com.sun.source.tree.TypeParameterTree; 29 import java.util.Collections ; 30 import javax.lang.model.element.Modifier; 31 import javax.lang.model.type.TypeKind; 32 33 39 public final class ApplicationManagedResourceTransactionInjectableInEJB extends EntityManagerGenerationStrategySupport{ 40 41 42 public ClassTree generate() { 43 44 ClassTree modifiedClazz = getClassTree(); 45 46 ModifiersTree methodModifiers = getTreeMaker().Modifiers( 47 Collections.<Modifier>singleton(Modifier.PUBLIC), 48 Collections.<AnnotationTree>emptyList() 49 ); 50 51 modifiedClazz = createEntityManager(Initialization.INIT); 52 53 String text = 54 "em.getTransaction().begin();\n" + 55 "try {\n" + 56 generateCallLines() + 57 " em.getTransaction().commit();\n" + 58 "} catch (Exception e) {\n" + 59 " e.printStackTrace();\n" + 60 " em.getTransaction().rollback();\n" + 61 "}"; 62 63 MethodTree newMethod = getTreeMaker().Method( 64 methodModifiers, 65 computeMethodName(), 66 getTreeMaker().PrimitiveType(TypeKind.VOID), 67 Collections.<TypeParameterTree>emptyList(), 68 getParameterList(), 69 Collections.<ExpressionTree>emptyList(), 70 "{ " + text + "}", 71 null 72 ); 73 74 return getTreeMaker().addClassMember(modifiedClazz, newMethod); 75 } 76 77 } 78 | Popular Tags |