Author: vyemialyanchyk
Date: 2010-03-16 14:49:58 -0400 (Tue, 16 Mar 2010)
New Revision: 20854
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/
Removed:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6070 - initial step
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui
(from rev 20798, trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui)
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java 2010-03-16
18:49:58 UTC (rev 20854)
@@ -1,27 +0,0 @@
-package org.hibernate.eclipse.jdt.ui.internal;
-
-public class ELTransformer {
-
- /**
- * transform any #{el expressions} into named parameters so HQL validation won't
fail on it.
- * @param hql
- * @return
- */
- static public String removeEL(String hql) {
- int elStart = hql.indexOf("#{"); //$NON-NLS-1$
- int next = hql.indexOf("}", elStart); //$NON-NLS-1$
-
- while(elStart!=-1 && next!=-1) {
- String result = hql.substring(0, elStart);
- result += ":_" + hql.substring(elStart+2,
next).replaceAll("[^\\p{javaJavaIdentifierStart}]","_") +
"_"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- result += hql.substring(next+1);
-
- hql = result;
-
- elStart = hql.indexOf("#{"); //$NON-NLS-1$
- next = hql.indexOf("}", elStart); //$NON-NLS-1$
- }
-
- return hql;
- }
-}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java 2010-03-12
13:16:53 UTC (rev 20798)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java 2010-03-16
18:49:58 UTC (rev 20854)
@@ -1,7 +1,6 @@
package org.hibernate.eclipse.jdt.ui.internal;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -17,19 +16,17 @@
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.engine.query.HQLQueryPlan;
-import org.hibernate.impl.SessionFactoryImpl;
public class HQLDetector extends ASTVisitor {
private final IFile resource;
List<HQLProblem> problems = new ArrayList<HQLProblem>();
- private final ConsoleConfiguration consoleConfiguration;
+ private final ConsoleConfiguration consoleConfig;
private final CompilationUnit cu;
- public HQLDetector(CompilationUnit cu, ConsoleConfiguration consoleConfiguration,
IResource resource) {
+ public HQLDetector(CompilationUnit cu, ConsoleConfiguration consoleConfig, IResource
resource) {
this.cu = cu;
- this.consoleConfiguration = consoleConfiguration;
+ this.consoleConfig = consoleConfig;
this.resource = (IFile) resource;
}
@@ -44,7 +41,7 @@
if(value instanceof StringLiteral) {
StringLiteral sl = (StringLiteral)value;
try {
- checkQuery( consoleConfiguration, sl.getLiteralValue(), true );
+ consoleConfig.checkQuery(sl.getLiteralValue(), true);
} catch(RuntimeException re) {
problems.add(new HQLProblem(re.getLocalizedMessage(), true, resource,
sl.getStartPosition(), sl.getStartPosition()+sl.getLength()-1,
getLineNumber(sl.getStartPosition())));
}
@@ -82,7 +79,7 @@
StringLiteral sl = (StringLiteral) object;
String literalValue = sl.getLiteralValue();
try {
- checkQuery( consoleConfiguration, literalValue, true );
+ consoleConfig.checkQuery(literalValue, true);
} catch(RuntimeException re) {
problems.add(new HQLProblem(re.getLocalizedMessage(), true, resource,
sl.getStartPosition(), sl.getStartPosition()+sl.getLength()-1, getLineNumber(
sl.getStartPosition() )));
}
@@ -97,25 +94,6 @@
}
}
- /**
- * Given a ConsoleConfiguration and a query this method validates the query through
hibernate if a sessionfactory is available.
- * @param cc
- * @param query
- * @param allowEL if true, EL syntax will be replaced as a named variable
- * @throws HibernteException if something is wrong with the query
- */
- public static void checkQuery(ConsoleConfiguration cc, String query, boolean allowEL) {
- if(cc!=null && cc.isSessionFactoryCreated()) {
- if(allowEL) {
- query = ELTransformer.removeEL(query);
- }
- new HQLQueryPlan(query, false, Collections.EMPTY_MAP,
(SessionFactoryImpl)cc.getSessionFactory());
- } else {
- //messager.printWarning( annoValue.getPosition(), "Could not verify syntax.
SessionFactory not created." );
- }
- }
-
-
public List<HQLProblem> getProblems() {
return problems;
}