Fundamentals – PL/SQL


I was and will always be fascinated by Oracle PL/SQL. Its one of those sophisticated language that will “almost” always be used in every project – and theres a good reason why.

  • Industry Standard
  • DM* (Data Manipulation) – can be isolated, packaged and reused.
  • Wide array of intrinsic functions to manipulate data –  as well as objects.
  • Easier to learn  - as it has a very straight forward approach in its procedural nature.
  • Callable by universally by any platform available. – APIs are already available to call database objects.

I don’t want to bore you with details so here are some very useful guides for PL/SQL here. The site has industry standard conventions, case studies, best practices and technical information on tips how to write injection proof PL/SQL. A good read for those who wants to improve and well informed in the technology.

For me, I have a few SQL scripts I’ve been working on to practice, you can download them from here.

cakestrap_snap

CakePHP + Bootstrap


I love PHP. That’s a fact that I managed to prove ever since college. I self studied the language as well as the underlying platform due to my interest in learning; which comes from the fact that I know its purpose.  For this post, I’m going to put some perspective on how do we create a CakePHP application and put the bootstrap in to make a more responsive user interface design for the web.

Step 1: Ready your Cake App – skip this if you already done some baking – if you want to get something going from scratch, follow my simple registration tutorial here: Registration Example

Step 2: Download BootStrap for CakePHP

Since the birth of boostrap a lot of developers created their own mix and match using the front-end framework. Either you download an existing one or create your own. For this tutorial, lets download an existing one: CakePHP Theme

Extract the zip and put it in your Theme directory inside your cakePHP project.

PHP_-_gasfinder_app_Controller_AppController.php_-_Eclipse_-__Users_alvinreyes_EclipseProjects_PHP

Step 3: Set the $theme on your cakePHP AppController.php

cakestrap_snap

We basically need to set up the global variable $theme and put the folder name of the bootstrap to use it.

Sample Output: Not perfect but it will give you a good start on the layout. You can now focus on the business logic and just take care of the UI later.Administrator

 

Introduction: Book Review – Developing Web Applications with Oracle ADF Essentials


I’ve been doing a lot of practical exercises for the past few weeks regarding  JSF, specifically using the Seam Framework. Yet what I’m more intrigue about is the Oracle’s own Implementation of JSF called Oracle ADF (application development framework).

screenshot-oraclefreeadf-2012

Experience with it?

I had some hands on experience with it in the past. I was trained for Oracle WebCenter Portal (basically the Enterprise Portal Solution of Oracle) and it uses Oracle ADF extensively in its core.  I was tasked back then to spearhead the implementation of Oracle WebCenter – I created the initial framework, setup, tech archiecture as well as the environment for Oracle WebCenter development. Its such a shame though that it did not push through. Although I wasn’t able to use the technology, I did find it very amusing and interesting – I even tried to create a Portal app of my own and create tutorial slides, but of course it was never really close to being one of my course skill.

A lull came when a particular publishing company contacted me to review their Book regarding Oracle ADF essentials. It was one of my goals to review and publish books of my expertise and this is a great start for me to do that.

So with the topic itself, for the new few days, I’ll try to document everything I learn and found out so far when reviewing the book. Hopefully, it will turn out great. Hopefully, this will be the key to my publisher / book author career. :)

The Book itself!

The Books is titled: Developing Web Applications with Oracle ADF Essentials by PACKT publishing – Author is Sten E. Vesterli

11-10-2013 2-19-03 PM

I read the introductory part of the book and I would say that there’s a lot of motivation behind the creation of this book. The author is a self proclaimed ADF Enthusiast and consider it as his core skill in his career. It was reviewed by number of peers that are highly regarded in their respective field - Eugene Fedorenko – Senior Analyst, Amr Gawish – Senior Oracle Fusion Middleware Consultant and Dimitrios Stasinopoulos – a Certified ADF implementation specialist. From their title alone, you can see that the very reason of the books existence. It was reviewed by technical expert of the field and the technology itself. Much like any other technical books (at least the majority of which), it came with a support files (ebooks, discount offers, downloadable samples). These support files will entirely help any person who uses and wish to learn the technology.

