protected String generateIdInsertSelect(Queryable persister, String tableAlias, ProcessedWhereClause whereClause) { Select select = new Select( sessionFactory.getDialect() ); SelectValues selectClause = new SelectValues( sessionFactory.getDialect() ) .addColumns( tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames() ); addAnyExtraIdSelectValues( selectClause ); select.setSelectClause( selectClause.render() ); String rootTableName = persister.getTableName(); String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false ); String whereJoinFragment = persister.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() ); InsertSelect insert = new InsertSelect( sessionFactory.getDialect() ); if ( sessionFactory.getSettings().isCommentsEnabled() ) { insert.setComment( "insert-select for " + persister.getEntityName() + " ids" ); } insert.setTableName( determineIdTableName( persister ) ); insert.setSelect( select ); return insert.toStatementString(); }
protected String generateIdSelect(Queryable persister, String tableAlias, ProcessedWhereClause whereClause) { Select select = new Select( sessionFactory.getDialect()); SelectValues selectClause = new SelectValues( sessionFactory.getDialect()).addColumns(tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames()); addAnyExtraIdSelectValues(selectClause); select.setSelectClause(selectClause.render()); String rootTableName = persister.getTableName(); String fromJoinFragment = persister.fromJoinFragment( tableAlias, true, false); String whereJoinFragment = persister.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.toStatementString(); }
protected String generateIdSelect(Queryable persister, String tableAlias, ProcessedWhereClause whereClause) { Select select = new Select(sessionFactory.getDialect()); SelectValues selectClause = new SelectValues( sessionFactory.getDialect()).addColumns(tableAlias, persister.getIdentifierColumnNames(), persister.getIdentifierColumnNames()); addAnyExtraIdSelectValues(selectClause); select.setSelectClause(selectClause.render()); String rootTableName = persister.getTableName(); String fromJoinFragment = persister.fromJoinFragment(tableAlias, true, false); String whereJoinFragment = persister.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.toStatementString(); }
protected void addAnyExtraIdSelectValues(SelectValues selectClause) { }
protected void addExtraIdSelectValues(final Queryable targetedPersister, SelectValues selectClause) { selectClause.addColumn(null, '\'' + generateDiscriminatorValue(targetedPersister) + '\'', discriminatorColumn); }