Search in sources :

Example 1 with SelectValues

use of org.hibernate.sql.SelectValues in project hibernate-orm by hibernate.

the class AbstractTableBasedBulkIdHandler method generateIdSelect.

protected Select generateIdSelect(String tableAlias, ProcessedWhereClause whereClause) {
    final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
    final Select select = new Select(dialect);
    final SelectValues selectClause = new SelectValues(dialect).addColumns(tableAlias, getTargetedQueryable().getIdentifierColumnNames(), getTargetedQueryable().getIdentifierColumnNames());
    addAnyExtraIdSelectValues(selectClause);
    select.setSelectClause(selectClause.render());
    String rootTableName = getTargetedQueryable().getTableName();
    String fromJoinFragment = getTargetedQueryable().fromJoinFragment(tableAlias, true, false);
    String whereJoinFragment = getTargetedQueryable().whereJoinFragment(tableAlias, true, false);
    select.setFromClause(rootTableName + ' ' + tableAlias + fromJoinFragment);
    if (whereJoinFragment == null) {
        whereJoinFragment = "";
    } else {
        whereJoinFragment = whereJoinFragment.trim();
        if (whereJoinFragment.startsWith("and")) {
            whereJoinFragment = whereJoinFragment.substring(4);
        }
    }
    if (whereClause.getUserWhereClauseFragment().length() > 0) {
        if (whereJoinFragment.length() > 0) {
            whereJoinFragment += " and ";
        }
    }
    select.setWhereClause(whereJoinFragment + whereClause.getUserWhereClauseFragment());
    return select;
}
Also used : Dialect(org.hibernate.dialect.Dialect) Select(org.hibernate.sql.Select) InsertSelect(org.hibernate.sql.InsertSelect) SelectValues(org.hibernate.sql.SelectValues)

Aggregations

Dialect (org.hibernate.dialect.Dialect)1 InsertSelect (org.hibernate.sql.InsertSelect)1 Select (org.hibernate.sql.Select)1 SelectValues (org.hibernate.sql.SelectValues)1