Reviewing the schema.xml, I was caught by surprise with this definition:
<dynamicField name="PHOTO_*" type="string" indexed="true" stored="true"/>
And the output is similar to this:
How can we achieve this? We can create a user-defined transformer using JAVA script. Here's what my data-config.xml would look like:
<dataSource driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@//hostname.com:port/SID"
user="username" password="password" />
<script>
<![CDATA[
function photoFunction(row) {
var seqNum = row.get("SEQ_NUM");
var imageName = row.get("IMAGE_NAME");
var fieldName = "PHOTO_" + segNum;
row.put(fieldName, imageName);
return row;
}
]]>
</script>
<document name="Doc">
<entity name="Ad" pk="AD_ID"
query="select a.ad_id, a.other_columns
from table_name a
where conditions">
<entity name="Photo"
query="select p.seq_num, p.image_name
from photo_table p
where p.ad_id = '${Ad.AD_ID}'
order by p.display_order"
transformer="script:photoFunction" />
</entity>
</document>
</dataConfig>
No comments:
Post a Comment