Search in sources :

Example 21 with ProcedureExecution

use of org.teiid.translator.ProcedureExecution in project teiid by teiid.

the class TestSwaggerQueryExecution method testHeadersInResponseWithReturn.

@Test
public void testHeadersInResponseWithReturn() throws Exception {
    String query = "exec loginUser(username=>'foo',password=>'bar');";
    String expectedURL = "http://petstore.swagger.io/v2/user/login?username=foo&password=bar";
    String response = "sucess";
    TimeZone tz = TimeZone.getDefault();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        ProcedureExecution excution = helpProcedureExecute(query, response, expectedURL, 200, true, "GET", null, getHeaders());
        assertArrayEquals(new Object[] { "sucess", 1, new Timestamp(1460110463000L) }, excution.next().toArray(new Object[3]));
        assertNull(excution.next());
    } finally {
        TimeZone.setDefault(tz);
    }
}
Also used : TimeZone(java.util.TimeZone) ProcedureExecution(org.teiid.translator.ProcedureExecution) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 22 with ProcedureExecution

use of org.teiid.translator.ProcedureExecution in project teiid by teiid.

the class TestFileExecutionFactory method testGetTextFiles.

@Test
public void testGetTextFiles() throws Exception {
    FileExecutionFactory fef = new FileExecutionFactory();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "text", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    fef.getMetadata(mf, null);
    Procedure p = mf.getSchema().getProcedure("getTextFiles");
    FileConnection fc = Mockito.mock(FileConnection.class);
    Mockito.stub(fc.getFile("*.txt")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*.txt"));
    Call call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*.txt", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    ProcedureExecution pe = fef.createProcedureExecution(call, null, null, fc);
    pe.execute();
    int count = 0;
    while (true) {
        List<?> val = pe.next();
        if (val == null) {
            break;
        }
        assertEquals(5, val.size());
        assertTrue(val.get(3) instanceof Timestamp);
        assertEquals(Long.valueOf(0), val.get(4));
        count++;
    }
    assertEquals(2, count);
    call = fef.getLanguageFactory().createCall("getTextFiles", Arrays.asList(new Argument(Direction.IN, new Literal("*1*", TypeFacility.RUNTIME_TYPES.STRING), TypeFacility.RUNTIME_TYPES.STRING, null)), p);
    pe = fef.createProcedureExecution(call, null, null, fc);
    Mockito.stub(fc.getFile("*1*")).toReturn(new File(UnitTestUtil.getTestDataPath(), "*1*"));
    pe.execute();
    count = 0;
    while (true) {
        if (pe.next() == null) {
            break;
        }
        count++;
    }
    assertEquals(1, count);
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) MetadataFactory(org.teiid.metadata.MetadataFactory) ProcedureExecution(org.teiid.translator.ProcedureExecution) Literal(org.teiid.language.Literal) Procedure(org.teiid.metadata.Procedure) File(java.io.File) FileConnection(org.teiid.translator.FileConnection) Test(org.junit.Test)

Example 23 with ProcedureExecution

use of org.teiid.translator.ProcedureExecution in project teiid by teiid.

the class MockConnector method createProcedureExecution.

@Override
public ProcedureExecution createProcedureExecution(Call procedure, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
    Properties props = new Properties();
    // $NON-NLS-1$ //$NON-NLS-2$
    props.setProperty("customBehaviour", "SkipExecute");
    AbstractMetadataRecord metaObject = procedure.getMetadataObject();
    // $NON-NLS-1$
    TestCase.assertEquals("AnyModel.ProcedureB", procedure.getProcedureName());
    // $NON-NLS-1$
    TestCase.assertEquals("PROC", metaObject.getNameInSource());
    TestCase.assertEquals(props, metaObject.getProperties());
    ProcedureExecution exec = Mockito.mock(ProcedureExecution.class);
    Mockito.stub(exec.next()).toReturn(null);
    return exec;
}
Also used : ProcedureExecution(org.teiid.translator.ProcedureExecution) Properties(java.util.Properties) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord)

