A common issue faced by enterprise application builders is how to fit together different elements, such as web controller architectures with DB interfaces, when they were built by different teams with little knowledge of eachother. IoC literally inverts control so that instead of application code calling libraries, libraries call the application code based on events occurring.
A good example of early IoC is the change in UIs, from being controlled by the application workflow, to GUIs which are controlled by events.
Another term for IoC is dependency injection, introduced by Martin Fowler, which is explained as follows: "The basic idea of Dependency Injection is to have a separate object, an assembler, that populates a field in X class with an implementation for Y interface."
Tuesday, July 13, 2010
JBoss Application Server Overview
JBoss is a J2EE compatible application server that has full support for J2EE web services and the SOA. It supports the AOP model for developing middleware solutions and integrates well with Hibernate (object persistence framework).
The JBoss architecture consists of the microcontainer, bootstrap beans loaded into the microcontainer, a collection of deployers for loading various deployment types, and various mbean (managed beans - Java objects that represent resources to be managed) and legacy mbean deployments.
The JBoss Microcontainer is a lightweight container for managing POJOs, their deployment, configuration, and lifecycle.
You don't have to run a monolithic server all the time, but may remove components that are not required and integrate additional services as required, into JBoss by writing your own mbeans.
The JBoss AS ships with a number of different server configurations:
<JBoss_Home>\server\
<JBoss_Home>\server\<instance-name>\deployers or deploy.
JBoss provides an embedded Hypersonic database along with a default datasource to connect applications to.
When the JBoss server is running, you can get a live view of the server by going to the JMX console application. This is a raw view of JMX beans which make up the server.
In JBoss, log4j is used for logging, controlled by conf/jboss-log4j.xml. The default output file is the server.log.
The JBoss AS comes with clustering support out of the box. Ina JBoss cluster, a node is a JBoss server instance. A cluster (partition) contains a set of nodes that work toward some goal. The JBoss AS supports two types of clustering architectures - client side interceptors (proxies/stubs), and load balancers.
The JBoss architecture consists of the microcontainer, bootstrap beans loaded into the microcontainer, a collection of deployers for loading various deployment types, and various mbean (managed beans - Java objects that represent resources to be managed) and legacy mbean deployments.
The JBoss Microcontainer is a lightweight container for managing POJOs, their deployment, configuration, and lifecycle.
You don't have to run a monolithic server all the time, but may remove components that are not required and integrate additional services as required, into JBoss by writing your own mbeans.
The JBoss AS ships with a number of different server configurations:
<JBoss_Home>\server\
- minimal - bare-bones server, no web container, EJB, or JMS support
- default - a default set of services
- standard - the Java EE5 certified configuration of services
- all - all available services
- web - lightweight web container-oriented configuration of services
<JBoss_Home>\server\<instance-name>\deployers or deploy.
JBoss provides an embedded Hypersonic database along with a default datasource to connect applications to.
When the JBoss server is running, you can get a live view of the server by going to the JMX console application. This is a raw view of JMX beans which make up the server.
In JBoss, log4j is used for logging, controlled by conf/jboss-log4j.xml. The default output file is the server.log.
The JBoss AS comes with clustering support out of the box. Ina JBoss cluster, a node is a JBoss server instance. A cluster (partition) contains a set of nodes that work toward some goal. The JBoss AS supports two types of clustering architectures - client side interceptors (proxies/stubs), and load balancers.
Monday, July 12, 2010
JSP Overview
JSP is a popular Java technology for web application development and is based on servlet technology. A JSP page is a text document that contains two types of text - static data which can be expressed in any text-based format (HTML, SVG, XML, etc) and JSP elements (standard JSP or XML) which construct dynamic content.
A JSP page services requests as a servlet. In an application server, the source for the servlet created from a JSP named myPage is myPage_jsp.java. Once the JSP has been translated and compiled, the page's servlet follows the standard servlet lifecycle.
Expressions that are evaluated immediately use the ${ } syntax. Expressions that are differed use the #{ } syntax. Immediate evaluation expressions are always read-only value expressions.
Implicit objects include:
To declare that a JSP page will use tags defined in a tag library, include the taglib directive.
An Applet or JavaBeans component can be included in a JSP by using the jsp:plugin element.
A JSP page services requests as a servlet. In an application server, the source for the servlet created from a JSP named myPage is myPage_jsp.java. Once the JSP has been translated and compiled, the page's servlet follows the standard servlet lifecycle.
Expressions that are evaluated immediately use the ${ } syntax. Expressions that are differed use the #{ } syntax. Immediate evaluation expressions are always read-only value expressions.
Implicit objects include:
- PageContext
- Servlet Context
- Session
- Request
- Response
- etc.
- The JSP:useBean element declares that the page will use a bean that is stored within and is accessible from the specified scope (application, session, request, or page)
- jsp:setProperty
- jsp:getProperty
To declare that a JSP page will use tags defined in a tag library, include the taglib directive.
An Applet or JavaBeans component can be included in a JSP by using the jsp:plugin element.
Friday, July 9, 2010
The REST architectural style
REST, Representational State Transfer, is an architural style that captures (post-hoc) the characteristics of the Web that made it so successful. It is a simpler alternative to SOAP and WSDL-based Web Services, where a representation of the requested resource is returned.
A concrete implementation of a REST web service follows four basic design principles:
The JAX-RS provides full support for building and deploying RESTful web services. It offers a number of utility classes and interfaces, and declarative annotations that allow you to:
A concrete implementation of a REST web service follows four basic design principles:
- Uses HTTP methods explicitly (POST, GET, PUT, DELETE)
- Stateless
- Exposes directure structure
- Transfer XML, Javascript Object Notation, or both
The JAX-RS provides full support for building and deploying RESTful web services. It offers a number of utility classes and interfaces, and declarative annotations that allow you to:
- Identify components of the application
- route requests to particular methods/classes
- extract data from requests into arguments of methods
- provide metadata used in responses
Hibernate
Hibernate is a Java framework that provides OR mapping functionality to define how Java objects are stored, modified, deleted, and retrieved.
The Hibernate architecture has 3 main components:
The Hibernate Session is the main runtime interface between a Java application and Hibernate. SessionFactory allows the application to create a Hibernate Session by reading the configuration from hibernate.cfg.xml.
Important elements of the Hibernate mapping file include the following:
Hibernate also supports native SQL statements.
The Hibernate architecture has 3 main components:
- connection management
- transaction management
- object-relational mapping
The Hibernate Session is the main runtime interface between a Java application and Hibernate. SessionFactory allows the application to create a Hibernate Session by reading the configuration from hibernate.cfg.xml.
Important elements of the Hibernate mapping file include the following:
- <hibernate-mapping> root element
- <class> maps classes to DB entities
- <id> maps to the primary key of a table
- <generator> is used to generate the primary key for a new record. Values include increment, sequence, and assigned
- <property> maps attributes to columns
Hibernate also supports native SQL statements.
SOAP vs other protocols
SOAP (Simple Object Access Protocol) is an XML-based protocol that allows objects of any kind (Java, COM, etc.) on any platform and in any language to communicate. SOAP follows a RPC-style request/response mechanism. Data can be serialised without regard to any specific transport protocol, although HTTP is typically the protocol of choice.
RMI, SOAP's chief competitor, is the process of activating a method on a remotely running object. Java RMI provides a mechanism for supporting distributed computing.
In RMI, a remote method is invoked directly through a remote object's stub.The invocation and results are encoded across the network. The biggest advantage here is:
RMI, SOAP's chief competitor, is the process of activating a method on a remotely running object. Java RMI provides a mechanism for supporting distributed computing.
In RMI, a remote method is invoked directly through a remote object's stub.The invocation and results are encoded across the network. The biggest advantage here is:
- type-safety - the direct use of method names is possible and compile-time errors occur if arguments are incorrect
- greater independence between client and server
Monday, July 5, 2010
Overriding HashCode
Overriding the default implementations of the Java class equals method provides a higher degree of semantic comparability between object instances. Under the default implementation, two references are equal only if they refer to the exact same object.
Cases where hashCode must be overridden include the following:
Cases where hashCode must be overridden include the following:
- if a class overrides the equals method it must override hashCode
- when they are both overridden, equals and hashCode must use the same set of fields
- if two objects are equal, then their hashCode values must be equal as well
A simple way of overriding the equals and hashcode methods in Eclipse is to generate them using the menu/context menu Source -> Generate hashCode() and equals().
All hash-based collections assume that an object's hash value will not change whilst it is in use as a key in the collection. If assumption were violated unpredictable results would occur.
PL/SQL Overview
PL/SQL bridges the gap between database technology and procedural programming languages. PL/SQL allows the use of SQL statements to manipulate Oracle data and flow-of-control statements to process the data. You can also:
And example PL/SQL script is given below (taken from Oracle docs):
Oracle uses work areas to execute SQL statements and store processing information. A
PL/SQL cursor is a construct that lets you name a work area and access its stored information. There are two kinds of cursors: implicit and explicit. PL/SQL implicitly declares a cursor for all SQL data manipulation statements, including queries that return only one row. For queries that return more than one row, you can explicitly declare a cursor to process the rows individually. For example (taken from Oracle docs):
- declare constants and variables
- define procedures and functions
- trap runtime errors.
And example PL/SQL script is given below (taken from Oracle docs):
DECLARE qty_on_hand NUMBER(5); BEGIN SELECT quantity INTO qty_on_hand FROM inventory WHERE product = 'TENNIS RACKET' FOR UPDATE OF quantity; IF qty_on_hand > 0 THEN -- check quantity UPDATE inventory SET quantity = quantity - 1 WHERE product = 'TENNIS RACKET'; INSERT INTO purchase_record VALUES ('Tennis racket purchased', SYSDATE); ELSE INSERT INTO purchase_record VALUES ('Out of tennis rackets', SYSDATE); END IF; COMMIT; END;
Control structures are the most important PL/SQL extension to SQL. PL/SQL provides the following control structures:
- if-then-else
- case
- for loop
- while loop
- exit when
- goto
Oracle uses work areas to execute SQL statements and store processing information. A
PL/SQL cursor is a construct that lets you name a work area and access its stored information. There are two kinds of cursors: implicit and explicit. PL/SQL implicitly declares a cursor for all SQL data manipulation statements, including queries that return only one row. For queries that return more than one row, you can explicitly declare a cursor to process the rows individually. For example (taken from Oracle docs):
DECLARE CURSOR c1 IS SELECT empno, ename, job FROM emp WHERE deptno = 20;
... BEGIN FOR emp_rec IN c1 LOOP ... salary_total := salary_total + emp_rec.sal; END LOOP;
The query returns a result set and the cursor allows you to process one row at the time.
Data Warehousing Concepts
A data warehouse is a non-volatile copy of data that is usually also subject-oriented, time-variant, and integrated from multiple data sources.
- non-volatile: Once the data is in the warehouse it will not be modified or deleted
- subject-oriented: The data is usually designed to facilitate analysis and reporting for a particular subject area (eg: sales)
- time-variant:Historical data is stored, as opposed to just the latest relevant transaction
- integrated: Data from multiple sources is merged into the warehouse
Thursday, July 1, 2010
Spring Overview
Spring is an open source framework created to address the complexity of enterprise application development and promote good programming practices. It does this by enabling a POJO-based programming model that is applicable in a wide range of environemnts.
Spring has a layered architecture so almost any part of it can be used in isolation. For example, Spring may be used just to simplify use of JDBC.
It consists of the following 7 modules:
The ApplicationContext builds on top of the BeanFactory and adds other functionality, such as easier integration with AOP features, message resource handling, event propagation, etc.
Spring has a layered architecture so almost any part of it can be used in isolation. For example, Spring may be used just to simplify use of JDBC.
It consists of the following 7 modules:
- Core container module - provides the IoC features
- Application context module -
- AOP module - provides an AOP implementation
- ORM module - provides integration layers for popular OR mapping APIs (eg: JPA, JDO, Hibernate)
- DAO module - provides a JDBC abstraction layer
- Web module - provides basic web-oriented integration features
- MVC framework - provides a MVC implementation for web applications
The ApplicationContext builds on top of the BeanFactory and adds other functionality, such as easier integration with AOP features, message resource handling, event propagation, etc.
Struts Overview
Struts is an open-source web application framework for developing servlet/JSP based applications. It concentrates on the web tier, and aside from providing a simple JDBC connection pool, does not attempt to address persistence requirements.
It does, however, suggest the use of a domain object model and business logic beans, and its tag libraries include a number of tags for working with JavaBeans.
The Struts framework provides 3 key components:
It does, however, suggest the use of a domain object model and business logic beans, and its tag libraries include a number of tags for working with JavaBeans.
The Struts framework provides 3 key components:
- A request handler provided by the application developer that is mapped to a standard URI.
- A response handler that transfers control to another resource which completes the response.
- A tag library that helps developers create interactive form-based applications with server pages.
- A servlet controller, which is provided by Struts
- JSP pages (the view)
- The application's business logic (the model)