Search in sources :

Example 16 with IApplication

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

the class RelatedValueList method fillWithQuery.

/**
 * Fill using query in case of multi-level relation
 *
 * @param relations
 * @throws ServoyException
 * @throws RemoteException
 */
@SuppressWarnings("nls")
protected void fillWithQuery(Relation[] relations) throws RemoteException, ServoyException {
    FoundSetManager foundSetManager = (FoundSetManager) application.getFoundSetManager();
    Pair<QuerySelect, BaseQueryTable> pair = createRelatedValuelistQuery(application, valueList, relations, parentState);
    if (pair == null) {
        return;
    }
    QuerySelect select = pair.getLeft();
    int showValues = valueList.getShowDataProviders();
    int returnValues = valueList.getReturnDataProviders();
    boolean showAndReturnAreSame = showValues == returnValues;
    // perform the query
    String serverName = relations[0].getForeignServerName();
    SQLStatement trackingInfo = null;
    if (foundSetManager.getEditRecordList().hasAccess(application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource()), IRepository.TRACKING_VIEWS)) {
        trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, serverName, pair.getRight().getName(), null, null);
        trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
    }
    IDataSet dataSet = application.getDataServer().performQuery(application.getClientID(), serverName, foundSetManager.getTransactionID(serverName), select, null, foundSetManager.getTableFilterParams(serverName, select), !select.isUnique(), 0, maxValuelistRows, IDataServer.VALUELIST_QUERY, trackingInfo);
    try {
        startBundlingEvents();
        // add empty row
        if (valueList.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS) {
            // $NON-NLS-1$
            addElement("");
            realValues.add(null);
        }
        if (dataSet.getRowCount() >= maxValuelistRows && Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
            if (application instanceof IApplication) {
                ((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
            } else {
                application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
            }
        }
        String[] displayFormat = getDisplayFormat((Table) application.getFoundSetManager().getTable(pair.getRight().getDataSource()));
        for (int i = 0; i < dataSet.getRowCount(); i++) {
            Object[] row = CustomValueList.processRow(dataSet.getRow(i), showValues, returnValues);
            Object element = null;
            if (displayFormat != null)
                element = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application).toString();
            else
                element = CustomValueList.handleRowData(valueList, concatShowValues, showValues, row, application);
            if (showAndReturnAreSame && indexOf(element) != -1)
                continue;
            addElement(element);
            realValues.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
        }
    } finally {
        stopBundlingEvents();
    }
    isLoaded = true;
}
Also used : QuerySelect(com.servoy.j2db.query.QuerySelect) IApplication(com.servoy.j2db.IApplication) BaseQueryTable(com.servoy.base.query.BaseQueryTable)

Example 17 with IApplication

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

the class EditRecordList method stopEditing.

/**
 * stop/save
 *
 * @param javascriptStop
 * @param recordsToSave null means all records
 * @return IRowChangeListener static final
 */
