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));
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations