Wednesday, 5 November 2008

Describ how the principle of "separation of concerns" has been applied to the layers of a Java EE application. Layers include application, virtual pl


Java EE Application

A Java EE application is packaged into one or more standard units for deployment to any Java EE platform-compliant system. Each unit contains:


A functional component or components (enterprise bean, JSP page, servlet, applet, etc.)

An optional deployment descriptor that describes its content


Once a Java EE unit has been produced, it is ready to be deployed. Deployment typically involves using a platform's deployment tool to specify location-specific information, such as a list of local users that can access it and the name of the local database. Once deployed on a local platform, the application is ready to run.

A Java EE application is delivered in an Enterprise Archive (EAR) file, a standard Java Archive (JAR) file with an .ear extension. Using EAR files and modules makes it possible to assemble a number of different Java EE applications using some of the same components. No extra coding is needed; it is only a matter of assembling (or packaging) various Java EE modules into Java EE EAR files.

An EAR file contains Java EE modules and deployment descriptors. A deployment descriptor is an XML document with an .xml extension that describes the deployment settings of an application, a module, or a component. Because deployment descriptor information is declarative, it can be changed without the need to modify the source code. At runtime, the Java EE server reads the deployment descriptor and acts upon the application, module, or component accordingly.

A Java EE module consists of one or more Java EE components for the same container type and one component deployment descriptor of that type. An enterprise bean module deployment descriptor, for example, declares transaction attributes and security authorizations for an enterprise bean. A Java EE module without an application deployment descriptor can be deployed as a stand-alone module. The four types of Java EE modules are as follows:


EJB modules, which contain class files for enterprise beans and an EJB deployment descriptor. EJB modules are packaged as JAR files with a .jar extension.

Web modules, which contain servlet class files, JSP files, supporting class files, GIF and HTML files, and a web application deployment descriptor. Web modules are packaged as JAR files with a .war (Web ARchive) extension.

Application client modules, which contain class files and an application client deployment descriptor. Application client modules are packaged as JAR files with a .jar extension.

Resource adapter modules, which contain all Java interfaces, classes, native libraries, and other documentation, along with the resource adapter deployment descriptor. Together, these implement the Connector architecture (J2EE Connector Architecture) for a particular EIS. Resource adapter modules are packaged as JAR files with an .rar (resource adapter archive) extension.


Java EE 5 APIs





Enterprise JavaBeans Technology

An Enterprise JavaBeans (EJB) component, or enterprise bean, is a body of code having fields and methods to implement modules of business logic. You can think of an enterprise bean as a building block that can be used alone or with other enterprise beans to execute business logic on the Java EE server.

There are two kinds of enterprise beans: session beans and message-driven beans. A session bean represents a transient conversation with a client. When the client finishes executing, the session bean and its data are gone. A message-driven bean combines features of a session bean and a message listener, allowing a business component to receive messages asynchronously. Commonly, these are Java Message Service (JMS) messages.

In Java EE 5, entity beans have been replaced by Java persistence API entities. An entity represents persistent data stored in one row of a database table. If the client terminates, or if the server shuts down, the persistence manager ensures that the entity data is saved.

Java Servlet Technology

Java servlet technology lets you define HTTP-specific servlet classes. A servlet class extends the capabilities of servers that host applications that are accessed by way of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers.

JavaServer Pages Technology

JavaServer Pages (JSP) technology lets you put snippets of servlet code directly into a text-based document. A JSP page is a text-based document that contains two types of text: static data (which can be expressed in any text-based format such as HTML, WML, and XML) and JSP elements, which determine how the page constructs dynamic content.

JavaServer Pages Standard Tag Library

The JavaServer Pages Standard Tag Library (JSTL) encapsulates core functionality common to many JSP applications. Instead of mixing tags from numerous vendors in your JSP applications, you employ a single, standard set of tags. This standardization allows you to deploy your applications on any JSP container that supports JSTL and makes it more likely that the implementation of the tags is optimized.

JSTL has iterator and conditional tags for handling flow control, tags for manipulating XML documents, internationalization tags, tags for accessing databases using SQL, and commonly used functions.

JavaServer Faces

JavaServer Faces technology is a user interface framework for building web applications. The main components of JavaServer Faces technology are as follows:


A GUI component framework.

A flexible model for rendering components in different kinds of HTML or different markup languages and technologies. A Renderer object generates the markup to render the component and converts the data stored in a model object to types that can be represented in a view.

A standard RenderKit for generating HTML/4.01 markup.


The following features support the GUI components:


Input validation

Event handling

Data conversion between model objects and components

Managed model object creation

Page navigation configuration


All this functionality is available using standard Java APIs and XML-based configuration files.

Java Message Service API

The Java Message Service (JMS) API is a messaging standard that allows Java EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.

Java Transaction API

The Java Transaction API (JTA) provides a standard interface for demarcating transactions. The Java EE architecture provides a default auto commit to handle transaction commits and rollbacks. An auto commit means that any other applications that are viewing data will see the updated data after each database read or write operation. However, if your application performs two separate database access operations that depend on each other, you will want to use the JTA API to demarcate where the entire transaction, including both operations, begins, rolls back, and commits.

JavaMail API

Java EE applications use the JavaMail API to send email notifications. The JavaMail API has two parts: an application-level interface used by the application components to send mail, and a service provider interface. The Java EE platform includes JavaMail with a service provider that allows application components to send Internet mail.

JavaBeans Activation Framework

The JavaBeans Activation Framework (JAF) is included because JavaMail uses it. JAF provides standard services to determine the type of an arbitrary piece of data, encapsulate access to it, discover the operations available on it, and create the appropriate JavaBeans component to perform those operations.

Java API for XML Processing

The Java API for XML Processing (JAXP), part of the Java SE platform, supports the processing of XML documents using Document Object Model (DOM), Simple API for XML (SAX), and Extensible Stylesheet Language Transformations (XSLT). JAXP enables applications to parse and transform XML documents independent of a particular XML processing implementation.

JAXP also provides namespace support, which lets you work with schemas that might otherwise have naming conflicts. Designed to be flexible, JAXP lets you use any XML-compliant parser or XSL processor from within your application and supports the W3C schema.

Java API for XML Web Services (JAX-WS)

The JAX-WS specification provides support for web services that use the JAXB API for binding XML data to Java objects. The JAX-WS specification defines client APIs for accessing web services as well as techniques for implementing web service endpoints. The Web Services for J2EE specification describes the deployment of JAX-WS-based services and clients. The EJB and servlet specifications also describe aspects of such deployment. It must be possible to deploy JAX-WS-based applications using any of these deployment models.

The JAX-WS specification describes the support for message handlers that can process message requests and responses. In general, these message handlers execute in the same container and with the same privileges and execution context as the JAX-WS client or endpoint component with which they are associated. These message handlers have access to the same JNDI java:comp/env namespace as their associated component. Custom serializers and deserializers, if supported, are treated in the same way as message handlers.

Java Architecture for XML Binding (JAXB)

The Java Architecture for XML Binding (JAXB) provides a convenient way to bind an XML schema to a representation in Java language programs. JAXB can be used independently or in combination with JAX-WS, where it provides a standard data binding for web service messages. All Java EE application client containers, web containers, and EJB containers support the JAXB API.

SOAP with Attachments API for Java

The SOAP with Attachments API for Java (SAAJ) is a low-level API on which JAX-WS and JAXR depend. SAAJ enables the production and consumption of messages that conform to the SOAP 1.1 specification and SOAP with Attachments note. Most developers do not use the SAAJ API, instead using the higherlevel JAX-WS API.

Java API for XML Registries

The Java API for XML Registries (JAXR) lets you access business and general-purpose registries over the web. JAXR supports the ebXML Registry and Repository standards and the emerging UDDI specifications. By using JAXR, developers can learn a single API and gain access to both of these important registry technologies.

Additionally, businesses can submit material to be shared and search for material that others have submitted. Standards groups have developed schemas for particular kinds of XML documents; two businesses might, for example, agree to use the schema for their industry’s standard purchase order form. Because the schema is stored in a standard business registry, both parties can use JAXR to access it.

J2EE Connector Architecture (JCA)

The J2EE Connector architecture is used by tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged in to any Java EE product. A resource adapter is a software component that allows Java EE application components to access and interact with the underlying resource manager of the EIS. Because a resource adapter is specific to its resource manager, typically there is a different resource adapter for each type of database or enterprise information system.

The J2EE Connector architecture also provides a performance-oriented, secure, scalable, and message-based transactional integration of Java EE-based web services with existing EISs that can be either synchronous or asynchronous. Existing applications and EISs integrated through the J2EE Connector architecture into the Java EE platform can be exposed as XML-based web services by using JAX-WS and Java EE component models. Thus JAX-WS and the J2EE Connector architecture are complementary technologies for enterprise application integration (EAI) and end-to-end business integration.

