Adobe Enterprise Technical Enablement Selecting Multiple Rows from a Database In this topic, you will learn about the Query for Multiple Rows as XML operation and how it is used to interact with databases. Objectives After completing this unit, you should be able to • Use the Query for Multiple Rows as XML operation to return a result set from a database • Use the XML Document Info Editor to define the XML document that is returned from a SQL query Concepts In this topic, you will learn about the following concepts • Selecting multiple rows of database data Copyright © 2011 Adobe Systems Incorporated 1 Selecting multiple rows of database data • The Query for Multiple Rows as XML operation is used to select multiple rows of data from a database from a process ■ Returns the complete result set as XML data Query for Multiple Rows as XML operation • Located in Services view > Foundation > JDBC - 1.0 Figure 1: Locating the Query for Multiple Rows as XML operation of the JDBC service Setting Query for Multiple Rows operation properties • When a Query for Multiple Rows as XML operation is added to a process, the following properties can be defined in the Properties view ■ Datasource name – literal value or variable – corresponds to the JNDI name configured for the data source – formatted with a ‘java:/’ prefix java:/adobeTraining ■ SQL Statement - the SQL statement to execute on the database server 2 Copyright © 2011 Adobe Systems Incorporated ■ XML information – The definition for the structure of the XML to use for returning the results set – the XML Document Info Editor dialog box is used to create the definition ■ XML Document - the XML type to use for storing the results set that is returned Figure 2: Query for Multiple Rows as XML properties Copyright © 2011 Adobe Systems Incorporated 3 XML Document Info Editor • The XML Document Info Editor is used to define the elements of the XML document that is used to return the results set of a SQL query • The XML Document Info Editor is opened by clicking the ellipsis button next to the XML information property in the Properties view • The following properties need to be specified ■ Root Element Name - root element of the XML document ■ Repeating Element Name – Represents the name of the XML element to use to contain the information from a row in the result set – The XML document includes one of these elements for each row in the result set ■ Column Name Mappings - mapping of the database columns to XML elements Figure 3: XML Document Info Editor 4 Copyright © 2011 Adobe Systems Incorporated Task 1: Selecting multiple rows In this task, you will perform the following • • • • • Open a process Verify contents of Employee table Configure a Query for Multiple Rows operation Write the query result to a file Test the process Setup 1. Import the Selecting_Multiple_Rows.lca file. Steps Open a process 1. Login to the Workbench. 2. Open the Selecting_Multiple_Rows application. 3. Expand the Processes folder, right-click the SelectingMultipleRows process and select Check Out. 4. Double-click the SelectingMultipleRows process to open it. 5. From the Variables view, create a process variable named xmlData of type xml. Verify contents of Employee table 6. To drop and re-create the employees table, open Windows Explorer and navigate to C:\AdobeTraining\Doc_Services\Foundation\Selecting_Multiple_Rows. Double-click on the create_db.bat file 7. To verify that there are employees in the database, double-click on the showEmployees.bat file. Note: This bat file executes a SELECT * FROM employee SQL statement on the database. It then lists all the records returned by the statement. 8. Verify that 3 employees are in the employee table. Copyright © 2011 Adobe Systems Incorporated 5 Configure a Query for Multiple Rows operation 9. From the process diagram palette, drag the Activity Picker activity onto your process diagram. 10. In the Define Activity dialog box, expand the Foundation category. 11. From the JDBC service, select the Query for Multiple Rows as XML operation and click OK. 12. Select the Query for Multiple Rows as XML operation and set the following properties. • Name: Select all Employees • Datasource name (literal value): java:/AdobeTraining • SQL Statement: SELECT * FROM employee 13. Click on the ellipsis next to the XML information property to open the XML Document Info Editor. 14. Click the Process Metadata button. The editor should populate with the column names from the employee table. 15. Set the Root Element Name to Employees. 16. Set the Repeating Element Name to Employee. 6 Copyright © 2011 Adobe Systems Incorporated 17. Click the Test button to verify that the SQL query returns an XML document with all the employees. 18. Click OK to close the XML Document Info Editor. 19. In the Output category, set the XML document to type variable and select the xmlData process variable. Write the query result to a file 20. From the process diagram palette, drag the Activity Picker activity onto your process diagram and drop it after the Select All Employees operation. 21. In the Define Activity dialog box, expand the Foundation category. 22. From the File Utilities service, select the Write XML operation and click OK. 23. Select the Write XML operation and set the following properties. • Name: Write XML Data • Pathname Pattern (literal value): C:\AdobeTraining\Doc_Services\Foundation\Selecting_Multiple_ Rows\Employees.xml • XML Document (variable): xmlData • Overwrite the existing file: checked 24. Connect the two operations with a route. 25. Confirm that the process appears as follows. 26. Save the process and Deploy the application. Copyright © 2011 Adobe Systems Incorporated 7 Test the process 27. Right-click in an empty area of the process diagram and select Invoke Process... Note: Click OK on the dialog boxes about the process having no input or output variables. 28. When the process completes, verify that the Employees.xml file was written to the C:\AdobeTraining\Doc_Services\Foundation\Selecting_Multiple_Rows directory. Open the file using Internet Explorer to verify the contents. 8 Copyright © 2011 Adobe Systems Incorporated Summary • The Query for Multiple Rows as XML operation queries a data source and outputs an XML document with all the rows • The Query for Multiple Rows as XML operation provides an XML Document Info Editor to map columns and rows to XML elements Copyright © 2011 Adobe Systems Incorporated 9 Review 1. What does Query for Multiple Rows as XML return? Adobe Systems Incorporated 345 Park Avenue San Jose, CA 95110-2704 USA www.adobe.com Adobe, Acrobat, Adobe AIR, AIR, Distiller, Flash, Flash Builder, Flash Catalyst, Flex, Adobe Digital Enterprise Platform, MXML, PostScript, Reader, SiteCatalyst, SearchCenter, Discover, Recommendations, Insight, Test&Target, ReportBuilder, Survey, Search&Promote, and Social Media are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. © 2011 Adobe Systems Incorporated. All rights reserved.