protected InsertStatement createAssoInsert( QNameInfo qNameInfo, SQLVendor vendor,
Integer amountOfParams )
{
ModificationFactory m = vendor.getModificationFactory();
LiteralFactory l = vendor.getLiteralFactory();
ColumnsFactory c = vendor.getColumnsFactory();
QueryFactory q = vendor.getQueryFactory();
TableReferenceFactory t = vendor.getTableReferenceFactory();
BooleanFactory b = vendor.getBooleanFactory();
String schemaName = this._state.schemaName().get();
// "INSERT INTO " + "%s" + "." + "%s" + "\n" + //
// "SELECT " + "?, " + "?, " + ENTITY_TABLE_PK_COLUMN_NAME + "\n" + // <-- here is 4 params
// when many-asso
// "FROM " + "%s" + "." + ENTITY_TABLE_NAME + "\n" + //
// "WHERE " + ENTITY_TABLE_IDENTITY_COLUMN_NAME + " = " + "?";
QuerySpecificationBuilder qBuilder = q.querySpecificationBuilder();
for( Integer x = 0; x < amountOfParams; ++x )
{
qBuilder.getSelect().addUnnamedColumns( c.colExp( l.param() ) );
}
qBuilder.getSelect().addUnnamedColumns( c.colName( DBNames.ENTITY_TABLE_PK_COLUMN_NAME ) );
qBuilder.getFrom().addTableReferences(
t.tableBuilder( t.table( t.tableName( schemaName, DBNames.ENTITY_TABLE_NAME ) ) ) );
qBuilder.getWhere().reset(
b.eq( c.colName( DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME ), l.param() ) );
return m
.insert()
.setTableName( t.tableName( schemaName, qNameInfo.getTableName() ) )
.setColumnSource( m.columnSourceByQuery( q.createQuery( qBuilder.createExpression() ) ) )