Java Database Connectivity (JDBC) API

The Java Database Connectivity (JDBC) API lets you invoke SQL commands from Java programming language methods. You use the JDBC API in an enterprise bean when you have a session bean access the database. You can also use the JDBC API from a servlet or a JSP page to access the database directly without going through an enterprise bean.

The JDBC API has two parts: an application-level interface used by the application components to access a database, and a service provider interface to attach a JDBC driver to the Java EE platform.

Java Persistence API (JPA)

The Java Persistence API is a Java standards-based solution for persistence. Persistence uses an object-relational mapping approach to bridge the gap between an object oriented model and a relational database. Java Persistence consists of three areas:


The Java Persistence API

The query language

Object/relational mapping metadata


Java Naming and Directory Interface (JNDI)

The Java Naming and Directory Interface (JNDI) provides naming and directory functionality, enabling applications to access multiple naming and directory services, including existing naming and directory services such as LDAP, NDS, DNS, and NIS. It provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes. Using JNDI, a Java EE application can store and retrieve any type of named Java object, allowing Java EE applications to coexist with many legacy applications and systems.

Java EE naming services provide application clients, enterprise beans, and web components with access to a JNDI naming environment. A naming environment allows a component to be customized without the need to access or change the component's source code. A container implements the component's environment and provides it to the component as a JNDI naming context.

Java Authentication and Authorization Service

The Java Authentication and Authorization Service (JAAS) provides a way for a Java EE application to authenticate and authorize a specific user or group of users to run it.

JAAS is a Java programming language version of the standard Pluggable Authentication Module (PAM) framework, which extends the Java Platform security architecture to support user-based authorization.


Container Services

Containers are the interface between a component and the low-level platform-specific functionality that supports the component. Before a web, enterprise bean, or application client component can be executed, it must be assembled into a Java EE module and deployed into its container.

The assembly process involves specifying container settings for each component in the Java EE application and for the Java EE application itself. Container settings customize the underlying support provided by the Java EE server, including services such as security, transaction management, Java Naming and Directory Interface (JNDI) lookups, and remote connectivity. Here are some of the highlights:


The Java EE security model lets you configure a web component or enterprise bean so that system resources are accessed only by authorized users.

The Java EE transaction model lets you specify relationships among methods that make up a single transaction so that all methods in one transaction are treated as a single unit.

JNDI lookup services provide a unified interface to multiple naming and directory services in the enterprise so that application components can access these services.

The Java EE remote connectivity model manages low-level communications between clients and enterprise beans. After an enterprise bean is created, a client invokes methods on it as if it were in the same virtual machine.


Because the Java EE architecture provides configurable services, application components within the same Java EE application can behave differently based on where they are deployed. For example, an enterprise bean can have security settings that allow it a certain level of access to database data in one production environment and another level of database access in another production environment.

The container also manages nonconfigurable services such as enterprise bean and servlet life cycles, database connection resource pooling, data persistence, and access to the Java EE platform APIs.

Communication Technologies

Communication technologies provide mechanisms for communication between clients and servers and between collaborating objects hosted by different servers. The J2EE specification requires support for the following types of communication technologies:


Internet protocols

Internet protocols define the standards by which the different pieces of the J2EE platform communicate with each other and with remote entities. The J2EE platform supports the following Internet protocols:


TCP/IP - Transport Control Protocol over Internet Protocol. These two protocols provide for the reliable delivery of streams of data from one host to another. Internet Protocol (IP), the basic protocol of the Internet, enables the unreliable delivery of individual packets from one host to another. IP makes no guarantees as to whether the packet will be delivered, how long it will take, or if multiple packets will arrive in the order they were sent. The Transport Control Protocol (TCP) adds the notions of connection and reliability.

HTTP 1.0 - Hypertext Transfer Protocol. The Internet protocol used to fetch hypertext objects from remote hosts. HTTP messages consist of requests from client to server and responses from server to client.

SSL 3.0 - Secure Socket Layer. A security protocol that provides privacy over the Internet. The protocol allows client-server applications to communicate in a way that cannot be eavesdropped or tampered with. Servers are always authenticated and clients are optionally authenticated.


Remote Method Invocation Protocols

Remote Method Invocation (RMI) is a set of APIs that allow developers to build distributed applications in the Java programming language. RMI uses Java language interfaces to define remote objects and a combination of Java serialization technology and the Java Remote Method Protocol (JRMP) to turn local method invocations into remote method invocations. The J2EE platform supports the JRMP protocol, the transport mechanism for communication between objects in the Java language in different address spaces.

Object Management Group Protocols

Object Management Group (OMG) protocols allow objects hosted by the J2EE platform to access remote objects developed using the OMG's Common Object Request Broker Architecture (CORBA) technologies and vice versa. CORBA objects are defined using the Interface Definition Language (IDL). An application component provider defines the interface of a remote object in IDL and then uses an IDL compiler to generate client and server stubs that connect object implementations to an Object Request Broker (ORB), a library that enables CORBA objects to locate and communicate with one another. ORBs communicate with each other using the Internet Inter-ORB Protocol (IIOP). The OMG technologies required by the J2EE platform are Java IDL and RMI-IIOP.


Java IDL

Java IDL allows Java clients to invoke operations on CORBA objects that have been defined using IDL and implemented in any language with a CORBA mapping. Java IDL is part of the J2SE platform. It consists of a CORBA API and ORB. An application component provider uses the idlj IDL compiler to generate a Java client stub for a CORBA object defined in IDL. The Java client is linked with the stub and uses the CORBA API to access the CORBA object.

RMI-IIOP

RMI-IIOP is an implementation of the RMI API over IIOP. RMI-IIOP allows application component providers to write remote interfaces in the Java programming language. The remote interface can be converted to IDL and implemented in any other language that is supported by an OMG mapping and an ORB for that language. Clients and servers can be written in any language using IDL derived from the RMI interfaces. When remote interfaces are defined as Java RMI interfaces, RMI over IIOP provides interoperability with CORBA objects implemented in any language.


Messaging Technologies

Messaging technologies provide a way to asynchronously send and receive messages. The Java Message Service API provides an interface for handling asynchronous requests, reports, or events that are consumed by enterprise applications. JMS messages are used to coordinate these applications. The JavaMail API provides an interface for sending and receiving messages intended for users. Although either API can be used for asynchronous notification, JMS is preferred when speed and reliability are a primary requirement.


Java Message Service API

The Java Message Service (JMS) API allows J2EE applications to access enterprise messaging systems such as IBM MQ Series and TIBCO Rendezvous. JMS messages contain well-defined information that describe specific business actions. Through the exchange of these messages, applications track the progress of enterprise activities. The JMS API supports both point-to-point and publish-subscribe styles of messaging.

JavaMail API

The JavaMail API provides a set of abstract classes and interfaces that comprise an electronic mail system. The abstract classes and interfaces support many different implementations of message stores, formats, and transports. Many simple applications will only need to interact with the messaging system through these base classes and interfaces.


Data Formats

Data formats define the types of data that can be exchanged between components. The J2EE platform requires support for the following data formats:


HTML - The markup language used to define hypertext documents accessible over the Internet. HTML enables the embedding of images, sounds, video streams, form fields, references to other HTML documents, and basic text formatting. HTML documents have a globally unique location and can link to one another.

Image files - The J2EE platform supports two formats for image files: GIF (Graphics Interchange Format), a protocol for the online transmission and interchange of raster graphic data, and JPEG (Joint Photographic Experts Group), a standard for compressing gray-scale or color still images.

JAR file - A platform-independent file format that permits many files to be aggregated into one file.

Class file - The format of a compiled Java file as specified in the Java Virtual Machine specification. Each class file contains one Java language type - either a class or an interface - and consists of a stream of 8-bit bytes.

XML - A text-based markup language that allows you to define the markup needed to identify the data and text in structured documents. As with HTML, you identify data using tags. But unlike HTML, XML tags describe the data, rather than the format for displaying it. In the same way that you define the field names for a data structure, you are free to use any XML tags that make sense for a given application. When multiple applications share XML data, they have to agree on the tag names they intend to use.

