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/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-1 / +4 lines)
Lines 91-96 Link Here
91
    }
91
    }
92
    
92
    
93
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
93
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
94
        long start  = System.nanoTime();
94
        Object modEl = ctx.getModelElement();
95
        Object modEl = ctx.getModelElement();
95
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
96
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
96
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
97
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
Lines 131-136 Link Here
131
        JPQLQueryHelper helper = new JPQLQueryHelper();
132
        JPQLQueryHelper helper = new JPQLQueryHelper();
132
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
133
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
133
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
134
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
135
        ManagedTypeProvider mtp = new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData());
134
        for(int index=0;index<values.size();index++){
136
        for(int index=0;index<values.size();index++){
135
            String value = values.get(index);
137
            String value = values.get(index);
136
            String qName = names.get(index);
138
            String qName = names.get(index);
Lines 140-146 Link Here
140
                nq.setQuery(value);
142
                nq.setQuery(value);
141
                nq.setName(qName);
143
                nq.setName(qName);
142
            }
144
            }
143
            helper.setQuery(new Query(nq, value, new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData())));
145
            helper.setQuery(new Query(nq, value, mtp));
144
            List<JPQLQueryProblem> tmp = null;
146
            List<JPQLQueryProblem> tmp = null;
145
            try{
147
            try{
146
                tmp = helper.validate();
148
                tmp = helper.validate();
Lines 151-156 Link Here
151
            }
153
            }
152
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
154
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
153
            helper.dispose();
155
            helper.dispose();
156
            System.out.println("TIME TO COMPLETE: "+(System.nanoTime() - start));
154
        }
157
        }
155
        if (problems != null && problems.size()>0){
158
        if (problems != null && problems.size()>0){
156
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
159
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-1 / +1 lines)
Lines 153-159 Link Here
153
            }
153
            }
154
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
154
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
155
            helper.dispose();
155
            helper.dispose();
156
            System.out.println("TIME TO COMPLETE: "+(System.nanoTime() - start));
156
            //System.out.println("TIME TO COMPLETE: "+(System.nanoTime() - start));
157
        }
157
        }
158
        if (problems != null && problems.size()>0){
158
        if (problems != null && problems.size()>0){
159
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
159
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-11 / +16 lines)
Lines 70-117 Link Here
70
 */
70
 */
71
public class TypeRepository implements ITypeRepository {
71
public class TypeRepository implements ITypeRepository {
72
    private final Project project;
72
    private final Project project;
73
    private final Map<String, IType> types;
73
    private final Map<String, IType[]> types;
74
    private PUDataObject dObj;
74
    private PUDataObject dObj;
75
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
75
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
76
76
77
    TypeRepository(Project project){
77
    TypeRepository(Project project){
78
        this.project = project;
78
        this.project = project;
79
        types = new HashMap<String, IType>();
79
        types = new HashMap<String, IType[]>();
80
    }
80
    }
81
    
81
    
82
    @Override
82
    @Override
83
    public IType getEnumType(String fqn) {
83
    public IType getEnumType(String fqn) {
84
        IType ret = types.get(fqn);
84
        System.out.println("ENUM: "+fqn);
85
        IType[] ret = types.get(fqn);
85
        if(ret == null){
86
        if(ret == null){
86
            fillTypeElement(fqn);
87
            fillTypeElement(fqn);
87
            ret = types.get(fqn);
88
            ret = types.get(fqn);
88
        }
89
        }
89
        return ret;
90
        return ret[0];
90
    }
91
    }
91
92
92
    @Override
93
    @Override
93
    public IType getType(Class<?> type) {
94
    public IType getType(Class<?> type) {
94
        String fqn = type.getCanonicalName();
95
        String fqn = type.getCanonicalName();
95
        IType ret = types.get(fqn);
96
        System.out.println("TYPECL: "+fqn);
97
        IType[] ret = types.get(fqn);
96
        if(ret == null){
98
        if(ret == null){
97
            fillTypeElement(type);
99
            fillTypeElement(type);
98
            ret = types.get(fqn);
100
            ret = types.get(fqn);
99
        }
101
        }
100
        return ret;
102
        return ret[0];
101
    }
103
    }
102
104
103
    @Override
105
    @Override
104
    public IType getType(String fqn) {
106
    public IType getType(String fqn) {
105
        IType ret = types.get(fqn);
107
        System.out.println("TYPEFQ: "+fqn);
108
        IType[] ret = types.get(fqn);
106
        if(ret == null){
109
        if(ret == null){
107
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
110
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
108
                types.put(fqn, new Type(this, fqn));
111
                types.put(fqn, new Type[] {new Type(this, fqn)});
109
            } else {
112
            } else {
110
                fillTypeElement(fqn);
113
                fillTypeElement(fqn);
111
            }
114
            }
112
            ret = types.get(fqn);
115
            ret = types.get(fqn);
113
        }
116
        }
114
        return ret;
117
        return ret[0];
115
    }
118
    }
116
119
117
    @Override
120
    @Override
Lines 120-127 Link Here
120
    }
123
    }
121
    
124
    
122
    private void fillTypeElement(final String fqn){
125
    private void fillTypeElement(final String fqn){
126
        System.out.println("FILL FQN: "+fqn);
123
        Sources sources=ProjectUtils.getSources(project);
127
        Sources sources=ProjectUtils.getSources(project);
124
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
128
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
129
        types.put(fqn, new Type[]{null});
125
        if(groups != null && groups.length>0){
130
        if(groups != null && groups.length>0){
126
            SourceGroup firstGroup=groups[0];
131
            SourceGroup firstGroup=groups[0];
127
            FileObject fo=firstGroup.getRootFolder();
132
            FileObject fo=firstGroup.getRootFolder();
Lines 132-138 Link Here
132
                    @Override
137
                    @Override
133
                    public void run(WorkingCopy wc) throws Exception {
138
                    public void run(WorkingCopy wc) throws Exception {
134
                        TypeElement te = wc.getElements().getTypeElement(fqn);
139
                        TypeElement te = wc.getElements().getTypeElement(fqn);
135
                        if(te != null)types.put(fqn, new Type(TypeRepository.this, te));
140
                        if(te!=null) types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
136
                    }
141
                    }
137
                });
142
                });
138
            } catch (IOException ex) {
143
            } catch (IOException ex) {
Lines 141-147 Link Here
141
        }
146
        }
142
    }
147
    }
143
    private void fillTypeElement(Class<?> type){
148
    private void fillTypeElement(Class<?> type){
144
        types.put(type.getName(), new Type(TypeRepository.this, type));
149
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
145
    }
150
    }
146
    
151
    
147
}
152
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-4 lines)
Lines 81-87 Link Here
81
    
81
    
82
    @Override
82
    @Override
