Search in sources :

Example 26 with Argument

use of org.teiid.language.Argument 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 27 with Argument

use of org.teiid.language.Argument in project teiid by teiid.

the class JDBCProcedureExecution method getOutputParameterValues.

@Override
public List<?> getOutputParameterValues() throws TranslatorException {
    try {
        Call proc = (Call) this.command;
        List<Object> result = new ArrayList<Object>();
        int paramIndex = 1;
        if (proc.getReturnType() != null) {
            if (proc.getReturnParameter() != null) {
                addParameterValue(result, paramIndex, proc.getReturnType());
            }
            paramIndex++;
        }
        for (Argument parameter : proc.getArguments()) {
            switch(parameter.getDirection()) {
                case IN:
                    paramIndex++;
                    break;
                case INOUT:
                case OUT:
                    addParameterValue(result, paramIndex++, parameter.getType());
                    break;
            }
        }
        return result;
    } catch (SQLException e) {
        throw new TranslatorException(JDBCPlugin.Event.TEIID11005, e);
    }
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

Argument (org.teiid.language.Argument)27 TranslatorException (org.teiid.translator.TranslatorException)13 Literal (org.teiid.language.Literal)12 ArrayList (java.util.ArrayList)9 Call (org.teiid.language.Call)9 SQLException (java.sql.SQLException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 List (java.util.List)4 Test (org.junit.Test)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 IOException (java.io.IOException)3 Timestamp (java.sql.Timestamp)3 HashMap (java.util.HashMap)3 StringTokenizer (java.util.StringTokenizer)3 ResourceException (javax.resource.ResourceException)3 DB (com.mongodb.DB)2 DBObject (com.mongodb.DBObject)2 SObject (com.sforce.soap.partner.sobject.SObject)2 XmlObject (com.sforce.ws.bind.XmlObject)2