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
-
Do I put this code client side? What jar file can I use for the JSONEncoder? I tried JBRGates jar but it won't work on the client side without a gwt.xml file or the source code.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:
When I call encode, an exception gets thrown. Here is the stack trace: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
-
This worked. My end goal though is to get the same query that is logged by smartclient such asOriginally posted by IsomorphicHmm, there's no apparent reason for that crash, but please try calling criteria.getJSObj() and passing that to encode() instead.
Is there no way to grab this sql statement? This is what I need, because I'm going to need to modify the query and do other things with it.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
-
Well what I am trying to avoid is to have to parse the criteria myself and create a sql query based on the criteria. Since I see on the logs that the query is already constructed somewhere, I would just like to grab that instead, and work from there. I agree that the Criteria object is more portable but I think grabbing the statement fits my use case best. There is no api for this in 2.x? Is this the correct api? http://www.smartclient.com/smartgwtee/server/javadoc/com/isomorphic/sql/SQLDataSource.html If so, I don't see SQLDataSource.getSQLClause()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
-
Since this is what you recommend, what is the simplest way to for me to get the criteria, parse it, and create a query from it. I am going to use this query to create an image that represents the data in the listgrid so it needs to match.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