@SuppressWarnings("nls")
public int stopEditing(boolean javascriptStop, List<IRecord> recordsToSave) {
    int stopped = stopEditingImpl(javascriptStop, recordsToSave, 0);
    if ((stopped == ISaveConstants.VALIDATION_FAILED || stopped == ISaveConstants.SAVE_FAILED) && !javascriptStop) {
        IApplication application = fsm.getApplication();
        Solution solution = application.getSolution();
        int mid = solution.getOnAutoSaveFailedMethodID();
        if (mid > 0) {
            ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(mid);
            if (sm != null) {
                // the validation failed in a none javascript stop (so this was an autosave failure)
                List<JSRecordMarkers> failedMarkers = failedRecords.stream().map(record -> record.getRecordMarkers()).collect(Collectors.toList());
                try {
                    application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge((new Object[] { failedMarkers.toArray() }), Utils.parseJSExpressions(solution.getFlattenedMethodArguments(IContentSpecConstants.PROPERTY_ONAUTOSAVEDFAILEDMETHODID))), false, false);
                } catch (Exception e) {
                    application.reportJSError("Failed to run the solutions auto save failed method", e);
                }
            } else {
                application.reportJSWarning("Solution " + application.getSolutionName() + " onautosavefailed method not found for id " + mid);
            }
        }
    }
    return stopped;
}
Also used : DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) Arrays(java.util.Arrays) Placeholder(com.servoy.j2db.query.Placeholder) LoggerFactory(org.slf4j.LoggerFactory) Debug(com.servoy.j2db.util.Debug) HashMap(java.util.HashMap) Solution(com.servoy.j2db.persistence.Solution) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) NativeObject(org.mozilla.javascript.NativeObject) Utils(com.servoy.j2db.util.Utils) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) StaticContentSpecLoader(com.servoy.j2db.persistence.StaticContentSpecLoader) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) Utils.equalObjects(com.servoy.j2db.util.Utils.equalObjects) Logger(org.slf4j.Logger) IBaseColumn(com.servoy.base.persistence.IBaseColumn) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) JavaScriptException(org.mozilla.javascript.JavaScriptException) Predicate(java.util.function.Predicate) IContentSpecConstants(com.servoy.j2db.persistence.IContentSpecConstants) IRepository(com.servoy.j2db.persistence.IRepository) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ITable(com.servoy.j2db.persistence.ITable) Collectors(java.util.stream.Collectors) Table(com.servoy.j2db.persistence.Table) IApplication(com.servoy.j2db.IApplication) IntHashMap(com.servoy.j2db.util.IntHashMap) Objects(java.util.Objects) IServer(com.servoy.j2db.persistence.IServer) List(java.util.List) Entry(java.util.Map.Entry) BlobMarkerValue(com.servoy.j2db.dataprocessing.ValueFactory.BlobMarkerValue) Column(com.servoy.j2db.persistence.Column) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPrepareForSave(com.servoy.j2db.IPrepareForSave) Arrays.stream(java.util.Arrays.stream) Collections(java.util.Collections) QueryInsert(com.servoy.j2db.query.QueryInsert) IApplication(com.servoy.j2db.IApplication) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) Solution(com.servoy.j2db.persistence.Solution) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 18 with IApplication

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

the class DBValueList method fill.

