Search in sources :

Example 1 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class ProcedureSQLBuilder method visit.

private void visit(EdmParameter edmParameter) throws TeiidProcessingException {
    Class<?> runtimeType = resolveParameterType(this.procedure.getName(), edmParameter.getName());
    Integer sqlType = JDBCSQLTypeInfo.getSQLType(DataTypeManager.getDataTypeName(runtimeType));
    Object value = this.parameterValueProvider.getValue(edmParameter, runtimeType);
    this.sqlParameters.add(new SQLParameter(edmParameter.getName(), value, sqlType));
}
Also used : SQLParameter(org.teiid.odata.api.SQLParameter)

Example 2 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class ProcedureSQLBuilder method buildProcedureSQL.

public String buildProcedureSQL() {
    StringBuilder sql = new StringBuilder();
    // fully qualify the procedure name
    if (getReturn().hasResultSet()) {
        // $NON-NLS-1$
        sql.append("{");
    } else {
        // $NON-NLS-1$
        sql.append("{? = ");
    }
    // $NON-NLS-1$
    sql.append("call ").append(SQLStringVisitor.escapeSinglePart(this.procedure.getFullName()));
    // $NON-NLS-1$
    sql.append("(");
    boolean first = true;
    for (SQLParameter parameter : this.sqlParameters) {
        if (!first) {
            // $NON-NLS-1$
            sql.append(",");
        }
        first = false;
        // $NON-NLS-1$
        sql.append(SQLStringVisitor.escapeSinglePart(parameter.getName())).append("=>?");
    }
    // $NON-NLS-1$
    sql.append(")");
    // $NON-NLS-1$
    sql.append("}");
    return sql.toString();
}
Also used : SQLParameter(org.teiid.odata.api.SQLParameter)

Example 3 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class ODataExpressionToSQLVisitor method visit.

@Override
public void visit(Literal expr) {
    try {
        Object value = null;
        if (expr.getText() != null && !expr.getText().equalsIgnoreCase("null")) {
            String type = expr.getType().getFullQualifiedName().getFullQualifiedNameAsString();
            value = ODataTypeManager.parseLiteral(type, expr.getText());
        }
        if (this.prepared) {
            if (value == null) {
                this.stack.add(new Constant(value));
            } else {
                Function ref = new Function(CONVERT, new org.teiid.query.sql.symbol.Expression[] { new Reference(this.params.size()), new Constant(DataTypeManager.getDataTypeName(value.getClass())) });
                stack.add(ref);
                this.params.add(new SQLParameter(value, JDBCSQLTypeInfo.getSQLTypeFromClass(value.getClass().getName())));
            }
        } else {
            this.stack.add(new Constant(value));
        }
    } catch (TeiidException e) {
        throw new TeiidRuntimeException(e);
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) Reference(org.teiid.query.sql.symbol.Reference) ScalarSubquery(org.teiid.query.sql.symbol.ScalarSubquery) SQLParameter(org.teiid.odata.api.SQLParameter) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Example 4 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class ODataSQLBuilder method asParam.

static SQLParameter asParam(EdmProperty edmProp, Object value, boolean rawValue) throws TeiidException {
    String teiidType = ODataTypeManager.teiidType((SingletonPrimitiveType) edmProp.getType(), edmProp.isCollection());
    int sqlType = JDBCSQLTypeInfo.getSQLType(teiidType);
    if (value == null) {
        return new SQLParameter(null, sqlType);
    }
    if (rawValue) {
        return new SQLParameter(ODataTypeManager.convertByteArrayToTeiidRuntimeType(DataTypeManager.getDataTypeClass(teiidType), (byte[]) value, ((SingletonPrimitiveType) edmProp.getType()).getFullQualifiedName().getFullQualifiedNameAsString()), sqlType);
    }
    return new SQLParameter(ODataTypeManager.convertToTeiidRuntimeType(DataTypeManager.getDataTypeClass(teiidType), value, ((SingletonPrimitiveType) edmProp.getType()).getFullQualifiedName().getFullQualifiedNameAsString()), sqlType);
}
Also used : SQLParameter(org.teiid.odata.api.SQLParameter) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)

Example 5 with SQLParameter

use of org.teiid.odata.api.SQLParameter in project teiid by teiid.

the class ODataSQLBuilder method updateStreamProperty.

public Update updateStreamProperty(EdmProperty edmProperty, final InputStream content) throws TeiidException {
    Update update = new Update();
    update.setGroup(this.context.getGroupSymbol());
    Column column = this.context.getColumnByName(edmProperty.getName());
    ElementSymbol symbol = new ElementSymbol(column.getName(), this.context.getGroupSymbol());
    update.addChange(symbol, new Reference(0));
    Class<?> lobType = DataTypeManager.getDataTypeClass(column.getRuntimeType());
    int sqlType = JDBCSQLTypeInfo.getSQLType(column.getRuntimeType());
    if (content == null) {
        this.params.add(new SQLParameter(null, sqlType));
    } else {
        Object value = null;
        InputStreamFactory isf = new InputStreamFactory() {

            @Override
            public InputStream getInputStream() throws IOException {
                return content;
            }
        };
        if (lobType.isAssignableFrom(SQLXML.class)) {
            value = new SQLXMLImpl(isf);
        } else if (lobType.isAssignableFrom(ClobType.class)) {
            value = new ClobImpl(isf, -1);
        } else if (lobType.isAssignableFrom(BlobType.class)) {
            value = new BlobImpl(isf);
        } else {
            throw new TeiidException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16031, column.getName()));
        }
        this.params.add(new SQLParameter(value, sqlType));
    }
    update.setCriteria(this.context.getCriteria());
    return update;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) Reference(org.teiid.query.sql.symbol.Reference) SQLParameter(org.teiid.odata.api.SQLParameter) InputStreamFactory(org.teiid.core.types.InputStreamFactory) SubqueryHint(org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint) TeiidException(org.teiid.core.TeiidException) ClobType(org.teiid.core.types.ClobType) Column(org.teiid.metadata.Column) ClobImpl(org.teiid.core.types.ClobImpl) BlobImpl(org.teiid.core.types.BlobImpl)

Aggregations

SQLParameter (org.teiid.odata.api.SQLParameter)7 TeiidException (org.teiid.core.TeiidException)2 SubqueryHint (org.teiid.query.sql.lang.ExistsCriteria.SubqueryHint)2 Reference (org.teiid.query.sql.symbol.Reference)2 CallableStatement (java.sql.CallableStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 BlobImpl (org.teiid.core.types.BlobImpl)1 ClobImpl (org.teiid.core.types.ClobImpl)1 ClobType (org.teiid.core.types.ClobType)1 InputStreamFactory (org.teiid.core.types.InputStreamFactory)1 SQLXMLImpl (org.teiid.core.types.SQLXMLImpl)1 Column (org.teiid.metadata.Column)1 Client (org.teiid.odata.api.Client)1 EntityCollectionResponse (org.teiid.olingo.service.EntityCollectionResponse)1 ParseInfo (org.teiid.query.parser.ParseInfo)1 CacheHint (org.teiid.query.sql.lang.CacheHint)1 Query (org.teiid.query.sql.lang.Query)1 Constant (org.teiid.query.sql.symbol.Constant)1