use of com.servoy.j2db.util.xmlxport.ColumnInfoDef in project servoy-client by Servoy.
the class FoundSetManager method getViewFoundSet.
@SuppressWarnings("nls")
@Override
public ViewFoundSet getViewFoundSet(String name, QBSelect query, boolean register) {
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(), config.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;
}
}
}
}
registerViewFoundSet(vfs, !register);
return vfs;
}
Aggregations