public class OpenJPAPostgresqlDictionaryPatch extends PostgresDictionary { @Override public SQLBuffer toOperation(String op, SQLBuffer selects, SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having, SQLBuffer order, boolean distinct, long start, long end, String forUpdateClause, boolean subselect) { String whereSQL = where.getSQL(); int p = whereSQL.indexOf("LIKE"); int offset = 0; while (p != -1) { where.replaceSqlString(p + offset, p + offset + 4, "ILIKE"); p = whereSQL.indexOf("LIKE", p + 1); offset++; } return super.toOperation(op, selects, from, where, group, having, order, distinct, start, end, forUpdateClause, subselect); } }
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index, String operator) { ArgsExpState astate = (ArgsExpState) state; for (int i = 0; i < _args.length; i++) { _args[i].appendTo(sel, ctx, astate.states[i], sql, index); if( operator != null ) { sql.addCastForParam(operator, _args[i]); } if (i < _args.length-1) sql.append(", "); } }
@Override protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect) { if (end != Long.MAX_VALUE) buf.append(" LIMIT ").appendValue(end - start); if (start != 0) buf.append(" OFFSET ").appendValue(start); }
/** * Add the given condition to the HAVING clause. */ private void having(SQLBuffer sql, PathJoins pj) { // no need to use joins... if (sql == null || sql.isEmpty()) return; if (_having == null) _having = new SQLBuffer(_dict); else if (!_having.isEmpty()) _having.append(" AND "); _having.append(sql); }
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer buf) { DBDictionary dict = ctx.store.getDBDictionary(); dict.assertSupport(dict.supportsSubselect, "SupportsSubselect"); Select sub = ctx.store.getSQLFactory().newSelect(); sub.setParent(sel, null); ExpState estate = _exp.initialize(sub, ctx, ((NotContainsExpState) state).contains); sub.where(sub.and(null, estate.joins)); SQLBuffer where = new SQLBuffer(dict).append("("); _exp.appendTo(sub, ctx, estate, where); if (where.getSQL().length() > 1) sub.where(where.append(")")); buf.append("0 = "); buf.appendCount(sub, ctx.fetch); }
buf.append(pre); val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { val.appendTo(buf); String sqlString = buf.getSQL(false); if (sqlString.endsWith("?")) { typeName = typeName + "(" + characterColumnSize + ")"; String str = "CAST(? AS " + typeName + ")"; buf.replaceSqlString(sqlString.length() - 1, sqlString.length(), str);
/** * Overrides SQL formation by replacing COUNT(column) by COUNT(*) when specific conditions are met and * DBDictionary configuration <code>useWildCardForCount</code> is set. */ @Override public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) { if (isCountDistinctMultiCols()) { getValue().appendTo(sel, ctx, state, sql, 0); sql.addCastForParam(getOperator(), getValue()); } else super.appendTo(sel, ctx, state, sql, index); if ((ctx.store.getDBDictionary().useWildCardForCount && state.joins.isEmpty()) || !isCountDistinct && isCountMultiColumns){ String s = sql.getSQL(); if (s.startsWith("COUNT(") && s.endsWith(")")) { sql.replaceSqlString("COUNT(".length(), s.length()-1, "*"); } } }
private void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index, boolean size) { QueryExpressionsState substate = new QueryExpressionsState(); Select sub = _cons.evaluate(ctx, sel, _subqAlias, _exps, substate); _cons.select(sub, ctx, _candidate, _subs, _exps, substate, JDBCFetchConfiguration.EAGER_NONE); if (size) sql.appendCount(sub, ctx.fetch); else sql.append(sub, ctx.fetch); }
/** * Return the SQL for this buffer. */ public String getSQL() { return getSQL(false); }
/** * Create and populate the parameters of a prepared statement using * the SQL in this buffer. */ public CallableStatement prepareCall(Connection conn) throws SQLException { return prepareCall(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); }
/** * This method is to provide override for non-JDBC or JDBC-like * implementation of preparing statement. */ protected PreparedStatement prepareStatement(Connection conn, SQLBuffer sql) throws SQLException { return sql.prepareStatement(conn); }
/** * Perform a shallow clone of this SQL Buffer. */ public Object clone() { return new SQLBuffer(this); }
/** * Return true if the select with the given parameters needs a * subselect to apply a range. */ private boolean requiresSubselectForRange(long start, long end, boolean distinct, SQLBuffer order) { if (start == 0 && end == Long.MAX_VALUE) return false; return start != 0 || distinct || (order != null && !order.isEmpty()); }
public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer buf) { DBDictionary dict = ctx.store.getDBDictionary(); dict.assertSupport(dict.supportsSubselect, "SupportsSubselect"); Select sub = ctx.store.getSQLFactory().newSelect(); sub.setParent(sel, null); // this subselect has the same context as its parent sub.setContext(sel.ctx()); // the context select should still belong to parent sub.ctx().setSelect(sel); ExpState estate = _exp.initialize(sub, ctx, ((NotContainsExpState) state).contains); sub.where(sub.and(null, estate.joins)); SQLBuffer where = new SQLBuffer(dict).append("("); _exp.appendTo(sub, ctx, estate, where); if (where.getSQL().length() > 1) sub.where(where.append(")")); buf.append("0 = "); buf.appendCount(sub, ctx.fetch); }
buf.append(pre); val.appendTo(buf); buf.append(mid); buf.append(getTypeName(type)); appendLength(buf, type); buf.append(post); } else { val.appendTo(buf); String sqlString = buf.getSQL(false); if (sqlString.endsWith("?")) { typeName = typeName + "(" + getCastStringColumnSize(val) + ")"; String str = "CAST(? AS " + typeName + ")"; buf.replaceSqlString(sqlString.length() - 1, sqlString.length(), str);
/** * Overrides SQL formation by replacing COUNT(column) by COUNT(*) when specific conditions are met and * DBDictionary configuration <code>useWildCardForCount</code> is set. */ @Override public void appendTo(Select sel, ExpContext ctx, ExpState state, SQLBuffer sql, int index) { if (isCountDistinctMultiCols()) { getValue().appendTo(sel, ctx, state, sql, 0); sql.addCastForParam(getOperator(), getValue()); } else super.appendTo(sel, ctx, state, sql, index); if ((ctx.store.getDBDictionary().useWildCardForCount && state.joins.isEmpty()) || !isCountDistinct && isCountMultiColumns){ String s = sql.getSQL(); if (s.startsWith("COUNT(") && s.endsWith(")")) { sql.replaceSqlString("COUNT(".length(), s.length()-1, "*"); } } }
@Override protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect) { if (end != Long.MAX_VALUE) buf.append(" LIMIT ").appendValue(end - start); if (start != 0) { if(end == Long.MAX_VALUE) buf.append(" LIMIT 0"); buf.append(" OFFSET ").appendValue(start); } }