83
    public IType getEnumType(String fqn) {
83
    public IType getEnumType(String fqn) {
84
        System.out.println("ENUM: "+fqn);
85
        IType[] ret = types.get(fqn);
84
        IType[] ret = types.get(fqn);
86
        if(ret == null){
85
        if(ret == null){
87
            fillTypeElement(fqn);
86
            fillTypeElement(fqn);
Lines 93-99 Link Here
93
    @Override
92
    @Override
94
    public IType getType(Class<?> type) {
93
    public IType getType(Class<?> type) {
95
        String fqn = type.getCanonicalName();
94
        String fqn = type.getCanonicalName();
96
        System.out.println("TYPECL: "+fqn);
97
        IType[] ret = types.get(fqn);
95
        IType[] ret = types.get(fqn);
98
        if(ret == null){
96
        if(ret == null){
99
            fillTypeElement(type);
97
            fillTypeElement(type);
Lines 104-110 Link Here
104
102
105
    @Override
103
    @Override
106
    public IType getType(String fqn) {
104
    public IType getType(String fqn) {
107
        System.out.println("TYPEFQ: "+fqn);
108
        IType[] ret = types.get(fqn);
105
        IType[] ret = types.get(fqn);
109
        if(ret == null){
106
        if(ret == null){
110
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
107
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
Lines 123-129 Link Here
123
    }
120
    }
124
    
121
    
125
    private void fillTypeElement(final String fqn){
122
    private void fillTypeElement(final String fqn){
126
        System.out.println("FILL FQN: "+fqn);
127
        Sources sources=ProjectUtils.getSources(project);
123
        Sources sources=ProjectUtils.getSources(project);
128
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
124
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
129
        types.put(fqn, new Type[]{null});
125
        types.put(fqn, new Type[]{null});
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-6 / +3 lines)
Lines 60-66 Link Here
60
import org.eclipse.persistence.jpa.internal.jpql.JPQLQueryProblemResourceBundle;
60
import org.eclipse.persistence.jpa.internal.jpql.JPQLQueryProblemResourceBundle;
61
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
61
import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper;
62
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
62
import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem;
63
import org.eclipse.persistence.jpa.jpql.spi.IQuery;
64
import org.netbeans.api.project.FileOwnerQuery;
63
import org.netbeans.api.project.FileOwnerQuery;
65
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.Project;
66
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
65
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
Lines 81-87 Link Here
81
 * Verify content of @NamedQuery query
80
 * Verify content of @NamedQuery query
82
 * TODO: good to move warning to query level instead of class level
81
 * TODO: good to move warning to query level instead of class level
83
 */
82
 */
84
public class JPQLValidation extends JPAClassRule {
83
public class JPQLValidation extends JPAClassRule{
85
    
84
    
86
    /** Creates a new instance of NonFinalClass */
85
    /** Creates a new instance of NonFinalClass */
87
    public JPQLValidation() {
86
    public JPQLValidation() {
Lines 91-97 Link Here
91
    }
90
    }
92
    
91
    
93
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
92
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
94
        long start  = System.nanoTime();
95
        Object modEl = ctx.getModelElement();
93
        Object modEl = ctx.getModelElement();
96
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
94
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
97
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
95
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
Lines 133-139 Link Here
133
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
131
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
134
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
132
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
135
        ManagedTypeProvider mtp = new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData());
133
        ManagedTypeProvider mtp = new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData());
136
        for(int index=0;index<values.size();index++){
134
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
137
            String value = values.get(index);
135
            String value = values.get(index);
138
            String qName = names.get(index);
136
            String qName = names.get(index);
139
            NamedQuery nq = null;
137
            NamedQuery nq = null;
Lines 153-161 Link Here
153
            }
151
            }
154
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
152
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
155
            helper.dispose();
153
            helper.dispose();
156
            //System.out.println("TIME TO COMPLETE: "+(System.nanoTime() - start));
157
        }
154
        }
158
        if (problems != null && problems.size()>0){
155
        if (!ctx.isCancelled() && problems != null && problems.size()>0){
159
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
156
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
160
            for(int i=0;i<ret.length;i++){
157
            for(int i=0;i<ret.length;i++){
161
                ListResourceBundle msgBundle = null;
158
                ListResourceBundle msgBundle = null;
(-)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.22
3
OpenIDE-Module-Specification-Version: 1.22.1
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/nbproject/project.xml (-1 / +1 lines)
Lines 71-77 Link Here
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <specification-version>1.29</specification-version>
74
                        <specification-version>1.31.1</specification-version>
75
                    </run-dependency>
75
                    </run-dependency>
76
                </dependency>
76
                </dependency>
77
                <dependency>
77
                <dependency>
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/CancelListener.java (+50 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.j2ee.jpa.verification;
43
44
/**
45
 * handle verification cancelling with this interface
46
 * @author sp153251
47
 */
48
public interface CancelListener {
49
    void cancelled();
50
}
(-)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 (-5 / +17 lines)
Lines 63-68 Link Here
63
import org.netbeans.api.project.FileOwnerQuery;
63
import org.netbeans.api.project.FileOwnerQuery;
64
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.Project;
65
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
65
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
66
import org.netbeans.modules.j2ee.jpa.verification.CancelListener;
66
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule;
67
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule;
67
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints;
68
import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints;
68
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemContext;
69
import org.netbeans.modules.j2ee.jpa.verification.JPAProblemContext;
Lines 80-86 Link Here
80
 * Verify content of @NamedQuery query
81
 * Verify content of @NamedQuery query
81
 * TODO: good to move warning to query level instead of class level
82
 * TODO: good to move warning to query level instead of class level
82
 */
83
 */
83
public class JPQLValidation extends JPAClassRule{
84
public class JPQLValidation extends JPAClassRule implements CancelListener{
85
    
86
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
84
    
87
    
85
    /** Creates a new instance of NonFinalClass */
88
    /** Creates a new instance of NonFinalClass */
86
    public JPQLValidation() {
89
    public JPQLValidation() {
Lines 90-95 Link Here
90
    }
93
    }
91
    
94
    
92
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
95
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
96
        JPAProblemContext jpaCtx = (JPAProblemContext)ctx;
97
        jpaCtx.addCancelListener(this);
93
        Object modEl = ctx.getModelElement();
98
        Object modEl = ctx.getModelElement();
94
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
99
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
95
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
100
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
Lines 130-136 Link Here
130
        JPQLQueryHelper helper = new JPQLQueryHelper();
135
        JPQLQueryHelper helper = new JPQLQueryHelper();
131
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
136
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
132
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
137
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
133
        ManagedTypeProvider mtp = new ManagedTypeProvider(project, ((JPAProblemContext)ctx).getMetaData());
138
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData());
134
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
139
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
135
            String value = values.get(index);
140
            String value = values.get(index);
136
            String qName = names.get(index);
141
            String qName = names.get(index);
Lines 152-159 Link Here
152
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
157
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
153
            helper.dispose();
158
            helper.dispose();
154
        }
159
        }
160
        ErrorDescription[] ret = null;
155
        if (!ctx.isCancelled() && problems != null && problems.size()>0){
161
        if (!ctx.isCancelled() && problems != null && problems.size()>0){
156
            ErrorDescription[] ret = new ErrorDescription[problems.size()];
162
            ret = new ErrorDescription[problems.size()];
157
            for(int i=0;i<ret.length;i++){
163
            for(int i=0;i<ret.length;i++){
158
                ListResourceBundle msgBundle = null;
164
                ListResourceBundle msgBundle = null;
159
                try{
165
                try{
Lines 169-177 Link Here
169
                }
175
                }
170
                ret[i] = createProblem(subject, ctx, pos + ": " + message , Severity.WARNING);
176
                ret[i] = createProblem(subject, ctx, pos + ": " + message , Severity.WARNING);
171
            }
177
            }
172
            return ret;
173
        }
178
        }
174
        return null;
179
        jpaCtx.removeCancelListener(this);
180
        mtp = null;
181
        return ret;
175
    }
182
    }
176
    
183
    
177
    @Override protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
184
    @Override protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
Lines 179-182 Link Here
179
        
186
        
180
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
187
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
181
    }
188
    }
189
190
    @Override
191
    public void cancelled() {
192
        if(mtp != null)mtp.invalidate();
193
    }
182
}
194
}
(-)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.31.0
44
spec.version.base=1.31.1
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/spi/jpql/ManagedTypeProvider.java (-10 / +15 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;
51
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
48
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
52
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
49
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
53
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
50
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
Lines 56-70 Link Here
56
import org.eclipse.persistence.jpa.jpql.spi.IType;
53
import org.eclipse.persistence.jpa.jpql.spi.IType;
57
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
54
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
58
import org.netbeans.api.project.Project;
55
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;
56
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappings;
63
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
57
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
64
import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils;
58
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
59
69
/**
60
/**
70
 *
61
 *
Lines 76-81 Link Here
76
    private Map<String, IManagedType> managedTypes;
67
    private Map<String, IManagedType> managedTypes;
77
    private ITypeRepository typeRepository;
68
    private ITypeRepository typeRepository;
78
    private final EntityMappings mappings;
69
    private final EntityMappings mappings;
70
    private boolean valid = true;//used to conrol long tasks, if not valid long tasks should be either terminated or goes short way
79
71
80
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData) {
72
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData) {
81
        this.project = project;
73
        this.project = project;
Lines 124-130 Link Here
124
    @Override
116
    @Override
125
    public ITypeRepository getTypeRepository() {
117
    public ITypeRepository getTypeRepository() {
126
        if (typeRepository == null) {
118
        if (typeRepository == null) {
127
            typeRepository = new TypeRepository(project);
119
            typeRepository = new TypeRepository(project, this);
128
        }
120
        }
129
        return typeRepository;
121
        return typeRepository;
130
    }
122
    }
Lines 141-146 Link Here
141
        initializeManagedTypes();
133
        initializeManagedTypes();
142
        return Collections.unmodifiableCollection(managedTypes.values());
134
        return Collections.unmodifiableCollection(managedTypes.values());
143
    }
135
    }
136
    
137
    public boolean isValid() {
138
        return valid;
139
    }
140
    
141
    /**
142
     * make model invalid and it shoul case processing to stop, minimize etc.
143
     * results with SPI may not be consider valid if provider isn't valid
144
     */
145
    public void invalidate() {
146
        valid = false;
147
        //TODO: may have sense to clean stored data
148
    }
144
149
145
    private void initializeManagedTypes() {
150
    private void initializeManagedTypes() {
146
        if (managedTypes == null) {
151
        if (managedTypes == null) {
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-4 / +11 lines)
Lines 73-81 Link Here
73
    private final Map<String, IType[]> types;
73
    private final Map<String, IType[]> types;
74
    private PUDataObject dObj;
74
    private PUDataObject dObj;
75
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
75
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
76
    private final ManagedTypeProvider mtp;
76
77
77
    TypeRepository(Project project){
78
79
    TypeRepository(Project project, ManagedTypeProvider mtp) {
78
        this.project = project;
80
        this.project = project;
81
        this.mtp = mtp;
79
        types = new HashMap<String, IType[]>();
82
        types = new HashMap<String, IType[]>();
80
    }
83
    }
81
    
84
    
Lines 123-129 Link Here
123
        Sources sources=ProjectUtils.getSources(project);
126
        Sources sources=ProjectUtils.getSources(project);
124
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
127
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
125
        types.put(fqn, new Type[]{null});
128
        types.put(fqn, new Type[]{null});
126
        if(groups != null && groups.length>0){
129
        if(mtp.isValid() && groups != null && groups.length>0){
127
            SourceGroup firstGroup=groups[0];
130
            SourceGroup firstGroup=groups[0];
128
            FileObject fo=firstGroup.getRootFolder();
131
            FileObject fo=firstGroup.getRootFolder();
129
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
132
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
Lines 132-139 Link Here
132
                javaSource.runModificationTask(new Task<WorkingCopy>() {
135
                javaSource.runModificationTask(new Task<WorkingCopy>() {
133
                    @Override
136
                    @Override
134
                    public void run(WorkingCopy wc) throws Exception {
137
                    public void run(WorkingCopy wc) throws Exception {
135
                        TypeElement te = wc.getElements().getTypeElement(fqn);
138
                        if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
136
                        if(te!=null) types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
139
                            TypeElement te = wc.getElements().getTypeElement(fqn);
140
                            if(te!=null) {
141
                                types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
142
                            }
143
                        }
137
                    }
144
                    }
138
                });
145
                });
139
            } catch (IOException ex) {
146
            } catch (IOException ex) {
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-1 / +18 lines)
Lines 86-92 Link Here
86
    public IType getEnumType(String fqn) {
86
    public IType getEnumType(String fqn) {
87
        IType[] ret = types.get(fqn);
87
        IType[] ret = types.get(fqn);
88
        if(ret == null){
88
        if(ret == null){
89
            fillTypeElement(fqn);
89
            //get main type
90
            int lastPoint = fqn.lastIndexOf('.');
91
            String mainPart = lastPoint > 0 ? fqn.substring(0, lastPoint) : null;
92
            if(mainPart != null){
93
                IType[] mainType = types.get(mainPart);
94
                if(mainType == null){
95
                    fillTypeElement(mainPart);
96
                }
97
                mainType = types.get(mainPart);
98
                if(mainType[0] != null){
99
                    fillTypeElement(fqn);
100
                } else {
101
                    types.put(fqn, new Type[]{null});
102
                }
103
            } else {
104
                //shouldn't happens
105
                fillTypeElement(fqn);
106
            }
90
            ret = types.get(fqn);
107
            ret = types.get(fqn);
91
        }
108
        }
92
        return ret[0];
109
        return ret[0];
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java (-17 lines)
Lines 150-172 Link Here
150
    private void initializeManagedTypes() {
150
    private void initializeManagedTypes() {
151
        if (managedTypes == null) {
151
        if (managedTypes == null) {
152
            managedTypes = new HashMap<String, IManagedType>();
152
            managedTypes = new HashMap<String, IManagedType>();
153
            //TODO fill
154
//            EntityClassScope entityClassScope = EntityClassScope.getEntityClassScope(project.getProjectDirectory());
155
//            MetadataModel<EntityMappingsMetadata> model = entityClassScope.getEntityMappingsModel(true);
156
//            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>>() {
157
//
158
//                @Override
159
//                public List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity> run(EntityMappingsMetadata metadata) {
160
//                    return Arrays.asList(metadata.getRoot().getEntity());
161
//                }
162
//            });
163
//            List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity> entities = null;
164
//            try {
165
//                entities = readHelper.getResult();
166
//            } catch (ExecutionException ex) {
167
//                Exceptions.printStackTrace(ex);
168
//            }
169
170
            //TODO: not only entities but mapped superclasses and embeddable?
153
            //TODO: not only entities but mapped superclasses and embeddable?
171
            for (org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity persistentType : mappings.getEntity()) {
154
            for (org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity persistentType : mappings.getEntity()) {
172
155
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java (-1 / +3 lines)
Lines 238-244 Link Here
238
        
238
        
239
        TypeElement tmpEl = el;
239
        TypeElement tmpEl = el;
240
        while(tmpEl != null){
240
        while(tmpEl != null){
241
            if(tmpEl.getQualifiedName().toString().equals(name)) return true;
241
            if(tmpEl.getQualifiedName().contentEquals(name)) {
242
                return true;
243
            }
242
            else {
244
            else {
243
                TypeMirror supMirror = tmpEl.getSuperclass();
245
                TypeMirror supMirror = tmpEl.getSuperclass();
244
                if (supMirror.getKind() == TypeKind.DECLARED) {
246
                if (supMirror.getKind() == TypeKind.DECLARED) {
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-1 / +11 lines)
Lines 47-52 Link Here
47
import java.util.Map;
47
import java.util.Map;
48
import javax.lang.model.element.TypeElement;
48
import javax.lang.model.element.TypeElement;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
50
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
50
import org.eclipse.persistence.jpa.jpql.spi.IType;
51
import org.eclipse.persistence.jpa.jpql.spi.IType;
51
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
52
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
52
import org.netbeans.api.java.project.JavaProjectConstants;
53
import org.netbeans.api.java.project.JavaProjectConstants;
Lines 127-133 Link Here
127
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
128
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
128
                types.put(fqn, new Type[] {new Type(this, fqn)});
129
                types.put(fqn, new Type[] {new Type(this, fqn)});
129
            } else {
130
            } else {
130
                fillTypeElement(fqn);
131
                //try to find in managed
132
                int lastPnt = fqn.lastIndexOf('.');
133
                ManagedType mt = (ManagedType) (lastPnt > -1 ? mtp.getManagedType(fqn.substring(lastPnt+1)) :  mtp.getManagedType(fqn));
134
                if(mt != null  && mt.getPersistentObject() != null && mt.getPersistentObject().getTypeElement()!=null && mt.getPersistentObject().getTypeElement().getQualifiedName().contentEquals(fqn)) {
135
                    TypeElement te = mt.getPersistentObject().getTypeElement();
136
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
137
                } else {
138
                    //
139
                    fillTypeElement(fqn);
140
                }
131
            }
141
            }
132
            ret = types.get(fqn);
142
            ret = types.get(fqn);
133
        }
143
        }
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java (-11 / +28 lines)
Lines 56-61 Link Here
56
import org.eclipse.persistence.jpa.jpql.spi.IType;
56
import org.eclipse.persistence.jpa.jpql.spi.IType;
57
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
57
import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration;
58
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
58
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
59
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
59
60
60
/**
61
/**
61
 *
62
 *
Lines 64-69 Link Here
64
public class Type implements IType{
65
public class Type implements IType{
65
    
66
    
66
    private final Element element;
67
    private final Element element;
68
    private PersistentObject po;
67
    private final ITypeRepository repository;
69
    private final ITypeRepository repository;
68
    private ITypeDeclaration tDeclaration;
70
    private ITypeDeclaration tDeclaration;
69
    private final Class<?> type;
71
    private final Class<?> type;
Lines 71-76 Link Here
71
    private String[] enumConstants;
73
    private String[] enumConstants;
72
    private  String typeName;
74
    private  String typeName;
73
75
76
    public Type(ITypeRepository typeRepository, PersistentObject po) {
77
        element = null;
78
        this.po = po;
79
        this.repository = typeRepository;
80
        type = null;
81
    }
82
    
74
    public Type(ITypeRepository typeRepository, Element element){
83
    public Type(ITypeRepository typeRepository, Element element){
75
        this.element = element;
84
        this.element = element;
76
        this.repository = typeRepository;
85
        this.repository = typeRepository;
Lines 97-103 Link Here
97
    public Iterable<IConstructor> constructors() {
106
    public Iterable<IConstructor> constructors() {
98
        if(constructors == null){
107
        if(constructors == null){
99
            constructors = new ArrayList<IConstructor>();
108
            constructors = new ArrayList<IConstructor>();
100
            if(element != null){
109
            if(po!=null) {
110
                collectConstructors(constructors, po.getTypeElement());
111
            } else if(element != null){
101
                collectConstructors(constructors, element);
112
                collectConstructors(constructors, element);
102
            } else if (type != null) {
113
            } else if (type != null) {
103
                collectConstructors(constructors, type);
114
                collectConstructors(constructors, type);
Lines 124-132 Link Here
124
    @Override
135
    @Override
125
    public String[] getEnumConstants() {
136
    public String[] getEnumConstants() {
126
        if(enumConstants == null){
137
        if(enumConstants == null){
127
            if(element != null){
138
            Element elt = po != null ? po.getTypeElement() : element;
139
            if(elt != null){
128
                ArrayList<String> constants = new ArrayList<String>();
140
                ArrayList<String> constants = new ArrayList<String>();
129
                for( Element el:element.getEnclosedElements() ){
141
                for( Element el:elt.getEnclosedElements() ){
130
                    if(el.getKind() == ElementKind.ENUM_CONSTANT){
142
                    if(el.getKind() == ElementKind.ENUM_CONSTANT){
131
                        constants.add(el.getSimpleName().toString());
143
                        constants.add(el.getSimpleName().toString());
132
                    }
144
                    }
Lines 154-162 Link Here
154
    @Override
166
    @Override
155
    public String getName() {
167
    public String getName() {
156
        if(typeName == null){
168
        if(typeName == null){
157
            if(element != null){
169
            Element elt = po != null ? po.getTypeElement() : element;
158
                if(element instanceof TypeElement) typeName = ((TypeElement) element).getQualifiedName().toString();
170
            if(elt != null){
159
                else typeName = element.asType().toString();
171
                if(elt instanceof TypeElement) typeName = ((TypeElement) elt).getQualifiedName().toString();
172
                else typeName = elt.asType().toString();
160
            } else if (type != null) {
173
            } else if (type != null) {
161
                typeName = type.getName();
174
                typeName = type.getName();
162
            }
175
            }
Lines 174-190 Link Here
174
187
175
    @Override
188
    @Override
176
    public boolean hasAnnotation(Class<? extends Annotation> type) {
189
    public boolean hasAnnotation(Class<? extends Annotation> type) {
177
        return element != null ? (element.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
190
        Element elt = po != null ? po.getTypeElement() : element;
191
        return elt != null ? (elt.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
178
    }
192
    }
179
193
180
    @Override
194
    @Override
181
    public boolean isAssignableTo(IType itype) {
195
    public boolean isAssignableTo(IType itype) {
182
        if(this == itype) return true;
196
        if(this == itype) return true;
183
        Type tp = (Type) itype;
197
        Type tp = (Type) itype;
184
        if(element != null && tp.element !=null){
198
        Element elt1 = po != null ? po.getTypeElement() : element;
199
        Element elt2 = tp.po != null ? tp.po.getTypeElement() : tp.element;
200
        if(elt1 != null && elt2 !=null){
185
            //interbal nb type
201
            //interbal nb type
186
            String rootName = itype.getName();
202
            String rootName = itype.getName();
187
            TypeElement tEl = (TypeElement) (element instanceof TypeElement ? element : null);
203
            TypeElement tEl = (TypeElement) (elt1 instanceof TypeElement ? elt1 : null);
188
            return haveInHierarchy(tEl, rootName);
204
            return haveInHierarchy(tEl, rootName);
189
        } else if (type !=null && tp.type!=null) {
205
        } else if (type !=null && tp.type!=null) {
190
            //java type
206
            //java type
Lines 196-207 Link Here
196
212
197
    @Override
213
    @Override
198
    public boolean isEnum() {
214
    public boolean isEnum() {
199
        return  (element instanceof TypeElement ? ((TypeElement)element).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
215
        Element elt = po != null ? po.getTypeElement() : element;
216
        return  (elt instanceof TypeElement ? ((TypeElement)elt).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
200
    }
217
    }
201
218
202
    @Override
219
    @Override
203
    public boolean isResolvable() {
220
    public boolean isResolvable() {
204
        return type!=null || element!=null;
221
        return type!=null || element!=null || po!=null;
205
    }
222
    }
206
223
207
    @Override
224
    @Override
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-3 / +6 lines)
Lines 59-64 Link Here
59
import org.netbeans.api.project.ProjectUtils;
59
import org.netbeans.api.project.ProjectUtils;
60
import org.netbeans.api.project.SourceGroup;
60
import org.netbeans.api.project.SourceGroup;
61
import org.netbeans.api.project.Sources;
61
import org.netbeans.api.project.Sources;
62
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper;
63
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
62
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
64
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
63
import org.netbeans.modules.j2ee.persistence.unit.PUDataObject;
65
import org.netbeans.modules.j2ee.persistence.unit.PUDataObject;
64
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
66
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
Lines 132-139 Link Here
132
                int lastPnt = fqn.lastIndexOf('.');
134
                int lastPnt = fqn.lastIndexOf('.');
133
                ManagedType mt = (ManagedType) (lastPnt > -1 ? mtp.getManagedType(fqn.substring(lastPnt+1)) :  mtp.getManagedType(fqn));
135
                ManagedType mt = (ManagedType) (lastPnt > -1 ? mtp.getManagedType(fqn.substring(lastPnt+1)) :  mtp.getManagedType(fqn));
134
                if(mt != null  && mt.getPersistentObject() != null && mt.getPersistentObject().getTypeElement()!=null && mt.getPersistentObject().getTypeElement().getQualifiedName().contentEquals(fqn)) {
136
                if(mt != null  && mt.getPersistentObject() != null && mt.getPersistentObject().getTypeElement()!=null && mt.getPersistentObject().getTypeElement().getQualifiedName().contentEquals(fqn)) {
135
                    TypeElement te = mt.getPersistentObject().getTypeElement();
137
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, mt.getPersistentObject())});
136
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
137
                } else {
138
                } else {
138
                    //
139
                    //
139
                    fillTypeElement(fqn);
140
                    fillTypeElement(fqn);
Lines 157-162 Link Here
157
            SourceGroup firstGroup=groups[0];
158
            SourceGroup firstGroup=groups[0];
158
            FileObject fo=firstGroup.getRootFolder();
159
            FileObject fo=firstGroup.getRootFolder();
159
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
160
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
161
            final AnnotationModelHelper helper = AnnotationModelHelper.create(classpathInfo);
160
            JavaSource javaSource = JavaSource.create(classpathInfo);
162
            JavaSource javaSource = JavaSource.create(classpathInfo);
161
            try {
163
            try {
162
                javaSource.runModificationTask(new Task<WorkingCopy>() {
164
                javaSource.runModificationTask(new Task<WorkingCopy>() {
Lines 165-171 Link Here
165
                        if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
167
                        if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
166
                            TypeElement te = wc.getElements().getTypeElement(fqn);
168
                            TypeElement te = wc.getElements().getTypeElement(fqn);
167
                            if(te!=null) {
169
                            if(te!=null) {
168
                                types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
170
                                PersistentObject po = new PersistentObject(helper, te) {};
171
                                types.put(fqn, new Type[]{new Type(TypeRepository.this, po)});
169
                            }
172
                            }
170
                        }
173
                        }
171
                    }
174
                    }
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java (-1 / +1 lines)
Lines 95-101 Link Here
95
    public IManagedType getManagedType(IType itype) {
95
    public IManagedType getManagedType(IType itype) {
96
        initializeManagedTypes();
96
        initializeManagedTypes();
97
        for (IManagedType mt : managedTypes.values()) {
97
        for (IManagedType mt : managedTypes.values()) {
98
            if (mt.getType().equals(itype)) {
98
            if (isValid() && mt.getType().equals(itype)) {
99
                return mt;
99
                return mt;
100
            }
100
            }
101
        }
101
        }
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java (-7 / +33 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-62 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;
59
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
62
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
63
import org.openide.util.Exceptions;
60
64
61
/**
65
/**
62
 *
66
 *
Lines 78-83 Link Here
78
        this.po = po;
82
        this.po = po;
79
        this.repository = typeRepository;
83
        this.repository = typeRepository;
80
        type = null;
84
        type = null;
85
        typeName = po.getTypeElementHandle().getQualifiedName();
81
    }
86
    }
82
    
87
    
83
    public Type(ITypeRepository typeRepository, Element element){
88
    public Type(ITypeRepository typeRepository, Element element){
Lines 107-113 Link Here
107
        if(constructors == null){
112
        if(constructors == null){
108
            constructors = new ArrayList<IConstructor>();
113
            constructors = new ArrayList<IConstructor>();
109
            if(po!=null) {
114
            if(po!=null) {
110
                collectConstructors(constructors, po.getTypeElement());
115
                collectConstructors(constructors, getTypeElement(po));
111
            } else if(element != null){
116
            } else if(element != null){
112
                collectConstructors(constructors, element);
117
                collectConstructors(constructors, element);
113
            } else if (type != null) {
118
            } else if (type != null) {
Lines 135-141 Link Here
135
    @Override
140
    @Override
136
    public String[] getEnumConstants() {
141
    public String[] getEnumConstants() {
137
        if(enumConstants == null){
142
        if(enumConstants == null){
138
            Element elt = po != null ? po.getTypeElement() : element;
143
            Element elt = po != null ? getTypeElement(po) : element;
139
            if(elt != null){
144
            if(elt != null){
140
                ArrayList<String> constants = new ArrayList<String>();
145
                ArrayList<String> constants = new ArrayList<String>();
141
                for( Element el:elt.getEnclosedElements() ){
146
                for( Element el:elt.getEnclosedElements() ){
Lines 166-172 Link Here
166
    @Override
171
    @Override
167
    public String getName() {
172
    public String getName() {
168
        if(typeName == null){
173
        if(typeName == null){
169
            Element elt = po != null ? po.getTypeElement() : element;
174
            Element elt = po != null ? getTypeElement(po) : element;
170
            if(elt != null){
175
            if(elt != null){
171
                if(elt instanceof TypeElement) typeName = ((TypeElement) elt).getQualifiedName().toString();
176
                if(elt instanceof TypeElement) typeName = ((TypeElement) elt).getQualifiedName().toString();
172
                else typeName = elt.asType().toString();
177
                else typeName = elt.asType().toString();
Lines 187-193 Link Here
187
192
188
    @Override
193
    @Override
189
    public boolean hasAnnotation(Class<? extends Annotation> type) {
194
    public boolean hasAnnotation(Class<? extends Annotation> type) {
190
        Element elt = po != null ? po.getTypeElement() : element;
195
        Element elt = po != null ? getTypeElement(po) : element;
191
        return elt != null ? (elt.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
196
        return elt != null ? (elt.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type));
192
    }
197
    }
193
198
Lines 195-202 Link Here
195
    public boolean isAssignableTo(IType itype) {
200
    public boolean isAssignableTo(IType itype) {
196
        if(this == itype) return true;
201
        if(this == itype) return true;
197
        Type tp = (Type) itype;
202
        Type tp = (Type) itype;
198
        Element elt1 = po != null ? po.getTypeElement() : element;
203
        Element elt1 = po != null ? getTypeElement(po) : element;
199
        Element elt2 = tp.po != null ? tp.po.getTypeElement() : tp.element;
204
        Element elt2 = tp.po != null ? getTypeElement(tp.po) : tp.element;
200
        if(elt1 != null && elt2 !=null){
205
        if(elt1 != null && elt2 !=null){
201
            //interbal nb type
206
            //interbal nb type
202
            String rootName = itype.getName();
207
            String rootName = itype.getName();
Lines 212-218 Link Here
212
217
213
    @Override
218
    @Override
214
    public boolean isEnum() {
219
    public boolean isEnum() {
215
        Element elt = po != null ? po.getTypeElement() : element;
220
        Element elt = po != null ? getTypeElement(po) : element;
216
        return  (elt instanceof TypeElement ? ((TypeElement)elt).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
221
        return  (elt instanceof TypeElement ? ((TypeElement)elt).getKind() == ElementKind.ENUM : (type != null) && type.isEnum());
217
    }
222
    }
218
223
Lines 284-287 Link Here
284
    ITypeRepository getTypeRepository() {
289
    ITypeRepository getTypeRepository() {
285
        return repository;
290
        return repository;
286
    }
291
    }
292
    
293
    private TypeElement getTypeElement(final PersistentObject po){
294
        if(true)return po.getTypeElement();
295
        TypeElement te = null;
296
       TypeRepository tr = (TypeRepository) this.repository;
297
       final AnnotationModelHelper amh = tr.getAnnotationModelHelper();
298
       if(amh!=null) {
299
            try {
300
                te = amh.runJavaSourceTask(new Callable<TypeElement>() {
301
302
                @Override
303
                public TypeElement call() throws Exception {
304
                    return po.getTypeElement();
305
                }
306
            });
307
            } catch (IOException ex) {
308
               
309
            }
310
       }
311
       return te;
312
    }
287
}
313
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-29 / +35 lines)
Lines 45-60 Link Here
45
import java.util.HashMap;
45
import java.util.HashMap;
46
import java.util.List;
46
import java.util.List;
47
import java.util.Map;
47
import java.util.Map;
48
import java.util.concurrent.Callable;
48
import javax.lang.model.element.TypeElement;
49
import javax.lang.model.element.TypeElement;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
50
import org.eclipse.persistence.jpa.jpql.TypeHelper;
50
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
51
import org.eclipse.persistence.jpa.jpql.spi.IType;
51
import org.eclipse.persistence.jpa.jpql.spi.IType;
52
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
52
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
53
import org.netbeans.api.java.project.JavaProjectConstants;
53
import org.netbeans.api.java.project.JavaProjectConstants;
54
import org.netbeans.api.java.source.ClasspathInfo;
54
import org.netbeans.api.java.source.ClasspathInfo;
55
import org.netbeans.api.java.source.JavaSource;
56
import org.netbeans.api.java.source.Task;
57
import org.netbeans.api.java.source.WorkingCopy;
58
import org.netbeans.api.project.Project;
55
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.ProjectUtils;
56
import org.netbeans.api.project.ProjectUtils;
60
import org.netbeans.api.project.SourceGroup;
57
import org.netbeans.api.project.SourceGroup;
Lines 62-71 Link Here
62
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper;
59
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper;
63
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
60
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
64
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
61
import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata;
65
import org.netbeans.modules.j2ee.persistence.unit.PUDataObject;
66
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
62
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
67
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileObject;
68
import org.openide.util.Exceptions;
69
64
70
/**
65
/**
71
 *
66
 *
Lines 74-82 Link Here
74
public class TypeRepository implements ITypeRepository {
69
public class TypeRepository implements ITypeRepository {
75
    private final Project project;
70
    private final Project project;
76
    private final Map<String, IType[]> types;
71
    private final Map<String, IType[]> types;
77
    private PUDataObject dObj;
78
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
72
    private MetadataModelReadHelper<EntityMappingsMetadata, List<org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity>> readHelper;
79
    private final ManagedTypeProvider mtp;
73
    private final ManagedTypeProvider mtp;
74
    private AnnotationModelHelper amh;
80
75
81
76
82
    TypeRepository(Project project, ManagedTypeProvider mtp) {
77
    TypeRepository(Project project, ManagedTypeProvider mtp) {
Lines 151-180 Link Here
151
    }
146
    }
152
    
147
    
153
    private void fillTypeElement(final String fqn){
148
    private void fillTypeElement(final String fqn){
154
        Sources sources=ProjectUtils.getSources(project);
155
        SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
156
        types.put(fqn, new Type[]{null});
149
        types.put(fqn, new Type[]{null});
157
        if(mtp.isValid() && groups != null && groups.length>0){
150
        if(mtp.isValid()){ 
158
            SourceGroup firstGroup=groups[0];
151
            getAnnotationModelHelper();
159
            FileObject fo=firstGroup.getRootFolder();
152
            if(amh != null && mtp.isValid()) {
160
            ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
153
                try {
161
            final AnnotationModelHelper helper = AnnotationModelHelper.create(classpathInfo);
154
                    amh.runJavaSourceTask(new Callable<Void>() {
162
            JavaSource javaSource = JavaSource.create(classpathInfo);
155
163
            try {
156
                        @Override
164
                javaSource.runModificationTask(new Task<WorkingCopy>() {
157
                        public Void call() throws Exception {
165
                    @Override
158
                                if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
166
                    public void run(WorkingCopy wc) throws Exception {
159
                                    TypeElement te = amh.getCompilationController().getElements().getTypeElement(fqn);
167
                        if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
160
                                    if(te!=null) {
168
                            TypeElement te = wc.getElements().getTypeElement(fqn);
161
                                        PersistentObject po = new PersistentObject(amh, te) {};
169
                            if(te!=null) {
162
                                        types.put(fqn, new Type[]{new Type(TypeRepository.this, po)});
170
                                PersistentObject po = new PersistentObject(helper, te) {};
163
                                    }
171
                                types.put(fqn, new Type[]{new Type(TypeRepository.this, po)});
164
                                }
172
                            }
165
                                return null;
173
                        }
166
                        }
174
                    }
167
                    });
175
                });
168
                } catch (IOException ex) {
176
            } catch (IOException ex) {
169
                    //TODO: any logging?
177
                Exceptions.printStackTrace(ex);
170
                }
178
            }
171
            }
179
        }
172
        }
180
    }
173
    }
Lines 182-185 Link Here
182
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
175
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
183
    }
176
    }
184
    
177
    
178
    AnnotationModelHelper getAnnotationModelHelper() {
179
        if(amh == null) {
180
                Sources sources=ProjectUtils.getSources(project);
181
                SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
182
                if(groups != null && groups.length>0){
183
                    SourceGroup firstGroup=groups[0];
184
                    FileObject fo=firstGroup.getRootFolder();
185
                    ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
186
                    amh = AnnotationModelHelper.create(classpathInfo);
187
                }            
188
        }
189
        return amh;
190
    }
185
}
191
}
(-)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/Type.java (-18 / +5 lines)
Lines 291-313 Link Here
291
    }
291
    }
292
    
292
    
293
    private TypeElement getTypeElement(final PersistentObject po){
293
    private TypeElement getTypeElement(final PersistentObject po){
294
        if(true)return po.getTypeElement();
294
        if(((TypeRepository) repository).isValid()){
295
        TypeElement te = null;
295
            return po.getTypeElement();
296
       TypeRepository tr = (TypeRepository) this.repository;
296
        } else {
297
       final AnnotationModelHelper amh = tr.getAnnotationModelHelper();
297
            return null;
298
       if(amh!=null) {
298
        }
299
            try {
300
                te = amh.runJavaSourceTask(new Callable<TypeElement>() {
301
302
                @Override
303
                public TypeElement call() throws Exception {
304
                    return po.getTypeElement();
305
                }
306
            });
307
            } catch (IOException ex) {
308
               
309
            }
310
       }
311
       return te;
312
    }
299
    }
313
}
300
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-4 / +8 lines)
Lines 121-127 Link Here
121
    @Override
121
    @Override
122
    public IType getType(String fqn) {
122
    public IType getType(String fqn) {
123
        IType[] ret = types.get(fqn);
123
        IType[] ret = types.get(fqn);
124
        if(ret == null){
124
        if(ret == null && isValid()){
125
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
125
            if(IType.UNRESOLVABLE_TYPE.equals(fqn)){
126
                types.put(fqn, new Type[] {new Type(this, fqn)});
126
                types.put(fqn, new Type[] {new Type(this, fqn)});
127
            } else {
127
            } else {
Lines 147-161 Link Here
147
    
147
    
148
    private void fillTypeElement(final String fqn){
148
    private void fillTypeElement(final String fqn){
149
        types.put(fqn, new Type[]{null});
149
        types.put(fqn, new Type[]{null});
150
        if(mtp.isValid()){ 
150
        if(isValid()){ 
151
            getAnnotationModelHelper();
151
            getAnnotationModelHelper();
152
            if(amh != null && mtp.isValid()) {
152
            if(amh != null && isValid()) {
153
                try {
153
                try {
154
                    amh.runJavaSourceTask(new Callable<Void>() {
154
                    amh.runJavaSourceTask(new Callable<Void>() {
155
155
156
                        @Override
156
                        @Override
157
                        public Void call() throws Exception {
157
                        public Void call() throws Exception {
158
                                if(mtp.isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
158
                                if(isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
159
                                    TypeElement te = amh.getCompilationController().getElements().getTypeElement(fqn);
159
                                    TypeElement te = amh.getCompilationController().getElements().getTypeElement(fqn);
160
                                    if(te!=null) {
160
                                    if(te!=null) {
161
                                        PersistentObject po = new PersistentObject(amh, te) {};
161
                                        PersistentObject po = new PersistentObject(amh, te) {};
Lines 188-191 Link Here
188
        }
188
        }
189
        return amh;
189
        return amh;
190
    }
190
    }
191
    
192
    boolean isValid(){
193
        return mtp.isValid();
194
    }
191
}
195
}
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-3 / +5 lines)
Lines 84-90 Link Here
84
public class JPQLValidation extends JPAClassRule implements CancelListener{
84
public class JPQLValidation extends JPAClassRule implements CancelListener{
85
    
85
    
86
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
86
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
87
    
87
    private JPQLQueryHelper helper;
88
    /** Creates a new instance of NonFinalClass */
88
    /** Creates a new instance of NonFinalClass */
89
    public JPQLValidation() {
89
    public JPQLValidation() {
90
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
90
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
Lines 132-141 Link Here
132
                }
132
                }
133
            }
133
            }
134
        }
134
        }
135
        JPQLQueryHelper helper = new JPQLQueryHelper();
135
        helper = new JPQLQueryHelper();
136
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
136
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
137
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
137
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
138
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData());
138
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData(), jpaCtx.getCompilationInfo().getElements());
139
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
139
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
140
            String value = values.get(index);
140
            String value = values.get(index);
141
            String qName = names.get(index);
141
            String qName = names.get(index);
Lines 178-183 Link Here
178
        }
178
        }
179
        jpaCtx.removeCancelListener(this);
179
        jpaCtx.removeCancelListener(this);
180
        mtp = null;
180
        mtp = null;
181
        helper = null;
181
        return ret;
182
        return ret;
182
    }
183
    }
183
    
184
    
Lines 190-194 Link Here
190
    @Override
191
    @Override
191
    public void cancelled() {
192
    public void cancelled() {
192
        if(mtp != null)mtp.invalidate();
193
        if(mtp != null)mtp.invalidate();
194
        if(helper != null)helper.dispose();
193
    }
195
    }
194
}
196
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/editor/completion/ETCompletionContextResolver.java (-2 / +2 lines)
Lines 138-144 Link Here
138
            JPQLQueryHelper helper = new JPQLQueryHelper();
138
            JPQLQueryHelper helper = new JPQLQueryHelper();
139
139
140
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
140
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
141
            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())));
142
            int offset = ctx.getCompletionOffset() - nnattr.getValueOffset() - (nnattr.isValueQuoted() ? 1 : 0);
142
            int offset = ctx.getCompletionOffset() - nnattr.getValueOffset() - (nnattr.isValueQuoted() ? 1 : 0);
143
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
143
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
144
            
144
            
Lines 168-174 Link Here
168
            completedValue = org.netbeans.modules.j2ee.persistence.editor.completion.Utils.unquote(completedValue);
168
            completedValue = org.netbeans.modules.j2ee.persistence.editor.completion.Utils.unquote(completedValue);
169
169
170
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
170
            Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
171
            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())));
172
            int offset = ctx.getCompletionOffset() - method.getValueOffset() - (method.isWithQ() ? 1 : 0);
172
            int offset = ctx.getCompletionOffset() - method.getValueOffset() - (method.isWithQ() ? 1 : 0);
173
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
173
            ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset);
174
174
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java (-3 / +8 lines)
Lines 45-50 Link Here
45
import java.util.Collections;
45
import java.util.Collections;
46
import java.util.HashMap;
46
import java.util.HashMap;
47
import java.util.Map;
47
import java.util.Map;
48
import javax.lang.model.util.Elements;
48
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
49
import org.eclipse.persistence.jpa.jpql.spi.IEntity;
49
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
50
import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion;
50
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
51
import org.eclipse.persistence.jpa.jpql.spi.IManagedType;
Lines 68-82 Link Here
68
    private ITypeRepository typeRepository;
69
    private ITypeRepository typeRepository;
69
    private final EntityMappings mappings;
70
    private final EntityMappings mappings;
70
    private boolean valid = true;//used to conrol long tasks, if not valid long tasks should be either terminated or goes short way
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;
71
73
72
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData) {
74
    public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData, Elements elements) {
73
        this.project = project;
75
        this.project = project;
74
        this.mappings = metaData.getRoot();
76
        this.mappings = metaData.getRoot();
77
        this.elements = elements;
75
    }
