public Join(String sourceTablePrefix, Property sourceJoinProperty, AbstractDao<DST, ?> daoDestination, Property destinationJoinProperty, String joinTablePrefix) { this.sourceTablePrefix = sourceTablePrefix; this.joinPropertySource = sourceJoinProperty; this.daoDestination = daoDestination; this.joinPropertyDestination = destinationJoinProperty; tablePrefix = joinTablePrefix; whereCollector = new WhereCollector<DST>(daoDestination, joinTablePrefix); }
/** * Adds the given conditions to the where clause using an logical AND. To create new conditions, use the properties * given in the generated dao classes. */ public Join<SRC, DST> where(WhereCondition cond, WhereCondition... condMore) { whereCollector.add(cond, condMore); return this; }
WhereCondition combineWhereConditions(String combineOp, WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { StringBuilder builder = new StringBuilder("("); List<Object> combinedValues = new ArrayList<Object>(); addCondition(builder, combinedValues, cond1); builder.append(combineOp); addCondition(builder, combinedValues, cond2); for (WhereCondition cond : condMore) { builder.append(combineOp); addCondition(builder, combinedValues, cond); } builder.append(')'); return new WhereCondition.StringCondition(builder.toString(), combinedValues.toArray()); }
/** * Creates a WhereCondition by combining the given conditions using AND. The returned WhereCondition must be used * inside {@link #where(WhereCondition, WhereCondition...)} or * {@link #whereOr(WhereCondition, WhereCondition, WhereCondition...)}. */ public WhereCondition and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { return whereCollector.combineWhereConditions(" AND ", cond1, cond2, condMore); }
private void appendJoinsAndWheres(StringBuilder builder, String tablePrefixOrNull) { values.clear(); for (Join<T, ?> join : joins) { builder.append(" JOIN "); builder.append('"').append(join.daoDestination.getTablename()).append('"').append(' '); builder.append(join.tablePrefix).append(" ON "); SqlUtils.appendProperty(builder, join.sourceTablePrefix, join.joinPropertySource).append('='); SqlUtils.appendProperty(builder, join.tablePrefix, join.joinPropertyDestination); } boolean whereAppended = !whereCollector.isEmpty(); if (whereAppended) { builder.append(" WHERE "); whereCollector.appendWhereClause(builder, tablePrefixOrNull, values); } for (Join<T, ?> join : joins) { if (!join.whereCollector.isEmpty()) { if (!whereAppended) { builder.append(" WHERE "); whereAppended = true; } else { builder.append(" AND "); } join.whereCollector.appendWhereClause(builder, join.tablePrefix, values); } } }
void add(WhereCondition cond, WhereCondition... condMore) { checkCondition(cond); whereConditions.add(cond); for (WhereCondition whereCondition : condMore) { checkCondition(whereCondition); whereConditions.add(whereCondition); } }
void checkCondition(WhereCondition whereCondition) { if (whereCondition instanceof WhereCondition.PropertyCondition) { checkProperty(((WhereCondition.PropertyCondition) whereCondition).property); } }
/** * Creates a WhereCondition by combining the given conditions using AND. The returned WhereCondition must be used * inside {@link #where(WhereCondition, WhereCondition...)} or * {@link #whereOr(WhereCondition, WhereCondition, WhereCondition...)}. */ public WhereCondition and(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { return whereCollector.combineWhereConditions(" AND ", cond1, cond2, condMore); }
private void appendJoinsAndWheres(StringBuilder builder, String tablePrefixOrNull) { values.clear(); for (Join<T, ?> join : joins) { builder.append(" JOIN ").append(join.daoDestination.getTablename()).append(' '); builder.append(join.tablePrefix).append(" ON "); SqlUtils.appendProperty(builder, join.sourceTablePrefix, join.joinPropertySource).append('='); SqlUtils.appendProperty(builder, join.tablePrefix, join.joinPropertyDestination); } boolean whereAppended = !whereCollector.isEmpty(); if (whereAppended) { builder.append(" WHERE "); whereCollector.appendWhereClause(builder, tablePrefixOrNull, values); } for (Join<T, ?> join : joins) { if (!join.whereCollector.isEmpty()) { if (!whereAppended) { builder.append(" WHERE "); whereAppended = true; } else { builder.append(" AND "); } join.whereCollector.appendWhereClause(builder, join.tablePrefix, values); } } }
void addCondition(StringBuilder builder, List<Object> values, WhereCondition condition) { checkCondition(condition); condition.appendTo(builder, tablePrefix); condition.appendValuesTo(values); }
protected StringBuilder append(StringBuilder builder, Property property) { whereCollector.checkProperty(property); builder.append(tablePrefix).append('.').append('\'').append(property.columnName).append('\''); return builder; }
/** * Adds the given conditions to the where clause using an logical AND. To create new conditions, use the properties * given in the generated dao classes. */ public QueryBuilder<T> where(WhereCondition cond, WhereCondition... condMore) { whereCollector.add(cond, condMore); return this; }
/** * Creates a WhereCondition by combining the given conditions using OR. The returned WhereCondition must be used * inside {@link #where(WhereCondition, WhereCondition...)} or * {@link #whereOr(WhereCondition, WhereCondition, WhereCondition...)}. */ public WhereCondition or(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { return whereCollector.combineWhereConditions(" OR ", cond1, cond2, condMore); }
void add(WhereCondition cond, WhereCondition... condMore) { checkCondition(cond); whereConditions.add(cond); for (WhereCondition whereCondition : condMore) { checkCondition(whereCondition); whereConditions.add(whereCondition); } }
protected QueryBuilder(AbstractDao<T, ?> dao, String tablePrefix) { this.dao = dao; this.tablePrefix = tablePrefix; values = new ArrayList<Object>(); joins = new ArrayList<Join<T, ?>>(); whereCollector = new WhereCollector<T>(dao, tablePrefix); stringOrderCollation = " COLLATE NOCASE"; }
void checkCondition(WhereCondition whereCondition) { if (whereCondition instanceof WhereCondition.PropertyCondition) { checkProperty(((WhereCondition.PropertyCondition) whereCondition).property); } }
WhereCondition combineWhereConditions(String combineOp, WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { StringBuilder builder = new StringBuilder("("); List<Object> combinedValues = new ArrayList<Object>(); addCondition(builder, combinedValues, cond1); builder.append(combineOp); addCondition(builder, combinedValues, cond2); for (WhereCondition cond : condMore) { builder.append(combineOp); addCondition(builder, combinedValues, cond); } builder.append(')'); return new WhereCondition.StringCondition(builder.toString(), combinedValues.toArray()); }
/** * Adds the given conditions to the where clause using an logical OR. To create new conditions, use the properties * given in the generated dao classes. */ public QueryBuilder<T> whereOr(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { whereCollector.add(or(cond1, cond2, condMore)); return this; }
/** * Creates a WhereCondition by combining the given conditions using OR. The returned WhereCondition must be used * inside {@link #where(WhereCondition, WhereCondition...)} or * {@link #whereOr(WhereCondition, WhereCondition, WhereCondition...)}. */ public WhereCondition or(WhereCondition cond1, WhereCondition cond2, WhereCondition... condMore) { return whereCollector.combineWhereConditions(" OR ", cond1, cond2, condMore); }
void addCondition(StringBuilder builder, List<Object> values, WhereCondition condition) { checkCondition(condition); condition.appendTo(builder, tablePrefix); condition.appendValuesTo(values); }