The Chapters!

By looking at the table of contents and chapters – users who wishes to learn the technology will ultimately be interested from the get go. It tackles real world examples as well as beginners journal / entry to the technology. It uses Open source software such as MySQL, GlassFish and the most stable JDK as of this writing, Java 7.

  1. Chapter 1: Basics – Develop your first ADF Essential Application
  2. Chapter 2: Creating business services – using JDeveloper and ADF underlying technological components.
  3. Chapter 3: Creating Task flows – essential for creating process driven applications
  4. Chapter 4: Addition the business logic – Tackles the essentials of creating business logic using the pre-defined set of rules of governance to create such components.
  5. Chapter 5: Building Enterprise Applications – build the structure of your code, apply design patterns, use ADF controls to create an enterprise grade applications. This chapter tackles on the activities (preferred ones) on building Enterprise Applications.
  6. Chapter 6: Debugging ADF Applications – the means of debugging is a general activity for every developer. One must know how to debug, set breakpoints and modify the controls to create the ultimate, valued solution.
  7. Chapter 7: Security – Enterprise applications must be secured since it can be used to manage highly sensitive data. This chapter will focus on implementing security controls on your application.
  8. Chapter 8: Build and Deploy – Finally, build your application and deploy them to a live environment. This chapter will help you create a build and deploy scheme to successfully run the application on a live environment.

I’ll try to be informative as I progress with the review  and put some of my example up here!

int_a

Basic Injection / Qualifiers, Scope


This is a continuation of the DI/CDI Basics tackled last week  - in this post, I’ll be discussing Basic Injection, Qualifiers and Scope.

In our last topic, there we’re a great deal of information regarding the concepts of DI/CDI, we also discussed how these beans or class loaded using the annotations  -that makes up the composition of the object and created samples on how can we declare them programmatically. In this post, we will tackle more on the injection part, e.i how to acquire a certain resource and inject them on another resource for usage.

So how to inject a bean in the first place?

Basic Injection

How do you inject a Bean?

  • Use @Inject <Java-Type> <variable> for field injection
  • <Java-Type> can be Java class or Java interface
public class MyGreeter {
   // Inject Greeting object for field injection
   @Inject Greeting greeting;
   public sayGreeting(String name){
      // You can then used the injected Greeting object
      System.out.println(greeting.greet(name)); 
   }
}

Where can beans be injected?

Bean can be injected at “Injection points”

  • Field
  • Method parameter

Method can be:

  • Constructor (useful for created immutable object) > Initializer
  • Setter method
  • Producer
  • Observer
public class MyGreeter {
   private Greeting greeting;
   // Use constructor method injection
   @Inject
   public MyGreeter(Greeting greeting) {
      this.greeting = greeting; 
   }
   public sayGreeting(String name){
      System.out.println(greeting.greet(name)); 
   }
}

Qualifiers

Qualifiers are used to assign a specific bean if there are multiple implementation type (interface and child classes). Say you have two candidates (implementation class) for a specific interface:

  • Interface is Person
  • Class 1 is Regular Person
  • Class 2 is NonRegular Person

c_diagram_person

We can use Qualifiers to cleanly designate the implementation of classes by introducing / creating an Qualifier annotation of your own:

RegularPerson Qualifier Annotation:

p_qualifier

NonRegularPerson Qualifier Annotation:

non_reg_qualifier

Now we need to create an implementation class and tag it to the Qualifier we created.

RegularPersonImpl:

regular_impl

NonRegularPersonImpl:

non_reg_impl

Note: You can have as many qualifiers as possible – remember that Qualifiers are meant to separate logical objects implementation from its common interface.

Now that the implementation is set, we can now Inject the class and use its qualifier.

implIn this example, you can clearly see the usage, by introducing a Qualifier, developer can clearly specify the implementation type by annotation.

Download the example here.

Other things you can do with Qualifiers?

