Search in sources :

Example 41 with ServoyException

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

the class DebugHeadlessClient method errorToDebugger.

@Override
public void errorToDebugger(String message, Object errorDetail) {
    if (Boolean.valueOf(settings.getProperty(Settings.DISABLE_SERVER_LOG_FORWARDING_TO_DEBUG_CLIENT_CONSOLE, "false")).booleanValue()) {
        Object detail = errorDetail;
        RemoteDebugScriptEngine engine = (RemoteDebugScriptEngine) getScriptEngine();
        if (engine != null) {
            DBGPDebugger debugger = engine.getDebugger();
            if (debugger != null) {
                RhinoException rhinoException = null;
                if (detail instanceof Exception) {
                    Throwable exception = (Exception) detail;
                    while (exception != null) {
                        if (exception instanceof RhinoException) {
                            rhinoException = (RhinoException) exception;
                            break;
                        }
                        exception = exception.getCause();
                    }
                }
                String msg = message;
                if (rhinoException != null) {
                    if (msg == null) {
                        msg = rhinoException.getLocalizedMessage();
                    } else
                        msg += '\n' + rhinoException.getLocalizedMessage();
                    msg += '\n' + rhinoException.getScriptStackTrace();
                } else if (detail instanceof Exception) {
                    Object e = ((Exception) detail).getCause();
                    if (e != null) {
                        detail = e;
                    }
                    // complete stack?
                    msg += "\n > " + detail.toString();
                    if (detail instanceof ServoyException && ((ServoyException) detail).getScriptStackTrace() != null) {
                        msg += '\n' + ((ServoyException) detail).getScriptStackTrace();
                    }
                } else if (detail != null) {
                    msg += "\n" + detail;
                }
                debugger.outputStdErr(msg.toString() + '\n');
            }
        }
    }
}
Also used : DBGPDebugger(org.eclipse.dltk.rhino.dbgp.DBGPDebugger) RhinoException(org.mozilla.javascript.RhinoException) RhinoException(org.mozilla.javascript.RhinoException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException)

Example 42 with ServoyException

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

the class DebugNGClient method refreshForms.

private void refreshForms(Collection<IFormController> forms, boolean forcePageReload) {
    boolean reload = forcePageReload;
    if (forms != null && forms.size() > 0) {
        reload = true;
        List<IFormController> cachedFormControllers = getFormManager().getCachedFormControllers();
        for (IFormController formController : cachedFormControllers) {
            if (formController.getFormUI() instanceof WebFormUI) {
                ((WebFormUI) formController.getFormUI()).clearCachedFormElements();
            }
        }
        // should we also use these?
        List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
        for (IFormController controller : forms) {
            boolean isVisible = controller.isFormVisible();
            if (isVisible)
                controller.notifyVisible(false, invokeLaterRunnables);
            if (controller.getFormModel() != null && !Utils.stringSafeEquals(controller.getDataSource(), controller.getFormModel().getDataSource())) {
                // for now we just destroy the form and recreate it with the other datasource;
                // TODO we just load the shared foundset for that datasource - can we improve this somehow so that the loaded foundset is closer to the current runtime situation of the form? (related tabs etc.)
                String name = controller.getName();
                controller.destroy();
                controller = getFormManager().leaseFormPanel(name);
                IFoundSetInternal foundset;
                try {
                    foundset = getFoundSetManager().getSharedFoundSet(controller.getDataSource());
                    foundset.loadAllRecords();
                    controller.loadRecords(foundset);
                } catch (ServoyException e) {
                    Debug.error(e);
                }
            } else {
                if (!controller.isDestroyed())
                    ((WebFormController) controller).initFormUI();
            }
            if (isVisible)
                controller.notifyVisible(true, invokeLaterRunnables);
        }
    }
    if (reload) {
        WebsocketSessionWindows allendpoints = new NGClientWebsocketSessionWindows(getWebsocketSession());
        allendpoints.executeAsyncServiceCall(getWebsocketSession().getClientService(NGRuntimeWindowManager.WINDOW_SERVICE), "reload", null, null);
        try {
            allendpoints.flush();
        } catch (IOException e) {
            reportError("error sending changes to the client", e);
        }
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ServoyException(com.servoy.j2db.util.ServoyException) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) WebsocketSessionWindows(org.sablo.eventthread.WebsocketSessionWindows) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) IFormController(com.servoy.j2db.IFormController)

