Saturday, November 26, 2011

Database: Oracle NoSQL Database is here!

The Oracle NoSQL Database is a distributed key-value database. It is designed to provide highly reliable, scalable and available data storage across a configurable set of systems that function as storage nodes.

Data is stored as key-value pairs, which are written to particular storage node(s), based on the hashed value of the primary key. Storage nodes are replicated to ensure high availability, rapid failover in the event of  a node failure and optimal load balancing of queries. 
Customer applications are written using an easy-to-use Java API to read and write data. The NoSQL Database links with the customer application, providing access to the data via the appropriate storage node for the requested key-value.

The NoSQL Database intelligent driver includes the hashing algorithms to ensure proper data distribution, as well as state and performance information about each storage node which enable it to provide optimal load balancing and query processing. The NoSQL Database provides easy administration via either a web console or command line interface.

Key Features


The Oracle NoSQL Database includes the following key features:
  • Simple Data Model
    • Key-value pair data structure, keys are composed of Major & Minor keys
    • Easy-to-use Java API with simple Put, Delete and Get operations
  • Scalability
    • Automatic, hash-function based data partitioning and distribution
    • Intelligent NoSQL Database driver is topology and latency aware, providing optimal data access
  • Predictable behavior
    • ACID transactions, configurable globally and per operation
    • Bounded latency via B-tree caching and efficient query dispatching
  • High Availability 
    • No single point of failure
    • Built-in, configurable replication
    • Resilient to single and multi-storage node failure
    • Disaster recovery via data center replication
  • Easy Administration
    • Web console or command line interface
    • System and node management
    • Shows system topology, status, current load, trailing and average latency, events and alerts


Key Components


 Intelligent Driver Key-Value Pairs API
 Storage Nodes Transactions Administration


Oracle Website

Friday, November 25, 2011

ADF; Notify the server when user tabs out of ADF input field


Though the use case covered in this section is more of an individual problem than of generic interest, the code involved to implement the solution may be useful. 
First the use case: For an input text component, a notification should be sent to the server when the user steps out of the field using mouse or the keyboard navigation. The notification should be sent no matter if users changed the field content (in which case a value change listener would have done) or not (in which case a value change listener is not enough). 
The solution to this problem is to use an af:clientListener tag on the input tag component to invoke a JavaScript function when the user leaves the field (The component event for this is "blur").
Using an af:serverListener tag on the input text component then allows to notify the server from the JavaScript function.
<f:view>
  <af:document id="d1"> 
    <af:resource type="javascript">
       function onBlurTxtField(evt){
          var source = evt.getSource(); 
          var custEvent = new AdfCustomEvent(source,"onBlurNotifyServer",
                       {submittedValue : source.getSubmittedValue(),
                        localValue : source.getValue()}
                         ,true);
          custEvent.queue(); 
       }
   </af:resource>
   <af:form id="f1">
     <af:inputText label="Label 1" id="it1">
        <af:clientListener   method="onBlurTxtField" type="blur"/>
        <af:serverListener   type="onBlurNotifyServer"
                             method="#{TxtHelper.onBlurNotify}"/>
     </af:inputText>
     <af:inputText label="Label 2" id="it2"/>
   </af:form>
  </af:document>  
</f:view>
The page code above sends a custom event to the server whenever a user leaves the input text field. 
The payload sent to the server contains the submitted and the local component value. Note that in the above sample --- as we will see next --- the payload is not really required because the same information can be accessed from the component instance in the referenced managed bean method.

<af:serverListener type="onBlurNotifyServer"
                   method="#{TxtHelper.onBlurNotify}"/>
The managed bean method receives a single argument of type ClienEvent:
public void onBlurNotify(ClientEvent clientEvent) {
    // get a hold of the input text component
    RichInputText inputTxt =  RichInputText) clientEvent.getComponent(); 
    //do some work on it here (e.g. manipulating its readOnly state)
    //…
    //Get access to the payload
   Map  parameters = clientEvent.getParameters();
   System.out.println("SubmittedValue = "+parameters.get("submittedValue"));
   System.out.println("LocalValue =  +parameters.get("localValue"));
}
As mentioned, the use case may not be of generic interest. However, the way you work with the client and server listener for sure made sense to publish as an example.