Describe how the principle of "separation of concerns" has been applied to the main system tiers of a Java EE application. Tiers include client (both

The Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and the various application components that make up a Java EE application are installed on different machines depending on the tier in the multitiered Java EE environment to which the application component belongs. Figure below shows two multitiered Java EE applications divided into the tiers described in the following list:


Client-tier components run on the client machine.

Web-tier components run on the Java EE server.

Business-tier components run on the Java EE server.

Enterprise information system (EIS)-tier software runs on the EIS server.





Although a Java EE application can consist of the three or four tiers, Java EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations: client machines, the Java EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage.

Java EE applications are made up of components. A Java EE component is a self-contained functional software unit that is assembled into a Java EE application with its related classes and files and that communicates with other components. The Java EE specification defines the following Java EE components:


Application clients and applets are components that run on the client.

Java Servlet, JavaServer Faces, and JavaServer Pages (JSP) technology components are web components that run on the server.

Enterprise JavaBeans (EJB) components (enterprise beans) are business components that run on the server.


Java EE Clients


Web Clients

A Web Client consists of two parts:


Dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the web tier.

Web browser, which renders the pages received from the server.


A Web Client is sometimes called a thin client. Thin clients usually do not query databases, execute complex business rules, or connect to legacy applications. When you use a thin client, such heavyweight operations are off-loaded to enterprise beans executing on the Java EE server, where they can leverage the security, speed, services, and reliability of Java EE server-side technologies.

A web page received from the web tier can include an embedded applet. An applet is a small client application written in the Java programming language that executes in the Java virtual machine installed in the web browser. However, client systems will likely need the Java Plug-in and possibly a security policy file for the applet to successfully execute in the web browser.

Web components (Servlets, JSF or JSP) are the preferred API for creating a web client program because no plug-ins or security policy files are needed on the client systems. Also, web components enable cleaner and more modular application design because they provide a way to separate applications programming from web page design. Personnel involved in web page design thus do not need to understand Java programming language syntax to do their jobs.

Application Clients

An application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a markup language. It typically has a graphical user interface (GUI) created from the Swing or the Abstract Window Toolkit (AWT) API, but a command-line interface is certainly possible.

Application clients directly access enterprise beans running in the business tier. However, if application requirements warrant it, an application client can open an HTTP connection to establish communication with a servlet running in the web tier. Application clients written in languages other than Java can interact with Java EE 5 servers, enabling the Java EE 5 platform to interoperate with legacy systems, clients, and non-Java languages.


Figure below shows the various elements that can make up the client tier. The client communicates with the business tier running on the Java EE server either directly or, as in the case of a client running in a browser, by going through JSP pages or servlets running in the web tier. Your Java EE application uses a thin browser-based client or thick application client. In deciding which one to use, you should be aware of the trade-offs between keeping functionality on the client and close to the user (thick client) and off-loading as much functionality as possible to the server (thin client). The more functionality you off-load to the server, the easier it is to distribute, deploy, and manage the application; however, keeping more functionality on the client can make for a better perceived user experience.




Web Components

Java EE web components are either servlets or pages created using JSP technology (JSP pages) and/or JavaServer Faces technology. Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content. JavaServer Faces technology builds on servlets and JSP technology and provides a user interface component framework for web applications.

Static HTML pages and applets are bundled with web components during application assembly but are not considered web components by the Java EE specification. Server-side utility classes can also be bundled with web components and, like HTML pages, are not considered web components.

As shown in figure below, the web tier, like the client tier, might include a JavaBeans component to manage the user input and send that input to enterprise beans running in the business tier for processing.




Business Components

Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier. Figure below shows how an enterprise bean receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.




The enterprise information system (EIS) tier handles EIS software and includes enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems. For example, Java EE application components might need access to enterprise information systems for database connectivity.

Chapter 1. Application Design Concepts and Principles

Explain the main advantages of an object oriented approach to system design including the effect of encapsulation, inheritance, delegation, and the use of interfaces, on architectural characteristics.

There are three major features in object-oriented programming: encapsulation, inheritance and polymorphism.


Encapsulation

Encapsulation enforces modularity.

Encapsulation refers to the creation of self-contained modules that bind processing functions to the data. These user-defined data types are called "classes," and one instance of a class is an "object." For example, in a payroll system, a class could be Manager, and Mikalai and Volha could be two instances (two objects) of the Manager class. Encapsulation ensures good code modularity, which keeps routines separate and less prone to conflict with each other.

Inheritance

Inheritance passes "knowledge" down.

Classes are created in hierarchies, and inheritance allows the structure and methods in one class to be passed down the hierarchy. That means less programming is required when adding functions to complex systems. If a step is added at the bottom of a hierarchy, then only the processing and data associated with that unique step needs to be added. Everything else about that step is inherited. The ability to reuse existing objects is considered a major advantage of object technology.

Polymorphism

Polymorphism takes any shape.

Object-oriented programming allows procedures about objects to be created whose exact type is not known until runtime. For example, a screen cursor may change its shape from an arrow to a line depending on the program mode. The routine to move the cursor on screen in response to mouse movement would be written for "cursor," and polymorphism allows that cursor to take on whatever shape is required at runtime. It also allows new shapes to be easily integrated.

SCEA5 (Sun Certified Enterprise Architect)

Objetive of SCEA 5

Preface
I. Exam Objectives
1. Application Design Concepts and Principles
Explain the main advantages of an object oriented approach to system design including the effect of encapsulation, inheritance, delegation, and the use of interfaces, on architectural characteristics.
Describe how the principle of "separation of concerns" has been applied to the main system tiers of a Java EE application. Tiers include client (both GUI and web), web (web container), business (EJB container), integration, and resource tiers.
Describe how the principle of "separation of concerns" has been applied to the layers of a Java EE application. Layers include application, virtual platform (component APIs), application infrastructure (containers), enterprise services (operating system and virtualization), compute and storage, and the networking infrastructure layers.
2. Common Architectures
Explain the advantages and disadvantages of two tier architectures when examined under the following topics: scalability, maintainability, reliability, availability, extensibility, performance, manageability, and security.
Explain the advantages and disadvantages of three tier architectures when examined under the following topics: scalability, maintainability, reliability, availability, extensibility, performance, manageability, and security.
Explain the advantages and disadvantages of multi-tier architectures when examined under the following topics: scalability, maintainability, reliability, availability, extensibility, performance, manageability, and security.
Explain the benefits and drawbacks of rich clients and browser-based clients as deployed in a typical Java EE application.
Explain appropriate and inappropriate uses for Web Services in the Java EE Platform.
3. Integration and Messaging
Explain possible approaches for communicating with an external system from a Java EE-based system given an outline description of those systems and outline the benefits and drawbacks of each approach.
Explain typical uses of Web Services and XML over HTTP as mechanisms to integrate distinct software components.
Explain how Java Connector Architecture and JMS are used to integrate distinct software components as part of an overall Java EE application.
4. Business Tier Technologies
Explain and contrast uses for Entity Beans, Entity Classes, Stateful and Stateless Session Beans, and Message Driven Beans and understand the advantages and disadvantages of each type.
Explain and contrast the following persistence strategies: Container Managed Persistence (CMP) BMP, JDO, JPA, ORM and using DAOs (Data Access Objects) and direct JDBC-based persistence under the following headings: ease of development, performance, scalability, extensibility and security.
Explain how Java EE supports the deployment of server-side components implemented as Web Services and the advantages and disadvantages of adopting such an approach.
Explain the benefits of the EJB3 development model over previous EJB generations for ease of development including how the EJB container simplifies EJB development.
5. Web Tier Technologies
State the benefits and drawbacks of adopting a web framework in designing a Java EE application.
Explain standard uses for JSP and Servlet technologies in a typical Java EE application.
Explain standard uses for JSF technology in a typical Java EE application.
Given a system requirements definition, explain and justify your rationale for choosing a web-centric or EJB-centric implementation to solve the requirements. Web-centric means that you are providing a solution that does not use EJBs. EJB-centric solution will require an application server that supports EJBs.
6. Applicability of Java EE Technology
Given a specified business problem, design a modular solution implemented using Java EE which solves that business problem.
Explain how the Java EE platform enables service oriented architecture (SOA) -based applications.
Explain how you would design a Java EE application to repeatedly measure critical non-functional requirements and outline a standard process with specific strategies to refactor that application to improve on the results of the measurements.
7. Patterns
From a list, select the most appropriate pattern for a given scenario. Patterns are limited to those documented in the book - Alur, Crupi and Malks (2003). Core J2EE Patterns: Best Practices and Design Strategies 2nd Edition and named using the names given in that book.
From a list, select the most appropriate pattern for a given scenario. Patterns are limited to those documented in the book - Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides (1995). Design Patterns: Elements of Reusable Object-Oriented Software and are named using the names given in that book.
Select from a list the benefits and drawbacks of a pattern drawn from the book - Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides (1995). Design Patterns: Elements of Reusable Object-Oriented Software.
Select from a list the benefits and drawbacks of a specified Core J2EE pattern drawn from the book - Alur, Crupi and Malks (2003). Core J2EE Patterns: Best Practices and Design Strategies 2nd Edition.
8. Security
Explain the client-side security model for the Java SE environment, including the Web Start and applet deployment modes.
Given an architectural system specification, select appropriate locations for implementation of specified security features, and select suitable technologies for implementation of those features.
Identify and classify potential threats to a system and describe how a given architecture will address the threats.
Describe the commonly used declarative and programmatic methods used to secure applications built on the Java EE platform, for example use of deployment descriptors and JAAS.

Wednesday, 22 October 2008

How To Validate Xml Against Schema



First of all, make sure that your XML parser supports schema validation. Not all do, yet.

Here's a quick sample for schema validation using Xerces:


import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import java.io.IOException;

public class SchemaValidationExample {

public static void main(String args[]) {
DOMParser parser = new DOMParser();
Document doc = null;
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "urn:mynamespace myschema.xsd");
parser.parse("myinstance.xml");
doc = parser.getDocument();
} catch (IOException e){
System.out.println("Could not read file: " + e.getMessage());
} catch (SAXNotRecognizedException e) {
System.out.println("Feature not recognized: " + e.getMessage());
} catch (SAXNotSupportedException e) {
System.out.println("Feature not supported: " + e.getMessage());
} catch (SAXException e) {
System.out.print("Parsing XML failed due to a " + e.getClass().getName() + ":");
System.out.println(e.getMessage());
}
}
}

