Search in sources :

Example 36 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter in project teiid by teiid.

the class TestResolver method testExecWithDuplicateNames.

@Test
public void testExecWithDuplicateNames() {
    MetadataStore metadataStore = new MetadataStore();
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs2 = RealMetadataFactory.createResultSet("rs2", new String[] { "in", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter rs2p2 = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    Procedure sq2 = RealMetadataFactory.createStoredProcedure("sq2", pm1, Arrays.asList(rs2p2));
    sq2.setResultSet(rs2);
    QueryMetadataInterface metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "example1");
    // $NON-NLS-1$ //$NON-NLS-2$
    helpResolveException("select * from pm1.sq2", metadata, "TEIID30114 Cannot access procedure pm1.sq2 using table semantics since the parameter and result set column names are not all unique.");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 37 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter in project teiid by teiid.

the class ODataSchemaBuilder method buildFunction.

static void buildFunction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlFunction> functions, ArrayList<CsdlFunctionImport> functionImports, CsdlSchema csdlSchema) {
    CsdlFunction edmFunction = new CsdlFunction();
    edmFunction.setName(proc.getName());
    edmFunction.setBound(false);
    ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
    for (ProcedureParameter pp : proc.getParameters()) {
        EdmPrimitiveTypeKind odataType = ODataTypeManager.odataType(pp.getRuntimeType());
        if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
            edmFunction.setReturnType(new CsdlReturnType().setType(odataType.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
            continue;
        }
        if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
            CsdlParameter parameter = buildParameter(pp, odataType);
            addOperationParameterAnnotations(pp, parameter, csdlSchema);
            params.add(parameter);
        }
    }
    edmFunction.setParameters(params);
    // add a complex type for return resultset.
    ColumnSet<Procedure> returnColumns = proc.getResultSet();
    if (returnColumns != null) {
        CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
        complexTypes.add(complexType);
        FullQualifiedName odataType = new FullQualifiedName(schemaName, complexType.getName());
        edmFunction.setReturnType((new CsdlReturnType().setType(odataType).setCollection(true)));
    }
    CsdlFunctionImport functionImport = new CsdlFunctionImport();
    functionImport.setName(proc.getName()).setFunction(new FullQualifiedName(schemaName, proc.getName()));
    addOperationAnnotations(proc, edmFunction, csdlSchema);
    functions.add(edmFunction);
    functionImports.add(functionImport);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)

Example 38 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter in project teiid by teiid.

the class ODataSchemaBuilder method buildAction.

static void buildAction(String schemaName, Procedure proc, ArrayList<CsdlComplexType> complexTypes, ArrayList<CsdlAction> actions, ArrayList<CsdlActionImport> actionImports, CsdlSchema csdlSchema) {
    CsdlAction edmAction = new CsdlAction();
    edmAction.setName(proc.getName());
    edmAction.setBound(false);
    ArrayList<CsdlParameter> params = new ArrayList<CsdlParameter>();
    for (ProcedureParameter pp : proc.getParameters()) {
        EdmPrimitiveTypeKind odatatype = ODataTypeManager.odataType(pp.getRuntimeType());
        if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
            edmAction.setReturnType(new CsdlReturnType().setType(odatatype.getFullQualifiedName()).setCollection(DataTypeManager.isArrayType(pp.getRuntimeType())));
            continue;
        }
        if (pp.getType().equals(ProcedureParameter.Type.In) || pp.getType().equals(ProcedureParameter.Type.InOut)) {
            CsdlParameter parameter = buildParameter(pp, odatatype);
            addOperationParameterAnnotations(pp, parameter, csdlSchema);
            params.add(parameter);
        }
    }
    edmAction.setParameters(params);
    // add a complex type for return resultset.
    ColumnSet<Procedure> returnColumns = proc.getResultSet();
    if (returnColumns != null) {
        CsdlComplexType complexType = buildComplexType(proc, returnColumns, csdlSchema);
        complexTypes.add(complexType);
        edmAction.setReturnType((new CsdlReturnType().setType(new FullQualifiedName(schemaName, complexType.getName())).setCollection(true)));
    }
    CsdlActionImport actionImport = new CsdlActionImport();
    actionImport.setName(proc.getName()).setAction(new FullQualifiedName(schemaName, proc.getName()));
    addOperationAnnotations(proc, edmAction, csdlSchema);
    actions.add(edmAction);
    actionImports.add(actionImport);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) FullQualifiedName(org.apache.olingo.commons.api.edm.FullQualifiedName) ArrayList(java.util.ArrayList) Procedure(org.teiid.metadata.Procedure) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)