78
    }
76
    
79
    
77
    public ManagedTypeProvider(Project project, EntityMappings mappings) {
80
    public ManagedTypeProvider(Project project, EntityMappings mappings, Elements elements) {
78
        this.project = project;
81
        this.project = project;
79
        this.mappings = mappings;
82
        this.mappings = mappings;
83
        this.elements = elements;
80
    }
84
    }
81
    
85
    
82
    @Override
86
    @Override
Lines 116-122 Link Here
116
    @Override
120
    @Override
117
    public ITypeRepository getTypeRepository() {
121
    public ITypeRepository getTypeRepository() {
118
        if (typeRepository == null) {
122
        if (typeRepository == null) {
119
            typeRepository = new TypeRepository(project, this);
123
            typeRepository = new TypeRepository(project, this, elements);
120
        }
124
        }
121
        return typeRepository;
125
        return typeRepository;
122
    }
126
    }
Lines 145-150 Link Here
145
    public void invalidate() {
149
    public void invalidate() {
146
        valid = false;
150
        valid = false;
147
        //TODO: may have sense to clean stored data
151
        //TODO: may have sense to clean stored data
152
        ((TypeRepository)typeRepository).invalidate();
148
    }
153
    }
149
154
150
    private void initializeManagedTypes() {
155
    private void initializeManagedTypes() {
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (-47 / +40 lines)
Lines 41-66 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 java.util.concurrent.Callable;
49
import javax.lang.model.element.TypeElement;
47
import javax.lang.model.element.TypeElement;
48
import javax.lang.model.util.Elements;
50
import org.eclipse.persistence.jpa.jpql.TypeHelper;
49
import org.eclipse.persistence.jpa.jpql.TypeHelper;
51
import org.eclipse.persistence.jpa.jpql.spi.IType;
50
import org.eclipse.persistence.jpa.jpql.spi.IType;
52
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
51
import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository;
53
import org.netbeans.api.java.project.JavaProjectConstants;
54
import org.netbeans.api.java.source.ClasspathInfo;
55
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
56
import org.netbeans.api.project.ProjectUtils;
57
import org.netbeans.api.project.SourceGroup;
58
import org.netbeans.api.project.Sources;
59
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper;
60
import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject;
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.util.MetadataModelReadHelper;
54
import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper;
63
import org.openide.filesystems.FileObject;
64
55
65
/**
56
/**
66
 *
57
 *
Lines 69-83 Link Here
69
public class TypeRepository implements ITypeRepository {
60
public class TypeRepository implements ITypeRepository {
70
    private final Project project;
61
    private final Project project;
71
    private final Map<String, IType[]> types;
62
    private final Map<String, IType[]> types;
63
    private final Map<String, Boolean> packages;
72
    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;
73
    private final ManagedTypeProvider mtp;
65
    private final ManagedTypeProvider mtp;
74
    private AnnotationModelHelper amh;
66
    private final Elements elements;
75
67
76
68
77
    TypeRepository(Project project, ManagedTypeProvider mtp) {
69
    TypeRepository(Project project, ManagedTypeProvider mtp, Elements elements) {
78
        this.project = project;
70
        this.project = project;
79
        this.mtp = mtp;
71
        this.mtp = mtp;
72
        this.elements = elements;
80
        types = new HashMap<String, IType[]>();
73
        types = new HashMap<String, IType[]>();
74
        packages = new HashMap<String, Boolean>();
81
    }
75
    }
82
    
76
    
83
    @Override
77
    @Override
Lines 90-96 Link Here
90
            if(mainPart != null){
84
            if(mainPart != null){
91
                IType[] mainType = types.get(mainPart);
85
                IType[] mainType = types.get(mainPart);
92
                if(mainType == null){
86
                if(mainType == null){
93
                    fillTypeElement(mainPart);
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
                    }
107
                    //
108
                    if(mainType == null){
109
                        fillTypeElement(mainPart);
110
                    }
94
                }
111
                }
95
                mainType = types.get(mainPart);
112
                mainType = types.get(mainPart);
96
                if(mainType[0] != null){
113
                if(mainType[0] != null){
Lines 137-143 Link Here
137
            }
154
            }
138
            ret = types.get(fqn);
155
            ret = types.get(fqn);
139
        }
156
        }
140
        return ret[0];
157
        return ret!=null ? ret[0] : null;
141
    }
158
    }
142
159
143
    @Override
160
    @Override
Lines 148-172 Link Here
148
    private void fillTypeElement(final String fqn){
165
    private void fillTypeElement(final String fqn){
149
        types.put(fqn, new Type[]{null});
166
        types.put(fqn, new Type[]{null});
150
        if(isValid()){ 
167
        if(isValid()){ 
151
            getAnnotationModelHelper();
168
            if(isValid()) {
152
            if(amh != null && isValid()) {
169
                TypeElement te = elements.getTypeElement(fqn);
153
                try {
170
                if(te!=null) {
154
                    amh.runJavaSourceTask(new Callable<Void>() {
171
                    types.put(fqn, new Type[]{new Type(TypeRepository.this, te)});
155
156
                        @Override
157
                        public Void call() throws Exception {
158
                                if(isValid()) {//model will be filled with nulls  after provider invalidation and with values only if valid provider
159
                                    TypeElement te = amh.getCompilationController().getElements().getTypeElement(fqn);
160
                                    if(te!=null) {
161
                                        PersistentObject po = new PersistentObject(amh, te) {};
162
                                        types.put(fqn, new Type[]{new Type(TypeRepository.this, po)});
163
                                    }
164
                                }
165
                                return null;
166
                        }
167
                    });
168
                } catch (IOException ex) {
169
                    //TODO: any logging?
170
                }
172
                }
171
            }
173
            }
172
        }
174
        }
Lines 174-195 Link Here
174
    private void fillTypeElement(Class<?> type){
176
    private void fillTypeElement(Class<?> type){
175
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
177
        types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)});
176
    }
178
    }
177
    
179
   
178
    AnnotationModelHelper getAnnotationModelHelper() {
179
        if(amh == null) {
180
                Sources sources=ProjectUtils.getSources(project);
181
                SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
182
                if(groups != null && groups.length>0){
183
                    SourceGroup firstGroup=groups[0];
184
                    FileObject fo=firstGroup.getRootFolder();
185
                    ClasspathInfo classpathInfo = ClasspathInfo.create(fo);
186
                    amh = AnnotationModelHelper.create(classpathInfo);
187
                }            
188
        }
189
        return amh;
190
    }
191
    
180
    
192
    boolean isValid(){
181
    boolean isValid(){
193
        return mtp.isValid();
182
        return mtp.isValid();
194
    }
183
    }
184
185
    void invalidate() {
186
        
187
    }
195
}
188
}
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java (-1 / +4 lines)
Lines 149-155 Link Here
149
    public void invalidate() {
149
    public void invalidate() {
150
        valid = false;
150
        valid = false;
151
        //TODO: may have sense to clean stored data
151
        //TODO: may have sense to clean stored data
152
        ((TypeRepository)typeRepository).invalidate();
152
        if(typeRepository != null) {
153
            ((TypeRepository)typeRepository).invalidate();
154
            typeRepository = null;
155
        }
153
    }
156
    }
154
157
155
    private void initializeManagedTypes() {
158
    private void initializeManagedTypes() {
(-)a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java (-83 / +48 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.netbeans.api.project.FileOwnerQuery;
58
import org.netbeans.api.project.FileOwnerQuery;
64
import org.netbeans.api.project.Project;
59
import org.netbeans.api.project.Project;
65
import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations;
66
import org.netbeans.modules.j2ee.jpa.verification.CancelListener;
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-179 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 implements CancelListener{
79
public class JPQLValidation extends JPAClassRule implements CancelListener {
85
    
80
86
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
81
    private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required
87
    private JPQLQueryHelper helper;
82
    private JPQLQueryHelper helper;
88
    /** Creates a new instance of NonFinalClass */
83
84
    /**
85
     * Creates a new instance of NonFinalClass
86
     */
89
    public JPQLValidation() {
87
    public JPQLValidation() {
90
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
88
        setClassContraints(Arrays.asList(ClassConstraints.ENTITY,
91
                ClassConstraints.EMBEDDABLE,
89
                ClassConstraints.EMBEDDABLE,
92
                ClassConstraints.MAPPED_SUPERCLASS));
90
                ClassConstraints.MAPPED_SUPERCLASS));
93
    }
91
    }