Simple Java DOM XML Example

A Simple XML Document
Unfortunately DOM XML documents in Java have a reputation for being hard to create. This simply isn't true. The construction process is very wordy though, but if you have a cheat sheet (like this tutorial), then they really aren't so bad.
I'm going to show you a base example that does everything that most documents need to do. It has a root element. The root contains another element that is its child. The root contains a comment too.
The child element has a name-value attribute. The child also contains some arbitrary text.
If you have ever written a simple web page you will find this very similar in format. XML documents are very human friendly. Here is the simple XML Document we'll create. You can base extremely complex documents off of this base example.


Filler, ... I could have had a FOO!

Now I do make the assumption that you know what XML is. You create your own mark-up language using the rules of XML. XML is not the tags, but the format of the tags. If that makes no sense, start with a tutorial that explains what XML is. XML is really quite fun when you get use to it.
Parts of the Java DOM Document
Now as I said earlier, there are several classes used when handling XML and they are spread across several packages. I wouldn't bother memorizing them. They will commit themselves to memory if you spend a significant amount of time using them. If you only use them once in a while, just remember where to find a good tutorial to review when you need to.
Now before you start looking at the code, you should realize that only three tasks occur in it. First you need a DOM document to put your XML into. Second, the XML is assembled in tree fashion with the root element at the top. The root is added to the Document object. Other elements can be added to the root, and attributes are added to any elements. Comments and Text may be added to any of the elements. Third you need to transform your XML tree into something like an OutputStream or Writer.
The Code
So here is the code. You can pretty much tell what is going on. Just look at the java docs if something isn't clear.
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
public class DomXmlExample {
/**
* Our goal is to create a DOM XML tree and then print the XML.
*/
public static void main (String args[]) {
new DomXmlExample();
}
public DomXmlExample() {
try {
/////////////////////////////
//Creating an empty XML Document
//We need a Document
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
////////////////////////
//Creating the XML tree
//create the root element and add it to the document
Element root = doc.createElement("root");
doc.appendChild(root);
//create a comment and put it in the root element
Comment comment = doc.createComment("Just a thought");
root.appendChild(comment);
//create child element, add an attribute, and add to root
Element child = doc.createElement("child");
child.setAttribute("name", "value");
root.appendChild(child);
//add a text element to the child
Text text = doc.createTextNode("Filler, ... I could have had a foo!");
child.appendChild(text);
/////////////////
//Output the XML
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
String xmlString = sw.toString();
//print xml
System.out.println("Here's the xml:\n\n" + xmlString);
} catch (Exception e) {
System.out.println(e);
}
}
}

Tuesday, 30 September 2008

PL SQL FAQ (Frequently Asked Questions)

What is PL/SQL and what is it used for?
SQL is a declarative language that allows database programmers to write a SQL declaration and hand it to the database for execution. As such, SQL cannot be used to execute procedural code with conditional, iterative and sequential statements. To overcome this limitation, PL/SQL was created.

PL/SQL is Oracle's Procedural Language extension to SQL. PL/SQL's language syntax, structure and data types are similar to that of Ada. Some of the statements provided by PL/SQL:

Conditional Control Statements:

IF ... THEN ... ELSIF ... ELSE ... END IF;
CASE ... WHEN ... THEN ... ELSE ... END CASE;
Iterative Statements:

LOOP ... END LOOP;
WHILE ... LOOP ... END LOOP;
FOR ... IN [REVERSE] ... LOOP ... END LOOP;
Sequential Control Statements:

GOTO ...;
NULL;
The PL/SQL language includes object oriented programming techniques such as encapsulation, function overloading, information hiding (all but inheritance).

PL/SQL is commonly used to write data-centric programs to manipulate data in an Oracle database.

Example PL/SQL blocks:

/* Remember to SET SERVEROUTPUT ON to see the output */
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World');
END;
/
BEGIN
-- A PL/SQL cursor
FOR cursor1 IN (SELECT * FROM table1) -- This is an embedded SQL statement
LOOP
DBMS_OUTPUT.PUT_LINE('Column 1 = ' || cursor1.column1 ||
', Column 2 = ' || cursor1.column2);
END LOOP;
END;
/
[edit]What is the difference between SQL and PL/SQL?
Both SQL and PL/SQL are languages used to access data within Oracle databases.

SQL is a limited language that allows you to directly interact with the database. You can write queries (SELECT), manipulate objects (DDL) and data (DML) with SQL. However, SQL doesn't include all the things that normal programming languages have, such as loops and IF...THEN...ELSE statements.

PL/SQL is a normal programming language that includes all the features of most other programming languages. But, it has one thing that other programming languages don't have: the ability to easily integrate with SQL.

Some of the differences:

SQL is executed one statement at a time. PL/SQL is executed as a block of code.
SQL tells the database what to do (declarative), not how to do it. In contrast, PL/SQL tell the database how to do things (procedural).
SQL is used to code queries, DML and DDL statements. PL/SQL is used to code program blocks, triggers, functions, procedures and packages.
You can embed SQL in a PL/SQL program, but you cannot embed PL/SQL within a SQL statement.
[edit]Should one use PL/SQL or Java to code procedures and triggers?
Both PL/SQL and Java can be used to create Oracle stored procedures and triggers. This often leads to questions like "Which of the two is the best?" and "Will Oracle ever desupport PL/SQL in favour of Java?".

Many Oracle applications are based on PL/SQL and it would be difficult of Oracle to ever desupport PL/SQL. In fact, all indications are that PL/SQL still has a bright future ahead of it. Many enhancements are still being made to PL/SQL. For example, Oracle 9i supports native compilation of Pl/SQL code to binaries. Not to mention the numerous PL/SQL enhancements made in Oracle 10g and 11g.

PL/SQL and Java appeal to different people in different job roles. The following table briefly describes the similarities and difference between these two language environments:

PL/SQL:

Can be used to create Oracle packages, procedures and triggers
Data centric and tightly integrated into the database
Proprietary to Oracle and difficult to port to other database systems
Data manipulation is slightly faster in PL/SQL than in Java
PL/SQL is a traditional procedural programming language
Java:

Can be used to create Oracle packages, procedures and triggers
Open standard, not proprietary to Oracle
Incurs some data conversion overhead between the Database and Java type systems
Java is an Object Orientated language, and modules are structured into classes
Java can be used to produce complete applications
PS: Starting with Oracle 10g, .NET procedures can also be stored within the database (Windows only). Nevertheless, unlike PL/SQL and JAVA, .NET code is not usable on non-Windows systems.

[edit]How can one see if somebody modified any code?
The source code for stored procedures, functions and packages are stored in the Oracle Data Dictionary. One can detect code changes by looking at the TIMESTAMP and LAST_DDL_TIME column in the USER_OBJECTS dictionary view. Example:

SELECT OBJECT_NAME,
TO_CHAR(CREATED, 'DD-Mon-RR HH24:MI') CREATE_TIME,
TO_CHAR(LAST_DDL_TIME, 'DD-Mon-RR HH24:MI') MOD_TIME,
STATUS
FROM USER_OBJECTS
WHERE LAST_DDL_TIME > '&CHECK_FROM_DATE';
Note: If you recompile an object, the LAST_DDL_TIME column is updated, but the TIMESTAMP column is not updated. If you modified the code, both the TIMESTAMP and LAST_DDL_TIME columns are updated.

[edit]How can one search PL/SQL code for a string/ key value?
The following query is handy if you want to know where certain tables, columns and expressions are referenced in your PL/SQL source code.