Example 39 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter in project teiid by teiid.

the class RestASMBasedWebArchiveBuilder method buildRestService.

private void buildRestService(String vdbName, String vdbVersion, String modelName, Procedure procedure, String method, String uri, ClassWriter cw, String contentType, String charSet, boolean passthroughAuth) {
    List<ProcedureParameter> params = new ArrayList<ProcedureParameter>(procedure.getParameters().size());
    boolean usingReturn = false;
    boolean hasLobInput = false;
    for (ProcedureParameter p : procedure.getParameters()) {
        if (p.getType() == Type.In || p.getType() == Type.InOut) {
            params.add(p);
        } else if (p.getType() == Type.ReturnValue && procedure.getResultSet() == null) {
            usingReturn = true;
        }
        if (!hasLobInput) {
            String runtimeType = p.getRuntimeType();
            hasLobInput = DataTypeManager.isLOB(runtimeType);
        }
    }
    int paramsSize = params.size();
    MethodVisitor mv;
    boolean useMultipart = false;
    if (method.toUpperCase().equals("POST") && hasLobInput) {
        useMultipart = true;
    }
    AnnotationVisitor av0;
    {
        StringBuilder paramSignature = new StringBuilder();
        paramSignature.append("(");
        for (int i = 0; i < paramsSize; i++) {
            paramSignature.append("Ljava/lang/String;");
        }
        paramSignature.append(")");
        if (useMultipart) {
            mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), "(Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;)Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" });
        } else {
            mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), paramSignature + "Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" });
        }
        {
            av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true);
            {
                AnnotationVisitor av1 = av0.visitArray("value");
                av1.visit(null, contentType);
                av1.visitEnd();
            }
            av0.visitEnd();
        }
        {
            av0 = mv.visitAnnotation("Ljavax/ws/rs/" + method.toUpperCase() + ";", true);
            av0.visitEnd();
        }
        {
            av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true);
            av0.visit("value", uri);
            av0.visitEnd();
        }
        {
            av0 = mv.visitAnnotation("Ljavax/annotation/security/PermitAll;", true);
            av0.visitEnd();
        }
        {
            av0 = mv.visitAnnotation("Lio/swagger/annotations/ApiOperation;", true);
            av0.visit("value", procedure.getName());
            av0.visitEnd();
        }
        {
            av0 = mv.visitAnnotation("Lio/swagger/annotations/ApiResponses;", true);
            ApiResponse[] array = new ApiResponse[] {};
            AnnotationVisitor av1 = av0.visitArray("value");
            for (int i = 0; i < array.length; i++) {
                av1.visit("value", array[i]);
            }
            av1.visitEnd();
            av0.visitEnd();
        }
        if (useMultipart) {
            av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true);
            {
                AnnotationVisitor av1 = av0.visitArray("value");
                av1.visit(null, "multipart/form-data");
                av1.visitEnd();
            }
            av0.visitEnd();
        }
        if (!useMultipart) {
            // post only accepts Form inputs, not path params
            HashSet<String> pathParms = getPathParameters(uri);
            for (int i = 0; i < paramsSize; i++) {
                String paramType = "Ljavax/ws/rs/FormParam;";
                if (method.toUpperCase().equals("GET")) {
                    paramType = "Ljavax/ws/rs/QueryParam;";
                }
                if (pathParms.contains(params.get(i).getName())) {
                    paramType = "Ljavax/ws/rs/PathParam;";
                }
                av0 = mv.visitParameterAnnotation(i, paramType, true);
                av0.visit("value", params.get(i).getName());
                av0.visitEnd();
                av0 = mv.visitParameterAnnotation(i, "Lio/swagger/annotations/ApiParam;", true);
                av0.visit("value", params.get(i).getName());
                av0.visitEnd();
            }
        }
        mv.visitCode();
        Label l0 = new Label();
        Label l1 = new Label();
        Label l2 = new Label();
        mv.visitTryCatchBlock(l0, l1, l2, "java/sql/SQLException");
        mv.visitLabel(l0);
        if (!useMultipart) {
            mv.visitTypeInsn(NEW, "java/util/LinkedHashMap");
            mv.visitInsn(DUP);
            mv.visitMethodInsn(INVOKESPECIAL, "java/util/LinkedHashMap", "<init>", "()V");
            mv.visitVarInsn(ASTORE, paramsSize + 1);
            for (int i = 0; i < paramsSize; i++) {
                mv.visitVarInsn(ALOAD, paramsSize + 1);
                mv.visitLdcInsn(params.get(i).getName());
                mv.visitVarInsn(ALOAD, i + 1);
                mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
                mv.visitInsn(POP);
            }
            mv.visitVarInsn(ALOAD, 0);
            mv.visitLdcInsn(vdbName);
            mv.visitLdcInsn(vdbVersion);
            mv.visitLdcInsn(procedure.getSQLString());
            mv.visitVarInsn(ALOAD, paramsSize + 1);
            mv.visitLdcInsn(charSet == null ? "" : charSet);
            mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0);
            mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0);
            mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "execute", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;");
            mv.visitLabel(l1);
            mv.visitInsn(ARETURN);
            mv.visitLabel(l2);
            mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" });
            mv.visitVarInsn(ASTORE, paramsSize + 1);
            mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, paramsSize + 1);
            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(7, paramsSize + 2);
            mv.visitEnd();
        } else {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitLdcInsn(vdbName);
            mv.visitLdcInsn(vdbVersion);
            mv.visitLdcInsn(procedure.getSQLString());
            mv.visitVarInsn(ALOAD, 1);
            mv.visitLdcInsn(charSet == null ? "" : charSet);
            mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0);
            mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0);
            mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "executePost", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;");
            mv.visitLabel(l1);
            mv.visitInsn(ARETURN);
            mv.visitLabel(l2);
            mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" });
            mv.visitVarInsn(ASTORE, 2);
            mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException");
            mv.visitInsn(DUP);
            mv.visitVarInsn(ALOAD, 2);
            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(8, 3);
            mv.visitEnd();
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) ArrayList(java.util.ArrayList) Label(org.objectweb.asm.Label) ApiResponse(io.swagger.annotations.ApiResponse) MethodVisitor(org.objectweb.asm.MethodVisitor) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) HashSet(java.util.HashSet)

