Tuesday, July 28, 2009

Entity Bean's Ready State & Pooled State

The idea of the “Pooled State” is to allow a container to maintain a pool of entity beans that has been created, but has not been yet “synchronized” or assigned to an EJBObject. This mean that the instances do represent entity beans, but they can be used only for serving Home methods (create or findBy), since those methods do not relay on the specific values of the bean.

All these instances are, in fact, exactly the same, so, they do not have meaningful state. It can be looked at it this way

If no client is using an entity bean of a particular type there is no need for caching it (the data is persisted in the database). Therefore, in such cases, the container will, after some time, move the entity bean from the “Ready State” to the “Pooled state” to save memory. Then, to save additional memory, the container may begin moving entity beans from the “Pooled State” to the “Does Not Exist State", because even though the bean’s cache has been cleared, the bean still takes up some memory just being in the “Pooled State".

Read more...

Sunday, July 26, 2009

Struts 2

Programming the abstract classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework

Most of the Struts 2 classes are based on interfaces and most of its core interfaces are HTTP independent

Unlike ActionForwards, Struts 2 Results provide flexibility to create multiple type of
outputs

In Struts 2 any java class with execute() method can be used as an Action class

ActionForms feature is no more known to the Struts 2 framework. Simple JavaBean flavored actions are used to put properties directly

Struts 2 Actions are HTTP independent and framework neutral. This enables to test struts applications very easily without resorting to mock objects

Java 5 annotations can be used as an alternative to XML and Java properties configuration

Struts 2 lets to customize the request handling per action, if desired. Struts 1 lets to customize the request processor per module

Struts 2 Actions are Spring-aware.Just need to add Spring beans

AJAX client side validation

Read more...

Thursday, July 23, 2009

Hibernate 3 Features

Hibernate 3’s “Hibernate for the Enterprise” focus has built on the success of Hibernate 2 and extended it with enterprise class functionality includes following additional features

  • Support for EJB 3.0 Annotations, Entity Manager, and Java Persistence API
  • ORM improvements that support virtualized filtering for temporal, historical, regional, and permissioned data
  • Single object to multi-table mapping, bulk update and delete by query, and the ability to override generated SQL with hand-written SQL
  • JMX-enabled statistics reporting and monitoring through any JMX console
  • XML binding that enables data to be represented as XML and Java objects interchangeably
  • Event-driven design that enables custom event objects to be created and registered to handle auditing scenarios or cascaded behavior semantics

Read more...

Wednesday, July 8, 2009

Pragmatic Ajax: A Web 2.0 Primer

Pragmatic Ajax: A Web 2.0 Primer eBook

Ajax turns static web pages into interactive applications. Now you can deploy rich-client applications to clients without sacrificing the easy deployment of web applications. But to many folks, Ajax seems difficult. That’s why we produced this book. As a Pragmatic guide, it strips away the mystery and shows you the easy way to make Ajax work for you.


Writing dynamic applications isn’t that hard. Folks are awed by Google Maps, but it isn’t rocket science (apart from the satellite pictures). As a special bonus, see how to implement your own Google Maps-like application using DHTML.

We cover the the basics of DHTML, JavaScript, and the infamous XmlHttpRequest call. You’ll see how to add Ajax to existing programs, and design new applications to exploit the power of Web 2.0. Learn the three layers of Ajax framework, and when (and how) to use each. See how to create rich clients, use visual effects, add client-side validation, and handle forms. Write applications that degrade gracefully if clients don’t support JavaScript. And see how to integrate your Ajaxified clients into Java, .NET, and Ruby on Rails server frameworks.

Authors: Justin Gehtland, Ben Galbraith, Dion Almaer

Read more...

Tuesday, July 7, 2009

Struts Framework Tag Libraries

The Struts framework includes custom JSP tag libraries that you can use to create JSP pages that work with the rest of the Struts framework objects in your web application

Struts HTML Tags

Used to create Struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces.

Struts Bean Tags

Useful in accessing beans and their properties, as well as defining new beans (based on these accesses) that are accessible to the remainder of the page via scripting variables and page scope attributes. Convenient mechanisms to create new beans based on the value of request cookies, headers, and parameters are also provided.

Struts Logic tag

Useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management.

Struts Nested

Brings a nested context to the functionality of the Struts custom tag library. The purpose of this tag library is to enable the tags to be aware of the tags which surround them so they can correctly provide the nesting property reference to the Struts system.

Struts Tiles Tags

Provides tiles tags. Tiles were previously called Components.

Struts Templates

Three tags: put, get, and insert. A put tag moves content into request scope, which is retrieved by a get tag in a different JSP page. That template is included with the insert tag. Tags from the various Struts custom JSP tag libraries appear in JDeveloper on the Component Palette.

Read more...

Monday, July 6, 2009

Entity Bean Method Types

Entity bean is used to represent data in the database. It provides an object-oriented interface to data that would normally be accessed by the JDBC or some other back-end API. More than that, entity beans provide a component model that allows bean developers to focus their attention on the business logic of the bean, while the container takes care of managing persistence, transactions, and access control.