94
    
92
95
    @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){
93
    @Override
96
        JPAProblemContext jpaCtx = (JPAProblemContext)ctx;
94
    public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx) {
95
        JPAProblemContext jpaCtx = (JPAProblemContext) ctx;
97
        jpaCtx.addCancelListener(this);
96
        jpaCtx.addCancelListener(this);
98
        Object modEl = ctx.getModelElement();
97
        Object modEl = ctx.getModelElement();
99
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
98
        Entity entity = (Entity) (modEl instanceof Entity ? modEl : null);
100
        List<AnnotationMirror> first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY);
101
        ArrayList<String> values = new ArrayList<String>();
102
        ArrayList<String> names = new ArrayList<String>();
103
        if(first == null || first.size()==0){
104
            AnnotationMirror qs = Utilities.findAnnotation(subject, JPAAnnotations.NAMED_QUERIES);
105
            if(qs != null){
106
                Map<? extends ExecutableElement, ? extends AnnotationValue> maps = qs.getElementValues();
107
                for(AnnotationValue vl:maps.values()){
108
                    List  lst = (List) vl.getValue();
109
                    for(Object val:lst){
110
                        if(val instanceof AnnotationMirror){
111
                            AnnotationMirror am = (AnnotationMirror) val;
112
                            if(JPAAnnotations.NAMED_QUERY.equals(am.getAnnotationType().toString())){
113
                                AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(am, "query");
114
                                AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(am, "name");
115
                                if(qAttrValue != null){
116
                                    values.add(qAttrValue.getValue().toString());
117
                                    names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString());
118
                                }
119
                            }
120
                        }
121
                    }
122
                }
123
            }