Example 40 with ProcedureParameter

use of org.teiid.metadata.ProcedureParameter in project teiid by teiid.

the class RestASMBasedWebArchiveBuilder method findContentType.

private String findContentType(Procedure procedure) {
    String contentType = "plain";
    ColumnSet<Procedure> rs = procedure.getResultSet();
    if (rs != null) {
        Column returnColumn = rs.getColumns().get(0);
        if (returnColumn.getDatatype().getRuntimeTypeName().equals(DataTypeManager.DefaultDataTypes.XML)) {
            // $NON-NLS-1$
            contentType = "xml";
        } else if (returnColumn.getDatatype().getRuntimeTypeName().equals(DataTypeManager.DefaultDataTypes.CLOB)) {
            contentType = "json";
        }
    } else {
        for (ProcedureParameter pp : procedure.getParameters()) {
            if (pp.getType().equals(ProcedureParameter.Type.ReturnValue)) {
                if (pp.getDatatype().getRuntimeTypeName().equals(DataTypeManager.DefaultDataTypes.XML)) {
                    // $NON-NLS-1$
                    contentType = "xml";
                } else if (pp.getDatatype().getRuntimeTypeName().equals(DataTypeManager.DefaultDataTypes.CLOB)) {
                    // $NON-NLS-1$
                    contentType = "json";
                }
            }
        }
    }
    return contentType;
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Column(org.teiid.metadata.Column) Procedure(org.teiid.metadata.Procedure)

Aggregations

ProcedureParameter (org.teiid.metadata.ProcedureParameter)43 Procedure (org.teiid.metadata.Procedure)35 Test (org.junit.Test)12 MetadataFactory (org.teiid.metadata.MetadataFactory)9 Schema (org.teiid.metadata.Schema)8 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)8 MetadataStore (org.teiid.metadata.MetadataStore)7 Column (org.teiid.metadata.Column)6 ArrayList (java.util.ArrayList)5 QueryNode (org.teiid.query.mapping.relational.QueryNode)5 List (java.util.List)4 Table (org.teiid.metadata.Table)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 EdmPrimitiveTypeKind (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)2 FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)2 Argument (org.teiid.language.Argument)2 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 TranslatorException (org.teiid.translator.TranslatorException)2 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)2