use of com.servoy.j2db.query.IQuerySelectValue in project servoy-client by Servoy.
the class FoundSetManager method getViewFoundSet.
@SuppressWarnings("nls")
@Override
public ViewFoundSet getViewFoundSet(String name, QBSelect query) {
if (query.getQuery().getColumns() == null || query.getQuery().getColumns().size() == 0) {
throw new RuntimeException("Can't create a ViewFoundset with name: " + name + " and query " + query + " that has no columns");
}
String dataSource = DataSourceUtils.createViewDataSource(name);
ViewFoundSet vfs = new ViewFoundSet(dataSource, query.build(), application.getFoundSetManager(), pkChunkSize);
// if this datasource defintion is created already in the developer then we need to check if the query columns are correctly matching it.
ServoyJSONObject columnsDef = null;
Iterator<TableNode> tblIte = application.getFlattenedSolution().getTableNodes(dataSource);
while (tblIte.hasNext() && columnsDef == null) {
TableNode tn = tblIte.next();
columnsDef = tn.getColumns();
if (columnsDef != null) {
TableDef def = DatabaseUtils.deserializeTableInfo(columnsDef);
for (ColumnInfoDef col : def.columnInfoDefSet) {
IQuerySelectValue selectValue = getSelectvalue(query, col.name);
if (selectValue == null) {
Debug.error("Column " + col.name + " of type " + col.columnType.toString() + " defined in view datasource '" + dataSource + "' was not found in the provided query.");
return null;
}
BaseColumnType columnType = selectValue.getColumnType();
// relax the mapping on default Servoy types
if (columnType != null && Column.mapToDefaultType(columnType.getSqlType()) != Column.mapToDefaultType(col.columnType.getSqlType())) {
Debug.error("Column type for column '" + col.name + " of type " + col.columnType.toString() + "' defined in view datasource '" + dataSource + "' does not match the one " + columnType + " provided in the query.");
return null;
}
}
}
}
return vfs;
}
use of com.servoy.j2db.query.IQuerySelectValue in project servoy-client by Servoy.
the class ViewFoundSet method loadAllRecordsImpl.
private void loadAllRecordsImpl() throws ServoyException {
String serverName = DataSourceUtils.getDataSourceServerName(select.getTable().getDataSource());
String transaction_id = manager.getTransactionID(serverName);
try {
IDataSet ds = manager.getApplication().getDataServer().performQuery(manager.getApplication().getClientID(), serverName, transaction_id, select, null, manager.getTableFilterParams(serverName, select), select.isUnique(), 0, currentChunkSize, IDataServer.FOUNDSET_LOAD_QUERY);
refresh = false;
ArrayList<IQuerySelectValue> cols = select.getColumns();
int currentSize = records.size();
List<ViewRecord> old = records;
records = new ArrayList<>(ds.getRowCount());
pkByDatasourceCache.clear();
String[] colNames = columnNames.values().toArray(new String[columnNames.size()]);
try (FireCollector fireCollector = getFireCollector()) {
for (int i = 0; i < ds.getRowCount(); i++) {
Object[] rowData = ds.getRow(i);
if (i < currentSize) {
ViewRecord current = old.get(i);
records.add(current);
current.updateValues(colNames, rowData);
} else {
records.add(new ViewRecord(colNames, rowData, this));
}
}
}
hasMore = ds.hadMoreRows();
fireDifference(currentSize, records.size());
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
use of com.servoy.j2db.query.IQuerySelectValue in project servoy-client by Servoy.
the class QBResult method getColumns.
/**
* returns an array with all the columns that will be in the select of this query.
* can return empty array. Then the system will auto append the pk when this query is used.
* @sample
* var columns = query.result.getColumns();
*
* @return An array of QBColumn thats in the select of this query.
*/
@JSFunction
public QBColumn[] getColumns() {
ArrayList<IQuerySelectValue> columns = getParent().getQuery().getColumns();
QBColumn[] result = new QBColumn[columns == null ? 0 : columns.size()];
for (int i = 0; i < result.length; i++) {
IQuerySelectValue selectValue = columns.get(i);
if (selectValue instanceof QueryColumn) {
result[i] = new QBColumn(getRoot(), getParent(), selectValue);
} else if (selectValue instanceof QueryAggregate) {
result[i] = new QBAggregate(getRoot(), getParent(), selectValue, ((QueryAggregate) selectValue).getType(), ((QueryAggregate) selectValue).getQuantifier());
} else if (selectValue instanceof QueryFunction) {
result[i] = new QBFunction(getRoot(), getParent(), ((QueryFunction) selectValue).getFunction(), ((QueryFunction) selectValue).getArgs());
}
}
return result;
}
use of com.servoy.j2db.query.IQuerySelectValue in project servoy-client by Servoy.
the class QBResult method add.
public QBResult add(IQueryBuilderColumn column, String alias) {
if (column == null) {
throw new RuntimeException("Cannot add null or undefined column to a query");
}
IQuerySelectValue querySelectValue = ((QBColumn) column).getQuerySelectValue();
getParent().getQuery().addColumn(alias == null ? querySelectValue : querySelectValue.asAlias(alias));
return this;
}
use of com.servoy.j2db.query.IQuerySelectValue in project servoy-client by Servoy.
the class QBSelect method createOperand.
IQuerySelectValue createOperand(Object value, BaseColumnType columnType, int flags) {
if (value instanceof QBColumn) {
return ((QBColumn) value).getQuerySelectValue();
}
Object val = value;
if (value instanceof QBParameter) {
TablePlaceholderKey key = ((QBParameter) value).getPlaceholderKey();
Placeholder placeholder = null;
if (query != null) {
placeholder = query.getPlaceholder(key);
}
val = placeholder == null ? new Placeholder(key) : placeholder;
} else if (columnType == null) {
if (value instanceof Date && !(value instanceof Timestamp) && !(value instanceof Time)) {
// make sure a date is a timestamp
val = new Timestamp(((Date) value).getTime());
}
} else if (!(value instanceof IQuerySelectValue)) {
// convert the value (especially UUID) to the type of the column
val = getAsRightType(value, columnType, flags);
}
if (val instanceof IQuerySelectValue) {
return (IQuerySelectValue) val;
}
return new QueryColumnValue(val, null);
}
Aggregations