Search in sources :

Example 1 with DerivedTable

use of com.servoy.j2db.query.DerivedTable in project servoy-client by Servoy.

the class QBJoin method createColumn.

@Override
protected QBColumn createColumn(String name) throws RepositoryException {
    ITableReference foreignTableReference = join.getForeignTableReference();
    if (foreignTableReference instanceof TableExpression) {
        Table joinTable = getRoot().getTable(foreignTableReference.getTable().getDataSource());
        if (joinTable == null) {
            throw new RepositoryException("Cannot find column '" + name + "' in data source '" + foreignTableReference.getTable().getDataSource() + "'");
        }
        Column col = joinTable.getColumn(name);
        if (col == null) {
            throw new RepositoryException("Cannot find column '" + name + "' in data source '" + foreignTableReference.getTable().getDataSource() + "'");
        }
        return new QBColumn(getRoot(), this, new QueryColumn(getQueryTable(), col.getID(), col.getSQLName(), col.getType(), col.getLength(), col.getScale(), col.getNativeTypename(), col.getFlags(), false));
    } else if (foreignTableReference instanceof DerivedTable) {
        QuerySelect query = ((DerivedTable) foreignTableReference).getQuery();
        for (IQuerySelectValue qcol : query.getColumns()) {
            if (name.equals(qcol.getAliasOrName()) || (qcol.getColumn() != null && name.equals(generateNormalizedNonReservedOSName(qcol.getColumn().getName())))) {
                return new QBColumn(getRoot(), this, new QueryColumn(foreignTableReference.getTable(), generateNormalizedNonReservedOSName(name)));
            }
        }
    }
    throw new RepositoryException("Cannot find column '" + name + "' in source '" + foreignTableReference + "'");
}
Also used : DerivedTable(com.servoy.j2db.query.DerivedTable) BaseQueryTable(com.servoy.base.query.BaseQueryTable) Table(com.servoy.j2db.persistence.Table) DerivedTable(com.servoy.j2db.query.DerivedTable) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) ITableReference(com.servoy.j2db.query.ITableReference) QueryColumn(com.servoy.j2db.query.QueryColumn) RepositoryException(com.servoy.j2db.persistence.RepositoryException) TableExpression(com.servoy.j2db.query.TableExpression) QuerySelect(com.servoy.j2db.query.QuerySelect) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Example 2 with DerivedTable

use of com.servoy.j2db.query.DerivedTable in project servoy-client by Servoy.

the class QBJoins method add.

public QBJoin add(IQueryBuilder subqueryBuilder, int joinType, String alias) {
    if (!DataSourceUtils.isSameServer(getRoot().getDataSource(), subqueryBuilder.getDataSource())) {
        throw new RuntimeException("Cannot add derived table join from different server: " + getRoot().getDataSource() + " vs " + subqueryBuilder.getDataSource());
    }
    QuerySelect subquery = ((QBSelect) subqueryBuilder).getQuery();
    QBJoin join = getJoin(alias);
    if (join == null) {
        join = addJoin(new QueryJoin(alias, parent.getQueryTable(), new DerivedTable(subquery, alias), new AndCondition(), joinType, true), subqueryBuilder.getDataSource(), alias);
    }
    return join;
}
Also used : DerivedTable(com.servoy.j2db.query.DerivedTable) QueryJoin(com.servoy.j2db.query.QueryJoin) QuerySelect(com.servoy.j2db.query.QuerySelect) AndCondition(com.servoy.j2db.query.AndCondition)

Aggregations

DerivedTable (com.servoy.j2db.query.DerivedTable)2 QuerySelect (com.servoy.j2db.query.QuerySelect)2 BaseQueryTable (com.servoy.base.query.BaseQueryTable)1 Column (com.servoy.j2db.persistence.Column)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Table (com.servoy.j2db.persistence.Table)1 AndCondition (com.servoy.j2db.query.AndCondition)1 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)1 ITableReference (com.servoy.j2db.query.ITableReference)1 QueryColumn (com.servoy.j2db.query.QueryColumn)1 QueryJoin (com.servoy.j2db.query.QueryJoin)1 TableExpression (com.servoy.j2db.query.TableExpression)1