This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 216053
Collapse All | Expand All

(-)a/j2ee.jpa.verification/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.j2ee.jpa.verification
2
OpenIDE-Module: org.netbeans.modules.j2ee.jpa.verification
3
OpenIDE-Module-Specification-Version: 1.21.1
3
OpenIDE-Module-Specification-Version: 1.21.2
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/jpa/verification/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/jpa/verification/Bundle.properties
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
6
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/JPAProblemContext.java (+26 lines)
Lines 44-49 Link Here
44
44
45
package org.netbeans.modules.j2ee.jpa.verification;
45
package org.netbeans.modules.j2ee.jpa.verification;
46
46
47
import java.util.HashSet;
48
import java.util.Set;
47
import org.netbeans.modules.j2ee.jpa.model.AccessType;
49
import org.netbeans.modules.j2ee.jpa.model.AccessType;
48
import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext;
50
import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext;
49
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
51
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
Lines 60-65 Link Here
60
    private boolean mappedSuperClass;
62
    private boolean mappedSuperClass;
61
    private AccessType accessType;
63
    private AccessType accessType;
62
    private EntityMappingsMetadata metadata;
64
    private EntityMappingsMetadata metadata;
65
    private Set<CancelListener> cListeners;
63
    
66
    
64
    public boolean isEntity(){
67
    public boolean isEntity(){
65
        return entity;
68
        return entity;
Lines 112-115 Link Here
112
    public boolean isJPAClass(){
115
    public boolean isJPAClass(){
113
        return entity || embeddable || idClass || mappedSuperClass;
116
        return entity || embeddable || idClass || mappedSuperClass;
114
    }
117
    }
118
119
    @Override
120
    public void setCancelled(boolean cancelled) {
121
        super.setCancelled(cancelled);
122
        if(cancelled && cListeners != null) {
123
            for(CancelListener cl:cListeners) {
124
                cl.cancelled();
125
            }
126
        }
127
    }
128
129
    public void addCancelListener(CancelListener aThis) {
130
        if(cListeners == null) {
131
            cListeners = new HashSet();
132
        }
133
        cListeners.add(aThis);
134
    }
135
    
136
    public void removeCancelListener(CancelListener cl) {
137
        if(cListeners != null) {
138
            cListeners.remove(cl);
139
        }
140
    }
115
}
141
}
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-85 / +66 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
45
package org.netbeans.modules.j2ee.jpa.verification.rules.entity;
44
package org.netbeans.modules.j2ee.jpa.verification.rules.entity;
46
45
47
import java.util.ArrayList;
46
import java.util.ArrayList;
Lines 49-75 Link Here
49
import java.util.List;
48
import java.util.List;
50
import java.util.ListResourceBundle;
49
import java.util.ListResourceBundle;
51
import java.util.Locale;
50
import java.util.Locale;
52
import java.util.Map;
53
import java.util.MissingResourceException;
51
import java.util.MissingResourceException;
54
import java.util.ResourceBundle;
52
import java.util.ResourceBundle;
55
import java.util.logging.Level;
53
import java.util.logging.Level;
56
import javax.lang.model.element.AnnotationMirror;
57
import javax.lang.model.element.AnnotationValue;
58
import javax.lang.model.element.ExecutableElement;
59
import javax.lang.model.element.TypeElement;
54
import javax.lang.model.element.TypeElement;
60
import org.eclipse.persistence.jpa.internal.jpql.JPQLQueryProblemResourceBundle;
55
import org.eclipse.persistence.jpa.internal.jpql.JPQLQueryProblemResourceBundle;
61
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
56
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
62
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
57
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
63
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
64
import org.netbeans.api.project.FileOwnerQuery;
58
import org.netbeans.api.project.FileOwnerQuery;
65
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.Project;
66
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
60
import org.netbeans.modules.j2ee.jpa.verification.CancelListener;
67
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule;
61
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule;
68
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints;
62
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints;
69
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemContext;
63
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemContext;
70
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemFinder;
64
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemFinder;
71
import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext;
65
import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext;
72
import org.netbeans.modules.j2ee.jpa.verification.common.Utilities;
73
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity;
66
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity;
74
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.NamedQuery;
67
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.NamedQuery;
75
import org.netbeans.modules.j2ee.persistence.spi.jpql.ManagedTypeProvider;
68
import org.netbeans.modules.j2ee.persistence.spi.jpql.ManagedTypeProvider;
Lines 78-182 Link Here
78
import org.netbeans.spi.editor.hints.Severity;
71
import org.netbeans.spi.editor.hints.Severity;
79
72
80
/**
73
/**
81
 * Verify content of @NamedQuery query
74
 * Verify content of
82
 * TODO: good to move warning to query level instead of class level
75
 *
76
 * @NamedQuery query TODO: good to move warning to query level instead of class
77
 * level
83
 */
78
 */
84
public class JPQLValidation extends JPAClassRule {
79
public class JPQLValidation extends JPAClassRule implements CancelListener {
85
    
80
86
    /** Creates a new instance of NonFinalClass */
81
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
82
    private JPQLQueryHelper helper;
83
84
    /**
85
     * Creates a new instance of NonFinalClass
86
     */
87
    public JPQLValidation() {
87
    public JPQLValidation() {
88
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
88
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
89
                ClassConstraints.EMBEDDABLE,
89
                ClassConstraints.EMBEDDABLE,
90
                ClassConstraints.MAPPED_SUPERCLASS));
90
                ClassConstraints.MAPPED_SUPERCLASS));
91
    }
91
    }
92
    
92
93
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
93
    @Override
94
    public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx) {
95
        JPAProblemContext jpaCtx = (JPAProblemContext) ctx;
96
        jpaCtx.addCancelListener(this);
94
        Object modEl = ctx.getModelElement();
97
        Object modEl = ctx.getModelElement();
95
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
98
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
96
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
99
        helper = new JPQLQueryHelper();
97
        ArrayList<String> values = new ArrayList<String>();
100
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
98
        ArrayList<String> names = new ArrayList<String>();
101
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
99
        if(first == null || first.size()==0){
102
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData(), jpaCtx.getCompilationInfo().getElements());
100
            AnnotationMirror qs = Utilities.findAnnotation(subject, JPAAnnotations.NAMED_QUERIES);
103
        if (entity != null) {
101
            if(qs != null){
104
            for (NamedQuery nq : entity.getNamedQuery()) {
102
                Map<? extends ExecutableElement, ? extends AnnotationValue> maps = qs.getElementValues();
105
                if(nq!=null && nq.getQuery()!=null){
103
                for(AnnotationValue vl:maps.values()){
106
                    helper.setQuery(new Query(nq, nq.getQuery(), mtp));
104
                    List  lst = (List) vl.getValue();
107
                    List<JPQLQueryProblem> tmp = null;
105
                    for(Object val:lst){
108
                    try {
106
                        if(val instanceof AnnotationMirror){
109
                        tmp = helper.validate();
107
                            AnnotationMirror am = (AnnotationMirror) val;
110
                    } catch (UnsupportedOperationException ex) {
108
                            if(JPAAnnotations.NAMED_QUERY.equals(am.getAnnotationType().toString())){
111
                        JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex);
109
                                AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(am, "query");
112
                    } catch (NullPointerException ex) {
110
                                AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(am, "name");
113
                        JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex);
111
                                if(qAttrValue != null){
112
                                    values.add(qAttrValue.getValue().toString());
113
                                    names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString());
114
                                }
115
                            }
116
                        }
117
                    }
114
                    }
115
                    if (tmp != null && tmp.size() > 0) {
116
                        problems.addAll(tmp);
117
                    }
118
                    helper.dispose();
118
                }
119
                }
119
            }
120
            }
120
        }
121
        }
121
        else {
122
        ErrorDescription[] ret = null;
122
            for(AnnotationMirror mr:first){
123
        if (!ctx.isCancelled() && problems != null && problems.size() > 0) {
123
                AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(mr, "query");
124
            ret = new ErrorDescription[problems.size()];
124
                AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(mr, "name");
125
            for (int i = 0; i < ret.length; i++) {
125
                if(qAttrValue != null){
126
                    values.add(qAttrValue.getValue().toString());
127
                    names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString());
128
                }
129
            }
130
        }
131
        JPQLQueryHelper helper = new JPQLQueryHelper();
132
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
133
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
134
        for(int index=0;index<values.size();index++){
135
            String value = values.get(index);
136
            String qName = names.get(index);
137
            NamedQuery nq = null;
138
            if(entity != null) {
139
                nq = entity.newNamedQuery();
140
                nq.setQuery(value);
141
                nq.setName(qName);
142
            }
143
            helper.setQuery(new Query(nq, value, new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData())));
144
            List<JPQLQueryProblem> tmp = null;
145
            try{
146
                tmp = helper.validate();
147
            } catch (UnsupportedOperationException ex) {
148
                JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex);
149
            }catch (NullPointerException ex) {
150
                JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex);
151
            }
152
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
153
            helper.dispose();
154
        }
155
        if (problems != null && problems.size()>0){
156
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
157
            for(int i=0;i<ret.length;i++){
158
                ListResourceBundle msgBundle = null;
126
                ListResourceBundle msgBundle = null;
159
                try{
127
                try {
160
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName());//NOI18N
128
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName());//NOI18N
161
                } catch (MissingResourceException ex) {//default en
129
                } catch (MissingResourceException ex) {//default en
162
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName(), Locale.ENGLISH);//NOI18N
130
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName(), Locale.ENGLISH);//NOI18N
163
                }
131
                }
164
                String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[])  problems.get(i).getMessageArguments());
132
                String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[]) problems.get(i).getMessageArguments());
165
                String pos = "["+problems.get(i).getStartPosition() + ";"+problems.get(i).getEndPosition()+"]";
133
                String pos = "[" + problems.get(i).getStartPosition() + ";" + problems.get(i).getEndPosition() + "]";
166
                Query q = (Query) problems.get(i).getQuery();
134
                Query q = (Query) problems.get(i).getQuery();
167
                if(q.getNamedQuery() != null && q.getNamedQuery().getName()!=null){
135
                if (q.getNamedQuery() != null && q.getNamedQuery().getName() != null) {
168
                    pos = q.getNamedQuery().getName()+pos;
136
                    pos = q.getNamedQuery().getName() + pos;
169
                }
137
                }
170
                ret[i] = createProblem(subject, ctx, pos + ": " + message , Severity.WARNING);
138
                ret[i] = createProblem(subject, ctx, pos + ": " + message, Severity.WARNING);
171
            }
139
            }
172
            return ret;
