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;
}
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;
}
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);
}
}
}
Aggregations