This is an automated email from the ASF dual-hosted git repository. matthiasblaesing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new dabf55f848 Added ability for Jakarta EE projects to: * Create entities from database tables * Create message driven, stateful, stateless and session beans new 0bee9d3691 Merge pull request #6129 from asbachb/jakarta-namespace-entity-sessionbeans dabf55f848 is described below commit dabf55f848ceccb42bbf0afb6fbcd5f30d7f08eb Author: Benjamin Asbach <asbachb....@impl.it> AuthorDate: Tue Jun 20 16:18:10 2023 +0800 Added ability for Jakarta EE projects to: * Create entities from database tables * Create message driven, stateful, stateless and session beans This should fix #4827 #4828 --- enterprise/j2ee.ejbcore/licenseinfo.xml | 6 ++ .../org-netbeans-modules-j2ee-ejbcore.sig | 13 ++-- .../api/codegeneration/SessionGenerator.java | 71 +++++++++++++++++----- .../wizard/jpa/dao/AppServerValidationPanel.java | 16 +++-- .../ejb/wizard/session/SessionEJBWizard.java | 10 +-- .../modules/j2ee/ejbcore/resources/layer.xml | 47 ++++++++++++++ .../templates/EJB40MessageDrivenBean.template | 31 ++++++++++ .../resources/templates/EJB40SessionLocal.template | 20 ++++++ .../templates/EJB40SessionRemote.template | 20 ++++++ .../templates/EJB40SingletonEjbClass.template | 39 ++++++++++++ .../templates/EJB40StatefulEjbClass.template | 28 +++++++++ .../templates/EJB40StatelessEjbClass.template | 39 ++++++++++++ .../api/codegeneration/SessionGeneratorTest.java | 15 ++--- .../PersistenceClientEntitySelectionVisual.java | 2 +- .../persistence/wizard/entity/EntityWizard.java | 25 +++++--- .../wizard/fromdb/JavaPersistenceGenerator.java | 65 ++++++++++++-------- .../wizard/entity/EntityWizardTest.java | 4 +- 17 files changed, 371 insertions(+), 80 deletions(-) diff --git a/enterprise/j2ee.ejbcore/licenseinfo.xml b/enterprise/j2ee.ejbcore/licenseinfo.xml index f7b02f913a..4332fbe249 100644 --- a/enterprise/j2ee.ejbcore/licenseinfo.xml +++ b/enterprise/j2ee.ejbcore/licenseinfo.xml @@ -46,6 +46,12 @@ <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB30StatefulEjbClass.template</file> <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB30StatelessEjbClass.template</file> <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB31SingletonEjbClass.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatelessEjbClass.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatefulEjbClass.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionLocal.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionRemote.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40MessageDrivenBean.template</file> + <file>src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SingletonEjbClass.template</file> <file>src/org/netbeans/modules/j2ee/ejbcore/resources/CachingServiceLocator.template</file> <file>src/org/netbeans/modules/j2ee/ejbcore/resources/ServiceLocator.template</file> <license ref="Apache-2.0-ASF" /> diff --git a/enterprise/j2ee.ejbcore/nbproject/org-netbeans-modules-j2ee-ejbcore.sig b/enterprise/j2ee.ejbcore/nbproject/org-netbeans-modules-j2ee-ejbcore.sig index 9a7bd564ac..ad286923b7 100644 --- a/enterprise/j2ee.ejbcore/nbproject/org-netbeans-modules-j2ee-ejbcore.sig +++ b/enterprise/j2ee.ejbcore/nbproject/org-netbeans-modules-j2ee-ejbcore.sig @@ -1,5 +1,5 @@ #Signature file v4.1 -#Version 1.71 +#Version 1.72 CLSS public abstract java.awt.Component cons protected init() @@ -656,7 +656,7 @@ supr java.lang.Object hfds key,value CLSS public final org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator -cons protected init(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,boolean,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean,boolean) +cons protected init(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,org.netbeans.api.j2ee.core.Profile,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean,boolean) fld public final static java.lang.String ANNOTATION_LOCAL_BEAN = "javax.ejb.LocalBean" fld public final static java.lang.String EJB21_EJBCLASS = "Templates/J2EE/EJB21/SessionEjbClass.java" fld public final static java.lang.String EJB21_LOCAL = "Templates/J2EE/EJB21/SessionLocal.java" @@ -668,15 +668,20 @@ fld public final static java.lang.String EJB30_REMOTE = "Templates/J2EE/EJB30/Se fld public final static java.lang.String EJB30_STATEFUL_EJBCLASS = "Templates/J2EE/EJB30/StatefulEjbClass.java" fld public final static java.lang.String EJB30_STATELESS_EJBCLASS = "Templates/J2EE/EJB30/StatelessEjbClass.java" fld public final static java.lang.String EJB31_SINGLETON_EJBCLASS = "Templates/J2EE/EJB31/SingletonEjbClass.java" +fld public final static java.lang.String EJB40_LOCAL = "Templates/J2EE/EJB40/SessionLocal.java" +fld public final static java.lang.String EJB40_REMOTE = "Templates/J2EE/EJB40/SessionRemote.java" +fld public final static java.lang.String EJB40_SINGLETON_EJBCLASS = "Templates/J2EE/EJB40/SingletonEjbClass.java" +fld public final static java.lang.String EJB40_STATEFUL_EJBCLASS = "Templates/J2EE/EJB40/StatefulEjbClass.java" +fld public final static java.lang.String EJB40_STATELESS_EJBCLASS = "Templates/J2EE/EJB40/StatelessEjbClass.java" fld public final static java.lang.String TEMPLATE_PROPERTY_INTERFACES = "interfaces" fld public final static java.lang.String TEMPLATE_PROPERTY_LOCAL_BEAN = "annotationLocalBean" meth public org.openide.filesystems.FileObject generate() throws java.io.IOException meth public static java.lang.String getScheduleAnnotationValue(org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean) -meth public static org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator create(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,boolean,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean) +meth public static org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator create(java.lang.String,org.openide.filesystems.FileObject,boolean,boolean,java.lang.String,org.netbeans.api.j2ee.core.Profile,boolean,boolean,org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions,boolean,boolean) meth public static org.openide.filesystems.FileObject createRemoteInterfacePackage(org.netbeans.api.project.Project,java.lang.String,org.openide.filesystems.FileObject) throws java.io.IOException meth public void initRemoteInterfacePackage(org.netbeans.api.project.Project,java.lang.String,org.openide.filesystems.FileObject) throws java.io.IOException supr java.lang.Object -hfds displayName,ejbClassName,ejbName,ejbNameOptions,hasLocal,hasRemote,isSimplified,isXmlBased,localHomeName,localName,packageName,packageNameWithDot,pkg,remoteHomeName,remoteName,remotePkg,sessionType,templateParameters +hfds displayName,ejbClassName,ejbName,ejbNameOptions,enterpriseProfile,hasLocal,hasRemote,isXmlBased,localHomeName,localName,packageName,packageNameWithDot,pkg,remoteHomeName,remoteName,remotePkg,sessionType,templateParameters CLSS public abstract org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.AbstractMethodController cons public init(java.lang.String,org.netbeans.modules.j2ee.metadata.model.api.MetadataModel<org.netbeans.modules.j2ee.dd.api.ejb.EjbJarMetadata>) diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java index b1241ecc57..93991809bf 100644 --- a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGenerator.java @@ -22,12 +22,10 @@ package org.netbeans.modules.j2ee.ejbcore.api.codegeneration; import org.netbeans.modules.j2ee.core.api.support.java.GenerationUtils; import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; -import javax.lang.model.element.Modifier; +import org.netbeans.api.j2ee.core.Profile; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.JavaClassPathConstants; import org.netbeans.api.java.project.JavaProjectConstants; @@ -42,18 +40,12 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.libraries.Library; import org.netbeans.api.project.libraries.LibraryManager; import org.netbeans.modules.j2ee.common.J2eeProjectCapabilities; -import org.netbeans.modules.j2ee.core.api.support.java.method.MethodModel; import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor; import org.netbeans.modules.j2ee.dd.api.ejb.ContainerTransaction; -import org.netbeans.modules.j2ee.ejbcore.action.BusinessMethodGenerator; import org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.TimerOptions; import org.netbeans.modules.j2ee.ejbcore.naming.EJBNameOptions; -import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; -import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; -import org.openide.util.RequestProcessor; /** * Generator of Session EJBs for EJB 2.1 and 3.0 @@ -73,6 +65,12 @@ public final class SessionGenerator { public static final String EJB30_LOCAL = "Templates/J2EE/EJB30/SessionLocal.java"; // NOI18N public static final String EJB30_REMOTE = "Templates/J2EE/EJB30/SessionRemote.java"; // NOI18N + public static final String EJB40_STATELESS_EJBCLASS = "Templates/J2EE/EJB40/StatelessEjbClass.java"; // NOI18N + public static final String EJB40_STATEFUL_EJBCLASS = "Templates/J2EE/EJB40/StatefulEjbClass.java"; // NOI18N + public static final String EJB40_LOCAL = "Templates/J2EE/EJB40/SessionLocal.java"; // NOI18N + public static final String EJB40_REMOTE = "Templates/J2EE/EJB40/SessionRemote.java"; // NOI18N + public static final String EJB40_SINGLETON_EJBCLASS = "Templates/J2EE/EJB40/SingletonEjbClass.java"; // NOI18N + public static final String EJB31_SINGLETON_EJBCLASS = "Templates/J2EE/EJB31/SingletonEjbClass.java"; // NOI18N public static final String ANNOTATION_LOCAL_BEAN = "javax.ejb.LocalBean"; @@ -86,7 +84,7 @@ public final class SessionGenerator { private final boolean hasRemote; private final boolean hasLocal; private final String sessionType; - private final boolean isSimplified; + private final Profile enterpriseProfile; // private final boolean hasBusinessInterface; private final boolean isXmlBased; @@ -106,21 +104,21 @@ public final class SessionGenerator { private final Map<String, Object> templateParameters; public static SessionGenerator create(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal, - String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased, + String sessionType, Profile enterpriseProfile, boolean hasBusinessInterface, boolean isXmlBased, TimerOptions timerOptions, boolean exposeTimer, boolean nonPersistentTimer) { - return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, isSimplified, + return new SessionGenerator(wizardTargetName, pkg, hasRemote, hasLocal, sessionType, enterpriseProfile, hasBusinessInterface, isXmlBased, timerOptions, exposeTimer, nonPersistentTimer, false); } protected SessionGenerator(String wizardTargetName, FileObject pkg, boolean hasRemote, boolean hasLocal, - String sessionType, boolean isSimplified, boolean hasBusinessInterface, boolean isXmlBased, + String sessionType, Profile enterpriseProfile, boolean hasBusinessInterface, boolean isXmlBased, TimerOptions timerOptions, boolean exposeTimer, boolean nonPersistentTimer, boolean isTest) { this.pkg = pkg; this.remotePkg = pkg; this.hasRemote = hasRemote; this.hasLocal = hasLocal; this.sessionType = sessionType; - this.isSimplified = isSimplified; + this.enterpriseProfile = enterpriseProfile; // this.hasBusinessInterface = hasBusinessInterface; this.isXmlBased = isXmlBased; this.ejbNameOptions = new EJBNameOptions(); @@ -187,7 +185,17 @@ public final class SessionGenerator { public FileObject generate() throws IOException { FileObject resultFileObject = null; - if (isSimplified) { + if (enterpriseProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) { + resultFileObject = generateEJB40Classes(); + + //put these lines in a common function at the appropriate place after EA1 + //something like public EjbJar getEjbJar() + //This method will be used whereever we construct/get DD object graph to ensure + //corresponding config listners attached to it. + Project project = FileOwnerQuery.getOwner(pkg); + J2eeModuleProvider j2eeModuleProvider = project.getLookup().lookup(J2eeModuleProvider.class); + j2eeModuleProvider.getConfigSupport().ensureConfigurationReady(); + } else if (enterpriseProfile.isAtLeast(Profile.JAVA_EE_5)) { resultFileObject = generateEJB30Classes(); //put these lines in a common function at the appropriate place after EA1 @@ -269,6 +277,39 @@ public final class SessionGenerator { return ejbClassFO; } + private FileObject generateEJB40Classes() throws IOException { + String ejbClassTemplateName = ""; + if (sessionType.equals(Session.SESSION_TYPE_STATELESS)){ + ejbClassTemplateName = EJB40_STATELESS_EJBCLASS; + } else if (sessionType.equals(Session.SESSION_TYPE_STATEFUL)){ + ejbClassTemplateName = EJB40_STATEFUL_EJBCLASS; + } else if (sessionType.equals(Session.SESSION_TYPE_SINGLETON)){ + ejbClassTemplateName = EJB40_SINGLETON_EJBCLASS; + } else{ + assert false; + } + + if (hasLocal && hasRemote){ + this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, remoteName + ", " + localName); //NOI18N + } else if (hasLocal){ + this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, localName); + } else if (hasRemote){ + this.templateParameters.put(TEMPLATE_PROPERTY_INTERFACES, remoteName); + } else { + this.templateParameters.put(TEMPLATE_PROPERTY_LOCAL_BEAN, Boolean.TRUE.toString()); + } + + final FileObject ejbClassFO = GenerationUtils.createClass(ejbClassTemplateName, pkg, ejbClassName, null, templateParameters); + if (hasRemote) { + GenerationUtils.createClass(EJB40_REMOTE, remotePkg, remoteName, null, templateParameters); + } + if (hasLocal) { + GenerationUtils.createClass(EJB40_LOCAL, pkg, localName, null, templateParameters); + } + + return ejbClassFO; + } + private void generateEJB21Xml() throws IOException { org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(pkg); FileObject ddFO = ejbModule.getDeploymentDescriptor(); diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/jpa/dao/AppServerValidationPanel.java b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/jpa/dao/AppServerValidationPanel.java index 928acd13c3..e6ff0b5e72 100644 --- a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/jpa/dao/AppServerValidationPanel.java +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/jpa/dao/AppServerValidationPanel.java @@ -56,13 +56,7 @@ public final class AppServerValidationPanel extends DelegatingWizardDescriptorPa } WebModule wm = WebModule.getWebModule(project.getProjectDirectory()); - if (wm != null && (wm.getJ2eeProfile() == Profile.JAVA_EE_6_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_6_WEB - || wm.getJ2eeProfile() == Profile.JAVA_EE_7_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_7_WEB - || wm.getJ2eeProfile() == Profile.JAVA_EE_8_FULL || wm.getJ2eeProfile() == Profile.JAVA_EE_8_WEB - || wm.getJ2eeProfile() == Profile.JAKARTA_EE_8_FULL || wm.getJ2eeProfile() == Profile.JAKARTA_EE_8_WEB - || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_FULL - || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_1_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_9_1_FULL - || wm.getJ2eeProfile() == Profile.JAKARTA_EE_10_WEB || wm.getJ2eeProfile() == Profile.JAKARTA_EE_10_FULL)) { + if (wm != null && (wm.getJ2eeProfile().isAtLeast(Profile.JAVA_EE_6_WEB))) { // check that server is EJB lite sufficient EjbSupport ejbSupport = EjbSupport.getInstance(j2eePlatform); if (!ejbSupport.isEjb31LiteSupported(j2eePlatform)) { @@ -93,8 +87,12 @@ public final class AppServerValidationPanel extends DelegatingWizardDescriptorPa */ private static boolean isSessionBeanCodeGenerationAlowed(Project project) { ClassPath classpath = ClassPath.getClassPath(project.getProjectDirectory(), ClassPath.COMPILE); - return !(classpath.findResource("javax/ejb/Stateless.class") == null //NOI18N + return !(classpath.findResource("jakarta/ejb/Stateless.class") == null //NOI18N + || classpath.findResource("jakarta/ejb/Stateful.class") == null //NOI18N + || classpath.findResource("jakarta/ejb/Singleton.class") == null //NOI18N + || //NOI18N + !(classpath.findResource("javax/ejb/Stateless.class") == null //NOI18N || classpath.findResource("javax/ejb/Stateful.class") == null //NOI18N - || classpath.findResource("javax/ejb/Singleton.class") == null); //NOI18N + || classpath.findResource("javax/ejb/Singleton.class") == null)); //NOI18N } } diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java index 731ba814b1..6b22078aed 100644 --- a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/session/SessionEJBWizard.java @@ -88,20 +88,14 @@ public final class SessionEJBWizard implements WizardDescriptor.AsynchronousInst EjbJar ejbModule = EjbJar.getEjbJar(pkg); // TODO: UI - add checkbox for Java EE 5 to create also EJB 2.1 style EJBs Profile profile = ejbModule.getJ2eeProfile(); - boolean isSimplified = Profile.JAVA_EE_5.equals(profile) || Profile.JAVA_EE_6_FULL.equals(profile) || Profile.JAVA_EE_6_WEB.equals(profile) - || Profile.JAVA_EE_7_FULL.equals(profile) || Profile.JAVA_EE_7_WEB.equals(profile) - || Profile.JAVA_EE_8_FULL.equals(profile) || Profile.JAVA_EE_8_WEB.equals(profile) - || Profile.JAKARTA_EE_8_FULL.equals(profile) || Profile.JAKARTA_EE_8_WEB.equals(profile) - || Profile.JAKARTA_EE_9_FULL.equals(profile) || Profile.JAKARTA_EE_9_WEB.equals(profile) - || Profile.JAKARTA_EE_9_1_FULL.equals(profile) || Profile.JAKARTA_EE_9_1_WEB.equals(profile) - || Profile.JAKARTA_EE_10_FULL.equals(profile) || Profile.JAKARTA_EE_10_WEB.equals(profile); + boolean isSimplified = profile.isAtLeast(Profile.JAVA_EE_5); SessionGenerator sessionGenerator = SessionGenerator.create( Templates.getTargetName(wiz), pkg, ejbPanel.hasRemote(), ejbPanel.hasLocal(), ejbPanel.getSessionType(), - isSimplified, + profile, true, // TODO: UI - add checkbox for creation of business interface !isSimplified, // TODO: UI - add checkbox for option XML (not annotation) usage ejbPanel.getTimerOptions(), diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml index db891376d4..35b1d147bc 100644 --- a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/layer.xml @@ -223,6 +223,53 @@ </file> </folder> + <folder name="EJB40"> + <attr name="position" intvalue="0"/> + <file name="StatelessEjbClass.java" url="templates/EJB40StatelessEjbClass.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/session/SessionNodeIcon.gif"/> + </file> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.resources.Bundle"/> + <file name="StatefulEjbClass.java" url="templates/EJB40StatefulEjbClass.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/session/SessionNodeIcon.gif"/> + </file> + <file name="SessionLocal.java" url="templates/EJB40SessionLocal.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/java/resources/class.gif"/> + </file> + <file name="SessionRemote.java" url="templates/EJB40SessionRemote.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/java/resources/class.gif"/> + </file> + <file name="MessageDrivenBean.java" url="templates/EJB40MessageDrivenBean.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/mdb/MessageNodeIcon.gif"/> + </file> + <file name="SingletonEjbClass.java" url="templates/EJB40SingletonEjbClass.template"> + <attr name="template" boolvalue="true"/> + <attr name="templateCategory" stringvalue="ejb-templates"/> + <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/> + <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle"/> + <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/session/SessionNodeIcon.gif"/> + </file> + </folder> + <folder name="EJB31"> <attr name="position" intvalue="0"/> <file name="SingletonEjbClass.java" url="templates/EJB31SingletonEjbClass.template"> diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40MessageDrivenBean.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40MessageDrivenBean.template new file mode 100644 index 0000000000..7113f9559e --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40MessageDrivenBean.template @@ -0,0 +1,31 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +package ${package}; + +import jakarta.ejb.ActivationConfigProperty; +import jakarta.ejb.MessageDriven; +import jakarta.jms.Message; +import jakarta.jms.MessageListener; + +/** + * + * @author ${user} + */ +@MessageDriven(<#if useMappedName?? && useMappedName>mappedName = "${messageDestinationName}", </#if>activationConfig = { +<#list activationConfigProperties as property> + @ActivationConfigProperty(propertyName = "${property.getKey()}", propertyValue = "${property.getValue()}")<#if property_has_next>,</#if> +</#list> + }) +public class ${name} implements MessageListener { + + public ${name}() { + } + + @Override + public void onMessage(Message message) { + } + +} diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionLocal.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionLocal.template new file mode 100644 index 0000000000..5b5730667e --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionLocal.template @@ -0,0 +1,20 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +package ${package}; + +import jakarta.ejb.Local; + +/** + * + * @author ${user} + */ +@Local +public interface ${name} { + +<#if timerExist && exposeTimer> + public void myTimer(); +</#if> +} diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionRemote.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionRemote.template new file mode 100644 index 0000000000..db10558812 --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SessionRemote.template @@ -0,0 +1,20 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +package ${package}; + +import jakarta.ejb.Remote; + +/** + * + * @author ${user} + */ +@Remote +public interface ${name} { + +<#if timerExist && exposeTimer> + public void myTimer(); +</#if> +} diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SingletonEjbClass.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SingletonEjbClass.template new file mode 100644 index 0000000000..97e1694f03 --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40SingletonEjbClass.template @@ -0,0 +1,39 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +<#if package?? && package != ""> +package ${package}; +</#if> + +<#if timerExist> +import java.util.Date; +import jakarta.ejb.Schedule; +</#if> +import jakarta.ejb.Singleton; +<#if annotationLocalBean??> +import jakarta.ejb.LocalBean; +</#if> + +/** + * + * @author ${user} + */ +@Singleton +<#if annotationLocalBean??> +@LocalBean +</#if> +public class ${name} <#if interfaces??>implements ${interfaces} </#if>{ +<#if timerExist> + @Schedule(${timerString}) + <#if exposeTimer>@Override</#if> + public void myTimer() { + System.out.println("Timer event: " + new Date()); + } +</#if> + + // Add business logic below. (Right-click in editor and choose + // "Insert Code > Add Business Method") + +} diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatefulEjbClass.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatefulEjbClass.template new file mode 100644 index 0000000000..5680f559c5 --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatefulEjbClass.template @@ -0,0 +1,28 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +<#if package?? && package != ""> +package ${package}; +</#if> + +import jakarta.ejb.Stateful; +<#if annotationLocalBean??> +import jakarta.ejb.LocalBean; +</#if> + +/** + * + * @author ${user} + */ +@Stateful +<#if annotationLocalBean??> +@LocalBean +</#if> +public class ${name} <#if interfaces??>implements ${interfaces} </#if>{ + + // Add business logic below. (Right-click in editor and choose + // "Insert Code > Add Business Method") + +} diff --git a/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatelessEjbClass.template b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatelessEjbClass.template new file mode 100644 index 0000000000..71e7ec7202 --- /dev/null +++ b/enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/resources/templates/EJB40StatelessEjbClass.template @@ -0,0 +1,39 @@ +<#assign licenseFirst = "/*"> +<#assign licensePrefix = " * "> +<#assign licenseLast = " */"> +<#include "${project.licensePath}"> + +<#if package?? && package != ""> +package ${package}; +</#if> + +<#if timerExist> +import java.util.Date; +import jakarta.ejb.Schedule; +</#if> +import jakarta.ejb.Stateless; +<#if annotationLocalBean??> +import jakarta.ejb.LocalBean; +</#if> + +/** + * + * @author ${user} + */ +@Stateless +<#if annotationLocalBean??> +@LocalBean +</#if> +public class ${name} <#if interfaces??>implements ${interfaces} </#if>{ +<#if timerExist> + @Schedule(${timerString}) + <#if exposeTimer>@Override</#if> + public void myTimer() { + System.out.println("Timer event: " + new Date()); + } +</#if> + + // Add business logic below. (Right-click in editor and choose + // "Insert Code > Add Business Method") + +} diff --git a/enterprise/j2ee.ejbcore/test/unit/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGeneratorTest.java b/enterprise/j2ee.ejbcore/test/unit/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGeneratorTest.java index cd56606540..2ec34f8b2d 100644 --- a/enterprise/j2ee.ejbcore/test/unit/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGeneratorTest.java +++ b/enterprise/j2ee.ejbcore/test/unit/src/org/netbeans/modules/j2ee/ejbcore/api/codegeneration/SessionGeneratorTest.java @@ -20,6 +20,7 @@ package org.netbeans.modules.j2ee.ejbcore.api.codegeneration; import java.io.IOException; +import org.netbeans.api.j2ee.core.Profile; import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; @@ -49,7 +50,7 @@ public class SessionGeneratorTest extends TestBase { // Stateless EJB in Java EE 1.4 - SessionGenerator sessionGenerator = new SessionGenerator("TestStatelessLR", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, false, false, true, null, false, false, true); + SessionGenerator sessionGenerator = new SessionGenerator("TestStatelessLR", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, Profile.J2EE_14, false, true, null, false, false, true); sessionGenerator.generate(); EjbJar ejbJar = DDProvider.getDefault().getDDRoot(testModule.getDeploymentDescriptor()); EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans(); @@ -93,7 +94,7 @@ public class SessionGeneratorTest extends TestBase { // Stateful EJB in Java EE 1.4 - sessionGenerator = new SessionGenerator("TestStatefulLR", packageFileObject, false, true, Session.SESSION_TYPE_STATEFUL, false, false, true, null, false, false, true); + sessionGenerator = new SessionGenerator("TestStatefulLR", packageFileObject, false, true, Session.SESSION_TYPE_STATEFUL, Profile.J2EE_14, false, true, null, false, false, true); sessionGenerator.generate(); session = (Session) enterpriseBeans.findBeanByName(EnterpriseBeans.SESSION, Session.EJB_NAME, "TestStatefulLR"); @@ -137,7 +138,7 @@ public class SessionGeneratorTest extends TestBase { // Stateless EJB in Java EE 5.0 defined in annotations - SessionGenerator sessionGenerator = new SessionGenerator("TestStateless", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, true, false, false, null, false, false, true); + SessionGenerator sessionGenerator = new SessionGenerator("TestStateless", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, Profile.JAVA_EE_5, false, false, null, false, false, true); sessionGenerator.generate(); assertFile( @@ -158,7 +159,7 @@ public class SessionGeneratorTest extends TestBase { // Stateful EJB in Java EE 5.0 defined in annotations - sessionGenerator = new SessionGenerator("TestStateful", packageFileObject, true, false, Session.SESSION_TYPE_STATEFUL, true, false, false, null, false, false, true); + sessionGenerator = new SessionGenerator("TestStateful", packageFileObject, true, false, Session.SESSION_TYPE_STATEFUL, Profile.JAVA_EE_5, false, false, null, false, false, true); sessionGenerator.generate(); assertFile( @@ -185,7 +186,7 @@ public class SessionGeneratorTest extends TestBase { // Stateless EJB in Java EE 6.0 defined in annotations - SessionGenerator sessionGenerator = new SessionGenerator("TestStateless", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, true, false, false, null, false, false, true); + SessionGenerator sessionGenerator = new SessionGenerator("TestStateless", packageFileObject, true, true, Session.SESSION_TYPE_STATELESS, Profile.JAVA_EE_6_FULL, false, false, null, false, false, true); sessionGenerator.generate(); assertFile( @@ -206,7 +207,7 @@ public class SessionGeneratorTest extends TestBase { // Stateful EJB in Java EE 6.0 defined in annotations - sessionGenerator = new SessionGenerator("TestStateful", packageFileObject, true, false, Session.SESSION_TYPE_STATEFUL, true, false, false, null, false, false, true); + sessionGenerator = new SessionGenerator("TestStateful", packageFileObject, true, false, Session.SESSION_TYPE_STATEFUL, Profile.JAVA_EE_6_FULL, false, false, null, false, false, true); sessionGenerator.generate(); assertFile( @@ -224,7 +225,7 @@ public class SessionGeneratorTest extends TestBase { // Singleton EJB in Java EE 6.0 defined in annotations - sessionGenerator = new SessionGenerator("TestSingleton", packageFileObject, false, false, Session.SESSION_TYPE_SINGLETON, true, false, false, null, false, false, true); + sessionGenerator = new SessionGenerator("TestSingleton", packageFileObject, false, false, Session.SESSION_TYPE_SINGLETON, Profile.JAVA_EE_6_FULL, false, false, null, false, false, true); sessionGenerator.generate(); assertFile( diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/PersistenceClientEntitySelectionVisual.java b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/PersistenceClientEntitySelectionVisual.java index 5966f1b6a2..3a01e4bbf1 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/PersistenceClientEntitySelectionVisual.java +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/PersistenceClientEntitySelectionVisual.java @@ -407,7 +407,7 @@ public class PersistenceClientEntitySelectionVisual extends JPanel { SourceGroup[] groups = SourceGroups.getJavaSourceGroups(project); if (groups.length > 0) { ClassPath compileCP = ClassPath.getClassPath(groups[0].getRootFolder(), ClassPath.COMPILE); - if (compileCP==null || compileCP.findResource("javax/persistence/Entity.class") == null) { // NOI18N + if (compileCP==null || (compileCP.findResource("jakarta/persistence/Entity.class") == null && compileCP.findResource("javax/persistence/Entity.class") == null)) { // NOI18N wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class, "ERR_NoPersistenceProvider")); return false; } diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizard.java b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizard.java index 51e6e48786..624a6d09dc 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizard.java +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizard.java @@ -33,7 +33,6 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.modules.j2ee.core.api.support.java.SourceUtils; import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; @@ -59,6 +58,7 @@ import org.netbeans.modules.j2ee.core.api.support.wizard.Wizards; import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils; import org.netbeans.modules.j2ee.persistence.dd.common.PersistenceUnit; import org.netbeans.modules.j2ee.persistence.provider.InvalidPersistenceXmlException; +import org.netbeans.modules.j2ee.persistence.spi.moduleinfo.JPAModuleInfo; import org.netbeans.modules.j2ee.persistence.unit.PUDataObject; import org.netbeans.modules.j2ee.persistence.util.EntityMethodGenerator; import org.netbeans.modules.j2ee.persistence.util.JPAClassPathHelper; @@ -80,6 +80,7 @@ import org.openide.util.NbBundle; */ public final class EntityWizard implements WizardDescriptor.InstantiatingIterator { + private WizardDescriptor.Panel[] panels; private int index = 0; private EntityWizardDescriptor ejbPanel; @@ -135,17 +136,25 @@ public final class EntityWizard implements WizardDescriptor.InstantiatingIterato @Override public Set instantiate() throws IOException { + Project project = Templates.getProject(wiz); + + ClassPath compileCP = ClassPath.getClassPath(sourceGroups[0].getRootFolder(), ClassPath.COMPILE); + + String enterprisePrefix = "jakarta"; + if (compileCP != null && compileCP.findResource("javax/persistence/Entity.class") != null) { + enterprisePrefix = "javax"; + } FileObject result = generateEntity( Templates.getTargetFolder(wiz), Templates.getTargetName(wiz), ejbPanel.getPrimaryKeyClassName(), - true // setting field access type by default + true, // setting field access type by default + enterprisePrefix ); try{ boolean isCreatePU = ejbPanel.isCreatePU(); - Project project = Templates.getProject(wiz); if(isCreatePU) { PersistenceUnit punit = Util.buildPersistenceUnitUsingData(project, puPanel.getPersistenceUnitName(), puPanel.getPersistenceConnection()!=null ? puPanel.getPersistenceConnection().getName() : puPanel.getDatasource(), TableGeneration.NONE, puPanel.getSelectedProvider()); @@ -253,7 +262,7 @@ public final class EntityWizard implements WizardDescriptor.InstantiatingIterato * @return a FileObject representing the generated entity. */ public static FileObject generateEntity(final FileObject targetFolder, final String targetName, - final String primaryKeyClassName, final boolean isAccessProperty) throws IOException { + final String primaryKeyClassName, final boolean isAccessProperty, final String enterprisePrefix) throws IOException { FileObject entityFo = GenerationUtils.createClass(targetFolder, targetName, null); ClassPath boot = ClassPath.getClassPath(targetFolder, ClassPath.BOOT); @@ -294,9 +303,9 @@ public final class EntityWizard implements WizardDescriptor.InstantiatingIterato ModifiersTree idMethodModifiers = genUtils.createModifiers(Modifier.PUBLIC); MethodTree idGetter = genUtils.createPropertyGetterMethod(idMethodModifiers, idFieldName, typeTree); MethodTree idSetter = genUtils.createPropertySetterMethod(idMethodModifiers, idFieldName, typeTree); - AnnotationTree idAnnotation = genUtils.createAnnotation("javax.persistence.Id"); //NOI18N - ExpressionTree generationStrategy = genUtils.createAnnotationArgument("strategy", "javax.persistence.GenerationType", "AUTO"); //NOI18N - AnnotationTree generatedValueAnnotation = genUtils.createAnnotation("javax.persistence.GeneratedValue", Collections.singletonList(generationStrategy)); //NOI18N + AnnotationTree idAnnotation = genUtils.createAnnotation(enterprisePrefix + ".persistence.Id"); //NOI18N + ExpressionTree generationStrategy = genUtils.createAnnotationArgument("strategy", enterprisePrefix + ".persistence.GenerationType", "AUTO"); //NOI18N + AnnotationTree generatedValueAnnotation = genUtils.createAnnotation(enterprisePrefix + ".persistence.GeneratedValue", Collections.singletonList(generationStrategy)); //NOI18N if (isAccessProperty){ idField = genUtils.addAnnotation(idField, idAnnotation); @@ -313,7 +322,7 @@ public final class EntityWizard implements WizardDescriptor.InstantiatingIterato modifiedClazz = make.addClassMember(modifiedClazz, idGetter); modifiedClazz = make.addClassMember(modifiedClazz, idSetter); modifiedClazz = genUtils.addImplementsClause(modifiedClazz, "java.io.Serializable"); - modifiedClazz = genUtils.addAnnotation(modifiedClazz, genUtils.createAnnotation("javax.persistence.Entity")); + modifiedClazz = genUtils.addAnnotation(modifiedClazz, genUtils.createAnnotation(enterprisePrefix + ".persistence.Entity")); String entityClassFqn = typeElement.getQualifiedName().toString(); EntityMethodGenerator methodGenerator = new EntityMethodGenerator(workingCopy, genUtils, typeElement); diff --git a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java index b3b1cea7f4..32c9bf8568 100644 --- a/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java +++ b/java/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java @@ -636,6 +636,8 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { private boolean decimalCommentExist = false; + protected final String enterprisePrefix; + public ClassGenerator(WorkingCopy copy, EntityClass entityClass) throws IOException { this.copy = copy; copy.toPhase(Phase.RESOLVED); @@ -659,6 +661,17 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { assert originalClassTree != null; newClassTree = originalClassTree; genUtils = GenerationUtils.newInstance(copy); + + String enterprisePrefix; + ClassPath compileClassPath = copy.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE); + if (compileClassPath.findResource("jakarta/persistence/EntityManager.class") != null) { + enterprisePrefix = "jakarta"; + } else if (compileClassPath.findResource("javax/persistence/EntityManager.class") != null) { + enterprisePrefix = "javax"; + } else { + enterprisePrefix = "jakarta"; + } + this.enterprisePrefix = enterprisePrefix; } protected String createFieldName(String capitalizedFieldName) { @@ -686,13 +699,13 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { //add @Id() only if not in an embeddable PK class if (isPKMember && !needsPKClass) { - annotations.add(genUtils.createAnnotation("javax.persistence.Id")); // NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.Id")); // NOI18N if (m.isAutoIncrement()) { // Can only support strategy=GenerationType.IDENTITY. // See issue 76357 - desc 17 List<ExpressionTree> annArguments = new ArrayList<>(); - annArguments.add(genUtils.createAnnotationArgument("strategy", "javax.persistence.GenerationType", "IDENTITY")); // NOI18N - annotations.add(genUtils.createAnnotation("javax.persistence.GeneratedValue", annArguments)); //NOI18N + annArguments.add(genUtils.createAnnotationArgument("strategy", enterprisePrefix + ".persistence.GenerationType", "IDENTITY")); // NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.GeneratedValue", annArguments)); //NOI18N } } @@ -700,7 +713,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if (!m.isNullable()) { List<ExpressionTree> basicAnnArguments = new ArrayList<>(); basicAnnArguments.add(genUtils.createAnnotationArgument("optional", false)); //NOI18N - annotations.add(genUtils.createAnnotation("javax.persistence.Basic", basicAnnArguments)); //NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.Basic", basicAnnArguments)); //NOI18N //Add @NotNull constraint if (generateValidationConstraints && !m.isAutoIncrement()) { //NOI18N annotations.add(genUtils.createAnnotation("javax.validation.constraints.NotNull")); //NOI18N @@ -709,7 +722,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { boolean isLobType = m.isLobType(); if (isLobType) { - annotations.add(genUtils.createAnnotation("javax.persistence.Lob")); // NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.Lob")); // NOI18N } List<ExpressionTree> columnAnnArguments = new ArrayList<>(); @@ -775,13 +788,13 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if(useDefaults && (columnAnnArguments == null || columnAnnArguments.isEmpty())){ //skip default } else { - annotations.add(genUtils.createAnnotation("javax.persistence.Column", columnAnnArguments)); //NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.Column", columnAnnArguments)); //NOI18N } String temporalType = getMemberTemporalType(m); if (temporalType != null) { - ExpressionTree temporalAnnValueArgument = genUtils.createAnnotationArgument(null, "javax.persistence.TemporalType", temporalType); //NOI18N - annotations.add(genUtils.createAnnotation("javax.persistence.Temporal", Collections.singletonList(temporalAnnValueArgument))); + ExpressionTree temporalAnnValueArgument = genUtils.createAnnotationArgument(null, enterprisePrefix + ".persistence.TemporalType", temporalType); //NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.Temporal", Collections.singletonList(temporalAnnValueArgument))); } return new Property(Modifier.PRIVATE, annotations, comment, memberType, memberName); @@ -1060,7 +1073,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { String pkFieldName = createFieldName(pkClassName); pkProperty = new Property( Modifier.PROTECTED, - Collections.singletonList(genUtils.createAnnotation("javax.persistence.EmbeddedId")), + Collections.singletonList(genUtils.createAnnotation(enterprisePrefix + ".persistence.EmbeddedId")), null, pkFQClassName, pkFieldName); @@ -1070,7 +1083,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if (UpdateType.UPDATE.equals(updateType)) { collectExistingColumns(); } else { - newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation(generateMappedSC ? "javax.persistence.MappedSuperclass" : "javax.persistence.Entity")); // NOI18N + newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation(generateMappedSC ? enterprisePrefix + ".persistence.MappedSuperclass" : enterprisePrefix + ".persistence.Entity")); // NOI18N List<ExpressionTree> tableAnnArgs = new ArrayList<>(); if(useDefaults && entityClassName.equalsIgnoreCase(dbMappings.getTableName())){ //skip @@ -1099,7 +1112,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { colArgs.add(genUtils.createAnnotationArgument(null, colName)); } ExpressionTree columnNamesArg = genUtils.createAnnotationArgument("columnNames", colArgs); // NOI18N - uniqueConstraintAnnotations.add(genUtils.createAnnotation("javax.persistence.UniqueConstraint", + uniqueConstraintAnnotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.UniqueConstraint", Collections.singletonList(columnNamesArg))); //NOI18N } @@ -1107,7 +1120,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { } if(!useDefaults || !tableAnnArgs.isEmpty()) { - newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation("javax.persistence.Table", tableAnnArgs));//NOI18N + newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation(enterprisePrefix + ".persistence.Table", tableAnnArgs));//NOI18N } if (generateJAXBAnnotations) { @@ -1367,7 +1380,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { namedQueryAnnArguments.add(genUtils.createAnnotationArgument( "query", namedQueryPrefix + //NOI18N memberAccessString + ((genNamedParams) ? (" = :" + memberName) : "= ?1"))); //NOI18N - namedQueryAnnotations.add(genUtils.createAnnotation("javax.persistence.NamedQuery", namedQueryAnnArguments)); //NOI18N + namedQueryAnnotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.NamedQuery", namedQueryAnnArguments)); //NOI18N } } @@ -1381,7 +1394,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { namedQueryAnnArguments.add(genUtils.createAnnotationArgument("query", queryString)); // NOI18N // Have the findAll as the first NameQuery - namedQueryAnnotations.add(0, genUtils.createAnnotation("javax.persistence.NamedQuery", namedQueryAnnArguments)); //NOI18N + namedQueryAnnotations.add(0, genUtils.createAnnotation(enterprisePrefix + ".persistence.NamedQuery", namedQueryAnnArguments)); //NOI18N } @Override @@ -1389,7 +1402,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if (!UpdateType.UPDATE.equals(updateType) && !generateMappedSC) { addFindAllNamedQueryAnnotation(); - newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation("javax.persistence.NamedQueries", // NOI18N + newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation(enterprisePrefix + ".persistence.NamedQueries", // NOI18N Collections.singletonList(genUtils.createAnnotationArgument(null, namedQueryAnnotations)))); } } @@ -1437,7 +1450,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { List<AnnotationTree> annotations = new ArrayList<>(); List<ExpressionTree> annArguments = new ArrayList<>(); if (role.isCascade()) { - annArguments.add(genUtils.createAnnotationArgument("cascade", "javax.persistence.CascadeType", "ALL")); // NOI18N + annArguments.add(genUtils.createAnnotationArgument("cascade", enterprisePrefix + ".persistence.CascadeType", "ALL")); // NOI18N } if (role.equals(role.getParent().getRoleB())) { // Role B String fName = role.getParent().getRoleA().getFieldName(); @@ -1487,7 +1500,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if (regenTablesAttrs && !columns[colIndex].isNullable()) { attrs.add(genUtils.createAnnotationArgument("nullable", false)); //NOI18N } - joinCols.add(genUtils.createAnnotation("javax.persistence.JoinColumn", attrs)); //NOI18N + joinCols.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinColumn", attrs)); //NOI18N } joinTableAnnArguments.add(genUtils.createAnnotationArgument("joinColumns", joinCols)); // NOI18N @@ -1501,11 +1514,11 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { if (regenTablesAttrs && !invColumns[colIndex].isNullable()) { attrs.add(genUtils.createAnnotationArgument("nullable", false)); //NOI18N } - inverseCols.add(genUtils.createAnnotation("javax.persistence.JoinColumn", attrs)); // NOI18N + inverseCols.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinColumn", attrs)); // NOI18N } joinTableAnnArguments.add(genUtils.createAnnotationArgument("inverseJoinColumns", inverseCols)); // NOI18N - annotations.add(genUtils.createAnnotation("javax.persistence.JoinTable", joinTableAnnArguments)); // NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinTable", joinTableAnnArguments)); // NOI18N } else { // ManyToOne, OneToMany, OneToOne ColumnData[] columns = dbMappings.getCmrFieldMapping().get(role.getFieldName()); CMPMappingModel relatedMappings = beanMap.get(role.getParent().getRoleB().getEntityName()).getCMPMapping(); @@ -1521,7 +1534,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { attrs.add(genUtils.createAnnotationArgument("nullable", false)); } makeReadOnlyIfNecessary(pkColumnNames, columns[0].getColumnName(), attrs); - annotations.add(genUtils.createAnnotation("javax.persistence.JoinColumn", attrs)); //NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinColumn", attrs)); //NOI18N } else { if(existingJoinColumnss.get(fieldType) != null){ return; //currently do not overgenerate and do not update etc existing JoinColumns @@ -1536,10 +1549,10 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { attrs.add(genUtils.createAnnotationArgument("nullable", false)); } makeReadOnlyIfNecessary(pkColumnNames, columns[colIndex].getColumnName(), attrs); - joinCols.add(genUtils.createAnnotation("javax.persistence.JoinColumn", attrs)); // NOI18N + joinCols.add(genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinColumn", attrs)); // NOI18N } ExpressionTree joinColumnsNameAttrValue = genUtils.createAnnotationArgument(null, joinCols); - AnnotationTree joinColumnsAnnotation = genUtils.createAnnotation("javax.persistence.JoinColumns", Collections.singletonList(joinColumnsNameAttrValue)); //NOI18N + AnnotationTree joinColumnsAnnotation = genUtils.createAnnotation(enterprisePrefix + ".persistence.JoinColumns", Collections.singletonList(joinColumnsNameAttrValue)); //NOI18N annotations.add(joinColumnsAnnotation); } } @@ -1565,13 +1578,13 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { //FetchType if (fetchType.equals(FetchType.LAZY)) { - annArguments.add(genUtils.createAnnotationArgument("fetch", "javax.persistence.FetchType", "LAZY")); // NOI18N + annArguments.add(genUtils.createAnnotationArgument("fetch", enterprisePrefix + ".persistence.FetchType", "LAZY")); // NOI18N } else if (fetchType.equals(FetchType.EAGER)) { - annArguments.add(genUtils.createAnnotationArgument("fetch", "javax.persistence.FetchType", "EAGER")); // NOI18N + annArguments.add(genUtils.createAnnotationArgument("fetch", enterprisePrefix + ".persistence.FetchType", "EAGER")); // NOI18N } // Create the relationship annotation - annotations.add(genUtils.createAnnotation("javax.persistence." + relationAnn, annArguments)); // NOI18N + annotations.add(genUtils.createAnnotation(enterprisePrefix + ".persistence." + relationAnn, annArguments)); // NOI18N if (generateJAXBAnnotations && role.isToMany()) { properties.add(new Property(Modifier.PRIVATE, annotations, null, fieldType, memberName, true)); @@ -1692,7 +1705,7 @@ public class JavaPersistenceGenerator implements PersistenceGenerator { newClassTree = genUtils.ensureNoArgConstructor(newClassTree); // primary key class must be serializable and @Embeddable newClassTree = genUtils.addImplementsClause(newClassTree, "java.io.Serializable"); //NOI18N - newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation("javax.persistence.Embeddable")); // NOI18N + newClassTree = genUtils.addAnnotation(newClassTree, genUtils.createAnnotation(enterprisePrefix + ".persistence.Embeddable")); // NOI18N } @Override diff --git a/java/j2ee.persistence/test/unit/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizardTest.java b/java/j2ee.persistence/test/unit/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizardTest.java index 82c0cb1ad4..1ee2dfa344 100644 --- a/java/j2ee.persistence/test/unit/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizardTest.java +++ b/java/j2ee.persistence/test/unit/src/org/netbeans/modules/j2ee/persistence/wizard/entity/EntityWizardTest.java @@ -46,12 +46,12 @@ public class EntityWizardTest extends SourceTestSupport{ } public void testGenerateEntityFieldAccess() throws Exception { - FileObject result = EntityWizard.generateEntity(getPkgFolder(), "MyEntity", "Long", true); + FileObject result = EntityWizard.generateEntity(getPkgFolder(), "MyEntity", "Long", true, "javax"); assertFile(result); } public void testGenerateEntityPropertyAccess() throws Exception { - FileObject result = EntityWizard.generateEntity(getPkgFolder(), "MyEntity", "java.lang.Long", false); + FileObject result = EntityWizard.generateEntity(getPkgFolder(), "MyEntity", "java.lang.Long", false, "javax"); assertFile(result); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists