Search in sources :

Example 1 with InsertSelect

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

the class AbstractTableBasedBulkIdHandler method generateIdInsertSelect.

/**
	 * Generate the {@code INSERT}-{@code SELECT} statement for holding matching ids.  This is the
	 * {@code INSERT} used to populate the bulk-id table with ids matching the restrictions defined in the
	 * original {@code WHERE} clause
	 *
	 * @param tableAlias The table alias to use for the entity
	 * @param whereClause The processed representation for the user-defined {@code WHERE} clause.
	 *
	 * @return The {@code INSERT}-{@code SELECT} for populating the bulk-id table.
	 */
protected String generateIdInsertSelect(String tableAlias, IdTableInfo idTableInfo, ProcessedWhereClause whereClause) {
    final Dialect dialect = sessionFactory.getJdbcServices().getJdbcEnvironment().getDialect();
    final Select select = generateIdSelect(tableAlias, whereClause);
    InsertSelect insert = new InsertSelect(dialect);
    if (sessionFactory.getSessionFactoryOptions().isCommentsEnabled()) {
        insert.setComment("insert-select for " + getTargetedQueryable().getEntityName() + " ids");
    }
    insert.setTableName(idTableInfo.getQualifiedIdTableName());
    insert.setSelect(select);
    return insert.toStatementString();
}
Also used : InsertSelect(org.hibernate.sql.InsertSelect) Dialect(org.hibernate.dialect.Dialect) Select(org.hibernate.sql.Select) InsertSelect(org.hibernate.sql.InsertSelect)

Aggregations

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