use of org.apache.cayenne.access.translator.ParameterBinding in project cayenne by apache.
the class Bind method bindValue.
protected void bindValue(Context context, Object value, String jdbcTypeName, int scale) {
int jdbcType;
if (jdbcTypeName != null) {
jdbcType = TypesMapping.getSqlTypeByName(jdbcTypeName);
} else if (value != null) {
jdbcType = TypesMapping.getSqlTypeByJava(value.getClass());
} else {
jdbcType = TypesMapping.getSqlTypeByName(TypesMapping.SQL_NULL);
}
processBinding(context, new ParameterBinding(value, jdbcType, scale));
}
use of org.apache.cayenne.access.translator.ParameterBinding in project cayenne by apache.
the class BindObjectEqual method apply.
@Override
public void apply(Context context, ASTExpression... expressions) {
Object object = expressions[0].evaluateAsObject(context);
Map<String, Object> idMap = toIdMap(object);
Object sqlColumns = null;
Object idColumns = null;
if (expressions.length > 1) {
sqlColumns = expressions[1].evaluateAsObject(context);
}
if (expressions.length > 2) {
idColumns = expressions[2].evaluateAsObject(context);
}
if (idMap == null) {
// assume null object, and bind all null values
if (sqlColumns == null || idColumns == null) {
throw new CayenneRuntimeException("Invalid parameters. " + "Either object has to be set or sqlColumns and idColumns or both.");
}
idMap = Collections.emptyMap();
} else if (sqlColumns == null || idColumns == null) {
// infer SQL columns from ID columns
sqlColumns = idMap.keySet().toArray();
idColumns = sqlColumns;
}
String[] sqlColumnsArray = toArray(sqlColumns);
String[] idColumnsArray = toArray(idColumns);
if (sqlColumnsArray.length != idColumnsArray.length) {
throw new CayenneRuntimeException("SQL columns and ID columns arrays have different sizes.");
}
for (int i = 0; i < sqlColumnsArray.length; i++) {
Object value = idMap.get(idColumnsArray[i]);
int jdbcType = (value != null) ? TypesMapping.getSqlTypeByJava(value.getClass()) : Types.INTEGER;
renderColumn(context, sqlColumnsArray[i], i);
render(context, new ParameterBinding(value, jdbcType, -1));
}
}
use of org.apache.cayenne.access.translator.ParameterBinding in project cayenne by apache.
the class Slf4jJdbcEventLogger method appendParameters.
@SuppressWarnings("unchecked")
private void appendParameters(StringBuilder buffer, String label, ParameterBinding[] bindings) {
int len = bindings.length;
if (len > 0) {
boolean hasIncluded = false;
for (int i = 0, j = 1; i < len; i++) {
ParameterBinding b = bindings[i];
if (b.isExcluded()) {
continue;
}
if (hasIncluded) {
buffer.append(", ");
} else {
hasIncluded = true;
buffer.append("[").append(label).append(": ");
}
buffer.append(j++);
if (b instanceof DbAttributeBinding) {
DbAttribute attribute = ((DbAttributeBinding) b).getAttribute();
if (attribute != null) {
buffer.append("->");
buffer.append(attribute.getName());
}
}
buffer.append(":");
if (b.getExtendedType() != null) {
buffer.append(b.getExtendedType().toString(b.getValue()));
} else if (b.getValue() == null) {
buffer.append("NULL");
} else {
buffer.append(b.getValue().getClass().getName()).append("@").append(System.identityHashCode(b.getValue()));
}
}
if (hasIncluded) {
buffer.append("]");
}
}
}
Aggregations