124
        }
125
        else {
126
            for(AnnotationMirror mr:first){
127
                AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(mr, "query");
128
                AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(mr, "name");
129
                if(qAttrValue != null){
130
                    values.add(qAttrValue.getValue().toString());
131
                    names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString());
132
                }
133
            }
134
        }
135
        helper = new JPQLQueryHelper();
99
        helper = new JPQLQueryHelper();
136
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
100
        Project project = FileOwnerQuery.getOwner(ctx.getFileObject());
137
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
101
        List<JPQLQueryProblem> problems = new ArrayList<JPQLQueryProblem>();
138
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData(), jpaCtx.getCompilationInfo().getElements());
102
        mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData(), jpaCtx.getCompilationInfo().getElements());
139
        for(int index=0;index<values.size() && !ctx.isCancelled();index++){
103
        if (entity != null) {
140
            String value = values.get(index);
104
            for (NamedQuery nq : entity.getNamedQuery()) {
141
            String qName = names.get(index);
105
                helper.setQuery(new Query(nq, nq.getQuery(), mtp));
142
            NamedQuery nq = null;
106
                List<JPQLQueryProblem> tmp = null;
143
            if(entity != null) {
107
                try {
144
                nq = entity.newNamedQuery();
108
                    tmp = helper.validate();
145
                nq.setQuery(value);
109
                } catch (UnsupportedOperationException ex) {
146
                nq.setName(qName);
110
                    JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex);
111
                } catch (NullPointerException ex) {
112
                    JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex);
113
                }
114
                if (tmp != null && tmp.size() > 0) {
115
                    problems.addAll(tmp);
116
                }
117
                helper.dispose();
147
            }
118
            }
