use of com.servoy.j2db.query.TableExpression in project servoy-client by Servoy.
the class QBJoins method add.
/**
* @clonedesc com.servoy.j2db.querybuilder.IQueryBuilderJoins#add(String, int, String)
* @sampleas add(String, int)
*
* @param dataSource data source
* @param joinType join type, one of {@link IQueryBuilderJoin#LEFT_OUTER_JOIN}, {@link IQueryBuilderJoin#INNER_JOIN}, {@link IQueryBuilderJoin#RIGHT_OUTER_JOIN}, {@link IQueryBuilderJoin#FULL_JOIN}
* @param alias the alias for joining table
*/
@JSFunction
public QBJoin add(String dataSource, int joinType, String alias) {
String name;
QBJoin join;
if (alias == null) {
name = UUID.randomUUID().toString();
join = null;
} else {
name = alias;
join = getJoin(name);
}
if (join == null) {
Table foreignTable = root.getTable(dataSource);
join = addJoin(new QueryJoin(name, parent.getQueryTable(), new TableExpression(new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema(), alias)), new AndCondition(), joinType, true), dataSource, name);
}
return join;
}
use of com.servoy.j2db.query.TableExpression 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 + "'");
}
Aggregations