ADF: New client behavior tag - af:checkUncommittedDataBehavior


In Oracle JDeveloper 11.1.2, a new client behavior tag af:checkUncommittedDataBehavior is provided to check for uncommitted data when navigating away from a page using a command button that has its immediate property set to true. The tag can be applied as a child of any command component, like
  • af:commandButton
  • af:commandLink
  • af:commandMenuItem
  • af:commandToolbarButton

For the client behavior to work, you must set the document tag's uncommittedDataWarning attribute to on, see more here.

Just as a reminder: Client behavior tags in ADF Faces execute on the client side. They are there to save you from writing JavaScript, thus abstracting you from the complexity of the underlying client side APIs.

ADF: Creating ADF Faces component at Runtime

Creating ADF Faces Comamnd Button at Runtime
In ADF Faces, the command button is an instance of RichCommandButton and can be created at runtime. While creating the button is not difficult at all, adding behavior to it requires knowing about how to dynamically create and add an action listener reference. 
The example code below shows two methods: The first method, handleButtonPress is a public method exposed on a managed bean.
public void handleButtonPress(ActionEvent event){ 
 System.out.println("Event handled"); 
 //optional: partially refresh changed components if command 
 //issued as a partial submit
}
The second method is called in response to a user interaction or on page load and dynamically creates and adds a command button. When the button is pressed, the managed bean method – the action handler – defined above is called. The action handler is referenced using EL in the created MethodExpression instance.

If the managed bean is in viewScope, backingBeanScope or pageFlowsScope, then you need to add these scopes as a prefix to the EL (as you would when configuring the managed bean reference at design time)

//Create command button and add it as a child to the parent component that is passed as an 
//argument to this method
private void createCommandButton(UIComponent parent){
  RichCommandButton edit = new RichCommandButton();
  //make the request partial
  edit.setPartialSubmit(true);
  edit.setText("Edit");                         
  
  //compose the method expression to invoke the event handler
  FacesContext fctx = FacesContext.getCurrentInstance();
  Application application = fctx.getApplication();
  ExpressionFactory elFactory = application.getExpressionFactory();
  ELContext elContext = facesCtx.getELContext();
  MethodExpression methodExpressio = null;
  //Make sure the EL expression references a valid managed bean method. Ensure
  //the bean scope is properly addressed 

  methodExpression =  elFactory.createMethodExpression( 
                            elContext,"#{myRequestScopeBean.handleButtonPress}", 
                            Object.class,new Class[] {ActionEvent.class});
  //Create the command buttonaction listener reference

  MethodExpressionActionListener al = null;        
  al= new MethodExpressionActionListener(methodExpression); 
  edit.addActionListener(al); 

   //add new command button to parent component and PPR the component for 
   //the button to show
   parent.getChildren().add(edit);
   AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance(); 
   adfFacesContext.addPartialTarget(parent); 
}

ADF: Detecting browser type and version from ADF Faces

Sometimes ADF applications need to know about the user browser type and version. 
For this, assuming you need this information in Java, you can use the Trinidad RequestContext object. You could also use the AdfFacesContext object for the same, but since the ADF Faces Agent class is marked as deprecated, using the equivalent Trinidad classes is the better choice.
The source code below prints the user browser information to the Oracle JDeveloper message window

import org.apache.myfaces.trinidad.context.Agent;
import org.apache.myfaces.trinidad.context.RequestContext;



RequestContext requestCtx = RequestContext.getCurrentInstance();
Agent agent = requestCtx.getAgent();
String version = agent.getAgentVersion();
String browser = agent.getAgentName();
String platform = agent.getPlatformName();
String platformVersion = agent.getPlatformVersion();

