Showing posts with label JDeveloper. Show all posts
Showing posts with label JDeveloper. Show all posts

Thursday, December 6, 2012

Oracle JDeveloper 11gR2 Cookbook

After almost a year of truly great effort by everyone involved, I am happy to announce that my Oracle JDeveloper 11gR2 Cookbook book is published by Packt Publishing. This book accumulates to a large degree my practical experience amassed over the last four years working on real world ADF projects.

Special Thanks goes to Frank Nimphius, Edwin Biemond and Spyros Doulgeridis for their insight, knowledge and advice.  

For further details about the book click here

Here are some peer references/reviews of the book from the blog sphere:

Tuesday, June 7, 2011

FAQ #35 - How to set default values for View object row attributes

Introduction

In this post we will see how to set default values to View object attributes. There are a number of places where you can do this:

  • In the overridden View object row create() method
  • Declaratively using a Groovy expression
  • In the attribute getter method

To demonstrate each case, consider the use case of setting the employee’s hire date to the current date for a newly created View object row.

Main Theme

Setting default attribute values in the overriden ViewImpl create()

To set the default value for a View object attribute in the overridden create() method, follow these steps:

  • Create a View Row custom Java implementation class for the Employees View object.
  • Open the EmployeesRowImpl.java custom View Row Java implementation class and override the create() method using the Override Methods… button – the green left arrow on the editor toolbar.
  • To set the default employee’s hire date to today’s date, add the following code to create() immediately after the call to super.create():
              // set the default hire date to today
             this.setHireDate((Date)Date.getCurrentDate());

Setting default attribute values with a Groovy expression

To set the attribute default value using a Groovy expression, follow these steps:
  • Open the Employees View object definition and go to the Attributes page.
  • Select the attribute that you want to initialize – HireDate in this case, and click on the Edit selected attribute(s) button (the pen icon).
  • On the Edit Attribute dialog select the View Attribute node.
  • Select Expression for the Value Type radio button in the Attribute section.
  • Enter the following Groovy expression in the Value field: adf.currentDate


Returning a default value from the attribute getter

Another way to set a default value for a View object attribute is in the attribute getter method. Follow these steps to set the default employee hire date:

  • Locate the View object attribute getter in the View object custom row implementation class. In this example is the getHireDate() method in EmployeesRowImpl.java.
  • Replace the existing code in getHireDate() with the following:

          // get the HireDate attribute value
          Date hireDate = (Date)getAttributeInternal(HIREDATE);
          // check for null and return today's date if needed
          return (hireDate == null) ? (Date)Date.getCurrentDate() : hireDate;

Note that using this technique we don’t actually set the attribute value; rather we return a default value, which can be subsequently applied to the attribute. Also notice that this is done only if the attribute does not already have a value (the check for null).

Actually setting an attribute value in a getter is not a recommended practice.

Attribute dependency

A common use case related to this topic is setting an attribute’s value based on the value of another related attribute. Consider for instance the use case where the employee’s commission should be set to a certain default value if the employee is part of the Sales department. Also consider the case where the employee’s commission should be cleared if the employee is not part of the Sales department. In addition to accomplishing this task with Groovy as stated earlier, it can also be implemented in the employee’s DepartmentId setter, i.e. in the setDepartmentId() method as it is shown below:

    public void setDepartmentId(Number value) {
        // set the department identifier
        setAttributeInternal(DEPARTMENTID, value);
        // set employee's commission based on employee's department
        try {
            // check for Sales department
            if (value != null && SALES_DEPARTMENT_ID == value.intValue()) {
                // if the commission has not been set yet
                if (this.getCommissionPct() == null) {
                    // set commission to default
                    this.setCommissionPct(new Number(DEFAULT_COMMISSION));
                }
            } else {
                // clear commission for non Sales department
                this.setCommissionPct(null);
            }
        } catch (SQLException e) {
            // log the exception
            LOGGER.severe(e);
        }
    }

Conclusion

As you can see, there are a number of different ways for initializing your View object row attributes. Which one you choose depends on the specific use case at hand. It is common on large projects that a combination of all (and more) is used. Setting a standard approach could be appropriate in this case.

Until the next time, keep on JDeveloping!

Wednesday, February 9, 2011

FAQ #31 - How to create your own in-house Update Center in JDeveloper

Introduction

If you ever used the Check for Updates... feature in JDeveloper, I am sure you've seen the list of available Update Centers from which you can download your JDeveloper extensions. In this post we will go through the process of adding your own Update Center to supply your own extensions in a corporate environment.


Main Theme

You can access the Check for Updates... feature in JDeveloper via the Help | Check for Updates... menu. Once you do so, a list of the available Update Centers is presented as shown in the picture below.


It is easy to add your own Update Center by clicking on the Add... button and supplying the necessary information, i.e. the name of the Update Center and its location.


