SQL query output in EMML

guruprasad.ks
guruprasad.ks's picture
User offline. Last seen 21 weeks 2 days ago. Offline
Joined: 10/10/2008
Points: 97

Hi Folks,

I've the scenario where the output(XML) from Mashup is being stored in database. I'm invoking SQL query in EMML to fetch this data. My observation was the Query output has <record>,<records> & <table_column_name> as the additional elements to the data that was saved.

code snippet for invoking SQL query in EMML :

<datasource driverclassname="oracle.jdbc.driver.OracleDriver"
                name="db" username="uid" password="pwd"
                url="jdbc:oracle:thin:@www.host.com:1521:orcl"/>
       <sql name="db" outputvariable='result' query='select my_column_name from my_table'/>

I tried applying filter and/or assign expression to get rid of additional elements to obtain only the actual data that was stored.

Filter code:

    <filter inputvariable="result" filterexpr = "/records/record/table_column_name" outputvariable="result"/>

Assing Expression

        <assign fromvariable="$result/records/record/table_column_name" outputvariable="result"/>

Even with this I'm getting <table_column_name> in the result.

Please do let me know if there's a way to handle this.

Thanking in advance.

Regards,

Guruprasad

5
Your rating: None Average: 5 (1 vote)
raj
raj's picture
User offline. Last seen 1 week 4 days ago. Offline
Joined: 09/22/2008
Points: 4

Hi Guruprasad,

It depends on the specific data format you want the multi-valued column data combined in.

For example, if the column data need to be combined in csv format i.e.,
value1, value2, value3

you can do the following :
        <variable name="tmpResult" type="string"/>
        <assign fromexpr="string-join($result//my_column_name/string(), ',')" outputvariable="tmpResult"/>

OR if you want the values space-separated :

        <assign fromexpr="string-join($result//my_column_name/string(), ' ')" outputvariable="tmpResult"/>
 

hth.

raj.  chief masher @ jackbe

guruprasad.ks
guruprasad.ks's picture
User offline. Last seen 21 weeks 2 days ago. Offline
Joined: 10/10/2008
Points: 97

Hi Raj,

Thanks for the quick response. Your suggestion solved my issue. :)

Regards,

Guruprasad

 

guruprasad.ks
guruprasad.ks's picture
User offline. Last seen 21 weeks 2 days ago. Offline
Joined: 10/10/2008
Points: 97

Hello Mashers,
In connection to this code, I'm not able to get Filter expression working.
First scenario :
I've a service that is invoked in EMML with the code 
  ... <invoke service = "myService" operation = "getData" outputvariable = "result"/>
On this result I'm applying filter as
<filter inputvariable="result" filterexpr = "/rss/channel/item[contains(lower-case(title),lower-case('Commerce'))]" outputvariable="result"/>.
The output obtained is as expected and data is getting filtered.

Second Scenario:
I'm invoking the service and storing the result (type = document) in database. I'm fetching the data in EMML using SQL query. I'm applying the following assign operation on my result.
<assign fromexpr="string-join($result//my_column_name/string(), ' ')" outputvariable="tmpResult"/>.
Later if I try to apply filter on this result, the filtering of data is not happening. Assuming the variable "tmpResult" can be of type String, so I tried converting "tmpResult" from <string> to <document> as indicated in http://www.jackbe.com/enterprise-mashup/forum/how-do-you-convert-string-....
Code Snippet used in my EMML code:
<assign fromvariable="myString" outputvariable="myXML" />
This is throwing up an exception as below....

