Search in sources :

Example 1 with DbJoin

use of com.healthmarketscience.sqlbuilder.dbspec.basic.DbJoin in project SmartCity-Market by TechnionYP5777.

the class SQLQueryGenerator method generateSelectInnerJoinWithQuery2Tables.

/**
	 * 
	 * Generate string of select query table inner join with other table
	 * 
	 * (note: inner join match only the rows that exists on the both table on the desired column value)
	 * 
	 * @param tabel
	 *            The table to select
	 * @param joinWithTable
	 *            The table to join with.
	 * @param joinByCol
	 *            join by this column
	 * @param orderByCol
	 *            order results by this column
	 * @param cs
	 *            Set of conditions
	 * @return string of select join query.
	 */
public static String generateSelectInnerJoinWithQuery2Tables(DbTable tabel, DbTable joinWithTable, DbColumn joinByCol, DbColumn orderByCol, Condition... cs) {
    DbJoin custJoin = SQLDatabaseEntities.spec.addJoin(null, tabel.getAbsoluteName(), null, joinWithTable.getAbsoluteName(), joinByCol.getColumnNameSQL());
    SelectQuery resultQuery = new SelectQuery().addAllTableColumns(tabel).addAllTableColumns(joinWithTable).addJoins(SelectQuery.JoinType.INNER, custJoin).addOrderings(orderByCol);
    for (int ¢ = 0; ¢ < cs.length; ++¢) resultQuery.addCondition(cs[¢]);
    return resultQuery.validate() + "";
}
Also used : SelectQuery(com.healthmarketscience.sqlbuilder.SelectQuery) DbJoin(com.healthmarketscience.sqlbuilder.dbspec.basic.DbJoin)

Example 2 with DbJoin

use of com.healthmarketscience.sqlbuilder.dbspec.basic.DbJoin in project SmartCity-Market by TechnionYP5777.

the class SQLQueryGenerator method generateSelectLeftJoinWithQuery2Tables.

/**
	 * 
	 * Generate string of select query table left join with other table
	 * 
	 * (note: left join always take all the rows in the left table and match them to the right table. if there is no match 
	 * then the row is matched with null)
	 * 
	 * @param tabel
	 *            The table to select
	 * @param joinWithTable
	 *            The table to join with.
	 * @param joinByCol
	 *            join by this column
	 * @param orderByCol
	 *            order results by this column
	 * @param cs
	 *            Set of conditions
	 * @return string of select join query.
	 */
public static String generateSelectLeftJoinWithQuery2Tables(DbTable tabel, DbTable joinWithTable, DbColumn joinByCol, DbColumn orderByCol, Condition... cs) {
    DbJoin custJoin = SQLDatabaseEntities.spec.addJoin(null, tabel.getAbsoluteName(), null, joinWithTable.getAbsoluteName(), joinByCol.getColumnNameSQL());
    SelectQuery resultQuery = new SelectQuery().addAllTableColumns(tabel).addAllTableColumns(joinWithTable).addJoins(SelectQuery.JoinType.LEFT_OUTER, custJoin).addOrderings(orderByCol);
    for (int ¢ = 0; ¢ < cs.length; ++¢) resultQuery.addCondition(cs[¢]);
    return resultQuery.validate() + "";
}
Also used : SelectQuery(com.healthmarketscience.sqlbuilder.SelectQuery) DbJoin(com.healthmarketscience.sqlbuilder.dbspec.basic.DbJoin)

Aggregations

SelectQuery (com.healthmarketscience.sqlbuilder.SelectQuery)2 DbJoin (com.healthmarketscience.sqlbuilder.dbspec.basic.DbJoin)2