Using smartgwtpower2.5, gwt 2.3.0. I've got a listgrid set up with the filterEditor showing connected to an Oracle database. I want to get a copy of the query that is executed when the filter button is pressed. Is this possible, if so how? I was initially thinking of calling getCriteria() on the list grid but I'd like to see if there is a better option because I'm going to need the query for later.
Announcement
Collapse
No announcement yet.
X
-
Originally posted by IsomorphicThe simplest thing is to use JSONEncoder.encode(AdvancedCriteria) to obtain a string which you can save. You the then reconstruct via "new AdvancedCriteria(JSONEncoder.decode(savedString))".
Comment
-
Sorry, exists in SmartClient but not yet in SmartGWT. Equivalent SmartGWT call is JSOHelper.eval().
Comment
-
I try the following with no success:
Code:// get the criteria from the listgrid Criteria criteria = theListGrid.getCriteria(); if(criteria != null) { JSONEncoder anEncoder = new JSONEncoder(); try { String theCriteria = anEncoder.encode(criteria); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(criteria.toString()); System.out.println(theListGrid.getViewState()); } }
Code:Content-Length: 1407 com.google.gwt.core.client.JavaScriptException: (null): null at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.smartgwt.client.util.JSONEncoder.encode(JSONEncoder.java) at myClass.onClick(myClass.java:257) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:99) at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1) at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1) at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193) at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88) at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127) at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214) at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) at java.lang.Thread.run(Thread.java:662)
Comment
-
Originally posted by IsomorphicHmm, there's no apparent reason for that crash, but please try calling criteria.getJSObj() and passing that to encode() instead.
Code:=== 2011-09-27 19:39:34,822 [l0-4] INFO SQLDriver - [builtinApplication.Product_fetch] Executing SQL query on 'Oracle': select count(*) from table where name='foo' and type='bar'
Comment
-
We'd recommend capturing the Criteria object instead unless it's impossible to address the use case that way. Capturing the criteria object means you are portable across databases and even different types of DataSources, you can more easily deal with table structure changes, and you get the benefit of improvements in our generated SQL over time.
However if capturing the SQL is the only way to handle the use case, in 3.x there's a new API SQLDataSource.getSQLClause() that will let you do this. Note further with using this API: it's fine to take the generated whereClause, for example, and use it in unmodified within a SQL query. However any dependencies on the actual text of the where clause itself would be depending on internals that are subject to change without notice.
Comment
-
Originally posted by IsomorphicWe'd recommend capturing the Criteria object instead unless it's impossible to address the use case that way. Capturing the criteria object means you are portable across databases and even different types of DataSources, you can more easily deal with table structure changes, and you get the benefit of improvements in our generated SQL over time.
However if capturing the SQL is the only way to handle the use case, in 3.x there's a new API SQLDataSource.getSQLClause() that will let you do this. Note further with using this API: it's fine to take the generated whereClause, for example, and use it in unmodified within a SQL query. However any dependencies on the actual text of the where clause itself would be depending on internals that are subject to change without notice.
Comment
-
Originally posted by IsomorphicCorrect, the API is in 3.x. You don't seem to have a reason to capture the SQL query so we'd definitely recommend serializing the criteria instead.
Comment
Comment