2009-01-12 17:08:23,474 INFO  [STDOUT] 2009-01-12 17:08:23,474 ERROR [com.jackbe.jbp.jems.moe.runtime.JEMSExecutorImpl] - <Error execution Mashup Script : com.jackbe.jbp.jems.moe.runtime.JEMSException: Error in assignment : java.util.ArrayList : EMML Line # 70 : EMML Line # : 1>
java.lang.RuntimeException: com.jackbe.jbp.jems.moe.runtime.JEMSException: Error in assignment : java.util.ArrayList : EMML Line # 70 : EMML Line # : 1
    at com.jackbe.jbp.jems.moe.runtime.MolInterpreter.execute(MolInterpreter.java:156)
    at com.jackbe.jbp.jems.moe.runtime.JEMSExecutorImpl.executeScript(JEMSExecutorImpl.java:302)
    at com.jackbe.jbp.jems.moe.runtime.JEMSExecutorImpl.invoke(JEMSExecutorImpl.java:113)
    at sun.reflect.GeneratedMethodAccessor197.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.jackbe.jbp.sas.saf.spa.pojo.POJOServiceProviderAdapter.invoke(POJOServiceProviderAdapter.java:127)
    at com.jackbe.jbp.sas.sg.controller.ServiceInvokerImpl.invokeService(ServiceInvokerImpl.java:194)
    at sun.reflect.GeneratedMethodAccessor171.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.jackbe.jbp.sas.security.ServiceInvocationInterceptor.invoke(ServiceInvocationInterceptor.java:82)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy65.invokeService(Unknown Source)
    at com.jackbe.jbp.jems.moe.runtime.commands.InvokeCommand.invokePrestoService(InvokeCommand.java:354)
    at com.jackbe.jbp.jems.moe.runtime.commands.InvokeCommand.invokeService(InvokeCommand.java:273)
    at com.jackbe.jbp.jems.moe.runtime.commands.InvokeCommand.invokeService(InvokeCommand.java:241)
    at com.jackbe.jbp.jems.moe.runtime.commands.InvokeCommand$1.call(InvokeCommand.java:113)
    at EDU.oswego.cs.dl.util.concurrent.FutureResult$1.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: com.jackbe.jbp.jems.moe.runtime.JEMSException: Error in assignment : java.util.ArrayList : EMML Line # 70
    at com.jackbe.jbp.jems.moe.runtime.commands.SequenceCommand.execute(SequenceCommand.java:50)
    at com.jackbe.jbp.jems.moe.runtime.commands.SequenceCommand.execute(SequenceCommand.java:36)
    at com.jackbe.jbp.jems.moe.runtime.commands.AbstractCommand.callExecute(AbstractCommand.java:62)
    at com.jackbe.jbp.jems.moe.runtime.MolInterpreter.execute(MolInterpreter.java:153)
    ... 23 more
Caused by: com.jackbe.jbp.jems.moe.runtime.JEMSException: Error in assignment : java.util.ArrayList
    at com.jackbe.jbp.jems.moe.runtime.commands.AssignCommand2.assignVariableToVariable(AssignCommand2.java:236)
    at com.jackbe.jbp.jems.moe.runtime.commands.AssignCommand2.assignVariableToVariable(AssignCommand2.java:203)
    at com.jackbe.jbp.jems.moe.runtime.commands.AssignCommand2.execute(AssignCommand2.java:96)
    at com.jackbe.jbp.jems.moe.runtime.commands.AbstractCommand.callExecute(AbstractCommand.java:62)
    at com.jackbe.jbp.jems.moe.runtime.commands.SequenceCommand.execute(SequenceCommand.java:47)
    ... 26 more
Caused by: java.lang.ClassCastException: java.util.ArrayList
    at com.jackbe.jbp.jems.moe.runtime.commands.AssignCommand2.assignVariableToVariable(AssignCommand2.java:222)
    ... 30 more

I'm using Presto 2.5.1. Should I be using any alternate code for converting "String" to "document"?

Please let me know if I'm going wrong. Thanks in advance.

Regards,
Guruprasad

raj
raj's picture
User offline. Last seen 1 week 4 days ago. Offline
Joined: 09/22/2008
Points: 4

Hi Guruprasad,

<assign fromexpr="string-join($result//my_column_name/string(), ' ')" outputvariable="tmpResult"/>.

Yes, tmpResult would be a string type, and hence  filter cannot be applied on it  (i.e. can only on document types).

also, asssigning it to document type wont help as tmpResult is not a well-formed XML string to be converted to document type.
You can create a temp document using <constructor/> i.e.

<constructor outputvariable="tmpDoc">

     <mydata>{tmpString}</mydata>

</constructor>

This creates a temp document with <mydata/> as its root. Now, you apply <filter/> on tmpDoc variable. If you still have issues, paste sample XML Data that goes in & out of problemantic EMML statement.

 

raj.  chief masher @ jackbe

guruprasad.ks
guruprasad.ks's picture
User offline. Last seen 21 weeks 2 days ago. Offline
Joined: 10/10/2008
Points: 97

Hi Raj,
When I use the <constructor>... code to create document, it throws up the exception
" The context item for axis step child::element(tmpString) is undefined".
<constructor outputvariable="tmpDoc">
<mydata>{tmpString}</mydata>
</constructor>

