Search in sources :

Example 1 with DataServerProxy

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

the class ClientState method getDataServerProxy.

public synchronized DataServerProxy getDataServerProxy() {
    IDataServer ds = getDataServer();
    if (ds != null && !(ds instanceof DataServerProxy)) {
        dataServer = new DataServerProxy(ds);
        ds = dataServer;
    }
    return (DataServerProxy) ds;
}
Also used : IDataServer(com.servoy.j2db.dataprocessing.IDataServer) DataServerProxy(com.servoy.j2db.dataprocessing.DataServerProxy)

Example 2 with DataServerProxy

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

the class ClientState method closeSolution.

public boolean closeSolution(boolean force, Object[] args) {
    if (solutionRoot.getSolution() == null || isClosing)
        return true;
    try {
        isClosing = true;
        String[] s_args = null;
        // we dont want to open anything again if this was a force close
        if (!force && args != null) {
            s_args = new String[args.length];
            for (int i = 0; i < args.length; i++) {
                if (args[i] instanceof NativeObject) {
                    StringBuilder sb = new StringBuilder();
                    NativeObject nativeObjectArg = (NativeObject) args[i];
                    Object defaultArg = null;
                    for (Object key : nativeObjectArg.keySet()) {
                        if ("a".equals(key.toString())) {
                            defaultArg = nativeObjectArg.get(key);
                        } else {
                            sb.append('&').append(key).append('=').append(nativeObjectArg.get(key));
                        }
                    }
                    if (defaultArg != null)
                        sb.insert(0, defaultArg.toString());
                    s_args[i] = sb.toString();
                } else {
                    s_args[i] = (args[i] != null && args[i] != Scriptable.NOT_FOUND && args[i] != Undefined.instance ? args[i].toString() : null);
                }
            }
        } else if (!force && args == null) {
            if (getPreferedSolutionNameToLoadOnInit() != null && isInDeveloper())
                s_args = new String[] { getPreferedSolutionNameToLoadOnInit() };
            if (!Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true")) && startupArguments != null) {
                if (s_args == null)
                    s_args = startupArguments;
                else {
                    for (String arg : startupArguments) {
                        if ((arg.startsWith("s:") || arg.startsWith("solution:")) && arg.substring(arg.indexOf(":")).equals(getPreferedSolutionNameToLoadOnInit())) {
                            s_args = startupArguments;
                            break;
                        }
                    }
                }
            }
        }
        boolean autoSaveBlocked = false;
        if (// always call stopEditing, also when ERL is not editing so that prepareForSave is always called
        foundSetManager != null) {
            // close solution is not a javaScript stop (do not save edited records if autoSave is off)
            int stopEditing = foundSetManager.getEditRecordList().stopEditing(false);
            if (stopEditing != ISaveConstants.AUTO_SAVE_BLOCKED || foundSetManager.getEditRecordList().getAutoSave() == true) {
                // so the stopEditing was not blocked because autoSave is off
                if (stopEditing != ISaveConstants.STOPPED) {
                    if (force) {
                        // just clean everything when in force mode
                        foundSetManager.getEditRecordList().init();
                    } else {
                        return false;
                    }
                }
            } else {
                // stopEditing was blocked because autoSave is off; this means unsaved changes will not be saved automatically
                // when this solution closes; however we must give the user the opportunity to save unsaved data on his solution close
                // handler - so we will clear edited records only after that method is called - and if the closing of the solution continues
                autoSaveBlocked = true;
            }
        }
        handleArguments(s_args);
        if (!callCloseSolutionMethod(force) && !force) {
            return false;
        }
        solutionClosed = true;
        if (autoSaveBlocked && foundSetManager != null) {
            // clear edited records so that they will not be auto-saved by the operations that follow
            foundSetManager.getEditRecordList().init();
        }
        checkForActiveTransactions(force);
        // formmanager does a savedata on visible form
        // $NON-NLS-1$
        J2DBGlobals.firePropertyChange(this, "solution", solutionRoot.getSolution(), null);
        solutionRoot.clearSecurityAccess();
        // do save after firePropertyChange because that may flush some changes (from undoable cmds)
        saveSolution();
        try {
            solutionRoot.close(getActiveSolutionHandler());
        } catch (Exception e) {
            // ignore any error
            Debug.error(e);
        }
        // Notify server!
        IClientHost ch = getClientHost();
        if (// can be null if failed to init
        ch != null) {
            try {
                if (clientInfo != null) {
                    clientInfo.setOpenSolutionId(-1);
                    ch.pushClientInfo(clientInfo.getClientId(), clientInfo);
                }
            } catch (Exception e1) {
                // incase connection to server is dead
                Debug.error(e1);
            }
        }
        if (foundSetManager != null) {
            // delete any foundsets
            foundSetManager.flushCachedItems();
            foundSetManager.init();
        }
        // inform messages of the closed solution
        refreshI18NMessages(true);
        if (scriptEngine != null) {
            scriptEngine.destroy();
            // delete current script engine
            scriptEngine = null;
        }
        getRuntimeProperties().put(IServiceProvider.RT_JSDATASET_FUNCTIONS, null);
        getRuntimeProperties().put(IServiceProvider.RT_JSFOUNDSET_FUNCTIONS, null);
        getRuntimeProperties().put(IServiceProvider.RT_JSRECORD_FUNCTIONS, null);
        // drop any temp tables for this client
        IDataServer ds = getDataServer();
        if (ds != null) {
            ds.dropTemporaryTable(getClientID(), null, null);
        }
    } catch (Exception ex) {
        Debug.error(ex);
    } finally {
        isClosing = false;
        if (solutionClosed && dataServer instanceof DataServerProxy)
            dataServer = ((DataServerProxy) dataServer).getEnclosingDataServer();
        // just set the solutionClosed boolean to false again here, now the solution should be null.
        solutionClosed = false;
    }
    return true;
}
Also used : NativeObject(org.mozilla.javascript.NativeObject) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) IClientHost(com.servoy.j2db.dataprocessing.IClientHost) NativeObject(org.mozilla.javascript.NativeObject) UnmarshalException(java.rmi.UnmarshalException) RhinoException(org.mozilla.javascript.RhinoException) RemoteException(java.rmi.RemoteException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) DataServerProxy(com.servoy.j2db.dataprocessing.DataServerProxy)

