private String createSQLStatement(final OneSelect _parentOnesel)
        throws EFapsException
    {
        final Attribute attr = this.type.getAttribute(this.attrName);

        if (attr == null) {
            LinkFromSelect.LOG.error("Could not find Attribute '{}' in Type '{}'", this.attrName, this.type.getName());
            throw new EFapsException(LinkFromSelect.class, "NoAttribute");
        }

        final SQLSelect select = new SQLSelect()
                .column(0, "ID")
                .column(0, attr.getSqlColNames().get(0))
                .from(this.type.getMainTable().getSqlTable(), 0);

        // on a from  select only one table is the base
        getAllSelects().get(0).append2SQLFrom(select);

        int colIndex = select.getColumns().size() + 1;

        for (final OneSelect oneSel : getAllSelects()) {
            colIndex += oneSel.append2SQLSelect(select, colIndex);
        }
        select.addPart(SQLPart.WHERE)
            .addColumnPart(0, attr.getSqlColNames().get(0))
            .addPart(SQLPart.IN).addPart(SQLPart.PARENTHESIS_OPEN);

        if (_parentOnesel.isMultiple()) {
            boolean first = true;
            final List<?> ids = (List<?>) _parentOnesel.getObject();
            for (final Object id : ids) {
                if (first) {
                    first = false;
                } else {
                    select.addPart(SQLPart.COMMA);
                }
                select.addValuePart(id);
            }
        } else {
            select.addValuePart(_parentOnesel.getObject());
        }
        select.addPart(SQLPart.PARENTHESIS_CLOSE);

        _parentOnesel.setValueSelect(null);

        // in a subquery the type must also be set
        if (this.type.getMainTable().getSqlColType() != null) {
            select.addPart(SQLPart.AND)
                .addColumnPart(0, this.type.getMainTable().getSqlColType())
                .addPart(SQLPart.IN).addPart(SQLPart.PARENTHESIS_OPEN);
            boolean first = true;
            if (this.type.isAbstract()) {
                for (final Type atype : getAllChildTypes(this.type)) {
                    if (first) {
                        first = false;
                    } else {
                        select.addPart(SQLPart.COMMA);
                    }
                    select.addValuePart(atype.getId());
                }
                if (first) {
                    LinkFromSelect.LOG.error("The type is declared abstract but does not have children: {}", this.type);
                }
            } else {
                select.addValuePart(this.type.getId());
            }
            select.addPart(SQLPart.PARENTHESIS_CLOSE);
        }

        for (final OneSelect oneSel : getAllSelects()) {
            oneSel.append2SQLWhere(select);
        }
        return select.getSQL();
    }
private String createSQLStatement ( final OneSelect _parentOnesel ) throws EFapsException { final Attribute attr = this . type . getAttribute ( this . attrName ) ; if ( attr == null ) { LinkFromSelect . LOG . error ( "Could not find Attribute '{}' in Type '{}'" , this . attrName , this . type . getName ( ) ) ; throw new EFapsException ( LinkFromSelect . class , "NoAttribute" ) ; } final SQLSelect select = new SQLSelect ( ) . column ( 0 , "ID" ) . column ( 0 , attr . getSqlColNames ( ) . get ( 0 ) ) . from ( this . type . getMainTable ( ) . getSqlTable ( ) , 0 ) ; getAllSelects ( ) . get ( 0 ) . append2SQLFrom ( select ) ; int colIndex = select . getColumns ( ) . size ( ) + 1 ; for ( final OneSelect oneSel : getAllSelects ( ) ) { colIndex += oneSel . append2SQLSelect ( select , colIndex ) ; } select . addPart ( SQLPart . WHERE ) . addColumnPart ( 0 , attr . getSqlColNames ( ) . get ( 0 ) ) . addPart ( SQLPart . IN ) . addPart ( SQLPart . PARENTHESIS_OPEN ) ; if ( _parentOnesel . isMultiple ( ) ) { boolean first = true ; final List < ? > ids = ( List < ? > ) _parentOnesel . getObject ( ) ; for ( final Object id : ids ) { if ( first ) { first = false ; } else { select . addPart ( SQLPart . COMMA ) ; } select . addValuePart ( id ) ; } } else { select . addValuePart ( _parentOnesel . getObject ( ) ) ; } select . addPart ( SQLPart . PARENTHESIS_CLOSE ) ; _parentOnesel . setValueSelect ( null ) ; if ( this . type . getMainTable ( ) . getSqlColType ( ) != null ) { select . addPart ( SQLPart . AND ) . addColumnPart ( 0 , this . type . getMainTable ( ) . getSqlColType ( ) ) . addPart ( SQLPart . IN ) . addPart ( SQLPart . PARENTHESIS_OPEN ) ; boolean first = true ; if ( this . type . isAbstract ( ) ) { for ( final Type atype : getAllChildTypes ( this . type ) ) { if ( first ) { first = false ; } else { select . addPart ( SQLPart . COMMA ) ; } select . addValuePart ( atype . getId ( ) ) ; } if ( first ) { LinkFromSelect . LOG . error ( "The type is declared abstract but does not have children: {}" , this . type ) ; } } else { select . addValuePart ( this . type . getId ( ) ) ; } select . addPart ( SQLPart . PARENTHESIS_CLOSE ) ; } for ( final OneSelect oneSel : getAllSelects ( ) ) { oneSel . append2SQLWhere ( select ) ; } return select . getSQL ( ) ; }
Method to create on Statement out of the different parts.

@param _parentOnesel instance
@return String containing the SQL statement
@throws EFapsException on error