简体   繁体   English

Mule和JDBC查询结果

[英]Mule and JDBC Query Result

I am using mule to connect to a Postgres database server. 我正在使用m子连接到Postgres数据库服务器。 I can't use the datamapper since I am using the community edition. 由于使用社区版,因此无法使用数据映射器。 The object to xml transformer is not giving a good formatted result. xml转换器的对象未提供良好的格式化结果。 Any ideas of how I can transform the jdbc response into a good format for parsing. 关于如何将jdbc响应转换为良好的解析格式的任何想法。 Here is my configuration file. 这是我的配置文件。 This is the datasource with the connector. 这是带有连接器的数据源。

<jdbc:postgresql-data-source name="PostgreSQL_Data_Source"
    user="USERNAME" password="PASSWORD"
    url="jdbc:postgresql://*******:***/*****"
    transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source" />
    <jdbc:connector name="organizations" dataSource-ref="PostgreSQL_Data_Source"
        validateConnections="true" queryTimeout="-1" pollingFrequency="0"
        doc:name="JDBC">
        <jdbc:query key="getOrganizations" value="SELECT * FROM organization" />
        <jdbc:query key="getOrganizationApplications"
            value="SELECT * FROM organization o,application a,organization_apps oa WHERE o.id=oa.org_id AND a.id=oa.app_id AND o.id=#[flowVars['org_id']]" />
        <jdbc:query key="insertOrganization"
            value="INSERT INTO organization(name, phone, email, address, website) VALUES (?, ?, ?, ?, ?)" />
        <jdbc:query key="getOrganizationUsers"
            value="SELECT * FROM &amp;quot;public&amp;quot;.user WHERE org_id=#[flowVars['org_id']]" />
    </jdbc:connector>

and this is the flow: 这是流程:

<flow name="logixy-platform-organizations-workflow" doc:name="logixy-platform-organizations-workflow">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8082" doc:name="HTTP" path="organization" />
        <set-variable variableName="choice"
            value="#[message.inboundProperties['choice']]" doc:name="Set Choice" />
        <choice doc:name="Choice">
            <when expression="#[flowVars['choice'] == '0']">
                <jdbc:outbound-endpoint exchange-pattern="request-response"
                    queryTimeout="-1" doc:name="getAllOrganizations" connector-ref="organizations"
                    queryKey="getOrganizations" />
            </when>
            <when expression="#[flowVars['choice'] == '2']">
                <set-variable variableName="org_id"
                    value="#[(int)(message.inboundProperties['org_id'])]" doc:name="Set Organization ID" />
                <jdbc:outbound-endpoint exchange-pattern="request-response"
                    queryKey="getOrganizationUsers" queryTimeout="-1" connector-ref="organizations"
                    doc:name="getOrganizationUsers" />
            </when>
            <when expression="#[flowVars['choice'] == '1']">
                <set-variable variableName="#['org_id']"
                    value="#[(int)(message.inboundProperties['org_id'])]" doc:name="Set Organization ID" />
                <jdbc:outbound-endpoint exchange-pattern="request-response"
                    queryKey="getOrganizationApplications" queryTimeout="-1"
                    connector-ref="organizations" doc:name="getOrganizationApplications" />
            </when>
        </choice>
        <mulexml:object-to-xml-transformer
            doc:name="Object to XML" />
    </flow>

You should really define "a good format for parsing", but I guess you don't like the "entry", "string", etc field names. 您应该真正定义“一种很好的解析格式”,但是我想您不喜欢“ entry”,“ string”等字段名称。

You have plenty of options to format the XML, for example: 您可以使用很多选项来格式化XML,例如:

  1. use XSLT to transform the generated XML to your preferred format 使用XSLT将生成的XML转换为您首选的格式
  2. define a class in Java or Groovy that corresponds to your return data and then either 在Java或Groovy中定义一个与您的返回数据相对应的类,然后
    1. use object-to-json and then json-to-object with your class as return class 使用对象到json,然后将json到对象与您的类作为返回类
    2. assign the return data to objects of your class in Java or Groovy 将返回数据分配给Java或Groovy中的类的对象

Once you have your data as custom objects, object-to-xml-transformer will print produce a much cleaner output. 一旦将数据作为自定义对象,object-to-xml-transformer就会打印出更清晰的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM