Author: rareddy
Date: 2012-08-26 15:02:32 -0400 (Sun, 26 Aug 2012)
New Revision: 4367
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
Log:
TEIID-2158: removing the getConnection method and fixing the unit test
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-25
20:38:37 UTC (rev 4366)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-26
19:02:32 UTC (rev 4367)
@@ -257,28 +257,12 @@
else if (contentType.equals("plain")) {
contentType = "text/plain";
}
- buildRestService(modelName, procedure, method, uri, cw, contentType, charSet);
+ buildRestService(vdbName, vdbVersion, modelName, procedure, method, uri, cw,
contentType, charSet);
hasValidProcedures = true;
}
}
}
- // getConnection method
- {
- mv = cw.visitMethod(ACC_PROTECTED, "getConnection",
"()Ljava/sql/Connection;", null, new String[] {
"java/sql/SQLException" });
- mv.visitCode();
- mv.visitTypeInsn(NEW, "org/teiid/jdbc/TeiidDriver");
- mv.visitInsn(DUP);
- mv.visitMethodInsn(INVOKESPECIAL, "org/teiid/jdbc/TeiidDriver",
"<init>", "()V");
- mv.visitVarInsn(ASTORE, 1);
- mv.visitVarInsn(ALOAD, 1);
- mv.visitLdcInsn("jdbc:teiid:"+vdbName+"."+vdbVersion);
- mv.visitInsn(ACONST_NULL);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jdbc/TeiidDriver",
"connect",
"(Ljava/lang/String;Ljava/util/Properties;)Lorg/teiid/jdbc/ConnectionImpl;");
- mv.visitInsn(ARETURN);
- mv.visitMaxs(3, 2);
- mv.visitEnd();
- }
cw.visitEnd();
if (!hasValidProcedures) {
@@ -314,7 +298,7 @@
return contentType;
}
- private void buildRestService(String modelName, Procedure procedure,
+ private void buildRestService(String vdbName, int vdbVersion, String modelName,
Procedure procedure,
String method, String uri, ClassWriter cw, String contentType,
String charSet) {
@@ -407,11 +391,16 @@
sb.append("?");
}
sb.append(") }");
+
+ mv.visitLdcInsn(vdbName);
+ mv.visitIntInsn(BIPUSH, vdbVersion);
+
mv.visitLdcInsn(sb.toString());
mv.visitVarInsn(ALOAD, paramsSize+1);
- mv.visitLdcInsn(charSet);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName,
"execute",
"(Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;)Ljava/io/InputStream;");
+ mv.visitLdcInsn(charSet==null?"":charSet);
+
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName,
"execute",
"(Ljava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;)Ljava/io/InputStream;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
@@ -423,7 +412,7 @@
mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status",
"INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;");
mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException",
"<init>",
"(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V");
mv.visitInsn(ATHROW);
- mv.visitMaxs(4, paramsSize+2);
+ mv.visitMaxs(6, paramsSize+2);
mv.visitEnd();
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java 2012-08-25
20:38:37 UTC (rev 4366)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java 2012-08-26
19:02:32 UTC (rev 4367)
@@ -38,14 +38,22 @@
import org.teiid.core.types.XMLType;
import org.teiid.core.util.ReaderInputStream;
import org.teiid.jboss.IntegrationPlugin;
+import org.teiid.jdbc.TeiidDriver;
import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.sql.symbol.XMLSerialize;
public abstract class TeiidRSProvider {
- public InputStream execute(String procedureSignature, LinkedHashMap<String,
String> parameters, String charSet) throws SQLException {
+ public InputStream execute(String vdbName, int version, String procedureSignature,
+ LinkedHashMap<String, String> parameters, String charSet) throws SQLException {
Object result = null;
- Connection conn = getConnection();
+
+ //the generated code sends a empty string rather than null.
+ if (charSet != null && charSet.trim().isEmpty()) {
+ charSet = null;
+ }
+
+ Connection conn = getConnection(vdbName, version);
boolean usingReturn = procedureSignature.startsWith("{ ?");
//$NON-NLS-1$
try {
//TODO: an alternative strategy would be to set the parameters based upon name
@@ -111,7 +119,10 @@
}
}
}
-
- protected abstract Connection getConnection() throws SQLException;
-
+
+ private Connection getConnection(String vdbName, int version) throws SQLException {
+ TeiidDriver driver = new TeiidDriver();
+ return driver.connect("jdbc:teiid:"+vdbName+"."+version, null);
+ }
+
}