173
        }
140
        }
174
        return null;
141
        jpaCtx.removeCancelListener(this);
142
        mtp = null;
143
        helper = null;
144
        return ret;
175
    }
145
    }
176
    
146
177
    @Override protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
147
    @Override
178
        JPAProblemContext jpaCtx = (JPAProblemContext)ctx;
148
    protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
179
        
149
        JPAProblemContext jpaCtx = (JPAProblemContext) ctx;
150
180
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
151
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
181
    }
152
    }
153
154
    @Override
155
    public void cancelled() {
156
        if (mtp != null) {
157
            mtp.invalidate();
158
        }
159
        if (helper != null) {
160
            helper.dispose();
161
        }
162
    }
182
}
163
}
(-)a/j2ee.persistence.kit/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.j2ee.persistence.kit
2
OpenIDE-Module: org.netbeans.modules.j2ee.persistence.kit
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/persistence/kit/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/persistence/kit/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.16.1
4
OpenIDE-Module-Specification-Version: 1.16.2
5
5
(-)a/j2ee.persistence.kit/src/org/netbeans/modules/j2ee/persistence/kit/Bundle.properties (-1 / +2 lines)
Lines 1-4 Link Here
1
OpenIDE-Module-Display-Category=Java SE
1
OpenIDE-Module-Display-Category=Java SE
2
OpenIDE-Module-Name=Java Persistence
2
OpenIDE-Module-Name=Java Persistence
3
OpenIDE-Module-Short-Description=Java Persistence API support
3
OpenIDE-Module-Short-Description=Java Persistence API support
4
OpenIDE-Module-Long-Description=Provides support for developing applications using the Java Persistence API: generating entity classes from a database or from scratch, hints and refactoring.
4
OpenIDE-Module-Long-Description=Provides support for developing applications using the Java Persistence API: generating entity classes from a database or from scratch, hints and refactoring. \
5
\nFor the list of included fixed bugs please check http://wiki.netbeans.org/NetBeans7.2PatchesInfo.
(-)a/j2ee.persistence/nbproject/project.properties (-1 / +1 lines)
Lines 41-47 Link Here
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
javac.source=1.6
43
javac.source=1.6
44
spec.version.base=1.30.1
44
spec.version.base=1.30.2
45
45
46
test.unit.run.cp.extra=${j2eeserver.dir}/modules/ext/jsr88javax.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar:${masterfs.dir}/modules/org-netbeans-modules-masterfs.jar
46
test.unit.run.cp.extra=${j2eeserver.dir}/modules/ext/jsr88javax.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar:${masterfs.dir}/modules/org-netbeans-modules-masterfs.jar
47
47
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/editor/completion/ETCompletionContextResolver.java (-4 / +3 lines)
Lines 51-57 Link Here
51
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
51
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
52
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
52
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
53
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
53
import org.eclipse.persistence.jpa.jpql.spi.IMapping;
54
import org.netbeans.api.db.explorer.DatabaseConnection;
55
import org.netbeans.api.project.FileOwnerQuery;
54
import org.netbeans.api.project.FileOwnerQuery;
56
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.Project;
57
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction;
56
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction;
Lines 139-148 Link Here
139
            JPQLQueryHelper helper = new JPQLQueryHelper();
138
            JPQLQueryHelper helper = new JPQLQueryHelper();
140
139
141
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
140
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
142
            helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings())));
141
            helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings(), ctx.getController().getElements())));
143
            int offset = ctx.getCompletionOffset() - nnattr.getValueOffset() - (nnattr.isValueQuoted() ? 1 : 0);
142
            int offset = ctx.getCompletionOffset() - nnattr.getValueOffset() - (nnattr.isValueQuoted() ? 1 : 0);
144
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
143
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
145
144
            
146
            if(buildContentAssistProposals!=null && buildContentAssistProposals.hasProposals()){
145
            if(buildContentAssistProposals!=null && buildContentAssistProposals.hasProposals()){
147
                for (String var : buildContentAssistProposals.identificationVariables()) {
146
                for (String var : buildContentAssistProposals.identificationVariables()) {
148
                    results.add(new JPACompletionItem.JPQLElementItem(var, nnattr.isValueQuoted(), nnattr.getValueOffset(), offset, nnattr.getValue().toString(), buildContentAssistProposals));
147
                    results.add(new JPACompletionItem.JPQLElementItem(var, nnattr.isValueQuoted(), nnattr.getValueOffset(), offset, nnattr.getValue().toString(), buildContentAssistProposals));
Lines 169-175 Link Here
169
            completedValue = org.netbeans.modules.j2ee.persistence.editor.completion.Utils.unquote(completedValue);
168
            completedValue = org.netbeans.modules.j2ee.persistence.editor.completion.Utils.unquote(completedValue);
170
169
171
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
170
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
172
            helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings())));
171
            helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings(), ctx.getController().getElements())));
173
            int offset = ctx.getCompletionOffset() - method.getValueOffset() - (method.isWithQ() ? 1 : 0);
172
            int offset = ctx.getCompletionOffset() - method.getValueOffset() - (method.isWithQ() ? 1 : 0);
174
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
173
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
175
174
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedType.java (+2 lines)
Lines 90-96 Link Here
90
    @Override
90
    @Override