148
            helper.setQuery(new Query(nq, value, mtp));
149
            List<JPQLQueryProblem> tmp = null;
150
            try{
151
                tmp = helper.validate();
152
            } catch (UnsupportedOperationException ex) {
153
                JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex);
154
            }catch (NullPointerException ex) {
155
                JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex);
156
            }
157
            if(tmp!=null && tmp.size()>0)problems.addAll(tmp);
158
            helper.dispose();
159
        }
119
        }
160
        ErrorDescription[] ret = null;
120
        ErrorDescription[] ret = null;
161
        if (!ctx.isCancelled() && problems != null && problems.size()>0){
121
        if (!ctx.isCancelled() && problems != null && problems.size() > 0) {
162
            ret = new ErrorDescription[problems.size()];
122
            ret = new ErrorDescription[problems.size()];
163
            for(int i=0;i<ret.length;i++){
123
            for (int i = 0; i < ret.length; i++) {
164
                ListResourceBundle msgBundle = null;
124
                ListResourceBundle msgBundle = null;
165
                try{
125
                try {
166
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName());//NOI18N
126
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName());//NOI18N
167
                } catch (MissingResourceException ex) {//default en
127
                } catch (MissingResourceException ex) {//default en
168
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName(), Locale.ENGLISH);//NOI18N
128
                    msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName(), Locale.ENGLISH);//NOI18N
169
                }
129
                }