Example 3 with DataServerProxy

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

the class ClientStub method notifyDataChange.

public void notifyDataChange(final String server_name, final String table_name, final IDataSet pks, final int sql_action, final Object[] insertColumnData) {
    if (client.isShutDown())
        return;
    if (Debug.tracing()) {
        Debug.trace(// $NON-NLS-1$//$NON-NLS-2$
        "Notify Data Change get from the server for dataserver: " + server_name + " table: " + table_name + ". Pks: " + (pks != null ? "not null" : "null") + ". Action type: " + sql_action);
    }
    synchronized (datachanges) {
        datachanges.push(new Object[] { server_name, table_name, pks, new Integer(sql_action), insertColumnData });
        if (datachangesHandler == null) {
            datachangesHandler = new Runnable() {

                public void run() {
                    while (datachangesHandler != null) {
                        final Object[] array;
                        synchronized (datachanges) {
                            if (datachanges.isEmpty()) {
                                // done
                                datachangesHandler = null;
                                break;
                            }
                            array = datachanges.pop();
                        }
                        client.invokeLater(new Runnable() {

                            public void run() {
                                if (client.isShutDown() || !client.isSolutionLoaded())
                                    return;
                                String sname = (String) array[0];
                                String tname = (String) array[1];
                                IDataSet pksDataSet = (IDataSet) array[2];
                                int action = ((Integer) array[3]).intValue();
                                Object[] insertColumndata = (Object[]) array[4];
                                IDataServer ds = client.getDataServer();
                                if (ds instanceof DataServerProxy) {
                                    // possibly switched from multiple servers to the same destination server.
                                    for (String srv : ((DataServerProxy) ds).getReverseMappedServerNames(sname)) {
                                        ((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(srv, tname), pksDataSet, action, insertColumndata);
                                    }
                                    return;
                                }
                                // not switched
                                ((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(sname, tname), pksDataSet, action, insertColumndata);
                            }
                        });
                    }
                }
            };
            client.getScheduledExecutor().execute(datachangesHandler);
        }
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) DataServerProxy(com.servoy.j2db.dataprocessing.DataServerProxy)

Aggregations

DataServerProxy (com.servoy.j2db.dataprocessing.DataServerProxy)3 IDataServer (com.servoy.j2db.dataprocessing.IDataServer)3 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 IClientHost (com.servoy.j2db.dataprocessing.IClientHost)1 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 ServoyException (com.servoy.j2db.util.ServoyException)1 RemoteException (java.rmi.RemoteException)1 UnmarshalException (java.rmi.UnmarshalException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1 NativeObject (org.mozilla.javascript.NativeObject)1 RhinoException (org.mozilla.javascript.RhinoException)1