91
    public IType getType() {
91
    public IType getType() {
92
        if (type == null) {
92
        if (type == null) {
93
            if(((ManagedTypeProvider)provider).isValid()){
93
                type = provider.getTypeRepository().getType(element.getTypeElement().getQualifiedName().toString());
94
                type = provider.getTypeRepository().getType(element.getTypeElement().getQualifiedName().toString());
95
            }
94
        }
96
        }
95
        return type;
97
        return type;
96
    }
98
    }
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java (-30 / +26 lines)
Lines 41-53 Link Here
41
 */
41
 */
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
43
43
44
import java.util.Arrays;
45
import java.util.Collection;
44
import java.util.Collection;
46
import java.util.Collections;
45
import java.util.Collections;
47
import java.util.HashMap;
46
import java.util.HashMap;
48
import java.util.List;
49
import java.util.Map;
47
import java.util.Map;
50
import java.util.concurrent.ExecutionException;
48
import javax.lang.model.util.Elements;
51
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
49
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
52
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
50
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
53
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
51
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
Lines 56-70 Link Here
56
import org.eclipse.persistence.jpa.jpql.spi.IType;
54
import org.eclipse.persistence.jpa.jpql.spi.IType;
57
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
55
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
58
import org.netbeans.api.project.Project;
56
import org.netbeans.api.project.Project;
59
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
60
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction;
61
import org.netbeans.modules.j2ee.persistence.api.EntityClassScope;
62
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappings;
57
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappings;
63
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
58
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
64
import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils;
59
import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils;
65
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
66
import org.netbeans.modules.j2ee.persistence.wizard.EntityClosure;
67
import org.openide.util.Exceptions;
68
60
69
/**
61
/**
70
 *
62
 *
Lines 76-90 Link Here
76
    private Map<String, IManagedType> managedTypes;
68
    private Map<String, IManagedType> managedTypes;
77
    private ITypeRepository typeRepository;
69
    private ITypeRepository typeRepository;
78
    private final EntityMappings mappings;
70
    private final EntityMappings mappings;
71
    private boolean valid = true;//used to conrol long tasks, if not valid long tasks should be either terminated or goes short way
72
    private final Elements elements;
79
73
80
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData) {
74
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData, Elements elements) {
81
        this.project = project;
75
        this.project = project;
82
        this.mappings = metaData.getRoot();
76
        this.mappings = metaData.getRoot();
77
        this.elements = elements;
83
    }
78
    }
84
    
79
    
85
    public ManagedTypeProvider(Project project, EntityMappings mappings) {
80
    public ManagedTypeProvider(Project project, EntityMappings mappings, Elements elements) {
86
        this.project = project;
81
        this.project = project;
87
        this.mappings = mappings;
82
        this.mappings = mappings;
83
        this.elements = elements;
88
    }
84
    }
89
    
85
    
90
    @Override
86
    @Override
Lines 103-109 Link Here
103
    public IManagedType getManagedType(IType itype) {
99
    public IManagedType getManagedType(IType itype) {
104
        initializeManagedTypes();
100
        initializeManagedTypes();
105
        for (IManagedType mt : managedTypes.values()) {
101
        for (IManagedType mt : managedTypes.values()) {
106
            if (mt.getType().equals(itype)) {
102
            if (isValid() && mt.getType().equals(itype)) {
107
                return mt;
103
                return mt;
108
            }
104
            }
109
        }
105
        }
Lines 124-130 Link Here
124
    @Override
120
    @Override
125
    public ITypeRepository getTypeRepository() {
121
    public ITypeRepository getTypeRepository() {
126
        if (typeRepository == null) {
122
        if (typeRepository == null) {
127
            typeRepository = new TypeRepository(project);
123
            typeRepository = new TypeRepository(project, this, elements);
128
        }
124
        }
129
        return typeRepository;
125
        return typeRepository;
130
    }
126
    }
Lines 141-167 Link Here
141
        initializeManagedTypes();
137
        initializeManagedTypes();
142
        return Collections.unmodifiableCollection(managedTypes.values());
138
        return Collections.unmodifiableCollection(managedTypes.values());
143
    }
139
    }
140
    
141
    public boolean isValid() {
142
        return valid;
143
    }
144
    
145
    /**
146
     * make model invalid and it shoul case processing to stop, minimize etc.
147
     * results with SPI may not be consider valid if provider isn't valid
148
     */
149
    public void invalidate() {
150
        valid = false;
151
        //TODO: may have sense to clean stored data
152
        if(typeRepository != null) {
153
            ((TypeRepository)typeRepository).invalidate();
154
            typeRepository = null;
155
        }
156
    }