The Update Center location is the http address of the Update Center descriptor as in http://192.168.5.134:8080/center.xml in the above example. The Update Center descriptor is an XML file describing the Update Center and the extensions that makes available. Below is an example descriptor:

The updates tag encloses all available extension updates that are made available by the Update Center. Each extension is listed within the update tag. The information provided in the nameversionauthorauthor-url and description tags are used by JDeveloper to present the necessary information about the specific extension. The bundle-url tag points to the location from where the extension can be downloaded. It does not need to reside in the update location necessarily.

After adding the update center, the Check for Updates... page will reflect the Update Center added as it is shown below:


Selecting the newly added Update Center and clicking Next will present a list of the extensions that are made available by the Update Center.



Conclusion

Adding your own JDeveloper Update Center to supply your own extensions is a pretty straightforward business. Just add it in the Check for Updates... and provide the appropriate Update Center descriptor to describe the JDeveloper extensions that are made available by the Update Center. Of course you've got to have your Update Center web server up and running and your extensions on-line to start serving the extension download requests ;)

Until the next time, keep on JDeveloping!








Friday, October 22, 2010

FAQ #26 - How to Install JDeveloper on Linux

Introduction

A recent post on OTN related to the installation of JDeveloper on Linux is the inspiration for this FAQ. Let's go over the installation then and discover on the way how difficult or - as it turns out - how easy it is.

Main Theme

Start by downloading the latest version of JDeveloper - at the writing of this, it is 11.1.1.3.0 - from the Oracle JDeveloper Downloads web page. This download page can be accessed directly by typing the following address on your browser: http://www.oracle.com/technetwork/developer-tools/jdev/downloads/soft11-098086.html.


Once the download is done, open a terminal window and go to the directory where the installation package file resides. Ensure that you have given read and execute permissions to the installation auto-extraction package file and start its execution by typing ./jdevstudio11113install.bin, where jdevstudio11113install.bin is the name of the downloaded installation package filename. This will start the unpacking of the installation package and upon completion it will present the Welcome installation page.


Note that if you are having trouble seeing the Welcome page in graphical mode, ensure that the $DISPLAY environment variable is set correctly.

Click Next to proceed to the Choose Middleware Home Directory page and possibly accept the default Middleware Home Directory proposed by the installation program, namely Oracle/Middleware.


In the Choose Install Type page you can choose Complete to install all available components, that is JDeveloper, ADF support and the WebLogic Server. This would be fine, unless you want to selectively install certain components only.


Click Next and confirm the installation directories in the Confirm Product Installation Directories page. Confirm and click Next once more to proceed to the Installation Summary page.


Review the installation summary and when ready press Next to proceed with the installation.


The installation will start and upon a successful installation you should see the Installation Complete page. Uncheck the Run Quickstart checkbox and click Done to exit.


That's all there is to it.

To start JDeveloper, go to the /jdeveloper/jdev/bin directory under the Middleware Home you selected during the installation and type ./jdev




JDeveloper should start.


You are know ready for developing your applications on Linux using JDeveloper. To make things easier create a shortcut to the specific file on your Linux desktop if you prefer.

Conclusion

As it turns out, installing JDeveloper on Linux is very simple. Simply download the Linux version of the JDeveloper installation package and run it. Follow the directions presented during the installation and when done, start JDeveloper by running the jdev executable in the /jdeveloper/jdev/bin directory.

Until the next time, keep on JDeveloping (on Linux)!







Friday, June 11, 2010

FAQ #25 - How to get started with SOA Suite 11g R1, Pt. 4

Introduction

In this part of the How to get started with SOA Suite 11g R1 series we will conclude the EmployeeInquirer composite by wiring the Web Service binding to the Database Adapter using a Mediator component. We will also deploy the composite to WLS and test it using Enterprise Manager.

Main Theme

Defining the transformations using a Mediator component

Open the EmployeeInquirer project and bring up the composite Design screen. The Web Service binding and the Database Adapter should be displayed on the Exposed Services and on the External Services part of the design canvas respectively. From the Component Palette grab a Mediator component and drop it on the Components section of the composite. Enter RouteRequest for the Name of the mediator and click OK.


The composite design screen should now look as it is shown below:


Now that all components have been laid out on the screen we can wire them together to define their interactions. First we will wire the Web Service to the Mediator. Click on the green binding arrowhead icon on the top right of the Web Service and drag it to the left of the Mediator. Similarly wire the Mediator to the Database Adapter by clicking on the green arrowhead icon at the right of the Mediator and dragging it to the Database Adapter. When you are done the composite should look like this:


Now that the components are wired, we will add the transformation of the request/reply messages to the Mediator. We do this by double-clicking on the Mediator component. Doing so will bring up the Mediator editor.



We will use the editor to define the XSLT transformations to both the request and reply messages, so click on the transformation icon next to the Transform Using combo - pointed above by the red arrow - to bring up the Request Transformation Map dialog.


Click on the Create New Mapper File radio button and click OK. This will open the XSLT mapping editor.