System.out.println("==================");
System.out.println("Your browser information: ");
System.out.println("Browser: "+browser);
System.out.println("Browser Version : "+version);
System.out.println("Browser Platform: "+platform);
System.out.println("Browser Platform Version:
"+platformVersion);
System.out.println("==================");

OS: How to Delete/Create/Stop/Start a Windows Service in Windows 7, Vista or XP

 If you are a fan of tweaking your system and disabling services, you might find that over time your Windows Services list becomes huge and unwieldy with a large number of services in the list that will never be enabled.
Instead of just disabling a service, you can alternatively completely delete the service. This technique can be especially helpful if you’ve installed some piece of software that doesn’t uninstall correctly, and leaves an item in the service list.
Important Note: Once you delete a service, it’s gone, and it’s going to be a pain to add it back. Use with caution.
Deleting a Service
The first thing you’ll need to do is identify the name of the service, so open up Services through the start menu or control panel, and then find the service in the list that you want to delete.
You’ll want to open up the properties by double-clicking on the service name, and then highlight the “Service name” value and copy it to the clipboard. This is what we’ll need to disable it.
You’ll need to open up a command prompt, and if you are using Windows 7 or Vista you’ll need to right-click the command prompt and choose Run as Administrator. We’ll use the sc command to actually do the work.
The syntax used to delete a service is this:
sc delete ServiceName
If your service name has spaces in it, you’ll need to wrap the service name in quotes, like this:
sc delete “Adobe LM Service”
Note that I’m not recommending deleting this particular service, it’s just an example.
Now if you use the F5 key to refresh your Services list, you’ll see that the service is gone.
I’ve found that using this technique (carefully) can make your Services list a lot more useful, since you don’t have to weed through dozens of items you will never have enabled.
Note: You should think long and hard before deleting a service, because it’s very difficult to get them back once they are gone.
For more information you can have a look at here.
You can also view services existing on the system or even delete them from this registry key :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services


Wednesday, November 23, 2011

ADF: Include meta data tags in HEAD element – using ADF af:document and metaContainer facet

ADF Faces 11g does not contain tags such as af:head and af:body. Instead there is af:document, an abstraction from the documents served to potentially different clients. 
A JSF page can be rendered as HTML – with a HEAD and BODY tag – but also to other clients and renderformats that do not have the HEAD and BODY concept. Hence the abstraction.
When your ADF Faces page does render as HTML to a web browser, the af:document will render both HEAD and BODY. If you want to specify the title attribute for the HEAD, you have to set the title attribute on af:document.
When you want to set the meta tags in the HEAD section – for example to do some SEO (Search Engine Optimization) you need to use the metaContainer facet of the af:document component. This facet is also used for including JavaScript snippets in the HEAD.
To set the values of meta-tags, you use code like this:
<af:document>
 <f:facet name="metaContainer">
   <f:verbatim>
     <meta name="description" content="Some very interesting bit of meta information about the page" />
     <meta name="keywords" content="money profit huge pile gold treasure rich filthy rich happy few" />
   </f:verbatim>
 </f:facet>
-- Note: that the f:verbatim is one way of dealing with the fact that <meta>  is not a recognized nor allowed child of a facet or any other JSF component.

Thursday, November 17, 2011

JavaFX: JavaFX 2.0 Is Here!

The big news at JavaOne 2011 was the release of JavaFX 2.0, an advanced Java UI platform for enterprise business applications—and the next step in the evolution of Java as a premier rich-client platform.

At the JavaOne technical keynote on Monday, October 4, Richard Bair, chief architect, client Java platform, at Oracle, detailed the general availability of JavaFX 2.0 for Windows (32-bit XP, 32- and 64-bit Windows Vista, and Windows 7). He also announced NetBeans 7.1 Beta (featuring full JavaFX 2.0 support); the JavaFX 2.0 developer preview for Mac OS X; and JavaFX Scene Builder early access.

Key features in JavaFX 2.0 include 100 percent Java APIs, the new FXML UI markup language, and full Swing integration. JavaFX 2.0 provides a Web component based on WebKit, which allows developers to seamlessly mix and match native Java capabilities and the dynamic capabilities of Web technologies.

At the Java strategy keynote on Tuesday, Oracle Vice President of Development Adam Messinger announced that Oracle is submitting a proposal to open source the JavaFX platform as a new project within the OpenJDK community. Oracle will be working with the JCP to propose JavaFX as an official standard part of the Java platform, Messinger said.

Oracle intends to initially contribute the JavaFX UI controls and related libraries; other JavaFX components are planned to follow in multiple phases.

Nandini Ramani, vice president of development, Java client group, at Oracle, generated a lot of buzz at that same keynote with a demo of JavaFX 2.0 running on an Apple iPad 2.0, a Samsung Galaxy Tab 10.1 running Android 3.1, and an Acer Windows 7 tablet. “We want to hear from the community,”

Ramani said. “If this is something you want to see, we’re happy to make it a priority.” (Read more in the Nandini Ramani interview, “Shock the Senses,” on page 32.) Looking to the future, full Mac OS X support will coincide with the Java 7 for Mac release, which will be followed by support for additional platforms (Linux, Solaris, and so on). You can listen to Nicolas Lorain’s JavaOne 2011 session “Introduction to JavaFX 2.0” and other JavaFX sessions at parleys.com.

SDLC: Software life cycle activities

Whichever software life cycle is adopted, the software engineering activities briefly described in the following sections will need to be carried out.

1- Requirements Analysis and Specification
In this phase, the user’s requirements are identified and analyzed. The requirements of the system to be  developed are specified in a Software Requirements Specification (SRS). The SRS is an external specification of the software. Its goal is to provide a complete description of what the system’s external behavior is without describing how the system works internally. The issues of what constitutes a SRS are described lucidly in Davis (1993).

With some systems, such as embedded systems, in which the software is part of a larger hardware/software system, it is likely that a systems requirements analysis and specification phase precedes the software requirements analysis and specification.

With this approach, system functional requirements are allocated to software and hardware before software requirements analysis begins (Davis 1993).

2- Architectural Design
A software architecture (Bass, Clements, and Kazman 2003; Shaw and Garlan 1996) separates the overall structure of the system, in terms of components and their interconnections, from the internal details of the individual components. The emphasis on components and their interconnections is sometimes referred to as programming-in-the-large, and detailed design of individual components is referred to as programming-in-the-small. During this phase, the system is structured into its constituent components and the interfaces between these components are defined.

3- Detailed Design
During the detailed design phase, the algorithmic details of each system component are defined. This is often achieved using a Program Design Language (PDL) notation, also referred to as Structured English or pseudocode. Internal data structures are also designed.

4- Coding
During the coding phase, each component is coded in the programming language selected for the project. Usually a set of coding and documentation standards have to be adhered to.

5- Software testing
Because of the difficulty of detecting errors and then locating and correcting the detected errors, software systems are usually tested in several stages (Ammann and Offutt 2008). Unit and integration testing are “white box” testing approaches, requiring knowledge of the internals of the software; system testing is a “black box” testing approach based on the software requirements specification, without knowledge
of the software internals.

5.1 Unit Testing
In unit testing, an individual component is tested before it is combined with other components. Unit testing approaches use test-coverage criteria. Frequently used test-coverage criteria are statement coverage and branch coverage.

Statement coverage requires that each statement should be executed at least once.
Branch coverage requires that every possible outcome of each branch should be tested at least once.

5.2 Integration Testing
Integration testing involves combining tested components into progressively more complex groupings of components and then testing these groupings until the whole software system has been put together and the interfaces tested.

5.3 System Testing
System testing is the process of testing an integrated hardware and software system to verify that the system meets its specified requirements (IEEE 1990). The whole system or major subsystems are tested to determine conformance with the requirements specification. To achieve greater objectivity, it is preferable to have system testing performed by an independent test team.

During system testing, several features of the software system need to be tested (Beizer 1995). These include the following:

Functional testing. To determine that the system performs the functions described in the requirements                specification.

Load (stress) testing. To determine whether the system can handle the large and varied workload it is expected to handle when operational.

Performance testing. To test that the system meets its response time requirements.

5.4 Acceptance Testing
The user organization or its representative usually carries out acceptance testing, typically at the user installation, prior to acceptance of the system. Most of the issues relating to system testing also apply to acceptance testing.

Thanks to Dr. Hassan Gomma 2011 book "Software Modeling and Design".


Wednesday, November 16, 2011

ADF: favicon and browser bookmark icons

The favicon is the little icon that displays in the Browser URL address field when a requested page loads. In Oracle JDeveloper 11.1.1.x releases, the favicon needed to be added to the page source. In JDeveloper 11.1.2 a new attribute, smallIconSource has been added to the af:document tag to serve the favicon easily.
smallIconSource
Specifies a small icon that the browser may insert into the address bar (commonly known as a "favicon"). If this attribute is not specified, the browser may default to using a file named "favicon.ico" located at the root of your server. (This default behavior is not something provided by this framework and may vary between browsers.) This attribute supports a space-delimited list of files (each file may be wrapped in quotes or apostrophes if the file path contains a space). If the file path specifies a single leading slash, this means that the file is located inside of the web application's root folder (so "/small-icon.png" would resolve to something like "http://www.oracle.com/adf-faces/small-icon.png"). If the file path specifies 2 leading slashes, this means that the file is located inside of the server's root folder (so "//small-icon.png" would resolve to something like "http://www.oracle.com/small-icon.png"). Browsers typically expect these files to be 16 pixels by 16 pixels. Typically, the first listed file will be the one used. Otherwise, if a browser only supports certain kinds of files, the first file in the list that uses a supported file extension will be the one that is used for that browser.
Another new attribute is the largeIconSource that applies an image to bookmark entries in borwsers.
largeIconSource
Specifies a large icon that the browser may use when bookmarking this page to your device's home screen. If this attribute is not specified, the browser may default to using a file named "apple-touch-icon.png" located at the root of your server. (This default behavior is not something provided by this framework and may vary between browsers.) This attribute supports a space-delimited list of files (each file may be wrapped in quotes or apostrophes if the file path contains a space). If the file path specifies a single leading slash, this means that the file is located inside of the web application's root folder (so "/large-icon.png" would resolve to something like "http://www.oracle.com/adf-faces/large-icon.png"). If the file path specifies 2 leading slashes, this means that the file is located inside of the server's root folder (so "//large-icon.png" would resolve to something like "http://www.oracle.com/large-icon.png"). Browsers typically expect these files to be 57 pixels by 57 pixels but could be larger, e.g. 72 pixels by 72 pixels or 129 pixels by 129 pixels. Typically, the first listed file will be the one used. Otherwise, if a browser only supports certain kinds of files, the first file in the list that uses a supported file extension will be the one that is used for that browser.
<af:document title="My Page"
  smallIconSource="/favicon.png /favicon.ico"
  largeIconSource="/touchicon.png">
  <af:form> ... </af:form>
</af:document>

ADF: How-to access UI component that queued a custom client event

In ADF Faces, to invoke a server side method in a managed bean, you use the af:serverListener tag. Theaf:serverListener tag is added as a child to the component that owns the event and called from JavaScript in a call to AdfCustomEvent.queue( … )
In this example, the af:serverListener is added to a table to notify a manage bean method about a double-click action.
<af:table ...>
 <af:column> ... </af:column>
 ...
 <af:clientListener method="handleTableDoubleClick"
                   type="dblClick"/>
<af:serverListener type="TableDoubleClickEvent"                          
                   method="#{myBean.handleTableDoubleClick}"/>
</af:table> 
The JavaScript function that is called by the af:clientListener is shown next.
function handleTableDoubleClick(evt){   
  var table = evt.getSource();
  AdfCustomEvent.queue(table, "TableDoubleClickEvent",{}, true);         
  evt.cancel();
}
The first argument in the call to AdfCustomEvent.queue represents the event owner, the table component. This information is passed to the managed bean method, which has the following signature.
public void handleTableDoubleClick(ClientEvent ce){
  RichTable richTable = (RichTable)ce.getComponent(); 
  //... work with rich table component
}
As you can see, there is no need to look up the event owning component by searching the JSF UIViewRoot with or without help of JSFUtils.

ADF: Disabling keyboard input on af:inputDate

Setting the ReadOnly property on an af:inputDate component to true does not only make the input field read-only but also hides the calendar icon.
If the use case is to force users to always select an input date from the popup calendar and to prevent keyboard input, as show in the image above, you can use a JavaScript based solution as shown below:
<af:resource>
  function disableEntry(evt){  
    evt.cancel(); 
  } 
 </af:resource>
<af:inputDate label="Label 1" id="id1" readOnly="false"
  contentStyle="background-color:lightgray;">
  <af:clientListener method="disableEntry" type="keyDown"/>
</af:inputDate>
The contentStyle attribute sets the af:inputDate field background color to light gray to indicate a read-only field.
Note: If the read-only setting is for all instances af:inputDate then, instead if using the contentStyle attribute, you use skinning af|inputDate::content{background-color:lightgray;}

ADF: How-to launch browser print dialog when showing printable page

The following code, when referenced from the beforePhase property of the f:view component, automatically opens the browser print dialog if a page is rendered as printable.
To this time however I used an internal flag, which doesn't feel right. The code used in this post only uses public APIs and thus is a solution that lasts.

The managed bean method is referenced from the f:view component as follows
<f:view beforePhase="#{SampleBean.beforePhaseMethod}">
  ...
</f:view>
With this listener and code, when the af:showPrintableBehavior tag is used on a command item to show a printable page, the browser print dialog is automatically opened. 
While the same code also works for page fragments, the f:view tag is only available for JSPX documents. In this case you either set the beforePhase method property on the JSPX document hosting the page fragment, or define a global phase listener (faces-config.xml) that then works for all pages in an application.

Tuesday, November 15, 2011

ADF: JSF 2.0 Preemptive Navigation in ADF 11.1.2.1

Preemptive navigation is a new feature in JavaServer Faces 2.0 and allows runtime introspection of control flow cases for their target view.The JSF API for this is the ConfigurableNavigationHander class that exposes the following methods
  •  getNavigationCase(FacesContext context, 
                      java.lang.String fromAction, 
                      java.lang.String outcome) 
  • getNavigationCases() – returns a Map<String, Set<NavigationCase>> that lists all available navigation cases with the viewId as the map keys 
  • performNavigation(java.lang.String outcome) – Navigates to the next view based on the outcome. Developers using this method must ensure it is used during JSF InvokeApplication phase as it cannot be used any later
The NavigationCase class wraps the information defined for a navigation, including the condition (also a new feature in JSF 2.0) in which the navigation case is valid.
Preemptive navigation can be used in an application to populate redirect components, like the goLink shown below with a target view, or for redirects in a managed bean, for which developers need to know the target view. The sample below shows an ADF Faces goLink pointing to a managed bean. The managed bean returns the redirect URL for the link to follow when clicked on.

 The managed bean accesses the NavigationHandler defined for the JSF instance and verifies it to be an instance of ConfigurableNavigationHandler before it looks up the target viewId for the control flow case.
Note that ADFc in Oracle JDeveloper 11g R2 also supports conditional navigation, in which case developers can define an EL expression on the control flow case, using the Property Inspector, that determines when a navigation case is valid and when it is not.

Also note that Preemptive navigation fails with a NullPointer exception if the referenced control flow case is conditionally set to disabled. To handle this, the managed bean code above needs to be surrounded with a try…catch block.