Search in sources :

Example 26 with ITable

use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.

the class JSDatabaseManager method js_updateTableFilterParam.

/**
 * Updates a previously defined table filter. Server/Table should not be changed.
 *
 * @sample var success = databaseManager.updateTableFilterParam('admin', 'higNumberedMessagesRule', query)
 *
 * @param serverName The name of the database server connection.
 * @param filterName The name of the filter that should be updated.
 * @param query condition to filter on.
 *
 * @return true if the filter could be updated.
 */
public boolean js_updateTableFilterParam(String serverName, String filterName, QBSelect query) throws ServoyException {
    if (serverName == null || filterName == null)
        return false;
    checkAuthorized();
    IFoundSetManagerInternal foundSetManager = application.getFoundSetManager();
    ITable table = foundSetManager.getTable(query.getDataSource());
    return foundSetManager.updateTableFilterParam(table.getServerName(), filterName, table, // make a deep clone and clone Table as well in case the same table is used in a new query.
    new QueryTableFilterdefinition(AbstractBaseQuery.deepClone(query.build(), true)));
}
Also used : ITable(com.servoy.j2db.persistence.ITable)

Example 27 with ITable

use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.

the class JSDatabaseManager method addTableFilterParamInternal.

private boolean addTableFilterParamInternal(String serverName, String tableName, String dataprovider, String operator, Object value, String filterName) throws ServoyException {
    checkAuthorized();
    try {
        if (value instanceof Wrapper) {
            value = ((Wrapper) value).unwrap();
        }
        IServer server = application.getSolution().getServer(serverName);
        if (server == null) {
            application.reportJSError("Table filter not applied to unknown server '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
            return false;
        }
        ITable table = null;
        if (tableName != null) {
            table = server.getTable(tableName);
            if (table == null) {
                application.reportJSError("Table filter not applied to unknown table: serverName = '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
                return false;
            }
        }
        // else table remains null: apply to all tables with that column
        DataproviderTableFilterdefinition dataproviderTableFilterdefinition = application.getFoundSetManager().createDataproviderTableFilterdefinition(table, dataprovider, operator, value);
        if (dataproviderTableFilterdefinition == null) {
            application.reportJSError("Table filter not created, column not found in table or operator invalid, filterName = '" + filterName + "', serverName = '" + serverName + "', table = '" + table + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "'", null);
            return false;
        }
        return (((FoundSetManager) application.getFoundSetManager()).addTableFilterParam(filterName, serverName, table, dataproviderTableFilterdefinition));
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return false;
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) IServer(com.servoy.j2db.persistence.IServer) ITable(com.servoy.j2db.persistence.ITable) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 28 with ITable

use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.

the class SortModel method setValue.

void setValue(IApplication app, String notused) {
    application = app;
    try {
        FormManager fm = (FormManager) application.getFormManager();
        FormController fc = fm.getCurrentMainShowingFormController();
        if (fc != null) {
            Form form = fc.getForm();
            ITable t = application.getFoundSetManager().getTable(form.getDataSource());
            if (t != null) {
                List<SortColumn> list = application.getFoundSetManager().getSortColumns(t, form.getInitialSort());
                init(app, t, list);
            }
        }
    } catch (RepositoryException e) {
        Debug.error(e);
    }
}
Also used : FormController(com.servoy.j2db.FormController) FormManager(com.servoy.j2db.FormManager) Form(com.servoy.j2db.persistence.Form) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SortColumn(com.servoy.j2db.dataprocessing.SortColumn)

Example 29 with ITable

use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.

the class SQLGenerator method createExistsCondition.

public static ISQLCondition createExistsCondition(IDataProviderHandler flattenedSolution, QuerySelect sqlSelect, ISQLCondition condition, List<IRelation> relations, BaseQueryTable columnTable, IGlobalValueEntry provider, BaseQueryColumn[] pkQueryColumns) throws RepositoryException {
    // exists (select 1 from innermain join related1 ... join relatedn where innermain.pk = main.pk having aggregate(relatedn))
    if (relations.size() == 0) {
        // searching for aggregate in main table, does no make sense.. ignore in search
        return null;
    }
    QuerySelect existsSelect = new QuerySelect(new QueryTable(sqlSelect.getTable().getName(), sqlSelect.getTable().getDataSource(), sqlSelect.getTable().getCatalogName(), sqlSelect.getTable().getSchemaName()));
    existsSelect.addColumn(new QueryColumnValue(Integer.valueOf(1), null, true));
    // innermain.pk = main.pk
    QueryColumn[] innerPkColumns = new QueryColumn[pkQueryColumns.length];
    for (int p = 0; p < pkQueryColumns.length; p++) {
        BaseQueryColumn pk = pkQueryColumns[p];
        innerPkColumns[p] = new QueryColumn(existsSelect.getTable(), pk.getId(), pk.getName(), pk.getColumnType().getSqlType(), pk.getColumnType().getLength(), pk.getColumnType().getScale(), pk.getNativeTypename(), pk.getFlags(), pk.isIdentity());
        // group by on the inner pk, some dbs (hxtt dbf) require that
        existsSelect.addGroupBy(innerPkColumns[p]);
    }
    existsSelect.addCondition("AGGREGATE-SEARCH", new // $NON-NLS-1$
    SetCondition(// $NON-NLS-1$
    new int[] { IBaseSQLCondition.EQUALS_OPERATOR }, // $NON-NLS-1$
    innerPkColumns, pkQueryColumns, true));
    // add the joins
    BaseQueryTable prevTable = existsSelect.getTable();
    for (IRelation relation : relations) {
        ITable foreignTable = flattenedSolution.getTable(relation.getForeignDataSource());
        QueryTable foreignQtable = new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema());
        existsSelect.addJoin(createJoin(flattenedSolution, relation, prevTable, foreignQtable, true, provider));
        prevTable = foreignQtable;
    }
    existsSelect.addHaving(AbstractBaseQuery.relinkTable(columnTable, prevTable, condition));
    return new ExistsCondition(existsSelect, true);
}
Also used : ExistsCondition(com.servoy.j2db.query.ExistsCondition) QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryColumn(com.servoy.j2db.query.QueryColumn) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) IRelation(com.servoy.j2db.persistence.IRelation) BaseQueryColumn(com.servoy.base.query.BaseQueryColumn) ITable(com.servoy.j2db.persistence.ITable) QuerySelect(com.servoy.j2db.query.QuerySelect) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryTable(com.servoy.j2db.query.QueryTable)

Example 30 with ITable

use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.

the class ViewFoundSet method getTable.

@Override
public ITable getTable() {
    if (table == null) {
        try {
            table = manager.getTable(getDataSource());
            if (table == null) {
                table = new Table(IServer.VIEW_SERVER, DataSourceUtils.getViewDataSourceName(getDataSource()), true, ITable.VIEW, null, null);
                ((Table) table).setDataSource(getDataSource());
                for (IQuerySelectValue col : select.getColumns()) {
                    Column newCol = null;
                    QueryColumn qCol = col.getColumn();
                    if (qCol != null && qCol.getTable() != null) {
                        ITable colTable = manager.getTable(qCol.getTable().getDataSource());
                        if (colTable != null) {
                            Column column = colTable.getColumn(qCol.getName());
                            if (column != null) {
                                String colname = getColunmName(col, qCol);
                                newCol = table.createNewColumn(DummyValidator.INSTANCE, colname, column.getType(), column.getLength(), column.getScale(), column.getAllowNull());
                                if (column.getColumnInfo() != null) {
                                    DatabaseUtils.createNewColumnInfo(manager.getApplication().getFlattenedSolution().getPersistFactory().getNewElementID(null), newCol, false);
                                    newCol.getColumnInfo().copyFrom(column.getColumnInfo());
                                }
                            }
                        }
                    }
                    if (newCol == null) {
                        // existing database column not found, create column on the fly
                        BaseColumnType columnType = col.getColumnType();
                        if (columnType == null) {
                            columnType = ColumnType.getColumnType(IColumnTypes.TEXT);
                        }
                        String colname = getColunmName(col, qCol);
                        table.createNewColumn(DummyValidator.INSTANCE, colname, columnType.getSqlType(), columnType.getLength(), columnType.getScale(), true);
                    }
                }
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    return table;
}
Also used : BaseQueryTable(com.servoy.base.query.BaseQueryTable) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) DerivedTable(com.servoy.j2db.query.DerivedTable) QueryColumn(com.servoy.j2db.query.QueryColumn) IColumn(com.servoy.j2db.persistence.IColumn) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue) BaseColumnType(com.servoy.base.query.BaseColumnType)

Aggregations

ITable (com.servoy.j2db.persistence.ITable)51 RepositoryException (com.servoy.j2db.persistence.RepositoryException)23 BaseQueryTable (com.servoy.base.query.BaseQueryTable)15 QueryTable (com.servoy.j2db.query.QueryTable)15 Column (com.servoy.j2db.persistence.Column)14 ServoyException (com.servoy.j2db.util.ServoyException)14 ArrayList (java.util.ArrayList)14 RemoteException (java.rmi.RemoteException)13 ApplicationException (com.servoy.j2db.ApplicationException)11 IColumn (com.servoy.j2db.persistence.IColumn)9 Relation (com.servoy.j2db.persistence.Relation)9 Table (com.servoy.j2db.persistence.Table)9 QueryColumn (com.servoy.j2db.query.QueryColumn)8 Form (com.servoy.j2db.persistence.Form)7 QuerySelect (com.servoy.j2db.query.QuerySelect)7 IBaseColumn (com.servoy.base.persistence.IBaseColumn)6 IServer (com.servoy.j2db.persistence.IServer)6 SQLException (java.sql.SQLException)6 ISQLTableJoin (com.servoy.j2db.query.ISQLTableJoin)5 IOException (java.io.IOException)5