Wednesday 31 December 2014

Oracle Database Architecture

In this tutorial we are going to see about Oracle Database and basic details of its various types of files and few background processes in brief.
Oracle is an Object Relational Database Management System (ORDBMS).  An Oracle database server consists of a database and at least one database instance. An Oracle database is a collection of data treated as a unit. The purpose of a database is to store and retrieve related information. A database server is the key to solving the problems of information management. The database has logical structures and physical structures. Because the physical and logical structures are separate, the physical storage of data can be managed without affecting the access to logical storage structures.

Database: It’s a set of files, located on disk which is used to store the data.

Instance: It’s a combination of System Global Area (SGA) and a set of background process which is used to manage database files.

The below diagram shows these details.




Physical Structures

Data file: It contains the actual data stored in the database objects like tables, indexes etc.

Control file: It contains the details of physical structure of the database like name of database, location of data file etc.

Redo log file: It contains details of the changes made to the database, which will be used in case of db failure. It’s a set of files always.

Parameter file: Contains the configuration details of instance and database, one machine readable (SPFILE) and human readable (PFILE).

Alert & Trace file: All background process write to these files when some abnormal activates happens in the database and for additional information when some operations is being performed.

Logical Structures

Data Blocks: It’s the lowest level where an Oracle exactly stores a data. One data block represent specific number of bytes.

Extends: It’s the next level of database space, which represent contiguous data blocks.

Segments: Its above extends, collects of extends stored for specific user object.

Tablespaces:  It’s the logical container for various segments, and each tablespace contains at least one data file.

Memory Structure

System Global Area (SGA): It’s a shared memory structure, which contain data (i.e. data block, shared SQL area) and information for a single oracle database instance. It’s shared by all server and background process.

Programmable Global Area (PGA): It’s shared memory stricter, which contain data and control information for a server or a background process. Each server process has its own PGA

User Global Area: Memory that is associated with a specific user session.

Client Process: These process are created and maintained to run the software code of an application program on an Oracle Tool.

Oracle Background Processes

PMON-Process Monitor: Manages all the process, performs recovery when a user process fails, cleaning cache, freeing resources.

SMON-System Monitor: Processes recovery after instance failure and monitors and cleans temporary segments and extends that are not used.

DBWn-Database Writer: It takes care of writing the modified blocks from the database buffer (RAM) to the data files.  

LGWR-Log writer: It writes the redo log entries to the disk.

CKPT-Checkpoint: It writes information to control files and data file headers.

MMON: Process to collect statistics for Automatic Workload Repository (AWR) report.

RECO-Recovered process: Used to resolve distributed transaction that are pending due to network or system failure in distributed database.

SGA Components

Database Buffer Cache: Contains the most recently used blocks of data. Contains both modified and unmodified blocks.  

Redo log buffer: Circular buffer in the SGA that stored the redo entries describing the changes made to the database. These contain information necessary to reconstruct, or redo, changes made to the db by DML or DDL operations.

Shared Pool: It’s the place where SGA has the library cache (SQL, PL/SQL code), dictionary cache (Oracle accessed data dictionary item used for SQL parsing) and result cache (results of SQL queries, PL/SQL that are cached).


Please provide your comments below the blog.

Wednesday 24 December 2014

Oracle ADF architecture


Oracle ADF is based on the Model-View-Controller (MVC) design pattern. An MVC application is separated into:

1) A MODEL layer that handles interaction with data-sources and runs the business logic,
2) A VIEW layer that handles the application user interface, and
3) A CONTROLLER that manages the application flow and acts as the interface between the Model and the View layers.

Separating applications into these three layers simplifies maintenance and reuse of components across applications. The independence of each layer from the others results in a loosely coupled, Service Oriented Architecture (SOA)




Oracle ADF implements MVC and further separates the model layer from the business services to enable service-oriented development of applications.
The Oracle ADF architecture is based on four layers:
• The Business Services layer – provides access to data from various sources and handles business logic. (EJB, Web Services, ADF BC, .xml Bean definition file) 
• The Model layer – provides an abstraction layer on top of the Business Services layer, enabling the View and Controller layers to work with different implementations of Business Services in a consistent way. (.cpx, .dcx, .xml) 
• The Controller layer – provides a mechanism to control the flow of the Web application. 
• The View layer – provides the user interface of the application. (VO files (__vo.xml), .java, .jsp, .jspx, .uix)

