Develop > Business logic layer > Work with the data service layer > Create a query
Create a new get-data-config.xml file
You can use getData tags and process-related service requests after creating a get-data-config.xml file. The get-data-config.xml file contains expression builders, each representing a different SQL query defined in the project's query template file. getData tags in the storefront JSP files can retrieve specific data from the database by referencing the appropriate expression builder.
Complete this task when creating a new service module, where the configuration file has not been provided for you. If you are changing the behavior of a service module that is ready for you to use as is, , however, extend the provided configuration file instead.
Procedure
- Create the get-data-config.xml file for the project.
- Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
- In the Project Explorer view, expand YourProject > WebContent > WEB_INF > config.
Where YourProject is the project running the code using the getData tag.
- Right-click config and select New > Folder.
- In the Folder name field, enter com.mycompany.commerce.project and click Finish.
- If the com.mycompany.commerce.project folder is not visible, right click on the config directory in the Enterprise Explorer view and click Refresh.
- Right-click the com.mycompany.commerce.project folder and select New > File .
- In the File name field, enter get-data-config.xml and click Finish. The newly created get-data-config.xml file automatically opens.
- Insert the project related expression builders into the get-data-config.xml file.
Each expression builder has the following properties:
- The name node uniquely identifies the expression builder, and is used by getData tags in the project JSP files when referring to an expression builder.
- The data-type-name node contains the noun type returned by this expression builder.
- The expression template node refers to an XPath query defined in the project query template file, used to retrieve specific information from the database. Parameters such as $projectID$ can be passed to the expression builder by a getData tag.
- Each param node contains a pair of name and value child nodes that define a parameter passed to the query template file. Each expression builder is associated with a specific Access Profile. This Access Profile, together with the defined XPath query, uniquely identifies a query in the query template file.
Each expression builder should resemble the following sample structure, replacing the empty nodes with the own project-related expression builders:
<!-- Project related expression builder 1. --> <expression-builder> <name> </name> <data-type-name> </data-type-name> <expression-template> </expression-template> <param> <name> </name> <value> </value> </param> </expression-builder> <!-- Project related expression builder 2. --> <expression-builder> <name> </name> <data-type-name> </data-type-name> <expression-template> </expression-template> <param> <name> </name> <value> </value> </param> </expression-builder> <!-- Project related expression builder 3. --> <expression-builder> <name> </name> <data-type-name> </data-type-name> <expression-template> </expression-template> <param> <name> </name> <value> </value> </param> </expression-builder> </wcf:get-data-config>
Although there are three expression builders in the sample expression builder structure, the own project-related expression builders can contain as many expression builders as needed.
- Deploy the changes using the WebSphere Administrative Console or the wsadmin tool:
- Deploy J2EE assets for a single file
- Deploys a single file asset into the J2EE application. Use this option to deploy the changes if the new get-data-config.xml file is the only file being changed.
- Deploy J2EE assets for a partial application
- Deploys several files into the J2EE application at the same time. Use this option to deploy the changes if changes have been made to more files than just the new get-data-config.xml file. For example: logic jars, JSP files, or other configuration XML files.
Results
After completing these steps, you have successfully created a new service module when the configuration file has not been provided for you.
Related tasks
Work with WebSphere Commerce service modules
Work with the data service layer
Extend the provided get-data-config.xml file