The sample XML data being used is as below.
*************** Yahoo RSS Feed **************
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:ynews="http://news.yahoo.com/rss/">
<channel>
<title>Yahoo! News: Top Stories</title>
<item>
<title> Democrats clear Burris as Obama&#039;s successor   (AP)</title>
<pubDate>Tue, 13 Jan 2009 02:44:37 GMT</pubDate>
<description>U.S. Senate leaders announced earlier Monday they&#039;ll accept Burris as President-elect Barack Obama&#039;s Senate.......</description>
</item>
</channel>
</rss>
******************************************************
Should I be creating a XSD file having "myData" being defined as an element? At present I'm trying to figure out this aspect. Please let me know the approach.

Thanking in Advance,
Regards,
Guruprasad

raj
raj's picture
User offline. Last seen 1 week 4 days ago. Offline
Joined: 09/22/2008
Points: 4

Hi Guruprasad,

The tmpString should be prefixed with $ i.e,

<constructor outputvariable="tmpDoc">
<mydata>{$tmpString}</mydata>
</constructor>

raj.  chief masher @ jackbe

krishna_cr
User offline. Last seen 2 years 42 weeks ago. Offline
Joined: 04/16/2009
Points: 0

Hi Folks,

     I have a problem while deploying jackbe with other application on Jboss server. I could able to successfully deploy mashup application with other application. But when I acess the services using jackbe wires and click on run icon. I am getting following error

2009-04-16 11:39:51,081 ERROR [com.jackbe.jbp.sas.sg.controller.ServiceInvokerImpl] - Service invocation error.
java.lang.ClassCastException: java.lang.ExceptionInInitializerError
        at com.jackbe.jbp.sas.saf.spa.pojo.POJOServiceProviderAdapter.invoke(POJOServiceProviderAdapter.java:183)
        at com.jackbe.jbp.sas.sg.controller.ServiceInvokerImpl.invokeService(ServiceInvokerImpl.java:194)
        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:585)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at com.jackbe.jbp.sas.security.ServiceInvocationInterceptor.invoke(ServiceInvocationInterceptor.java:82)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
 

I feel there some jar conflict issue and I listed out common jars between apps are

Only in myapp.ear/lib/: commons-beanutils-1.7.0.jar
Only in presto.ear/presto.war/WEB-INF/lib/: commons-beanutils.jar
Only in myapp.ear/lib/: commons-codec-1.2.jar
Only in presto.ear/presto.war/WEB-INF/lib/: commons-codec-1.3.jar
Only in myapp.ear/lib/: commons-collections-3.1.jar
Only in presto.ear/presto.war/WEB-INF/lib/: commons-collections-3.2.1.jar
Only in myapp.ear/lib/: commons-dbcp-1.2.1.jar
Only in presto.ear/presto.war/WEB-INF/lib/: commons-dbcp.jar
Only in myapp.ear/lib/: commons-pool-1.3.jar
Only in presto.ear/presto.war/WEB-INF/lib/: commons-pool.jar
Only in presto.ear/presto.war/WEB-INF/lib/: ehcache-1.3.0.jar
Only in myapp.ear/lib/: ehcache-1.4.1.jar
Only in presto.ear/presto.war/WEB-INF/lib/: jsonrpc-1.0.jar
Only in myapp.ear/lib/: jsr107cache-1.0-1.4.1.jar
Only in myapp.ear/lib/: rome-0.5.jar
Only in presto.ear/presto.war/WEB-INF/lib/: rome-0.9.jar
Only in myapp.ear/lib/: spring-2.5.2.jar
Only in presto.ear/presto.war/WEB-INF/lib/: spring.jar
Only in presto.ear/presto.war/WEB-INF/lib/: spring-mock.jar
Only in presto.ear/presto.war/WEB-INF/lib/: spring.tld
Only in v.ear/lib/: xalan-1.0.6.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xalan-2.7.0.jar
Only in myapp.ear/lib/: xercesImpl-1.0.6.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xercesImpl-2.8.1.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xercesImpl.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xml-apis-1.3.03.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xml-apis.jar
Only in myapp.ear/lib/: xsdlib-1.0.6.jar
Only in presto.ear/presto.war/WEB-INF/lib/: xsdlib.jar

Could anyone please look into the issue and provide the solution for the same?

Environment details

  • OS: Redhat Linux
  • Server: Jboss 4.2 eap

 

Thanks & Regards,

Krishna