Oracle ADF lets developers choose the technology they prefer to use when implementing each of the layers. The diagram above shows the various options available for developers when building Oracle ADF applications. The glue that integrates the various components of Java EE applications and makes development so flexible is the Oracle ADF model layer. EJB, Web Services, JavaBeans, JPA/EclipseLink/TopLink objects and many others can all be used as Business Services for the Oracle ADF Model. View layers can include Web based interfaces implemented with JSF, Desktop Swing applications and MS Office front ends, as well as interfaces for mobile devices.

The Business Services Layer
The Business Services layer manages interaction with a data persistence layer. It provides such services as data persistence, object/relational mapping, transaction management, and business logic execution.
The Business Services layer in Oracle ADF can be implemented in any of the following options: As simple Java classes, EJB, Web services, JPA objects, and Oracle ADF Business Components (VO, EO & AM). In addition, data can be consumed directly from files (XML or CSV) as well as REST.

The Controller Layer
The controller layer manages the applications flow and handles user input. For example, when you click a Search button on a page, the controller determines what action to perform (do a search) and where to navigate to (the results page).
There are two controller options for web-based applications in JDeveloper: the standard JSF controller or the ADF Controller which extends the JSF controller functionality. Whichever controller you use, you will typically design your application flow by laying out pages and navigation rules on a diagram.
With the ADF controller you can break your application’s flow into smaller, reusable task flows; include non-visual components such as method calls and decision points in your flow; and create “page fragment” flows that run inside a region of a single containing page. This approach encourages maximum reusability for user interface fragments and simplified integration into portals and smashup applications.

The View Layer
The View layer represents the user interface of the application.
Oracle ADF support multi-channel access to your business services allowing you to reuse your business services and access them from a Web client, a client-server swing desktop based application, Microsoft Excel spreadsheets, or a mobile devices such as a smart-phone.
For Web based interface Oracle ADF offers a rich set of over a 150 Ajax enabled JSF components that simplified the creation of dynamic and appealing user interfaces.

The Model Layer
The model layer connects the business services to the objects that use them in the other layers. Oracle ADF provides a model layer implementation that sits on top of business services, providing a single interface that can be used to access any type of business service. The model layer consists of two components, data controls and data bindings, which utilize metadata files to define the interface. Data controls abstract the business service implementation details from clients. Data bindings expose data control methods and attributes to UI components, providing a clean separation of the view and model. Due to the metadata architecture of the model layer, developers get the same development experience when binding any type of Business Service layer implementation to the View and Controller layers.


Please provide your comments below the blog.

Message box on Button Click in Android (TOAST)

This tutorial explains how to show a message box on button click of an Android application.

Create a new Android project:

Create a new project as in the Hello World Android tutorial.

Application Name:  Message Alert
Project Name: MessageAlert
Package Name: com.skk.messagealert

Minimum SDK:  API 8
Target SDK: API 20
Compile With: API 20
Theme: Holo Light with Dark Action Bar

Activity Name: Message_Alert

1)      Remove the existing TextView “HelloWorld”

2)      Drag and drop a button from the Forms Widget Pallet to Android Screen and rename the Text properties to “Show Alert”





3)      Response for the button click in Android can be done via any of the two following ways,

a.       By setting onClick event:
In the properties of the button change the onClick event value to sendMessage. This will update the XML as below

android:onClick="sendMessage"

 Complete XML File:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.skk.messagealert.MessageAlert" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="98dp"
        android:layout_marginTop="46dp"
        android:onClick="sendMessage"
        android:text="Show Alert" />

</RelativeLayout>

Now we need to write the code for showing the Message on button click i.e the event, go to the java file MessageAlert.java under src\com.skk.messageAlert\ add the following method in MessageAlert class

public void sendMessage(View view) {
              Toast.makeText(getApplicationContext(), "You have clicked me!", Toast.LENGTH_LONG).show();
       }

Typically in this method we set the text that needs to be displayed when button is clicked, and how long it should be shown and show the message to the user.