To map the employeeId from the source - left side - to the target - right side, grab the employeeId from the source side and drop it on the employeeId on the target side. The resulting mapping should look like this:


Now save the mapping and close the mapping editor. Back on the Mediator editor repeat the mapping process for the reply.


On the Reply Transformation Map dialog click on the Create New Mapper radio and click OK.


This will open the XSLT mapping editor for the reply. Map the firstName and lastName elements from the source to the destination. The result mapping is shown below:


This concludes the definition of the Mediator and concludes the project. Next we need to setup the database resource for the Database Adapter and deploy the composite to WebLogic.

Creating the database resources in WLS

Creating the data source

The database resources are required by the Database Adapter in order to access the HR schema in the database. First we need to define the data source, so start WLS and log in to the Administration Console. Navigate to Services | JDBC | Data Sources using the Domain Structure tree on the left and click the New button on the Data Sources table to create a new data source.


In the Name field enter hrDatabase. For the JNDI Name enter jdbc/hrDatabase. Select the Database Type and click Next.


On the next screen select the Database Driver and click Next.


On the Transaction Options screen click Next. On the Connection Properties screen enter the database connection information for the HR schema and click Next.


On the Test Database Connection screen click the Test Configuration button to test the connection. If all is OK a Connection test succeeded message will be displayed. Click Next to continue.


On the Select Targets screen select your SOA server and click Finish to complete the creation of the data source.


WLS will create the data source and update the Data Sources table showing the hrDatabase data source you just created.


Creating the connection pool

Next we will create a connection pool for the DbAdapter application. Since DbAdapter uses a deployment plan, you will first need to create a directory on your physical SOA server machine to contain it. I have created under the %SOA_HOME%\soa directory and I called it DBPlan. The explicit path is C:\Oracle\Middleware\Oracle_SOA1\soa\DBPlan.

Using the WLS Administration Console click on the Deployments node of the Domain Structure tree and click on the DbAdapter application shown in the Deployments table.


On the Settings for DbAdapter screen click on the Configuration tab and then on the Outbound Connection Pools tab. Click New to create a new pool.


Select the javax.resource.cci.ConnectionFactory radio button and click Next.


On the JNDI name for Outbound Connection Instance screen enter the JNDI name as you have entered it for the Database Adapter definition in the EmployeeInquirer project. To ensure that it is entered correctly, return to JDeveloper, double-click on the Database Adapter in the composite and copy it from the Service Connection page.


After you paste it on the JNDI Name field click Finish.


At this point you will be asked for the deployment plan location. Enter the path that you created earlier and enter Plan.xml for the deployment plan and click OK. Confirm the deployment plan name in the Overview tab.


Now edit the connection pool you just created to associate it with the data source previously created. Click on the Configuration tab and then on the Outbound Connection Pools tab. Expand the javax.resource.cci.ConnectionFactory connection factory and click on the eis/DB/HrConnection instance.


On the Outbound Connection Properties page enter the data source name - jdbc/hrDatabase - in the Property Value field of the xDatabaseSourceName Property Name and click Save.


Finally we will need to  update the DbAdapter application. Select Deployments from the Domain Structure tree and select the DbAdapter application. Click Update to update the application.


In the Update Application Assistant page select the Redeploy this application using the following deployment files: radio button and click Finish.


If all went well you should see these success messages:



Deploying the composite

Now we can deploy the composite to WLS. Create a connection to WLS, right-click on the project in the Application Navigator and select Deploy.


In the Deployment Action page of the Deploy wizard select Deploy to Application Server.


Click Next on the Deploy Configuration page. Select your WLS connection on the Select Server page and click Next. On the SOA Servers select your SOA server and click Next.


Verify the deployment summary on the Summary page and click Finish to start the deployment. If everything went OK you should see a BUILD SUCCESSFUL message in the SOA Log window.


The Deployment Log window should also indicate that the deployment went OK.


Testing the composite

To test the composite log in to the Enterprise Manager Fusion Middleware Control and click on the EmployeeInquirer composite on the SOA navigation tree. Then click on the Test tab.


On the Test Web Service page go the bottom of the page to the Input Arguments section and enter an Employee Id value - let's say 100, for the EmployeeId element of the request. Then click on the Test Web Service button.


The web service is executed and if everything goes OK the response will be shown on the Response tab.


This concludes our introduction to SOA Suite 11g.

Conclusion

In this series of posts we've seen how to get started with the SOA Suite 11g, from its installation to composite development - utilizing some of the basic components in JDeveloper, to testing the composite using Enterprise Manager Fusion Middleware Control. This just scratched the surface. SOA Suite is a vast technology with much more to offer.

Until the next time, keep on JDeveloping!


Code

http://code.google.com/p/jdeveloperfaq/downloads/detail?name=JDeveloperFAQNo25.rar&can=2&q=







Related Posts Plugin for WordPress, Blogger...