/** * Return the correct CAST function syntax * * @param val operand of cast * @param func original string * @return a String with the correct CAST function syntax */ public String getCastFunction(Val val, String func) { if (val instanceof Lit || val instanceof Param) if (func.indexOf("VARCHAR") == -1) func = addCastAsString(func, "{0}", " AS VARCHAR(1000)"); return func; }
public OpenJPAException newStoreException(String msg, SQLException[] causes, Object failed) { if (appendExtendedExceptionText == true && causes != null && causes.length > 0) { msg = appendExtendedExceptionMsg(msg, causes[0]); } return super.newStoreException(msg, causes, failed); }
/** * If this dictionary supports XML type, * use this method to append xml predicate. * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison * @param rhs the right hand side of the comparison * @param lhsxml indicates whether the left operand maps to xml * @param rhsxml indicates whether the right operand maps to xml */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml && rhsxml) appendXmlComparison2(buf, op, lhs, rhs); else if (lhsxml) appendXmlComparison1(buf, op, lhs, rhs); else appendXmlComparison1(buf, op, rhs, lhs); }
/** * add CAST for a function operator where operand is a param * * @param func function name * @param val type * @return updated string (func) */ public String addCastAsType(String func, Val val) { String fstring = null; String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val .getType()), false)); if (String.class.equals(val.getType())) type = type + "(" + getCastStringColumnSize(val) + ")"; fstring = "CAST(? AS " + type + ")"; return fstring; }
/** * add CAST for a function operator where operand is a param * * @param func function name * @param val type * @return updated string (func) */ public String addCastAsType(String func, Val val) { String fstring = null; String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val .getType()), false)); if (String.class.equals(val.getType())) type = type + "(" + characterColumnSize + ")"; fstring = "CAST(? AS " + type + ")"; return fstring; }
int type = 0; if (rhs.isConstant()) { type = getJDBCType(JavaTypes.getTypeCode(rc), false); castrhs = true; appendXmlExists(buf, lhs); appendXmlVar(buf, lhs); buf.append(", "); appendCast(buf, rhs, type); else rhs.appendTo(buf);
val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { if (sqlString.endsWith("?")) { String typeName = getTypeName(type); if (String.class.equals(val.getType())) typeName = typeName + "(" + getCastStringColumnSize(val) + ")"; String str = "CAST(? AS " + typeName + ")"; buf.replaceSqlString(sqlString.length() - 1,
/** * Append an xml comparison predicate. (both operands map to xml column) * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison (maps to xml column) * @param rhs the right hand side of the comparison (maps to xml column) */ private void appendXmlComparison2(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs) { appendXmlExists(buf, lhs); buf.append(" ").append(op).append(" "); buf.append("$").append(rhs.getColumnAlias( rhs.getFieldMapping().getColumns()[0])). append("/*/"); rhs.appendTo(buf); buf.append("]' PASSING "); appendXmlVar(buf, lhs); buf.append(", "); appendXmlVar(buf, rhs); buf.append(")"); }
val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { if (sqlString.endsWith("?")) { String typeName = getTypeName(type); if (String.class.equals(val.getType())) typeName = typeName + "(" + characterColumnSize + ")";
StringBuilder forUpdateString = new StringBuilder(getOptimizeClause(sel));
int type = 0; if (rhs.isConstant()) { type = getJDBCType(JavaTypes.getTypeCode(rc), false); castrhs = true; appendXmlExists(buf, lhs); appendXmlVar(buf, lhs); buf.append(", "); appendCast(buf, rhs, type); else rhs.appendTo(buf);
/** * add CAST for a function operator where operand is a param * * @param func function name * @param val type * @return updated string (func) */ public String addCastAsType(String func, Val val) { String fstring = null; String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val .getType()), false)); if (String.class.equals(val.getType())) type = type + "(" + getCastStringColumnSize(val) + ")"; fstring = "CAST(? AS " + type + ")"; return fstring; }
val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { if (sqlString.endsWith("?")) { String typeName = getTypeName(type); if (String.class.equals(val.getType())) typeName = typeName + "(" + getCastStringColumnSize(val) + ")"; String str = "CAST(? AS " + typeName + ")"; buf.replaceSqlString(sqlString.length() - 1,
/** * Append an xml comparison predicate. (both operands map to xml column) * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison (maps to xml column) * @param rhs the right hand side of the comparison (maps to xml column) */ private void appendXmlComparison2(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs) { appendXmlExists(buf, lhs); buf.append(" ").append(op).append(" "); buf.append("$").append(rhs.getColumnAlias( rhs.getFieldMapping().getColumns()[0])). append("/*/"); rhs.appendTo(buf); buf.append("]' PASSING "); appendXmlVar(buf, lhs); buf.append(", "); appendXmlVar(buf, rhs); buf.append(")"); }
protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel, int idx) { // if this is a literal value, add a cast... Object val = sel.getSelects().get(idx); if (val instanceof Lit) selectSQL.append("CAST("); // ... and add the select per super's behavior... super.appendSelect(selectSQL, alias, sel, idx); // ... and finish the cast if (val instanceof Lit) { Class c = ((Lit) val).getType(); int javaTypeCode = JavaTypes.getTypeCode(c); int jdbcTypeCode = getJDBCType(javaTypeCode, false); String typeName = getTypeName(jdbcTypeCode); selectSQL.append(" AS " + typeName); // if the literal is a string, use the default char col size // in the cast statement. if (String.class.equals(c)) selectSQL.append("(" + characterColumnSize + ")"); selectSQL.append(")"); } }
StringBuffer forUpdateString = new StringBuffer(getOptimizeClause(sel));
int type = 0; if (rhs.isConstant()) { type = getJDBCType(JavaTypes.getTypeCode(rc), false); castrhs = true; appendXmlExists(buf, lhs); appendXmlVar(buf, lhs); buf.append(", "); appendCast(buf, rhs, type); else rhs.appendTo(buf);
/** * add CAST for a function operator where operand is a param * * @param func function name * @param val type * @return updated string (func) */ public String addCastAsType(String func, Val val) { String fstring = null; String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val .getType()), false)); if (String.class.equals(val.getType())) type = type + "(" + getCastStringColumnSize(val) + ")"; fstring = "CAST(? AS " + type + ")"; return fstring; }
val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { if (sqlString.endsWith("?")) { String typeName = getTypeName(type); if (String.class.equals(val.getType())) typeName = typeName + "(" + getCastStringColumnSize(val) + ")"; String str = "CAST(? AS " + typeName + ")"; buf.replaceSqlString(sqlString.length() - 1,
/** * If this dictionary supports XML type, * use this method to append xml predicate. * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison * @param rhs the right hand side of the comparison * @param lhsxml indicates whether the left operand maps to xml * @param rhsxml indicates whether the right operand maps to xml */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml && rhsxml) appendXmlComparison2(buf, op, lhs, rhs); else if (lhsxml) appendXmlComparison1(buf, op, lhs, rhs); else appendXmlComparison1(buf, op, rhs, lhs); }