170
                String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[])  problems.get(i).getMessageArguments());
130
                String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[]) problems.get(i).getMessageArguments());
171
                String pos = "["+problems.get(i).getStartPosition() + ";"+problems.get(i).getEndPosition()+"]";
131
                String pos = "[" + problems.get(i).getStartPosition() + ";" + problems.get(i).getEndPosition() + "]";
172
                Query q = (Query) problems.get(i).getQuery();
132
                Query q = (Query) problems.get(i).getQuery();
173
                if(q.getNamedQuery() != null && q.getNamedQuery().getName()!=null){
133
                if (q.getNamedQuery() != null && q.getNamedQuery().getName() != null) {
174
                    pos = q.getNamedQuery().getName()+pos;
134
                    pos = q.getNamedQuery().getName() + pos;
175
                }
135
                }
176
                ret[i] = createProblem(subject, ctx, pos + ": " + message , Severity.WARNING);
136
                ret[i] = createProblem(subject, ctx, pos + ": " + message, Severity.WARNING);
177
            }
137
            }
178
        }
138
        }
179
        jpaCtx.removeCancelListener(this);
139
        jpaCtx.removeCancelListener(this);
Lines 181-196 Link Here
181
        helper = null;
141
        helper = null;
182
        return ret;
142
        return ret;
