Search in sources :

Example 6 with TableDef

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;
}
Also used : TableDef(com.servoy.j2db.util.xmlxport.TableDef)

Example 7 with TableDef

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;
}
Also used : ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) TableNode(com.servoy.j2db.persistence.TableNode) TableDef(com.servoy.j2db.util.xmlxport.TableDef) ColumnInfoDef(com.servoy.j2db.util.xmlxport.ColumnInfoDef) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) BaseColumnType(com.servoy.base.query.BaseColumnType)

Aggregations

TableDef (com.servoy.j2db.util.xmlxport.TableDef)7 ColumnInfoDef (com.servoy.j2db.util.xmlxport.ColumnInfoDef)6 BaseColumnType (com.servoy.base.query.BaseColumnType)4 TableNode (com.servoy.j2db.persistence.TableNode)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 ApplicationException (com.servoy.j2db.ApplicationException)2 InsertResult (com.servoy.j2db.dataprocessing.IDataServer.InsertResult)2 ITable (com.servoy.j2db.persistence.ITable)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ColumnType (com.servoy.j2db.query.ColumnType)2 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)2 QueryDelete (com.servoy.j2db.query.QueryDelete)2 QueryTable (com.servoy.j2db.query.QueryTable)2 ServoyException (com.servoy.j2db.util.ServoyException)2 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 MarshallException (org.jabsorb.serializer.MarshallException)2