Author: shawkins
Date: 2012-10-02 09:06:35 -0400 (Tue, 02 Oct 2012)
New Revision: 4501
Modified:
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java
Log:
TEIID-2176 refinements to jpa native query support
Modified:
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java
===================================================================
---
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java 2012-10-02
12:52:37 UTC (rev 4500)
+++
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java 2012-10-02
13:06:35 UTC (rev 4501)
@@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@@ -41,7 +40,7 @@
import org.teiid.translator.TranslatorException;
public class JPQLDirectQueryExecution extends JPQLBaseExecution implements
ProcedureExecution{
- private Iterator resultsIterator;
+ private Iterator<?> resultsIterator;
private List<Argument> arguments;
private int updateCount = -1;
private boolean updateQuery;
@@ -55,22 +54,17 @@
@Override
public void execute() throws TranslatorException {
String query = (String)arguments.get(0).getArgumentValue().getValue();
- String firstToken = null;
-
- StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
- if (st.hasMoreTokens()) {
- firstToken = st.nextToken();
- if (!firstToken.equalsIgnoreCase("search") &&
!firstToken.equalsIgnoreCase("create") &&
!firstToken.equalsIgnoreCase("update") &&
!firstToken.equalsIgnoreCase("delete")) { //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
- }
+ if (query.length() < 7) {
+ throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
-
+ String firstToken = query.substring(0, 6);
+
String jpql = query.substring(7);
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "JPA Source-Query:", jpql);
//$NON-NLS-1$
if (firstToken.equalsIgnoreCase("search")) { // //$NON-NLS-1$
Query queryCommand = this.enityManager.createQuery(jpql);
- List results = queryCommand.getResultList();
+ List<?> results = queryCommand.getResultList();
this.resultsIterator = results.iterator();
}
else if (firstToken.equalsIgnoreCase("create")) { // //$NON-NLS-1$
@@ -83,6 +77,8 @@
Query queryCmd = this.enityManager.createQuery(jpql);
this.updateCount = queryCmd.executeUpdate();
this.updateQuery = true;
+ } else {
+ throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
}
Show replies by date