144
157
145
    private void initializeManagedTypes() {
158
    private void initializeManagedTypes() {
146
        if (managedTypes == null) {
159
        if (managedTypes == null) {
147
            managedTypes = new HashMap<String, IManagedType>();
160
            managedTypes = new HashMap<String, IManagedType>();
148
            //TODO fill
149
//            EntityClassScope entityClassScope = EntityClassScope.getEntityClassScope(project.getProjectDirectory());
150
//            MetadataModel<EntityMappingsMetadata> model = entityClassScope.getEntityMappingsModel(true);
151
//            MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper = MetadataModelReadHelper.create(model, new MetadataModelAction<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>>() {
152
//
153
//                @Override
154
//                public List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity> run(EntityMappingsMetadata metadata) {
155
//                    return Arrays.asList(metadata.getRoot().getEntity());
156
//                }
157
//            });
158
//            List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity> entities = null;
159
//            try {
160
//                entities = readHelper.getResult();
161
//            } catch (ExecutionException ex) {
162
//                Exceptions.printStackTrace(ex);
163
//            }
164
165
            //TODO: not only entities but mapped superclasses and embeddable?
161
            //TODO: not only entities but mapped superclasses and embeddable?
166
            for (org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity persistentType : mappings.getEntity()) {
162
            for (org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity persistentType : mappings.getEntity()) {
167
163
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java (-12 / +44 lines)
Lines 41-50 Link Here
41
 */
41
 */
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
43
43
44
import java.io.IOException;
44
import java.lang.annotation.Annotation;
45
import java.lang.annotation.Annotation;
45
import java.util.ArrayList;
46
import java.util.ArrayList;
46
import java.util.Collection;
47
import java.util.Collection;
47
import java.util.Collections;
48
import java.util.Collections;
49
import java.util.concurrent.Callable;
48
import javax.lang.model.element.Element;
50
import javax.lang.model.element.Element;
49
import javax.lang.model.element.ElementKind;
51
import javax.lang.model.element.ElementKind;
50
import javax.lang.model.element.ExecutableElement;
52
import javax.lang.model.element.ExecutableElement;
Lines 56-61 Link Here
56
import org.eclipse.persistence.jpa.jpql.spi.IType;
58
import org.eclipse.persistence.jpa.jpql.spi.IType;
57
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
59
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
58
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
60
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
61
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper;
62
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
63
import org.openide.util.Exceptions;
59
64
60
/**
65
/**
61
 *
66
 *
Lines 64-69 Link Here
64
public class Type implements IType{
69
public class Type implements IType{
65
    
70
    
66
    private final Element element;
71
    private final Element element;
72
    private PersistentObject po;
67
    private final ITypeRepository repository;
73
    private final ITypeRepository repository;
68
    private ITypeDeclaration tDeclaration;
74
    private ITypeDeclaration tDeclaration;
69
    private final Class<?> type;
75
    private final Class<?> type;
Lines 71-76 Link Here
71
    private String[] enumConstants;
77
    private String[] enumConstants;
72
    private  String typeName;
78
    private  String typeName;
73
79
80
    public Type(ITypeRepository typeRepository, PersistentObject po) {
81
        element = null;
82
        this.po = po;
83
        this.repository = typeRepository;
84
        type = null;
85
        typeName = po.getTypeElementHandle().getQualifiedName();
86
    }
87
    
74
    public Type(ITypeRepository typeRepository, Element element){
88
    public Type(ITypeRepository typeRepository, Element element){
75
        this.element = element;
89
        this.element = element;
76
        this.repository = typeRepository;
90
        this.repository = typeRepository;
Lines 97-103 Link Here
97
    public Iterable<IConstructor> constructors() {
111
    public Iterable<IConstructor> constructors() {
98
        if(constructors == null){
112
        if(constructors == null){
99
            constructors = new ArrayList<IConstructor>();
113
            constructors = new ArrayList<IConstructor>();
100
            if(element != null){
114
            if(po!=null) {
115
                collectConstructors(constructors, getTypeElement(po));
116
            } else if(element != null){
101
                collectConstructors(constructors, element);
117
                collectConstructors(constructors, element);
102
            } else if (type != null) {
118
            } else if (type != null) {
103
                collectConstructors(constructors, type);
119
                collectConstructors(constructors, type);
Lines 124-132 Link Here
124
    @Override
140
    @Override
125
    public String[] getEnumConstants() {
141
    public String[] getEnumConstants() {
126
        if(enumConstants == null){
142
        if(enumConstants == null){
127
            if(element != null){
143
            Element elt = po != null ? getTypeElement(po) : element;
144
            if(elt != null){
128
                ArrayList<String> constants = new ArrayList<String>();
145
                ArrayList<String> constants = new ArrayList<String>();
129
                for( Element el:element.getEnclosedElements() ){
146
                for( Element el:elt.getEnclosedElements() ){
130
                    if(el.getKind() == ElementKind.ENUM_CONSTANT){
147
                    if(el.getKind() == ElementKind.ENUM_CONSTANT){
131
                        constants.add(el.getSimpleName().toString());
148
                        constants.add(el.getSimpleName().toString());
132
                    }
149
                    }
Lines 154-162 Link Here
154
    @Override
171
    @Override
155
    public String getName() {
172
    public String getName() {
156
        if(typeName == null){
173
        if(typeName == null){
157
            if(element != null){
174
            Element elt = po != null ? getTypeElement(po) : element;
158
                if(element instanceof TypeElement) typeName = ((TypeElement) element).getQualifiedName().toString();
175
            if(elt != null){
159
                else typeName = element.asType().toString();
176
                if(elt instanceof TypeElement) typeName = ((TypeElement) elt).getQualifiedName().toString();
177
                else typeName = elt.asType().toString();
160
            } else if (type != null) {
178
            } else if (type != null) {
161
                typeName = type.getName();
179
                typeName = type.getName();
162
            }
180
            }
Lines 174-190 Link Here
174
192
175
    @Override
193
    @Override
176
    public boolean hasAnnotation(Class<? extends Annotation> type) {
194
    public boolean hasAnnotation(Class<? extends Annotation> type) {
177
        return element != null ? (element.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
195
        Element elt = po != null ? getTypeElement(po) : element;
196
        return elt != null ? (elt.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
178
    }
197
    }
179
198
180
    @Override
199
    @Override
181
    public boolean isAssignableTo(IType itype) {
200
    public boolean isAssignableTo(IType itype) {
182
        if(this == itype) return true;
201
        if(this == itype) return true;
183
        Type tp = (Type) itype;
202
        Type tp = (Type) itype;
184
        if(element != null && tp.element !=null){
203
        Element elt1 = po != null ? getTypeElement(po) : element;
204
        Element elt2 = tp.po != null ? getTypeElement(tp.po) : tp.element;
205
        if(elt1 != null && elt2 !=null){
185
            //interbal nb type
206
            //interbal nb type
186
            String rootName = itype.getName();
207
            String rootName = itype.getName();
187
            TypeElement tEl = (TypeElement) (element instanceof TypeElement ? element : null);
208
            TypeElement tEl = (TypeElement) (elt1 instanceof TypeElement ? elt1 : null);
188
            return haveInHierarchy(tEl, rootName);
209
            return haveInHierarchy(tEl, rootName);
189
        } else if (type !=null && tp.type!=null) {
210
        } else if (type !=null && tp.type!=null) {
190
            //java type
211
            //java type
Lines 196-207 Link Here
196
217
197
    @Override
218
    @Override
198
    public boolean isEnum() {
219
    public boolean isEnum() {
199
        return  (element instanceof TypeElement ? ((TypeElement)element).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
220
        Element elt = po != null ? getTypeElement(po) : element;
221
        return  (elt instanceof TypeElement ? ((TypeElement)elt).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
200
    }
222
    }
201
223
202
    @Override
224
    @Override
203
    public boolean isResolvable() {
225
    public boolean isResolvable() {
204
        return type!=null || element!=null;
226
        return type!=null || element!=null || po!=null;
205
    }
227
    }
206
228
207
    @Override
229
    @Override
Lines 238-244 Link Here
238
        
260
        
239
        TypeElement tmpEl = el;
261
        TypeElement tmpEl = el;
240
        while(tmpEl != null){
262
        while(tmpEl != null){
241
            if(tmpEl.getQualifiedName().toString().equals(name)) return true;
263
            if(tmpEl.getQualifiedName().contentEquals(name)) {
264
                return true;
265
            }
242
            else {
266
            else {
243
                TypeMirror supMirror = tmpEl.getSuperclass();
267
                TypeMirror supMirror = tmpEl.getSuperclass();
244
                if (supMirror.getKind() == TypeKind.DECLARED) {
268
                if (supMirror.getKind() == TypeKind.DECLARED) {
Lines 265-268 Link Here
265
    ITypeRepository getTypeRepository() {
289
    ITypeRepository getTypeRepository() {
266
        return repository;
290
        return repository;
267
    }
291
    }
292
    
293
    private TypeElement getTypeElement(final PersistentObject po){
294
        if(((TypeRepository) repository).isValid()){
295
            return po.getTypeElement();
296
        } else {
297
            return null;
298
        }
299
    }
268
}
300
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-44 / +88 lines)
Lines 41-68 Link Here
41
 */
41
 */
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
42
package org.netbeans.modules.j2ee.persistence.spi.jpql;
43
43
44
import java.io.IOException;
45
import java.util.HashMap;
44
import java.util.HashMap;
46
import java.util.List;
45
import java.util.List;
47
import java.util.Map;
46
import java.util.Map;
48
import javax.lang.model.element.TypeElement;
47
import javax.lang.model.element.TypeElement;
48
import javax.lang.model.util.Elements;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
50
import org.eclipse.persistence.jpa.jpql.spi.IType;
50
import org.eclipse.persistence.jpa.jpql.spi.IType;
51
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
51
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
52
import org.netbeans.api.java.project.JavaProjectConstants;
53
import org.netbeans.api.java.source.ClasspathInfo;
54
import org.netbeans.api.java.source.JavaSource;
55
import org.netbeans.api.java.source.Task;
56
import org.netbeans.api.java.source.WorkingCopy;
57
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
58
import org.netbeans.api.project.ProjectUtils;
59
import org.netbeans.api.project.SourceGroup;
60
import org.netbeans.api.project.Sources;
61
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
53
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
62
import org.netbeans.modules.j2ee.persistence.unit.PUDataObject;
63
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
54
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
64
import org.openide.filesystems.FileObject;
65
import org.openide.util.Exceptions;
66
55
67
/**
56
/**
68
 *
57
 *
Lines 70-117 Link Here
70
 */
59
 */
71
public class TypeRepository implements ITypeRepository {
60
public class TypeRepository implements ITypeRepository {
72
    private final Project project;
61
    private final Project project;
73
    private final Map<String, IType> types;
62
    private final Map<String, IType[]> types;
74
    private PUDataObject dObj;
63
    private final Map<String, Boolean> packages;
75
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
64
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
65
    private final ManagedTypeProvider mtp;
66
    private final Elements elements;
76
67
77
    TypeRepository(Project project){
68
69
    TypeRepository(Project project, ManagedTypeProvider mtp, Elements elements) {
78
        this.project = project;
70
        this.project = project;
79
        types = new HashMap<String, IType>();
71
        this.mtp = mtp;
72
        this.elements = elements;
73
        types = new HashMap<String, IType[]>();
74
        packages = new HashMap<String, Boolean>();
80
    }
75
    }
81
    
76
    
82
    @Override
77
    @Override
83
    public IType getEnumType(String fqn) {
78
    public IType getEnumType(String fqn) {
84
        IType ret = types.get(fqn);
79
        IType[] ret = types.get(fqn);
85
        if(ret == null){
80
        if(ret == null){
86
            fillTypeElement(fqn);
81
            //get main type
82
            int lastPoint = fqn.lastIndexOf('.');
83
            String mainPart = lastPoint > 0 ? fqn.substring(0, lastPoint) : null;
84
            if(mainPart != null){
85
                IType[] mainType = types.get(mainPart);
86
                if(mainType == null){
87
                    //first check packages
88
                    int mainFirstPoint = mainPart.indexOf('.');
89
                    int mainLastPoint = mainPart.lastIndexOf('.');
90
                    
91
                    if(mainFirstPoint != mainLastPoint && mainFirstPoint>-1){
92
                        //we have at least 2 points and at least one for package (we may have nested enums)
93
                        for(int packagePartIndex = mainFirstPoint;packagePartIndex<mainLastPoint && packagePartIndex>-1;packagePartIndex = mainPart.indexOf('.', packagePartIndex+1)){
94
                            String packageStr = mainPart.substring(0,packagePartIndex);
95
                            Boolean exist = packages.get(packageStr);
96
                            if(exist == null){
97
                                packages.put(packageStr, elements.getPackageElement(packageStr)!=null);
98
                                exist = packages.get(packageStr);
99
                            }
100
                            if(Boolean.FALSE.equals(exist)){
101
                                mainType = new Type[]{null};
102
                                types.put(mainPart, mainType);
103
                                break;
104
                            }
105
                        }
106
                    } else if(mainFirstPoint == -1) {
107
                        mainType = new Type[]{null};
108
                        types.put(mainPart, mainType);
109
                    }
110
                    //
111
                    if(mainType == null){
112
                        fillTypeElement(mainPart);
113
                    }
114
                }
115
                mainType = types.get(mainPart);
116
                if(mainType[0] != null){
117
                    fillTypeElement(fqn);
118
                } else {
119
                    types.put(fqn, new Type[]{null});
120
                }
121
            } else {
122
                //shouldn't happens
123
                fillTypeElement(fqn);
124
            }
87
            ret = types.get(fqn);
125
            ret = types.get(fqn);
88
        }
126
        }
89
        return ret;
127
        return ret[0];
90
    }
128
    }
91
129
92
    @Override
130
    @Override
93
    public IType getType(Class<?> type) {
131
    public IType getType(Class<?> type) {
94
        String fqn = type.getCanonicalName();
132
        String fqn = type.getCanonicalName();
95
        IType ret = types.get(fqn);
133
        IType[] ret = types.get(fqn);
96
        if(ret == null){
134
        if(ret == null){
97
            fillTypeElement(type);
135
            fillTypeElement(type);
98
            ret = types.get(fqn);
136
            ret = types.get(fqn);
99
        }
137
        }
100
        return ret;
138
        return ret[0];
101
    }
139
    }
102
140
103
    @Override
141
    @Override
104
    public IType getType(String fqn) {
142
    public IType getType(String fqn) {
105
        IType ret = types.get(fqn);
143
        IType[] ret = types.get(fqn);
106
        if(ret == null){
144
        if(ret == null && isValid()){
107
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
145
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
108
                types.put(fqn, new Type(this, fqn));
146
                types.put(fqn, new Type[] {new Type(this, fqn)});
109
            } else {
147
            } else {
110
                fillTypeElement(fqn);
148
                //try to find in managed
149
                int lastPnt = fqn.lastIndexOf('.');
150
                ManagedType mt = (ManagedType) (lastPnt > -1 ? mtp.getManagedType(fqn.substring(lastPnt+1)) :  mtp.getManagedType(fqn));
151
                if(mt != null  && mt.getPersistentObject() != null && mt.getPersistentObject().getTypeElement()!=null && mt.getPersistentObject().getTypeElement().getQualifiedName().contentEquals(fqn)) {
152
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, mt.getPersistentObject())});
153
                } else {
154
                    //
155
                    fillTypeElement(fqn);
156
                }
111
            }
157
            }
112
            ret = types.get(fqn);
158
            ret = types.get(fqn);
113
        }
159
        }
114
        return ret;
160
        return ret!=null ? ret[0] : null;
115
    }
161
    }
116
162
117
    @Override
163
    @Override
Lines 120-147 Link Here
120
    }
166
    }
121
    
167
    
122
    private void fillTypeElement(final String fqn){
168
    private void fillTypeElement(final String fqn){
123
        Sources sources=ProjectUtils.getSources(project);
169
        types.put(fqn, new Type[]{null});
124
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
170
        if(isValid()){ 
125
        if(groups != null && groups.length>0){
171
            if(isValid()) {
126
            SourceGroup firstGroup=groups[0];
172
                TypeElement te = elements.getTypeElement(fqn);
127
            FileObject fo=firstGroup.getRootFolder();
173
                if(te!=null) {
128
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
174
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
129
            JavaSource javaSource = JavaSource.create(classpathInfo);
175
                }
130
            try {
131
                javaSource.runModificationTask(new Task<WorkingCopy>() {
132
                    @Override
133
                    public void run(WorkingCopy wc) throws Exception {
134
                        TypeElement te = wc.getElements().getTypeElement(fqn);
135
                        if(te != null)types.put(fqn, new Type(TypeRepository.this, te));
136
                    }
137
                });
138
            } catch (IOException ex) {
139
                Exceptions.printStackTrace(ex);
140
            }
176
            }
141
        }
177
        }
142
    }
178
    }
143
    private void fillTypeElement(Class<?> type){
179
    private void fillTypeElement(Class<?> type){
144
        types.put(type.getName(), new Type(TypeRepository.this, type));
180
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
145
    }
181
    }
182
   
146
    
183
    
184
    boolean isValid(){
185
        return mtp.isValid();
186
    }
187
188
    void invalidate() {
189
        
190
    }
147
}
191
}
(-)a/j2ee.persistenceapi/nbproject/project.properties (-1 / +1 lines)
Lines 47-53 Link Here
47
javadoc.apichanges=${basedir}/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
48
requires.nb.javac=true
48
requires.nb.javac=true
49
49
50
spec.version.base=1.19.1
50
spec.version.base=1.19.2
51
test.unit.cp.extra=${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar
51
test.unit.cp.extra=${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar
52
52
53
test.config.stableBTD.includes=**/*Test.class
53
test.config.stableBTD.includes=**/*Test.class
(-)a/j2ee.persistenceapi/src/org/netbeans/modules/j2ee/persistenceapi/metadata/orm/annotation/EntityImpl.java (-6 / +4 lines)
Lines 90-96 Link Here
90
        AnnotationMirror entityAnn = annByType.get("javax.persistence.Entity"); // NOI18N
90
        AnnotationMirror entityAnn = annByType.get("javax.persistence.Entity"); // NOI18N
91
        if (entityAnn == null) {
91
        if (entityAnn == null) {
92
            return false;
92
            return false;
93
        }annByType.get("javax.persistence.NamedQueries");
93
        }
94
        AnnotationParser parser = AnnotationParser.create(helper);
94
        AnnotationParser parser = AnnotationParser.create(helper);
95
        parser.expectString("name", AnnotationParser.defaultValue(typeElement.getSimpleName().toString())); // NOI18N
95
        parser.expectString("name", AnnotationParser.defaultValue(typeElement.getSimpleName().toString())); // NOI18N
96
        ParseResult parseResult = parser.parse(entityAnn); // NOI18N
96
        ParseResult parseResult = parser.parse(entityAnn); // NOI18N
Lines 101-110 Link Here
101
        // XXX locale?
101
        // XXX locale?
102
        table = new TableImpl(helper, annByType.get("javax.persistence.Table"), name.toUpperCase()); // NOI18N
102
        table = new TableImpl(helper, annByType.get("javax.persistence.Table"), name.toUpperCase()); // NOI18N
103
        //fill named queries
103
        //fill named queries
104
        AnnotationMirror nqsAnn = annByType.get("javax.persistence.NamedQueries");
104
        AnnotationMirror nqsAnn = annByType.get("javax.persistence.NamedQueries");// NOI18N
105
        ArrayList<AnnotationMirror> nqAnn = null;
105
        ArrayList<AnnotationMirror> nqAnn = null;
106
        if(nqsAnn == null){
106
        if(nqsAnn == null){
107
            nqsAnn = annByType.get("javax.persistence.NamedQuery");
107
            nqsAnn = annByType.get("javax.persistence.NamedQuery");// NOI18N
108
            if(nqsAnn != null){
108
            if(nqsAnn != null){
109
                nqAnn = new ArrayList<AnnotationMirror>();
109
                nqAnn = new ArrayList<AnnotationMirror>();
110
                nqAnn.add(nqsAnn);
110
                nqAnn.add(nqsAnn);
Lines 117-125 Link Here
117
                    for(Object val:lst){
117
                    for(Object val:lst){
118
                        if(val instanceof AnnotationMirror){
118
                        if(val instanceof AnnotationMirror){
119
                            AnnotationMirror am = (AnnotationMirror) val;
119
                            AnnotationMirror am = (AnnotationMirror) val;
120
                            if("javax.persistence.NamedQuery".equals(am.getAnnotationType().toString())){
120
                            if("javax.persistence.NamedQuery".equals(am.getAnnotationType().toString())){//NOI18N
121
                                nqAnn.add(am);
121
                                nqAnn.add(am);
122
                                //values.add(Utilities.getAnnotationAttrValue(am, "query").toString());
123
                            }
122
                            }
124
                        }
123
                        }
125
                    }
124
                    }
Lines 133-139 Link Here
133
            for(AnnotationMirror am:nqAnn){
132
            for(AnnotationMirror am:nqAnn){
134
                parseResult = parser.parse(am); // NOI18N
133
                parseResult = parser.parse(am); // NOI18N
135
                String nm = parseResult.get("name", String.class); // NOI18N            
134
                String nm = parseResult.get("name", String.class); // NOI18N            
136
                parseResult = parser.parse(am); // NOI18N
137
                String qr = parseResult.get("query", String.class); // NOI18N
135
                String qr = parseResult.get("query", String.class); // NOI18N
138
                this.addNamedQuery(new NamedQueryImpl(nm, qr));
136
                this.addNamedQuery(new NamedQueryImpl(nm, qr));
139
            }
137
            }

Return to bug 216053