Example 43 with ServoyException

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

the class FoundSet method performFind.

/**
 * Execute the find sql, returns the number of records found, returns -1 when the call was blocked by a trigger
 * @param clearLastResult
 * @param reduceSearch
 * @param clearIfZero
 * @param cancelFind
 * @param returnInvalidRangeConditions
 * @return
 * @throws ServoyException
 */
public int performFind(boolean clearLastResult, boolean reduceSearch, boolean clearIfZero, boolean cancelFind, List<String> returnInvalidRangeConditions) throws // perform the find
ServoyException {
    int numberOfFindStates = getSize();
    if (cancelFind) {
        // ignore find states
        pksAndRecords.setPks(null, 0);
        setSelectedIndex(-1);
    } else {
        try {
            if (!executeFoundsetTriggerBreakOnFalse(new Object[] { Boolean.valueOf(clearLastResult), Boolean.valueOf(reduceSearch) }, PROPERTY_ONSEARCHMETHODID, true)) {
                // $NON-NLS-1$
                Debug.trace("Foundset search was denied by onSearchFoundset method");
                // blocked
                return -1;
            }
        } catch (ServoyException e) {
            Debug.error(e);
            // blocked
            return -1;
        }
        if (clearLastResult)
            removeLastFound();
        setSelectedIndex(numberOfFindStates > 0 ? 0 : -1);
    }
    try {
        QuerySelect findSqlSelect = getCurrentStateQuery(reduceSearch, false);
        if (returnInvalidRangeConditions != null) {
            ISQLCondition sqlCondition = findSqlSelect.getCondition(SQLGenerator.CONDITION_SEARCH);
            returnInvalidRangeConditions.addAll(AbstractBaseQuery.getInvalidRangeConditions(sqlCondition));
        }
        // cache pks
        String transaction_id = fsm.getTransactionID(sheet);
        long time = System.currentTimeMillis();
        IDataSet findPKs = null;
        try {
            findPKs = performQuery(transaction_id, findSqlSelect, getRowIdentColumnTypes(), 0, fsm.config.pkChunkSize(), IDataServer.FIND_BROWSER_QUERY);
        } catch (RemoteException e) {
            throw new RepositoryException(e);
        }
        if (Debug.tracing()) {
            Debug.trace(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            "Find executed, time: " + (System.currentTimeMillis() - time) + " thread: " + Thread.currentThread().getName() + ", sql: " + findSqlSelect.toString());
        }
        IFoundSetChanges changes = null;
        if (findPKs.getRowCount() == 0) {
            if (clearIfZero) {
                changes = pksAndRecords.setPksAndQuery(null, 0, findSqlSelect);
                clearInternalState(true);
                setSelectedIndex(-1);
            }
        } else {
            fireSelectionAdjusting();
            changes = pksAndRecords.setPksAndQuery(findPKs, findPKs.getRowCount(), findSqlSelect);
            clearInternalState(true);
            // notify about aggregate change,because the find has cleared them all.
            fireAggregateChangeWithEvents(null);
        }
        initialized = true;
        fireDifference(numberOfFindStates, getSize(), changes);
        if (getSelectedIndex() == -1 && getSize() > 0) {
            setSelectedIndex(0);
        }
        int nfound = findPKs.getRowCount();
        try {
            executeFoundsetTrigger(null, PROPERTY_ONAFTERSEARCHMETHODID, false);
        } catch (ServoyException e) {
            Debug.error(e);
        }
        return nfound;
    } catch (ServoyException e) {
        pksAndRecords.setPks(null, 0);
        clearInternalState(true);
        setSelectedIndex(-1);
        fireDifference(numberOfFindStates, 0, null);
        throw e;
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException) QuerySelect(com.servoy.j2db.query.QuerySelect) ISQLCondition(com.servoy.j2db.query.ISQLCondition) ServoyException(com.servoy.j2db.util.ServoyException)

Example 44 with ServoyException

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

the class FoundSet method queryForMorePKs.

/*
	 * Fill the pks from pksAndRecordsCopy starting at originalPKRowcount.
	 */
protected void queryForMorePKs(PksAndRecordsHolder pksAndRecordsCopy, int originalPKRowcount, int maxResult, boolean fireChanges) {
    try {
        String transaction_id = fsm.getTransactionID(sheet);
        QuerySelect sqlSelect = pksAndRecordsCopy.getQuerySelectForReading();
        PKDataSet pks = pksAndRecordsCopy.getPks();
        int dbIndexLastPk = pksAndRecordsCopy.getDbIndexLastPk();
        int startRow;
        String lastPkHash;
        // corrected against added or removed PKs in db since first chunk select
        int correctedMaxResult;
        if (pks != null && dbIndexLastPk > 0 && originalPKRowcount > 0) {
            correctedMaxResult = maxResult > 0 ? (maxResult + dbIndexLastPk - originalPKRowcount) : maxResult;
            lastPkHash = RowManager.createPKHashKey(pks.getRow(originalPKRowcount - 1));
            // re-query the last pk
            startRow = dbIndexLastPk - 1;
        } else {
            correctedMaxResult = maxResult;
            startRow = originalPKRowcount;
            lastPkHash = null;
        }
        int size = getSize();
        long time = System.currentTimeMillis();
        IDataSet newpks = performQuery(transaction_id, sqlSelect, getRowIdentColumnTypes(), startRow, correctedMaxResult, IDataServer.FOUNDSET_LOAD_QUERY);
        if (Debug.tracing()) {
            Debug.trace(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            "Query for PKs, time: " + (System.currentTimeMillis() - time) + " thread: " + Thread.currentThread().getName() + " SQL: " + sqlSelect.toString());
        }
        int offset = 0;
        if (lastPkHash != null) {
            for (int i = 0; offset == 0 && i < newpks.getRowCount(); i++) {
                if (lastPkHash.equals(RowManager.createPKHashKey(newpks.getRow(i)))) {
                    // found the last pk from the previous set
                    if (i != 0) {
                        // out-of-sync
                        // $NON-NLS-1$
                        Debug.warn("Data has been added in the database since first select of foundSet, new data is ignored");
                    }
                    // ignore PKs before the last pk of previous set, they have been added since last chunk select
                    offset = i + 1;
                }
            }
            if (offset == 0 && startRow > 0) {
                // not found, reselect from start
                Debug.warn(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                "Could not connect next foundset chunk (" + startRow + "," + correctedMaxResult + "), re-loading entire PK set of datasource: " + getDataSource());
                // out-of-sync detected, this also flags that new PKS need to be matched against existing ones
                pks.createPKCache();
                startRow = 0;
                time = System.currentTimeMillis();
                newpks = performQuery(transaction_id, sqlSelect, getRowIdentColumnTypes(), startRow, correctedMaxResult, IDataServer.FOUNDSET_LOAD_QUERY);
                if (Debug.tracing()) {
                    Debug.trace(// $NON-NLS-1$//$NON-NLS-2$
                    "RE-query for PKs, time: " + (System.currentTimeMillis() - time) + " thread: " + Thread.currentThread().getName() + " SQL: " + // $NON-NLS-1$
                    sqlSelect.toString());
                }
            }
        }
        if (pks != null) {
            synchronized (pks) {
                int addIndex = originalPKRowcount;
                for (int i = offset; i < newpks.getRowCount(); i++) {
                    // check for duplicates
                    Object[] newpk = newpks.getRow(i);
                    if (!pks.hasPKCache() || /* only check for duplicates if foundset could not be connected */
                    !pks.containsPk(newpk)) {
                        pks.setRow(addIndex++, newpk, false);
                        // keep index in db of last added pk to correct maxresult in next chunk
                        dbIndexLastPk = startRow + 1 + i;
                    }
                }
                if (!newpks.hadMoreRows()) {
                    pks.clearHadMoreRows();
                }
            }
        }
        pksAndRecordsCopy.setDbIndexLastPk(dbIndexLastPk);
        if (fireChanges && newpks.getRowCount() != 0) {
            fireFoundSetEvent(size, getCorrectedSizeForFires(), FoundSetEvent.CHANGE_INSERT);
        }
    } catch (ServoyException ex) {
        // $NON-NLS-1$
        fsm.getApplication().reportError(fsm.getApplication().getI18NMessage("servoy.foundSet.error.retrievingMoreData"), ex);
        // $NON-NLS-1$
        throw new RuntimeException(fsm.getApplication().getI18NMessage("servoy.foundSet.error.retrievingMoreData"), ex);
    } catch (Exception ex) {
        // $NON-NLS-1$
        throw new RuntimeException(fsm.getApplication().getI18NMessage("servoy.foundSet.error.retrievingMoreData"), ex);
    }
}
Also used : QuerySelect(com.servoy.j2db.query.QuerySelect) ServoyException(com.servoy.j2db.util.ServoyException) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 45 with ServoyException

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

the class FoundSet method createRecord.

private IRecordInternal createRecord(Row rowData, boolean javascriptRecord) throws ApplicationException {
    if (findMode) {
        // limit to 200
        if (pksAndRecords.getCachedRecords().size() > fsm.config.pkChunkSize())
            return null;
        return new FindState(this);
    }
    if (javascriptRecord && !hasAccess(IRepository.INSERT)) {
        throw new ApplicationException(ServoyException.NO_CREATE_ACCESS, new Object[] { getTable().getName() });
    }
    if (rowData == null && relationName != null) {
        Relation relation = fsm.getApplication().getFlattenedSolution().getRelation(relationName);
        if (relation != null) {
            Placeholder ph = creationSqlSelect.getPlaceholder(SQLGenerator.createRelationKeyPlaceholderKey(creationSqlSelect.getTable(), relation.getName()));
            if (ph == null || !ph.isSet() || ph.getValue() == null || ((Object[]) ph.getValue()).length == 0) {
                Debug.trace(// $NON-NLS-1$
                "New record failed because related foundset had no parameters, or trying to make a new findstate when it is nested more then 2 deep");
                return null;
            }
            if (!relation.getAllowCreationRelatedRecords()) {
                ApplicationException applicationException = new ApplicationException(ServoyException.NO_RELATED_CREATE_ACCESS, new Object[] { relation.getName() });
                applicationException.setContext(this.toString());
                throw applicationException;
            }
        }
    }
    try {
        if (javascriptRecord && !executeFoundsetTriggerBreakOnFalse(null, PROPERTY_ONCREATEMETHODID, false)) {
            // $NON-NLS-1$
            Debug.trace("New record creation was denied by onCreateRecord method");
            return null;
        }
    } catch (ServoyException e) {
        Debug.error(e);
        return null;
    }
    IRecordInternal newRecord = null;
    if (rowData == null) {
        Object[] data = sheet.getNewRowData(fsm.getApplication(), this);
        newRecord = new Record(this, rowManager.createNotYetExistInDBRowObject(data, true));
        sheet.processCopyValues(newRecord);
    } else {
        newRecord = new Record(this, rowData);
    }
    try {
        if (javascriptRecord) {
            executeFoundsetTrigger(new Object[] { newRecord }, PROPERTY_ONAFTERCREATEMETHODID, false);
        }
    } catch (ServoyException e) {
        Debug.error(e);
    }
    return newRecord;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) Relation(com.servoy.j2db.persistence.Relation) ApplicationException(com.servoy.j2db.ApplicationException) IJSRecord(com.servoy.base.scripting.api.IJSRecord) ServoyException(com.servoy.j2db.util.ServoyException)

Aggregations

ServoyException (com.servoy.j2db.util.ServoyException)58 RepositoryException (com.servoy.j2db.persistence.RepositoryException)31 ApplicationException (com.servoy.j2db.ApplicationException)25 RemoteException (java.rmi.RemoteException)25 ArrayList (java.util.ArrayList)16 ITable (com.servoy.j2db.persistence.ITable)14 QuerySelect (com.servoy.j2db.query.QuerySelect)13 BaseQueryTable (com.servoy.base.query.BaseQueryTable)11 QueryTable (com.servoy.j2db.query.QueryTable)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)10 IOException (java.io.IOException)9 SQLException (java.sql.SQLException)9 JavaScriptException (org.mozilla.javascript.JavaScriptException)9 Column (com.servoy.j2db.persistence.Column)8 Table (com.servoy.j2db.persistence.Table)8 IBaseColumn (com.servoy.base.persistence.IBaseColumn)7 QueryColumn (com.servoy.j2db.query.QueryColumn)7 HashMap (java.util.HashMap)7 MarshallException (org.jabsorb.serializer.MarshallException)7 NativeObject (org.mozilla.javascript.NativeObject)7