Search in sources :

Example 1 with EdmPrimitiveTypeKind

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind in project teiid by teiid.

the class DocumentNode method getKeyPredicateExpression.

private static org.apache.olingo.server.api.uri.queryoption.expression.Expression getKeyPredicateExpression(UriParameter key, OData odata, Column column) {
    org.apache.olingo.server.api.uri.queryoption.expression.Expression expr = key.getExpression();
    if (expr == null) {
        EdmPrimitiveTypeKind primitiveTypeKind = ODataTypeManager.odataType(column.getRuntimeType());
        expr = new LiteralImpl(key.getText(), odata.createPrimitiveTypeInstance(primitiveTypeKind));
    }
    return expr;
}
Also used : LiteralImpl(org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)

Example 2 with EdmPrimitiveTypeKind

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind in project teiid by teiid.

the class ODataTypeManager method convertToODataURIValue.

public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException {
    if (val == null) {
        // is this correct? //$NON-NLS-1$
        return "null";
    }
    if (odataType.startsWith("Edm.")) {
        // $NON-NLS-1$
        odataType = odataType.substring(4);
    }
    if (val instanceof GeometryType) {
        Geometry g;
        try {
            g = GeometryUtils.getGeometry((GeometryType) val);
        } catch (FunctionExecutionException e1) {
            throw new EdmPrimitiveTypeException(e1.getMessage(), e1);
        }
        StringWriter sw = new StringWriter();
        // $NON-NLS-1$
        sw.write("geometry'SRID=");
        sw.write(String.valueOf(g.getSRID()));
        // $NON-NLS-1$
        sw.write(";");
        ODataWKTWriter writer = new ODataWKTWriter();
        try {
            writer.write(g, sw);
        } catch (IOException e) {
            throw new TeiidRuntimeException(e);
        }
        // $NON-NLS-1$
        sw.write("'");
        return sw.toString();
    }
    EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType);
    String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString(val, true, null, null, Integer.MAX_VALUE, true);
    if (kind == EdmPrimitiveTypeKind.String) {
        return EdmString.getInstance().toUriLiteral(value);
    }
    return value;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) StringWriter(java.io.StringWriter) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind) EdmString(org.apache.olingo.commons.core.edm.primitivetype.EdmString)

Example 3 with EdmPrimitiveTypeKind

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind 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 4 with EdmPrimitiveTypeKind

use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind 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)

Aggregations

EdmPrimitiveTypeKind (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind)4 ArrayList (java.util.ArrayList)2 FullQualifiedName (org.apache.olingo.commons.api.edm.FullQualifiedName)2 Procedure (org.teiid.metadata.Procedure)2 ProcedureParameter (org.teiid.metadata.ProcedureParameter)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 EdmPrimitiveTypeException (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)1 EdmString (org.apache.olingo.commons.core.edm.primitivetype.EdmString)1 LiteralImpl (org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1