use of com.servoy.j2db.util.xmlxport.TableDef in project servoy-client by Servoy.
the class DatabaseUtils method deserializeTableInfo.
/**
* Gets the table information from a .dbi (JSON format) file like structured String.
*
* @param stringDBIContent the table information in .dbi format
* @return the deserialized table information.
* @throws JSONException if the structure of the JSON in String stringDBIContent is bad.
*/
public static TableDef deserializeTableInfo(String stringDBIContent) throws JSONException {
ServoyJSONObject dbiContents = new ServoyJSONObject(stringDBIContent, true);
TableDef tableInfo = deserializeTableInfo(dbiContents);
tableInfo.dbiFileContents = stringDBIContent;
return tableInfo;
}
use of com.servoy.j2db.util.xmlxport.TableDef 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