// also called by universal field valueChanged
@SuppressWarnings("nls")
private void fill() {
    try {
        if (table == null)
            return;
        FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
        List<SortColumn> sortColumns = foundSetManager.getSortColumns(table, valueList.getSortOptions());
        FoundSet fs = (FoundSet) foundSetManager.getNewFoundSet(table, null, sortColumns);
        if (fs == null) {
            return;
        }
        if (// apply name as filter on column valuelist_name
        valueList.getUseTableFilter()) {
            // $NON-NLS-1$
            fs.addFilterParam("valueList.nameColumn", NAME_COLUMN, "=", valueList.getName());
        }
        // we do nothing with related foundsets so don't touch these
        fs.browseAllInternal();
        // browse all could trigger also a fill
        if (isLoaded)
            return;
        isLoaded = true;
        int showValues = valueList.getShowDataProviders();
        int returnValues = valueList.getReturnDataProviders();
        int total = (showValues | returnValues);
        // more than one value -> concat
        boolean concatShowValues = willConcat(showValues);
        boolean concatReturnValues = willConcat(returnValues);
        boolean singleColumn = (total & 7) == 1 || (total & 7) == 2 || (total & 7) == 4;
        try {
            startBundlingEvents();
            // add empty row
            if (valueList.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS) {
                // $NON-NLS-1$
                addElement("");
                realValues.add(null);
            }
            QuerySelect creationSQLParts = null;
            if (singleColumn && fs.getSize() >= ((FoundSetManager) application.getFoundSetManager()).config.pkChunkSize() && !containsCalculation) {
                creationSQLParts = createValuelistQuery(application, valueList, table);
            }
            if (creationSQLParts != null && creationSQLParts.isDistinct() && fs.getSize() >= ((FoundSetManager) application.getFoundSetManager()).config.pkChunkSize() && !containsCalculation) {
                ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), creationSQLParts);
                if (// apply name as filter on column valuelist_name in creationSQLParts
                valueList.getUseTableFilter()) {
                    if (tableFilterParams == null) {
                        tableFilterParams = new ArrayList<TableFilter>();
                    }
                    tableFilterParams.add(new // $NON-NLS-1$
                    TableFilter(// $NON-NLS-1$
                    "dbValueList.nameFilter", // $NON-NLS-1$
                    table.getServerName(), // $NON-NLS-1$
                    table.getName(), // $NON-NLS-1$
                    table.getSQLName(), // $NON-NLS-1$
                    NAME_COLUMN, IBaseSQLCondition.EQUALS_OPERATOR, valueList.getName()));
                }
                String transaction_id = foundSetManager.getTransactionID(table.getServerName());
                SQLStatement trackingInfo = null;
                if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
                    trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
                    trackingInfo.setTrackingData(creationSQLParts.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
                }
                IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, creationSQLParts, null, tableFilterParams, !creationSQLParts.isUnique(), 0, maxValuelistRows, IDataServer.VALUELIST_QUERY, trackingInfo);
                if (set.getRowCount() >= maxValuelistRows) {
                    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
                        if (application instanceof IApplication) {
                            ((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
                        } else {
                            application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
                        }
                    }
                }
                String[] displayFormat = getDisplayFormat();
                for (int i = 0; i < set.getRowCount(); i++) {
                    Object[] row = CustomValueList.processRow(set.getRow(i), showValues, returnValues);
                    Object displayValue = null;
                    if (displayFormat != null) {
                        displayValue = handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
                    } else {
                        displayValue = handleRowData(valueList, concatShowValues, showValues, row, application);
                    }
                    addElement(displayValue != null ? displayValue.toString() : displayValue);
                    realValues.add(handleRowData(valueList, concatReturnValues, returnValues, row, application));
                }
            } else {
                IRecordInternal[] array = fs.getRecords(0, maxValuelistRows);
                String[] displayFormat = getDisplayFormat();
                for (IRecordInternal r : array) {
                    if (r != null) {
                        Object val = handleRowData(valueList, displayFormat, concatShowValues, showValues, r, application);
                        Object rval = handleRowData(valueList, null, concatReturnValues, returnValues, r, application);
                        int index = indexOf(val);
                        if (index == -1 || !Utils.equalObjects(getRealElementAt(index), rval)) {
                            addElement(val);
                            realValues.add(rval);
                        }
                    }
                }
                if (fs.getSize() >= maxValuelistRows) {
                    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
                        if (application instanceof IApplication) {
                            ((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
                        } else {
                            application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
                        }
                    }
                }
            }
        } finally {
            stopBundlingEvents();
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : QuerySelect(com.servoy.j2db.query.QuerySelect) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IApplication(com.servoy.j2db.IApplication)

Aggregations

IApplication (com.servoy.j2db.IApplication)18 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)6 QuerySelect (com.servoy.j2db.query.QuerySelect)4 ServoyException (com.servoy.j2db.util.ServoyException)4 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 FormPreviewPanel (com.servoy.j2db.printing.FormPreviewPanel)3 ArrayList (java.util.ArrayList)3 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 ApplicationException (com.servoy.j2db.ApplicationException)2 IFormController (com.servoy.j2db.IFormController)2 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)2 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)2 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)2 Column (com.servoy.j2db.persistence.Column)2 Form (com.servoy.j2db.persistence.Form)2 IRepository (com.servoy.j2db.persistence.IRepository)2 Relation (com.servoy.j2db.persistence.Relation)2 Solution (com.servoy.j2db.persistence.Solution)2 Placeholder (com.servoy.j2db.query.Placeholder)2