183
    }
143
    }
184
    
144
185
    @Override protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
145
    @Override
186
        JPAProblemContext jpaCtx = (JPAProblemContext)ctx;
146
    protected boolean isApplicable(TypeElement subject, ProblemContext ctx) {
187
        
147
        JPAProblemContext jpaCtx = (JPAProblemContext) ctx;
148
188
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
149
        return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass());
189
    }
150
    }
190
151
191
    @Override
152
    @Override
192
    public void cancelled() {
153
    public void cancelled() {
193
        if(mtp != null)mtp.invalidate();
154
        if (mtp != null) {
194
        if(helper != null)helper.dispose();
155
            mtp.invalidate();
156
        }
157
        if (helper != null) {
158
            helper.dispose();
159
        }
195
    }
160
    }
196
}
161
}
(-)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
            }
(-)a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java (+3 lines)
Lines 103-108 Link Here
103
                                break;
103
                                break;
104
                            }
104
                            }
105
                        }
105
                        }
106
                    } else if(mainFirstPoint == -1) {
107
                        mainType = new Type[]{null};
108
                        types.put(mainPart, mainType);
106
                    }
109
                    }
107
                    //
110
                    //
108
                    if(mainType == null){
111
                    if(mainType == null){
(-)a/html.navigator/src/org/netbeans/modules/html/navigator/HtmlNavigatorPanelUI.java (-9 / +19 lines)
Lines 232-237 Link Here
232
            //no need to explicitly call pageModelDocumentChanged() as the
232
            //no need to explicitly call pageModelDocumentChanged() as the
233
            //PageModel fill fire change event
233
            //PageModel fill fire change event
234
        }
234
        }
235
        inspectedFileObject = getInspectedFileFromPageModel();
235
236
236
    }
237
    }
237
    
238
    
Lines 349-354 Link Here
349
    }
350
    }
350
    
351
    
351
    private void cacheDomToNb(Node root) {
352
    private void cacheDomToNb(Node root) {
353
        if (root==null)
354
            return;
352
        if (root instanceof HtmlElementNode) {
355
        if (root instanceof HtmlElementNode) {
353
            Node res = ((HtmlElementNode) root).getDOMNode();
356
            Node res = ((HtmlElementNode) root).getDOMNode();
354
            if (res!=null) {
357
            if (res!=null) {
Lines 363-371 Link Here
363
    private void refreshNodeDOMStatus() {
366
    private void refreshNodeDOMStatus() {
364
        LOGGER.fine("refreshNodeDOMStatus()");
367
        LOGGER.fine("refreshNodeDOMStatus()");
365
        HtmlElementNode root = getRootNode();
368
        HtmlElementNode root = getRootNode();
369
        boolean refresh = true;
366
        if (root != null) {
370
        if (root != null) {
367
            //if we are inspecting the current file, the source changes propagates just after the fresh DOM is received
371
            //if we are inspecting the current file, the source changes propagates just after the fresh DOM is received
368
            if(sourceDescription != null) {
372
            if(sourceDescription != null) {
373
                refresh = sourceDescription.getFileObject().equals(inspectedFileObject);
369
                root.setDescription(sourceDescription);
374
                root.setDescription(sourceDescription);
370
                sourceDescription = null;
375
                sourceDescription = null;
371
                setSynchronizationState(true);
376
                setSynchronizationState(true);
Lines 382-388 Link Here
382
                }
387
                }
383
            };
388
            };
384
            domDescription.addChangeListener(WeakListeners.change(changeListener, domDescription));
389
            domDescription.addChangeListener(WeakListeners.change(changeListener, domDescription));
385
            root.setDescription(domDescription);
390
            if (refresh) {
391
                root.setDescription(domDescription);
392
            } else {
393
                root.setDescription(WebKitNodeDescription.empty(WebKitNodeDescription.DOM));
394
            }
386
            
395
            
387
            LOGGER.fine("root.refreshDOMStatus() called");
396
            LOGGER.fine("root.refreshDOMStatus() called");
388
        }
397
        }
Lines 452-461 Link Here
452
        
461
        
453
        if (fo==null)
462
        if (fo==null)
454
            return;
463
            return;
455
        if (inspectedFileObject == fo) {
456
            refreshDOM();
457
            return;
458
        }
459
        
464
        
460
        if (!"text/html".equals(FileUtil.getMIMEType(fo))) {
465
        if (!"text/html".equals(FileUtil.getMIMEType(fo))) {
461
            return;
466
            return;
Lines 465-478 Link Here
465
        if (source == null) {
470
        if (source == null) {
466
            return;
471
            return;
467
        }
472
        }
468
        showWaitNode();
473
        
474
        //TODO: uncomment when working again
475
        //showWaitNode();
469
        
476
        
470
        try {
477
        try {
471
            ParserManager.parse(Collections.singleton(source), new UserTask() {
478
            ParserManager.parse(Collections.singleton(source), new UserTask() {
472
                @Override
479
                @Override
473
                public void run(ResultIterator resultIterator) throws Exception {
480
                public void run(ResultIterator resultIterator) throws Exception {
474
                    setParserResult((HtmlParserResult)resultIterator.getParserResult());
481
                    setParserResult((HtmlParserResult)resultIterator.getParserResult());
475
                    inspectedFileObject = fo;
482
                    //inspectedFileObject = getInspectedFileFromPageModel();
476
                    refreshDOM();
483
                    refreshDOM();
477
                }
484
                }
478
            });
485
            });
Lines 793-802 Link Here
793
                        if (node instanceof HtmlElementNode) {
800
                        if (node instanceof HtmlElementNode) {
794
                            final Node domNode = ((HtmlElementNode) node).getDOMNode();
801
                            final Node domNode = ((HtmlElementNode) node).getDOMNode();
795
                            if (domNode!=null) {
802
                            if (domNode!=null) {
796
                                node = domNode;
803
                                highlight = Arrays.asList(domNode);
804
                            } else {
805
                                highlight = Collections.EMPTY_LIST;
797
                            }
806
                            }
807
                        } else {
808
                            highlight = Arrays.asList(node);
798
                        }
809
                        }
799
                        highlight = Arrays.asList(node);
800
                    } else {
810
                    } else {
801
                        highlight = Collections.EMPTY_LIST;
811
                        highlight = Collections.EMPTY_LIST;
802
                    }
812
                    }

Return to bug 216053