I won’t be discussing further what else can you do with qualifiers, instead, I’ll give let you check this examples for you to try and explore:

Scope

Why in the first place we need Scope on our Objects? –  For Web applications, we need our beans to hold state over the duration of the user’s interaction with the application, for example, across multiple requests to the server.

There are 5 types of scopes that developers can assign to an object:

  • @Dependent (default)
    • The default scope if none is specified; it means that an object exists to serve exactly one client (bean) and has the same lifecycle as that client (bean).
  • @RequestScoped
    • State of an object is maintained during a user’s interaction with web application in a single HTTP request.
  • @SessionScoped
    • State of an object is maintained during user’s interaction with a web application across multiple HTTP requests.
  • @ApplicationScoped
    • Shared state across all users’ interactions with a web application.
  • @ConversationScoped
    • Conversation context is demarcated explicitly by the application
      • Spans multiple requests
      • But “Smaller” than session
    • Used when you want to have explicit boundaries of multiple conversations within a single session

I won’t be diving into the details here but what I’ll provide you are actual examples that you can run. Download the projects here.

Next Stop: DI / CDI – Advance

With this new features, you can clearly observe and imagine how it will improve developer productivity by simplifying a lot of processes to setup a Web Application – Qualifiers can be created to clearly separate logical / business beans with a common goal (by interface), scoping let developers control the flow and manage the state of objects – and the simplification of calling beans directly from the UI thru EL makes it more straightforward.

Please do check the samples and try them on your own, it would be better to check an actual example than by just reading thru the details and concepts. Enjoy!

feature_1

DI / CDI – Basics


Introduction (DI/CDI Basics)

First of all, I would assume there is a bit of confusion to this, but the truth of the matter is, they are just the same – the difference is that usage and its purpose.

DI (Dependency Injection) is the general term  - this feature is basically the one doing the bean discovery and bean wiring process on any application. Its not just you use it in your application, you can also use it in your unit tests and mocks. Of course, there are a lot of DI frameworks out there, you have: Guice, Seam, Spring (Seam and Spring extended the DI scheme and made their own), EJB 3.x and CDI itself.

CDI on the other hand, combines all this technology and introduce a lifecycle to the components – this allowed unification of DI technologies to making development of new features straight forward and mostly doable; you can combine Seams lifecycle mappings with Spring MVC with JPA as its persistence layer – these technologies were all created separately yet with CDI, application developers can combine them to create and development JEE application.

I will need to break down the topics as I would definitely bore everyone with words and letters here so:

  1. DI / CDI Basics
  2. Basic Injection
  3. Qualifiers, Scope
  4. DI / CDI Advance

I will be creating separate posts for each!

Lets Begin! 

SPI (Service Programming Interface)

It also has this so called SPI – apparently a feature set along with API, but has a different purpose entirely.

  • The API is the description of classes/interfaces/methods/… that you call and use to achieve a goal.
  • The SPI is the description of classes/interfaces/methods/… that you extend and implement to achieve a goal.

With SPI, you can actually extend the JEE6 to create a different framework of your own, showcasing portability, and extensibility. (But I’ll dive into that later).

Why CDI for JEE6?

CDI has been around in JEE5 (J2EE) and has been a major success. A lot of new development benefits from its approach that ultimately simplifies the overall development process. Several reasons why CDI was improved in JEE6.

  • JEE5 do support resource injection, but it still lacks a general purpose dependency – it only supports @EJB, @PersistenceContext, @PersistenceUnit, @Resources) – of course this is with the exception of Spring that introduce different annotations for managing bean lifecycle
  • Non-type based injection (and weak)  - String name and XML injection is really fragile. Improving type-based injetcion enables better tooling in general.

Terminology

CDI – Context and Dependency Injection

Weld

  • JSR 299 reference implementation – reference implementation is the SPI used to etxend a JSR specific implementation.
  • Provides extended CDI support for Servlet Container.
  • CDI enhancements for extension writers.
  • Maven Archetypes for CDI and Java EE (I love maven!).

