/** * Método para adicionar um join na consulta. * * @param clazzJoined - classe que será unido * @param joinedAlias - alias do join * @param property - propriedade para fazer o join * @param joinType - tipo do join * @return {@link Join} */ public Join addJoin( Class<?> clazzJoined, String joinedAlias, String property, JoinDBType joinType) { Join join = JoinBuilder.newJoin(entityClass, clazzJoined, fromAlias, joinedAlias, property, joinType); this.joins.add(join); return join; }
/** * Método para adicionar um join na consulta. * * @param clazzFrom - classe base * @param clazzJoined - classe que será unido * @param property - propriedade para fazer o join * @return {@link Join} */ public Join addJoin(Class<?> clazzFrom, Class<?> clazzJoined, String property) { String fromTableAlias = getTableName(clazzJoined); String tableJoinedAlias = getTableName(clazzJoined); Join join = JoinBuilder.newJoin(clazzFrom, clazzJoined, fromTableAlias, tableJoinedAlias, property); this.joins.add(join); return join; }
/** * Método para adicionar um join na consulta. * * @param clazzJoined - classe que será unido * @param property - propriedade para fazer o join * @param joinType - tipo do join * @return {@link Join} */ public Join addJoin(Class<?> clazzJoined, String property, JoinDBType joinType) { String tableJoinedAlias = getTableName(clazzJoined); Join join = JoinBuilder.newJoin( entityClass, clazzJoined, fromAlias, tableJoinedAlias, property, joinType); this.joins.add(join); return join; }
/** * Método para adicionar um join na consulta. * * @param clazzFrom - classe base * @param clazzJoined - classe que será unido * @param fromAlias - alias do from * @param joinedAlias - alias da classe do join * @param property - propriedade para fazer o join * @return {@link Join} */ public Join addJoin( Class<?> clazzFrom, Class<?> clazzJoined, String fromAlias, String joinedAlias, String property) { Join join = JoinBuilder.newJoin( clazzFrom, clazzJoined, fromAlias, joinedAlias, property, JoinDBType.INNER); this.joins.add(join); return join; }
@Override public String buildSQL() { final StringBuilder sql = new StringBuilder(); sql.append(SELECT.getSQLSelectType()); sql.append(" "); if (distinct) { sql.append(DISTINCT.getSQLSelectType()); sql.append(" "); } boolean readFieldsOfJoins = false; if (select.getFields().isEmpty()) { readFieldsOfJoins = true; Class<?> superTypeClass = entityClass.getSuperclass(); if (!(Object.class.equals(superTypeClass))) { addJoin(JoinBuilder.newJoin(entityClass, fromAlias)); } } sql.append(select.buildSQL()); if (readFieldsOfJoins) { for (Join j : joins) { if (!(sql.toString().endsWith(" "))) { sql.append(", "); } Select selectJoin = j.builSelect(); sql.append(selectJoin.buildSQL()); } } sql.append(" "); sql.append(FROM.getSQLSelectType()); sql.append(" "); sql.append(getTableName(entityClass)); if (fromAlias != null && !(fromAlias.isEmpty())) { sql.append(" " + AS.getSQLSelectType() + " " + fromAlias); } if (!joins.isEmpty()) { for (Join j : joins) { sql.append(" "); sql.append(j.buildSQL()); } } if (where != null) { sql.append(" "); sql.append(WHERE.getSQLSelectType()); sql.append(" "); sql.append(where.buildSQL()); } if (groupBy != null) { sql.append(" "); sql.append(groupBy.buildSQL()); } if (orderBy != null) { sql.append(" "); sql.append(orderBy.buildSQL()); } if (offset > DEFAULT_LIMIT_AND_OFFSET) { sql.append(" "); sql.append(OFFSET.getSQLSelectType()); sql.append(" "); sql.append(offset); } if (limit > DEFAULT_LIMIT_AND_OFFSET) { sql.append(" "); sql.append(LIMIT.getSQLSelectType()); sql.append(" "); sql.append(limit); } if (union != null) { sql.append(" "); sql.append(unionType.getUnionType()); sql.append(" "); sql.append(union.buildSQL()); } return sql.toString(); }
/** * Método para adicionar um join na consulta. * * @param clazzJoined - classe que será unido * @param property - propriedade para fazer o join * @return {@link Join} */ public Join addJoin(Class<?> clazzJoined, String property) { Join join = JoinBuilder.newJoin(entityClass, clazzJoined, fromAlias, "", property); this.joins.add(join); return join; }