SELECT type, name, line
FROM user_source
WHERE UPPER(text) LIKE UPPER('%&KEYWORD%');
If you run the above query from SQL*Plus, enter the string you are searching for when prompted for KEYWORD. If not, replace &KEYWORD with the string you are searching for.

[edit]How can one keep a history of PL/SQL code changes?
One can build a history of PL/SQL code changes by setting up an AFTER CREATE schema (or database) level trigger (available from Oracle 8.1.7). This way one can easily revert to previous code should someone make any catastrophic changes. Look at this example:

CREATE TABLE SOURCE_HIST -- Create history table
AS SELECT SYSDATE CHANGE_DATE, USER_SOURCE.*
FROM USER_SOURCE WHERE 1=2;

CREATE OR REPLACE TRIGGER change_hist -- Store code in hist table
AFTER CREATE ON SCOTT.SCHEMA -- Change SCOTT to your schema name
DECLARE
BEGIN
if DICTIONARY_OBJ_TYPE in ('PROCEDURE', 'FUNCTION',
'PACKAGE', 'PACKAGE BODY', 'TYPE') then
-- Store old code in SOURCE_HIST table
INSERT INTO SOURCE_HIST
SELECT sysdate, user_source.* FROM USER_SOURCE
WHERE TYPE = DICTIONARY_OBJ_TYPE
AND NAME = DICTIONARY_OBJ_NAME;
end if;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20000, SQLERRM);
END;
/
show errors
A better approach is to create an external CVS or SVN archive for the scripts that installs the PL/SQL code. The canonical version of what's in the database must match the latest CVS/SVN version or else someone would be cheating.

[edit]How can I protect my PL/SQL source code?
Oracle provides a binary wrapper utility that can be used to scramble PL/SQL source code. This utility was introduced in Oracle7.2 (PL/SQL V2.2) and is located in the ORACLE_HOME/bin directory.

The utility use human-readable PL/SQL source code as input, and writes out portable binary object code (somewhat larger than the original). The binary code can be distributed without fear of exposing your proprietary algorithms and methods. Oracle will still understand and know how to execute the code. Just be careful, there is no "decode" command available. So, don't lose your source!

The syntax is:

wrap iname=myscript.pls oname=xxxx.plb
Please note: there is no way to unwrap a *.plb binary file. You are supposed to backup and keep your *.pls source files after wrapping them.

[edit]Can one print to the screen from PL/SQL?
One can use the DBMS_OUTPUT package to write information to an output buffer. This buffer can be displayed on the screen from SQL*Plus if you issue the SET SERVEROUTPUT ON; command. For example:

set serveroutput on
begin
dbms_output.put_line('Look Ma, I can print from PL/SQL!!!');
end;
/
DBMS_OUTPUT is useful for debugging PL/SQL programs. However, if you print too much, the output buffer will overflow. In that case, set the buffer size to a larger value, eg.: set serveroutput on size 200000

If you forget to set serveroutput on type SET SERVEROUTPUT ON once you remember, and then EXEC NULL;. If you haven't cleared the DBMS_OUTPUT buffer with the disable or enable procedure, SQL*Plus will display the entire contents of the buffer when it executes this dummy PL/SQL block.

Note that DBMS_OUTPUT doesn't print blank or NULL lines. To overcome this problem, SET SERVEROUTPUT ON FORMAT WRAP; Look at this example with this option first disabled and then enabled:

SQL> SET SERVEROUTPUT ON
SQL> begin
2 dbms_output.put_line('The next line is blank');
3 dbms_output.put_line();
4 dbms_output.put_line('The above line should be blank');
5 end;
6 /
The next line is blank
The above line should be blank
SQL> SET SERVEROUTPUT ON FORMAT WRAP
SQL> begin
2 dbms_output.put_line('The next line is blank');
3 dbms_output.put_line();
4 dbms_output.put_line('The above line should be blank');
5 end;
6 /
The next line is blank

The above line should be blank
[edit]Can one read/write files from PL/SQL?
The UTL_FILE database package can be used to read and write operating system files.

A DBA user needs to grant you access to read from/ write to a specific directory before using this package. Here is an example:

CONNECT / AS SYSDBA
CREATE OR REPLACE DIRECTORY mydir AS '/tmp';
GRANT read, write ON DIRECTORY mydir TO scott;
Provide user access to the UTL_FILE package (created by catproc.sql):

GRANT EXECUTE ON UTL_FILE TO scott;
Copy and paste these examples to get you started:

Write File

DECLARE
fHandler UTL_FILE.FILE_TYPE;
BEGIN
fHandler := UTL_FILE.FOPEN('MYDIR', 'myfile', 'w');
UTL_FILE.PUTF(fHandler, 'Look ma, Im writing to a file!!!\n');
UTL_FILE.FCLOSE(fHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'Invalid path. Create directory or set UTL_FILE_DIR.');
END;
/
Read File

DECLARE
fHandler UTL_FILE.FILE_TYPE;
buf varchar2(4000);
BEGIN
fHandler := UTL_FILE.FOPEN('MYDIR', 'myfile', 'r');
UTL_FILE.GET_LINE(fHandler, buf);
dbms_output.put_line('DATA FROM FILE: '||buf);
UTL_FILE.FCLOSE(fHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'Invalid path. Create directory or set UTL_FILE_DIR.');
END;
/
NOTE: UTL_FILE was introduced with Oracle 7.3. Before Oracle 7.3 the only means of writing a file was to use DBMS_OUTPUT with the SQL*Plus SPOOL command.

[edit]Can one call DDL statements from PL/SQL?
One can call DDL statements like CREATE, DROP, TRUNCATE, etc. from PL/SQL by using the "EXECUTE IMMEDIATE" statement (native SQL). Examples:

begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
begin execute Immediate 'TRUNCATE TABLE emp'; end;
DECLARE
var VARCHAR2(100);
BEGIN
var := 'CREATE TABLE temp1(col1 NUMBER(2))';
EXECUTE IMMEDIATE var;
END;
NOTE: The DDL statement in quotes should not be terminated with a semicolon.

Users running Oracle versions below Oracle 8i can look at the DBMS_SQL package (see FAQ about Dynamic SQL).

[edit]Can one use dynamic SQL statements from PL/SQL?
Starting from Oracle8i one can use the "EXECUTE IMMEDIATE" statement to execute dynamic SQL and PL/SQL statements (statements created at run-time). Look at these examples. Note that the statements within quotes are NOT semicolon terminated:

EXECUTE IMMEDIATE 'CREATE TABLE x (a NUMBER)';

-- Using bind variables...'
sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)';
EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location;

-- Returning a cursor...
sql_stmt := 'SELECT * FROM emp WHERE empno = :id';
EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id;
One can also use the older DBMS_SQL package (V2.1 and above) to execute dynamic statements. Look at these examples:

CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;
/
More complex DBMS_SQL example using bind variables:

CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO%TYPE) AS
v_cursor integer;
v_dname char(20);
v_rows integer;
BEGIN
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor, 'select dname from dept where deptno > :x', DBMS_SQL.V7);
DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no);
DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1, v_dname, 20);
v_rows := DBMS_SQL.EXECUTE(v_cursor);
loop
if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then
exit;
end if;
DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1, v_dname);
DBMS_OUTPUT.PUT_LINE('Deptartment name: '||v_dname);
end loop;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
EXCEPTION
when others then
DBMS_SQL.CLOSE_CURSOR(v_cursor);
raise_application_error(-20000, 'Unknown Exception Raised: '||sqlcode||' '||sqlerrm);
END;
/
[edit]What is the difference between %TYPE and %ROWTYPE?
Both %TYPE and %ROWTYPE are used to define variables in PL/SQL as it is defined within the database. If the datatype or precision of a column changes, the program automically picks up the new definition from the database without having to make any code changes.

The %TYPE and %ROWTYPE constructs provide data independence, reduces maintenance costs, and allows programs to adapt as the database changes to meet new business needs.

%TYPE

%TYPE is used to declare a field with the same type as that of a specified table's column. Example:

DECLARE
v_EmpName emp.ename%TYPE;
BEGIN
SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1;
DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName);
END;
/
%ROWTYPE

%ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor. Examples:

DECLARE
v_emp emp%ROWTYPE;
BEGIN
v_emp.empno := 10;
v_emp.ename := 'XXXXXXX';
END;
/
[edit]How does one get the value of a sequence into a PL/SQL variable?
As you might know, one cannot use sequences directly from PL/SQL. Oracle (for some silly reason) prohibits this:

i := sq_sequence.NEXTVAL;
However, one can use embedded SQL statements to obtain sequence values:

select sq_sequence.NEXTVAL into :i from dual;
This FAQ was contributed by Ronald van Woensel