CDI Theme: Loose Coupling and Strong Typed

Loose coupling simply means objects is loosely independent to the objects that uses or currently using them. CDI introduces new features for decoupling such as qualifiers, enhances interceptors, decorators, message producer, consumer and its underlying events mechanisms. Will dive further in to each example on the advance topic of CDI.

Strong Typing - simply means that strict declaration of beans by letting the container create and map specific names to objects. This eliminates the need to do string based naming of beans, casting almost not needed since the casting is done by the container (by taking advantage of qualifiers).

Bean (What is it?)

There are technically many form of beans, you have: JSF Bean, EJB Bean, Spring, Seam, Guice CDI, Entity Beans, etc – but ultimately, beans are just POJOs that has special definition – definition that was defined by the Managed Bean 1.0 – specification made in Java EE6. What does this mean is that any POJOs can be any type of bean, as long as it complies with the specification standards – further simplifying the declaration and development process. The container does the work for managing the POJOs and will add support for it by giving / introducing common basic services such as:

  • Lifecycle Management (@PostConstruct, @PreDestory)
  • Injection of a resource (@Resource)
  • Interceptor (@Interceptors, @ArounInvoke)
@javax.annotation.ManagedBean
public class MyPojo {

@Resource   // Resource injection
private Datasource ds;

@PostConstruct  // Life-cycle
private void init() {
   ....
}  
@Interceptors(LoggingInterceptor.class)
   public void myMethod() {...}
}

With this in mind, what about EJBs, RESTs and CDI beans?

  • EJB bean service – managed bean, with the common services (above) and support for Transaction, security, thread safety and persistence.
  • REST bean service – managed bean with HTTP support
  • CDI bean – managed bean with lifecycle supports:
    • Auto discovery
    • Qualifiers
    • Scope
    • EL
    • Interceptors and Decorators
    • Alternative bean (by Qualifiers at runtime)

To put it into perspective, Manage Bean is ultimately an SPI that was extended for specific use. EJBs, Rest, Entity beans are all Managed Beans – but with additional services from the container. Thus, if you define a POJO with a @Stateless or @Stateful annotation, the container automatically detects that its an EJB bean and it needs container specific support like transactions, security, thread safety, extensions etc.

package mypackage;
import javax.ejb.Stateless;

@Stateless
public class GreetingBean {
  public String greet(String name){
      return "Hello " + name;
   }
}

A simple POJO class turned into a Stateless bean with just a flick of finger (actually typed in) that resulted to that one liner @Stateless code. Unlike how EJB was defined on the priori 3.x (such a pain).

Download the sample (above) from here: Click me

Automatic Bean Discovery

The CDI container is the one responsible for how the beans are discovered, but how does it do it?

  1. It first scan the classpath that contains both application and container archives.
    1. It tries to scan through the classpath and see what POJOs are tag for discovery – that is, Managed Bean. You can think of it that it puts in a pool and can readily available when another Managed Bean calls it thru injection (more on that on next blog topic)
  2. Then it detects presence of beans.xml (or any context xml file definition).
    1. For Spring fans, this is much like an applicationContext.xml (at least thats the convention, but loose) – you pass that xml on the contextConfiguration listener (thru parameter) and Spring CDI Container will automatically tag objects (beans) in it for discovery – of course you need to define scanning mechanisms (component-scan).

Ultimately, DI / CDI was introduce to simplify the development process, unify the technologies and overall to produce a more robust, extendible application. Letting all the container do the work in terms of tagging the common services of the bean makes the developer task easier and more over avoiding pitfalls as a result of previous frameworks. SPI – is really the definition of improvement here, allowing the actually JEE6 framework to be extendible creates a more dynamic nature – business application architects can now design their own framework and conventions. Put more business specific designs or annotations for their own rules and give the robustness and flexibility that is always required for enterprise application.

Next Topic: Basic Injection – I don’t want to put everything in one post, so I’ll leave it up to you to absorb first and check the sample I created. From here on now, I’ll tackle more on the examples of DI and CDI.