Example 24 with ProcedureExecution

use of org.teiid.translator.ProcedureExecution in project teiid by teiid.

the class TestResultsCache method testScope.

@Test
public void testScope() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("x");
    mmd.addProperty("teiid_rel:determinism", "USER_DETERMINISTIC");
    mmd.addSourceMapping("x", "x", null);
    mmd.addSourceMetadata("ddl", "create foreign table t (c string); create foreign procedure p () returns table (c string);");
    final AtomicBoolean setScope = new AtomicBoolean();
    server.addTranslator("x", new ExecutionFactory() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, final ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            return createProcedureExecution(null, executionContext, metadata, connection);
        }

        @Override
        public ProcedureExecution createProcedureExecution(Call command, final ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            return new ProcedureExecution() {

                boolean returned = false;

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (setScope.get()) {
                        // prevent caching altogether
                        executionContext.setScope(Scope.SESSION);
                    }
                    if (returned) {
                        return null;
                    }
                    returned = true;
                    return Arrays.asList(executionContext.getSession().getSessionId());
                }

                @Override
                public List<?> getOutputParameterValues() throws TranslatorException {
                    return null;
                }
            };
        }
    });
    server.deployVDB("x", mmd);
    Connection c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("/* cache */ select * from t");
    assertTrue(rs.next());
    String sessionid = rs.getString(1);
    // should be the same with same user/session
    rs = s.executeQuery("/* cache */ select * from t");
    assertTrue(rs.next());
    assertEquals(sessionid, rs.getString(1));
    c.close();
    c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
    s = c.createStatement();
    rs = s.executeQuery("/* cache */ select * from t");
    assertTrue(rs.next());
    assertEquals(sessionid, rs.getString(1));
    c.close();
    // for the final test
    setScope.set(true);
    // should be different with another user
    c = server.getDriver().connect("jdbc:teiid:x;user=bill", null);
    s = c.createStatement();
    rs = s.executeQuery("/* cache */ select * from t");
    assertTrue(rs.next());
    String sessionid1 = rs.getString(1);
    c.close();
    assertNotEquals(sessionid, sessionid1);
    c = server.getDriver().connect("jdbc:teiid:x;user=bill", null);
    s = c.createStatement();
    rs = s.executeQuery("/* cache */ select * from t");
    assertTrue(rs.next());
    // scope session should prevent reuse
    assertNotEquals(sessionid1, rs.getString(1));
    setScope.set(false);
    rs = s.executeQuery("/* cache */ call p()");
    assertTrue(rs.next());
    sessionid = rs.getString(1);
    c.close();
    c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
    s = c.createStatement();
    rs = s.executeQuery("/* cache */ call p()");
    assertTrue(rs.next());
    assertNotEquals(sessionid, rs.getString(1));
    c.close();
}
Also used : Call(org.teiid.language.Call) Statement(java.sql.Statement) Connection(java.sql.Connection) ExecutionFactory(org.teiid.translator.ExecutionFactory) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ProcedureExecution(org.teiid.translator.ProcedureExecution) ResultSet(java.sql.ResultSet) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Aggregations

ProcedureExecution (org.teiid.translator.ProcedureExecution)24 Test (org.junit.Test)20 MetadataFactory (org.teiid.metadata.MetadataFactory)7 CsdlReturnType (org.apache.olingo.commons.api.edm.provider.CsdlReturnType)6 List (java.util.List)5 ExecutionContext (org.teiid.translator.ExecutionContext)4 CsdlComplexType (org.apache.olingo.commons.api.edm.provider.CsdlComplexType)3 Call (org.teiid.language.Call)3 Command (org.teiid.language.Command)3 TranslatorException (org.teiid.translator.TranslatorException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 Connection (java.sql.Connection)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 DataSource (javax.activation.DataSource)2 TranslationUtility (org.teiid.cdk.api.TranslationUtility)2 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)2