a.       Using onClickListener event:
In this method we set the Listener event for the button. The below is the code for the same.

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_message_alert);
             
              Button bt1 = (Button) findViewById(R.id.button1);
              bt1.setOnClickListener(new View.OnClickListener() {
                    
                     @Override
                     public void onClick(View v) {
                           Toast.makeText(getApplicationContext(), "You have clicked me!", Toast.LENGTH_LONG).show();
                     }
              });
       }


Here we create a local variable to refer the button and add the EventHandler for that and on click of that we show the message using Toast.

4)      1)      After creating the code as in any one of the methods above, save and run the code as Android Application Project. This will launch the android application. Once you click the button you should be able to see the message being show.



Successfully we have created and deployed the sample message box in Android.

Additional Details:

Toast: Toast is used to show a small popup upon a specific action in Android, while the current activity remains visible and interactable.
makeText(): This is used to create the text message that needs to be displayed , duration and the application context.
show(): This method is called to displayed the created text message.
R.java:  This is an auto generated file for all the Android project, it creates a unique ID for all the elements in the Android application i.e Button, title, logo etc. Sample value below.

public static final int button1=0x7f05003c;


Note: The value of the button might differ for you.

Please provide your comments below the blog.

Hello World in Android more details


This tutorial explains provides you some basic explanation about the Android application project.

Following are the list of items which needs to be known when creating a simple application.

1)      Activity:
Activity is the one which provides screen to the user where he can interact with the application. There should be at least one activity in your Android application to run. Whenever an application icon is clicked any one Activity will be started.

2)      Layout:
Layout is one which defines how your application screen should look like. The layout that we use in the HelloWorld application is RelativeLayout. Which sets the items in a sequence based on other items. In every Android project there will be a folder called LAYOUT in which all the layout design files are stored in XML format.

3)      AndroidManifest.XML:
This file contains the configuration details of our Android application, the minSDK and targetSDK. List of permission that the application need access i.e internet, camera etc.., the first activity that needs to be run when the application launches. What’s the display name of the application, the theme that needs to be used etc.

Below is the file sample file of an Android application.

xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.skk.helloWorld"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>


4)      Values folder:
This section in the Android project contains the strings, styles, format of the UI elements etc. Below is the sample strings.xml which contains the strings and its values.

xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Hello Kumar</string>
    <string name="hello_world">Hello Kumar!</string>
    <string name="action_settings">Settings</string>

</resources>


5)      Drawable folders:
This section contains all the images that are used in the Android application. The images with various resolutions are kept in separate folders.

The above are the basic details that needs to be known for a sample application. Details in depth will be explained in separate posts.

Please provide your comments below the blog.

Hello World application in Android


This tutorial explains how to create a hello world program in Android.

For setting up the Android development environment check out this blog.

Create a new Android project:


1)      Open the Eclipse IDE, Click on the menu item File à New à Android Application Project

 
2)      Once you select the menu, you will be able to find a screen to enter the details of the
new project enter the details as show in the screenshot below.


Application Name: Name that appears to users after the app is installed.
Project Name: Name for uniquely identifying the project
Package Name: Package namespace for your files, this should be unique             across all packages installed on the Android system.
Minimum Required SDK: Lowest version of Android your application supports, to support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature.
Target SDK: Indicated the highest version of Android you have tested the application.
Compile With: Indicated the version with using the program is compiled and build.
Theme: Specifies the Android UI for your App.


The Minimum Required SDK, Target SDK & Compile With are noted with the Android API number.

3)      Just Click on Next in Configure Project screen


4)      You can configure the icon for your application in this screen, select any image icon from your computer. This image will display as the icon for your android application and click Next.


5)      In the Create Activity screen click on Next leaving it to the default selected value “Blank Activity”


6)      Now provide the name for your activity, rename that to SayHello and click on Finish.


7)      This will open a screen similar as below,


8)      1)      Under your project folder structure go to res à Values à strings.xml, change the value of the string hello_world to “Hello Kumar”,  i.e  Hello Kumar!

9)      Just Right Click on your project name select Run As à Android Application.


10)   Once the AVD is launched and the project is deployed you should be able to see the application running successfully as below.


If you go back to the application list page you will be able to see your application with the icon that you selected, sample screen shot below.


Finally successfully we have created the hello world application and ran it successfully.