[edit]Can one execute an operating system command from PL/SQL?
There is no direct way to execute operating system commands from PL/SQL. PL/SQL doesn't have a "host" command, as with SQL*Plus, that allows users to call OS commands. Nevertheless, the following workarounds can be used:

Database Pipes

Write an external program (using one of the precompiler languages, OCI or Perl with Oracle access modules) to act as a listener on a database pipe (SYS.DBMS_PIPE). Your PL/SQL program then put requests to run commands in the pipe, the listener picks it up and run the requests. Results are passed back on a different database pipe. For an Pro*C example, see chapter 8 of the Oracle Application Developers Guide.

CREATE OR REPLACE FUNCTION host_command( cmd IN VARCHAR2 )
RETURN INTEGER IS
status NUMBER;
errormsg VARCHAR2(80);
pipe_name VARCHAR2(30);
BEGIN
pipe_name := 'HOST_PIPE';
dbms_pipe.pack_message( cmd );
status := dbms_pipe.send_message(pipe_name);
RETURN status;
END;
/
External Procedure Listeners:

From Oracle 8 one can call external 3GL code in a dynamically linked library (DLL or shared object). One just write a library in C/ C++ to do whatever is required. Defining this C/C++ function to PL/SQL makes it executable. Look at this External Procedure example.

Using Java

See example at http://www.orafaq.com/scripts/plsql/oscmd.txt

DBMS_SCHEDULER

In Oracle 10g and above, one can execute OS commands via the DBMS_SCHEDULER package. Look at this example:

BEGIN
dbms_scheduler.create_job(job_name => 'myjob',
job_type => 'executable',
job_action => '/app/oracle/x.sh',
enabled => TRUE,
auto_drop => TRUE);
END;
/

exec dbms_scheduler.run_job('myjob');
[edit]How does one loop through tables in PL/SQL?
One can make use of cursors to loop through data within tables. Look at the following nested loops code example.

DECLARE
CURSOR dept_cur IS
SELECT deptno
FROM dept
ORDER BY deptno;

-- Employee cursor all employees for a dept number
CURSOR emp_cur (v_dept_no DEPT.DEPTNO%TYPE) IS
SELECT ename
FROM emp
WHERE deptno = v_dept_no;
BEGIN
FOR dept_rec IN dept_cur LOOP
dbms_output.put_line('Employees in Department '||TO_CHAR(dept_rec.deptno));

FOR emp_rec in emp_cur(dept_rec.deptno) LOOP
dbms_output.put_line('...Employee is '||emp_rec.ename);
END LOOP;

END LOOP;
END;
/
[edit]How often should one COMMIT in a PL/SQL loop? / What is the best commit strategy?
Contrary to popular belief, one should COMMIT less frequently within a PL/SQL loop to prevent ORA-1555 (Snapshot too old) errors. The higher the frequency of commit, the sooner the extents in the undo/ rollback segments will be cleared for new transactions, causing ORA-1555 errors.

To fix this problem one can easily rewrite code like this:

FOR records IN my_cursor LOOP
...do some stuff...
COMMIT;
END LOOP;
COMMIT;
... to ...

FOR records IN my_cursor LOOP
...do some stuff...
i := i+1;
IF mod(i, 10000) = 0 THEN -- Commit every 10000 records
COMMIT;
END IF;
END LOOP;
COMMIT;
If you still get ORA-1555 errors, contact your DBA to increase the undo/ rollback segments.

NOTE: Although fetching across COMMITs work with Oracle, is not supported by the ANSI standard.

[edit]I can SELECT from SQL*Plus but not from PL/SQL. What is wrong?
PL/SQL respect object privileges given directly to the user, but does not observe privileges given through roles. The consequence is that a SQL statement can work in SQL*Plus, but will give an error in PL/SQL. Choose one of the following solutions:

Grant direct access on the tables to your user. Do not use roles!
GRANT select ON scott.emp TO my_user;
Define your procedures with invoker rights (Oracle 8i and higher);
create or replace procedure proc1
authid current_user is
begin
...
Move all the tables to one user/schema.
[edit]What is a mutating and constraining table?
"Mutating" means "changing". A mutating table is a table that is currently being modified by an update, delete, or insert statement. When a trigger tries to reference a table that is in state of flux (being changed), it is considered "mutating" and raises an error since Oracle should not return data that has not yet reached its final state.

Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table off which it fires. If you must have triggers on tables that have referential constraints, the workaround is to enforce the referential integrity through triggers as well.

There are several restrictions in Oracle regarding triggers:

A row-level trigger cannot query or modify a mutating table. (Of course, NEW and OLD still can be accessed by the trigger).
A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the result of a CASCADE delete.
Etc.
[edit]Can one pass an object/table as an argument to a remote procedure?
The only way to reference an object type between databases is via a database link. Note that it is not enough to just use "similar" type definitions. Look at this example:

-- Database A: receives a PL/SQL table from database B
CREATE OR REPLACE PROCEDURE pcalled(TabX DBMS_SQL.VARCHAR2S) IS
BEGIN
-- do something with TabX from database B
null;
END;
/



-- Database B: sends a PL/SQL table to database A
CREATE OR REPLACE PROCEDURE pcalling IS
TabX DBMS_SQL.VARCHAR2S@DBLINK2;
BEGIN
pcalled@DBLINK2(TabX);
END;
/
[edit]What is the difference between stored procedures and functions?
Functions are normally used for computations where as procedures are normally used for executing business logic.
Functions MUST return a value, procedures doesn't need to.
You can have DML (insert,update, delete) statements in a function. But, you cannot call such a function in a SQL query. For example, if you have a function that is updating a table, you cannot call that function from a SQL query.
- select myFunction(field) from sometable; will throw error.
Function returns 1 value only. Procedure can return multiple values (max 1024).
Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution. Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values(SQL Server). Stored procedure is precompiled execution plan where as functions are not.
A procedure may modify an object where a function can only return a value.
PS: In earlier releases of Oracle it was better to put as much code as possible in procedures rather than triggers. At that stage procedures executed faster than triggers as triggers had to be re-compiled every time before executed (unless cached). In more recent releases both triggers and procedures are compiled when created (stored p-code) and one can add as much code as one likes in either procedures or triggers.

[edit]Is there a PL/SQL Engine in SQL*Plus?
No. Unlike Oracle Forms, SQL*Plus does not have an embedded PL/SQL engine. Thus, all your PL/SQL code is sent directly to the database engine for execution. This makes it much more efficient as SQL statements are not stripped off and sent to the database individually.

[edit]Is there a limit on the size of a PL/SQL block?
Yes, the max size is not an explicit byte limit, but related to the parse tree that is created when you compile the code. You can run the following select statement to query the size of an existing package or procedure:

SQL> select * from dba_object_size where name = 'procedure_name';
[edit]What's the PL/SQL compiler limits for block, record, subquery and label nesting?
The following limits apply:

Level of Block Nesting: 255
Level of Record Nesting: 32
Level of Subquery Nesting: 254
Level of Label Nesting: 98


[edit]Can one COMMIT/ ROLLBACK from within a trigger?
Changes made within triggers should be committed or rolled back as part of the transaction in which they execute. Thus, triggers are NOT allowed to execute COMMIT or ROLLBACK statements (with the exception of autonomous triggers). Here is an example of what will happen when they do:

SQL> CREATE TABLE tab1 (col1 NUMBER);
Table created.

SQL> CREATE TABLE log (timestamp DATE, operation VARCHAR2(2000));
Table created.

SQL> CREATE TRIGGER tab1_trig
2 AFTER insert ON tab1
3 BEGIN
4 INSERT INTO log VALUES (SYSDATE, 'Insert on TAB1');
5 COMMIT;
6 END;
7 /
Trigger created.

SQL> INSERT INTO tab1 VALUES (1);
INSERT INTO tab1 VALUES (1)
*
ERROR at line 1:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "SCOTT.TAB1_TRIG", line 3
ORA-04088: error during execution of trigger 'SCOTT.TAB1_TRIG'
Autonomous transactions:

As workaround, one can use autonomous transactions. Autonomous transactions execute separate from the current transaction.

Unlike regular triggers, autonomous triggers can contain COMMIT and ROLLBACK statements. Example:

SQL> CREATE OR REPLACE TRIGGER tab1_trig
2 AFTER insert ON tab1
3 DECLARE
4 PRAGMA AUTONOMOUS_TRANSACTION;
5 BEGIN
6 INSERT INTO log VALUES (SYSDATE, 'Insert on TAB1');
7 COMMIT; -- only allowed in autonomous triggers
8 END;
9 /
Trigger created.

SQL> INSERT INTO tab1 VALUES (1);
1 row created.
Note that with the above example will insert and commit log entries - even if the main transaction is rolled-back!

Retrieved from "http://www.orafaq.com/wiki/PL/SQL_FAQ"

Monday, 29 September 2008

About the Post Graduate Programme in Management at Hyderabad ISB

A) About the Post Graduate Programme in Management
1) What is the PGP?
The PGP refers to the ISB’s full-time one-year residential Post Graduate Programme in Management. The PGP is comparable in rigor and content to a regular two-year full-time MBA programme offered by global business schools.

2) Is the PGP similar to the Executive MBA programmes offered by several business schools?
No. As mentioned above, the Post Graduate Programme is similar in rigor and content to a regular two-year full-time MBA programme offered by global business schools.

3) Does the PGP award an MBA degree?
No. Unlike in other countries, degrees can only be awarded by universities in India.

4) What are the concentrations being offered in the PGP?
The concentrations offered can be viewed on our website at http://www.isb.edu/pgp/Curriculum.Shtml?menuid=106

5) How many students would you be admitting for PGP 2009-10?

We are planning to admit about 560 students for 2009-10.



B) Admissions Criteria
1) What is the criteria for admission to the ISB Post Graduate Programme?
The eligibility criteria are –

Students must possess an undergraduate/graduate or post-graduate degree in any discipline
A minimum of two years' full-time post qualification work experience is preferred
A GMAT score
TOEFL/IELTS score is required for students from countries other than India, where English is not the primary language of instruction
All short-listed applicants will be interviewed as a part of the selection process

a) GMAT
1) What is the GMAT?
The GMAT is the Graduate Management Admission Test conducted by Graduate Management Admission Council and is a globally recognised test for admission to business schools. For more information on GMAT please visit their official web site http://www.mba.com/mba/TaketheGMAT

2) Is there a cut-off score for the GMAT at the ISB?
There is no cut-off score for the GMAT; however, a competitive score strengthens the application but does not in anyway guarantee admission. Similarly a lower score also does not necessarily mean exclusion.
3) Is it mandatory to take the GMAT before applying to the ISB?
Yes it is. The applicant has to take the GMAT and submit his/her score before sending in the application.
4) Can I apply with a Test Centre/Unofficial GMAT Score Report?

Yes, you can. However, the official score report from Pearson VUE should reach the ISB at least by the time we short-list the applicants.
5) What is the validity period for a GMAT score?

Currently a GMAT score is valid for 5 years.
6) If I submit more than one GMAT score, which score will be considered by the ISB?
The higher score would be considered, provided it is within the validity period of five years.
7) How long does it take for the Official GMAT scores to reach ISB?
Normally it takes 2-3 weeks for the official GMAT score to reach us. Therefore, we strongly recommend that applicants plan and book the GMAT test dates well in advance.

8) Will I be considered for the deadline if I send my GMAT scores later?
You will not be allowed to submit your application without a valid GMAT score. However, you can submit the application with your test centre scores, but the official score should also reach us within 3 weeks of submission of your online application.
9) Are CAT/GRE scores accepted by the ISB in lieu of GMAT scores?
No. The ISB does not consider the CAT/GRE scores for admissions, only the GMAT.
10) Can the GMAT requirement be waived under exceptional circumstances?
No. The GMAT score cannot be waived under any circumstances.


b) English Proficiency Requirements
1) Does ISB require a test to prove proficiency in English?
A TOEFL/IELTS score is required for non-Indian students who did not have ENGLISH as the primary language of instruction during their undergraduate studies.
2) Where would we get more information about TOEFL?
Please visit their official web site www.toefl.org or write to toefl@ets.org
3) What is the IELTS?
IELTS is the International English Language Testing System. To know more about IELTS please visit their official website http://www.ielts.org

C) Application Process
1) Where do I get a copy of the application form?
The ISB’s entire application process is available online and therefore no printed copy of the form is available/accepted. You will therefore need access to an internet enabled computer to apply to the programme. You will also need to scan some documents to be uploaded and will therefore need access to a scanner.
2) Does the entire application need to be completed within one session?
No. You can complete the online application in multiple sessions and have the option to save parts of the application as you proceed.
3) Do I also need to submit a printed copy of the application form once I have submitted it online?
No. We will not require you to send a printed copy of the application form.
4) How do I send in my academic transcripts/mark sheets, other documents and photographs required as part of the application?
You may scan and upload the following documents as part of the online application in the format specified in the application.

Photograph
Passport
Proof of Income
As far as mark sheets/Transcripts and Certificates are concerned, you may submit photocopies ( for all the academic/award details listed in the application) at the time of interview, if short-listed. All overseas applicants may forward soft copies (in pdf) of the same to PGPAdmissions@isb.edu , soon after they receive an interview intimation.

5) How can my referees submit their recommendation forms?
We prefer online recommendations to be submitted as part of your application. Your referees will be sent an email with a link on which they will be able to complete your recommendation form. Please ensure you enter their official email addresses only since personal email addresses will not be considered.

6) How will the ISB verify my transcripts/documents?
At the time of joining the programme, you will need to bring all the original documents with which we will verify the photocopies/scans with these originals.
7) Can I reapply?
Yes. You can reapply. Please note that you cannot reapply within the same academic year. You have to submit a fresh online application along with the application fee and essays. An additional essay listing the changes in your profile from the last year is essential. However, it is important to show a significant overall improvement from the previous year in view of extreme intensity of competition.

If you are an applicant in 2008-09, you will be able to use the same evaluations for your 2009-10 application also. You may do that by selecting the option available on the evaluator details page. However, it is always recommended to use fresh evaluations to get more insights into any of your recent initiatives, skill sets and changes in profile.

8) Do you acknowledge receipt of application by mail?
We convey the status of your application online. Do remember to check your application status.


9) I have scanned and uploaded the required documents, but I found them oriented towards 90 degrees in the Application pdf. How do I correct this?
There is absolutely no problem with this. You may go ahead submitting your application.

10) How do I submit a resume as a part of the application?
There is no need for submitting a separate resume. The online application module will generate a resume in the required format with the details you have filled as part of the application. It includes your Academic details, Employment details (along with responsibilities/achievements) and awards & activities.
D) Interviews
1) Do you have a GD/Personal Interview as part of the admission criteria?
As a part of the admission process, all short listed candidates will be interviewed. There is no group discussion
2) How many applicants are called for interview in Round-1 & Round-2 and how many selected?
There is no fixed percentage of students being called by the ISB either for interviews or for admission.
3) What will be the mode of my interview if I am overseas at the time of interview?
You will be interviewed over telephone. You have to call the telephone number given in the interview mail sent to you.


E) Fees
1) Can I pay the tuition fees in instalments?
Tuition fees can be paid in two instalments; however, the ISB allows a discount on fees paid one time in full.
2) Are there different fee structures for Indian and International students?
Currently the fee structure is the same for all students.
3) How do I accept the offer of admission?
You may accept the offer made by remitting a non-refundable admission fee of INR 200,000 (or US $ 5,000 within the deadline specified in the offer mail. If the amount has not been paid within the deadline, it will be assumed that the applicant is not interested in joining the programme.
4) a) Is the admission fee in addition to the tuition fee?
No. The admission fee is part of the tuition fees.
b) I have paid the admission fee but due to unavoidable circumstances I will not be able to join the programme. Will the admission fee be refunded to me?
No. The admission fee is non-refundable.

5) How much time do I have to accept or decline an admission offer?
The ISB should receive your acceptance decision within 15 days from the date of the admission offer along with the admission fee.
6) Can the admission offer acceptance date be extended?
No. The acceptance dates are fixed by the Admissions Committee. If the acceptance amount is not received by the due date it will be assumed that the applicant is not interested in the programme and the offer made to the applicant will stand automatically withdrawn.


F) Financial Aid
I fulfil the eligibility criteria but cannot afford the full tuition fee. Can the ISB help?
Financial Aid is provided to students in the form of tuition waivers, scholarships and loans.
Tuition Waivers: The ISB awards both merit and need based tuition waivers to qualifying applicants ranging from INR 1,00,000 to INR 3,00,000. Details of these waivers will be indicated in the admission offer where applicable.

Scholarships: The details of scholarships available to students are available on our website. Please visit the link http://www.isb.edu/isbweb/isbcms/PGP/Scholarships.Shtml for these details.

Loans: Student loans are available through a few leading financial institutions. Please check the website http://www.isb.edu/isbweb/isbcms/PGP/Loans.Shtml for details. International students applying to ISB are eligible for loans from IEFC. You may visit http://www.iefc.org for further details.
1) What is the difference between tuition waivers and scholarships?
Tuition waivers are discounts on the tuition fee granted by the ISB and communicated in the admission offer while scholarships are generally granted by other organisations and dependent on your performance in the programme.
2) Does the ISB offer financial aid to International students?