An entity bean consists of 4 types of methods

create() methods

To create a new instance of a CMP entity bean, and therefore insert data into the database, the create() method on the bean's home interface must be invoked. They look like this: EntityBeanClass ejbCreateXXX(parameters), where EntityBeanClass is an Entity Bean you are trying to instantiate, ejbCreateXXX(parameters) methods are used for creating Entity Bean instances according to the parameters specified and to some programmer-defined conditions.

A bean's home interface may declare zero or more create() methods, each of which must have corresponding ejbCreate() and ejbPostCreate() methods in the bean class. These creation methods are linked at run time, so that when a create() method is invoked on the home interface, the container delegates the invocation to the corresponding ejbCreate() and ejbPostCreate() methods on the bean class.

finder() methods

The methods in the home interface that begin with "find" are called the find methods. These are used to query the EJB server for specific entity beans, based on the name of the method and arguments passed. Unfortunately, there is no standard query language defined for find methods, so each vendor will implement the find method differently. In CMP entity beans, the find methods are not implemented with matching methods in the bean class containers implement them when the bean is deployed in a vendor specific manner.

The deployer will use vendor specific tools to tell the container how a particular find method should behave. Some vendors will use object-relational mapping tools to define the behavior of a find method while others will simply require the deployer to enter the appropriate SQL command.

There are two basic kinds of find methods: single-entity and multi-entity. Single-entity find methods return a remote reference to the one specific entity bean that matches the find request. If no entity beans are found, the method throws an ObjectNotFoundException . Every entity bean must define the single-entity find method with the method name findByPrimaryKey(), which takes the bean's primary key type as an argument. The multi-entity find methods return a collection ( Enumeration or Collection type) of entities that match the find request. If no entities are found, the multi-entity find returns an empty collection.

remove() methods

These methods (you may have up to 2 remove methods, or don't have them at all) allow the client to physically remove Entity beans by specifying either Handle or a Primary Key for the Entity Bean.

home() methods

These methods are designed and implemented by a developer, and EJB specification doesn't have any requirements for them except the need to throw a RemoteException is each home method.

Read more...

Sunday, July 5, 2009

Struts and JSP

Struts makes it possible for JSP pages to externalize flow control, rather than specify physical links to various JSP pages within the JSP file, the JSP file contains a Struts-defined logical URI. The Struts URI defines a logical page request mapped to actions that may return different physical JSP pages depending on the context of the HTTP request.

Struts simplifies the development of the actual JSP file content by limiting it to user interface generation only. Java that would otherwise appear inside the JSP files appears in separate servlet action classes that the JSP page invokes at runtime.

Struts helps to separate the development roles into user interface designer (HTML or tag library user) and JSP action-handler developer. For example, one person can write JSP page using only HTML or suitable tag libraries, while another person works independently to create the page action handling classes in Java.

Struts externalizes JSP actions that would otherwise appear inside all the JSP pages of your project into a single configuration file. This greatly simplifies debugging and promotes reuse. Struts consolidates String resources that would otherwise appear inside all the JSP pages of your project into a single file. This simplifies the task of localizing JSP applications.

Read more...

Wednesday, July 1, 2009

Storing Images into Database using JDBC

We can store images into database using BLOB data type and also managing SQL 92 data types (BLOB, CLOB and Ref)

BLOB (Binary Large OBject)

  • Used to store binary informations like images, audio files etc
  • For each byte one byte of memory will be allocated
  • Size can vary up to 4GB for each entry
CLOB (Character LOB)
  • Used to store character information like plain, word documents
  • For each character two bytes of memory is allocated
  • Size up to 4GB
StoreImage.java
import java.sql.*;
import java.io.*;

public class StoreImage
{
public static void main(String rags[]) throws Exception

{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:yourdsn","scott", "tiger");
PreparedStatement pstmt=con.prepareStatement
("insert into ImgStore values(?,?)");

File f=new File("pic.jpg");
FileInputStream fis=new FileInputStream(f);

pstmt.setInt(1, 1);
pstmt.setBinaryStream(2, fis, (int)f.length());
int i=pstmt.executeUpdate();
System.out.println(i+" record inserted");
pstmt.close();
con.close();
}
}
sqlplus scott/tiger
cle scr
--create table ImgStore (id number, image BLOB);

ImageRestore.java
import java.io.*;
import java.sql.*;

public class RestoreImage
{
public static void main(String rags[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:yourdsn","scott", "tiger");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from temp");
if(rs.next())
{
System.out.println(rs.getInt(1));
InputStream in=rs.getBinaryStream(2);

FileOutputStream fos=new FileOutputStream("pic1.jpg");
int i=in.read();
while(i!=-1)
{
fos.write(i);
i=in.read();
}
fos.close();
in.close();
}
rs.close();

stmt.close();
con.close();
}
}

Read more...
Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP