In depth: Database Resource

Tags: , , , , , , | Posted in Blog, News on # February 24, 2009 | #No Comments

On the QAFE demo siteyou’ll see another sample application called “Database Sysdate Demo”.
This demo shows a simple database connection and a “commonly” known SQL statement to fetch the system time. Just like the previous post, this means that in QAFE this would be translated in two two tiers at least:

  • The Resource-tier
  • The Integration-tier
  • The Resource-Tier

    The resource-tier is as follows:

    <resource-tier>
        <resources>
        <drivermanager-datasource id="DatabaseResource"
                    statements-file-url="sysdate-statements.xml"
                    url="jdbc:oracle:thin:@mydatabaseserver:1521:XE"
                    username="scott" password="tiger"
                   driver-classname="oracle.jdbc.OracleDriver"/>
     </resources>
    </resource-tier>


    So here we something slightly different from what we saw in the previous post. We are defining here a driver-manager instead of a java-class. To summarize what is stated here. Create a driver-manager resource, with id equals “DatabaseResource” (so the name which can be used in the integration tier), username, password, url and driver-classname. The URL is conform the syntax that the vendor specified. In this case you’ll see the URL for JDBC connections to an Oracle database. That’s why the driver-classname is “oracle.jdbc.OracleDriver“.

    Note: a jndi-name is also possible.

    A total new one is the is the “statements-file-url“. This denotes the location of the custom queries/api for your database connection. The contents for the sysdate-statements.xml is as follows:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <statements xmlns="http://qafe.com/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://qafe.com/schema
     http://www.qafe.com/schema/application-statements.xsd">

    <select id="myDatabaseTime"
              sql="select TO_CHAR(sysdate, 'DD-MON-YYYY
              HH24:MI:SS') as mydate from dual"/>
    </statements>

    This file has one entry (method) which is a “select” method with id “myDatabaseTime“. In the sql attribute of this the actual statement that is sent to the database. This can be seen as a method that you can call.

    The Integration-Tier

    So now the connection is made to database with some custom statements. The method that we wanted was “myDatabaseTime“. The way to do that in QAFE is by defining a service in the integration-tier

    <integration-tier>
        <services>
             <service id="databaseService"
                       resource-ref="DatabaseResource">
                <method id="myDatabaseTime"
                       name="myDatabaseTime">
                       <out name="result"/>
                 </method>
           </service>
       </services>
    </integration-tier>


    We define in the integration-tier a service (we can define more than one service in the “services” tag). In this case the service id equals “databaseService” and it references to the resource id that we just defined in the previous step “DatabaseResource“.

    Since we wanted to call the method “myDatabaseTime” we create a method with the same name as id (<method id=”myDatabaseTime“>). We also want an explicit mapping to the id in the statements file, that why we use the name attribute. Note that this is case sensitive. Furthermore, this statement returns a value. We need to store that output in a variable. For this example we define an <out> child element of the method, with name equals “result“.

    It doesn’t matter how complex the resultset is that you return. QAFE easily manages that resultset and passes it through to the other layers (business-actions, presentation).

    In the next sessions we’ll talk more about datahandling in QAFE.

    Leave a Reply


    * will not be published

    Anti-Spam Quiz: