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 + "'");
}
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;
}
Aggregations