The ISB does offer financial aid to qualifying International students through tuition waivers.
3) What kinds of profiles usually get selected for scholarships?
The selection criteria usually depend on the organisation granting the scholarship. The qualifying process is highly competitive and the selection criteria vary from year to year.
4) How can an applicant apply for a tuition waiver?
The applicant has to write the required essay given in the application form and submit the latest income tax returns and pay slips of all the earning members in the family as supporting document.
5) When can one apply for an educational loan?
Once the admission process has been completed, all admitted students will be informed of the loan application deadlines through a separate mail.


G) Sponsorship
1) Can I get a sponsorship from the company where I am working?
Yes. Applicants are encouraged to get themselves sponsored by their employers.
2) Are there any other criteria to be fulfilled by the applicant for getting sponsorship from their employer?
No, there are no separate admission criteria for such candidates and the regular admission procedure will apply.
3) How does one apply to companies for sponsorships?
Each company has its own policies on sponsoring of high potential employees. It is up to you to ensure sponsorship from the company you are currently employed with.
4) Is there a different fee structure for sponsored students?
No. The fee structure and the selection criteria are universally applicable.


H) Exchange Programme
1) How many students normally go on Exchange Programmes?
The number varies from year to year and the outgoing exchange capacity for 2006-07 was in excess of 60 students. Globally 26 business schools currently participate in the ISB Exchange Network.
2) When do students go on Exchange Programmes?
Students go on an exchange programmes depending upon the mutual schedules of the ISB and the concerned exchanged partner school; this period can range from one to two ISB elective terms, most often terms 7 and 8 although some students do go in terms 5 & 6.
3) What are the selection criteria for the Exchange Programmes?
The students are allotted bidding points which they use to bid for their preferred exchange programme.
4) How does the bidding process work?
Each student is allotted an equal number of bidding points. Each term students must apply their points towards particular courses and the highest bidder is enrolled in each course. Normally most students get a majority of the courses that they bid for.
5) How do people manage possible time-clashes between the placement season and the Exchange Programme?
Most students return during placement week to participate, while others manage their placements from overseas.
6) Will all students admitted be allowed to participate in the exchange programmes?
Yes. For more details please visit http://www.isb.edu/pgp/ExchangeProgrammes.Shtml


I) Internship
1) Is there a summer internship at the ISB? If yes, how does it work?
As The ISB has a one year Post Graduate programme, a summer internship is not possible. However, the ISB offers the Experiential Learning Programme (ELP) to benefit students interested in doing projects while on campus. For more on ELP please visit http://www.isb.edu/pgp/ExperientialLearningProgramme.Shtml?


J) Placements
1) When do the Placements start?
Placements normally start in the mid 7th term and go on for a week. While a few companies start coming in from November onwards, the final offers are made/decided during the placement week only.
2) Does the ISB guarantee placements? What are the placements for graduates of the ISB PGP likely to be?
No. The ISB does not guarantee placements but every effort is made by the Career Advancement Services (CAS) Office to help students find and secure their ideal career opportunities. However placements are a function of demand and supply and the CAS helps students manage their career expectations realistically.

3) How was the placement scenario this year? Which are the companies that recruited this year? What was the average salary offered?
You will find details on the placement for the class of 2008 at http://www.isb.edu/pgp/Placement_Highlights.Shtml

K) Faculty
1) What is the role of visiting faculty at the ISB?

The ISB invites faculty to teach a course during a term and they are available on campus throughout the term. Faculty from Wharton, Kellogg, London Business School, Stanford, Chicago, Duke, and Texas among others, have taught at the ISB.
For more details please visit http://www.isb.edu/pgp/Distinctive%20Faculty.Shtml?menuid=105

2) How accessible are the faculty to the students?

Faculty members are easily accessible to the students, as they stay on campus throughout the term.


L) Credentials

1) Does AICTE/UGC recognise the ISB’s Post Graduation Programme in Management?

The ISB neither offers a diploma nor a degree. It is a certificate programme for students with experience. Therefore, we have not sought recognition for our Post Graduate Programme in Management from either the AICTE or the UGC.


M) Infrastructure & Facilities

1) Are all students required to live on campus?

Given the rigor of the course and The ISB’s aim to build a small but highly interactive campus community, it is a fully residential programme for all students.

2) Do you provide accommodation for married students?

We offer fully serviced studio apartment with preferential allotment to married students. However, your preferred type of accommodation cannot always be guaranteed, though every reasonable effort is made to address your specific requirements.

3) What all is provided in the accommodation?

Accommodation information can be found in http://www.isb.edu/KnowISb/Housing.Shtml

4) What are the facilities provide on campus?

The ISB provides the following facilities:
ICICI Bank branch
Daily Needs store- MORE
Infirmary – Branch of Apollo
Recreation Centre – Equipped with Squash, Swimming pool, basket ball ground, Tennis, Table Tennis, Gymnasium, Toddler’s room etc.
House Keeping
Washing machines in addition to laundry service
Please check the web site for further information http://www.isb.edu/pgp/WorldClassCampus.Shtml?menuid=105


N) Reservations

1) Do you have any quotas for NRI'S/SC/ST/BC?

No. We do not. However, the ISB encourages applications from candidates with diverse backgrounds.

2) Will Indian and foreign applicants be evaluated on the same basis?

Yes.


O) Campus Visits and Meeting the Alumni

1) I am interested in a Campus tour. How and when can I visit the campus?

Regular campus visits are organized by the ISB on all Fridays during the Admission period. For registration please visit http://www.isb.edu/pgp/AdmissionEvents.Shtml?menuid=109

2) How do I contact current batch students?

Please visit http://www.isb.edu/pgp/ContactAlumni_Students.aspx for more details on interacting with the current students.

3) How do I contact the Alumni?

Please visit the link http://isb.edu/pgp/ContactAlumni_Students.aspx and complete the online form. Once we receive this request we shall get back to you with the contact details of the alumnus or ask the alumnus to contact you directly.


P) Miscellaneous

1) Will part-time work experience be considered?

Work experience should be full-time. Part-time work experience will not be considered.

2) Will Army service be considered as work experience?

Yes, your work experience will be viewed in the context of the responsibilities you have handled.

3) I have worked in my family owned business for the past three years – will this experience be considered?

If this experience is full-time and if you can support this with relevant documents in your application, you can apply. The quality and relevance of your experience in your business will be critical. You will still have to furnish recommendations. Recommendations from your father, friends and family will not be accepted. You should furnish recommendation from people with whom you have a strictly professional interaction like your clients, vendors etc.

4) Do I need 16 years of formal education?

No, as long as you have been awarded a Bachelor's Degree from a recognized university, you are eligible to apply


5) Do you consider deferral of admissions?

The School does not normally permit deferral of admissions. However, in exceptional cases where applicants are unable to join after accepting the admission offer and depositing the stipulated acceptance fee, the School may consider deferment of admission to the following academic year. Such decisions, if any, will be made only after due validation of the genuineness of the request for deferment and compliance by the applicant concerned with the stipulated requirements. The decision of the School in this regard will be final.

6) How important are extra-curricular activities in the application?

The ISB would like to admit well-rounded students. Extra-curricular activities add that extra dimension to your personality. In the US it is routine for people to do community service, which they can mention as an extra-curricular activity in their applications. But Indian conditions are different, so not having done such activities is understandable. However, if you look deep down, you may find some things that you may have been doing. Did you tutor a kid anytime, did you organize a festival in your apartment complex, did you volunteer your time in some campaign or raise funds for some cause, etc.? If you haven't done anything at all, it's never too late to start. Don't do it just to get your B-school admission, but do what interests you. If you are in the IT area, think of something related to IT that you can do after office hours. How about persuading your company to donate their obsolete computers to charity? The possibilities are endless.

7) Will I need to buy text books?

Although most study material is included in the course packs, periodically you will need to buy text books for various courses. The expenditure on text books for the programme is estimated at INR 15,000-INR 20,000.

8) Are there any schools for children in the vicinity of the ISB?

Yes. There are a number of schools around the ISB. More information is available upon request.

9) Having done an MBA, am I eligible for the ISB programme?

There is no restriction in applying to our Programme but you should demonstrate very good reasons in your application for wanting to do the PGP from the ISB.

10) I hold a Master Mariner’s competency certificate. Will I be eligible for applying to the ISB?

Yes, you will be. However, you will need to obtain a certificate from World Education Services (http://www.wes.org ) to the effect that your certificate course is equivalent of a Bachelor’s Degree.
11) I have completed a three year diploma course but do not have an under-graduate degree. Am I eligible for the ISB Programme?

The eligibility criterion at the ISB requires all students to have an undergraduate degree. If your diploma is considered to be equivalent to a degree by the appropriate authorities then it will be acceptable otherwise not.