Вы находитесь на странице: 1из 11

----------- Part - 1 ----------------Presentation Layer (Struts-->JSF using develope view),conroller used for flow c

ontrol
Business Layer(EJB enterprise java beans) develop business logic
1. session beans (Business component)
2. entity beams (Database related opertion)
3. messageDrivenBeans
All are Inetface.
Database Layer(Sql server, JDBC)
Problem : BL->[1] EJB having heavyweight component.
Ex -approach to implment servlet
1.implements servlet we need to override 5 method.
2.genricservlet(I)(implement by above)
3.HTTPServlet(extend above)
so all 5 method coming in any servlet to implement.
[2] Testing is more complicate.(For this need middleware server)
When Error each time need to start server and stop the server.Time consuming pro
cess.
[3] More number of XML file need to develope.
[4] not possible to run EJB component outside the server.
Spring : only replacement of EJB technology.
Advatages :
1.Not develope server based XML file.only one time need to develope
2. Testing is very simple.

------------------ PART 2---------------Software (set of files contain)


Two type of FrameWork(It contains collection of jar file).(i.e. Juint,Strut,Spri
ng,Hibernate)
1. Invasive (need to implement predifined API)(i.e. Struts Heavywieght component
)
2. Non- Invasive ( No need) (i.e. Spring,Hibernate)
-- Placeing jar file in classpath location is intialization of framwork.
-- Framework Application develope in time .
After Spring FramWork :PL : Same
BL :
Spring FW
(Business component)
Hibernate FW (Database related opertion)
Layer : Webservice by using use same B logic in any other (. net , mainframe log
ic)
DL : Same
----------------- PART 4 ----------------[1] Spring IOC Module (dependency injection mechanisum)
IOC : inversion of controll

-- when create object of any class , each having different memory address. so no
t in time response.
Sol:
For this we will use spring framework(to create class object).So given object to
different application (is called Dependenct injection mec) .
Give same reference.
XML file : handover component to container(not understand XML code).
<DTD.....> /*SAX(java)/DOM(other) complier will actived , convert xml code into
container understand format.
<beans>
<bean id="id1" class="Class_name">
<property name = "------">
<value>welcome to spring demo</value>
</property>
</bean>
1. -- How Load the configration file HD to main memory
Package : org.springFramework.core.io.*
Resource(I)
implement 2 class
[1] classpathResource(); -- Configuration file available same location
[2] FileSystemResource(); -- not in same directory
using this we can load spring confi file.and handover to container
Two Container
1. Basic :
[A]BeanFactory(I) : org.springFramework.Beans.factory.*
--XmlbeanFactory(c) : org.springFramework.Beans.factory.xml.*
Both packages are required.
Example:
import
class client{
main(){
Resources res = new classpathResources(name.xml);
BeanFactory factory = new XmlBeanfactory(res);
Object o = factory.getBean("id1");
/* type Nastiing */
welcomeBean wb =
}
}
Two Jar file in classpath location
1. spring.jar
2. common_logging.jar
Different type of injection
1. selter (spring)
1. dependency in the form of primative and string based value
2.
objective.
3.
collection.

Class SampleBean
{
private int k;
private String nsg;
---------------private DemaBean db;
Problem :1. no seperate id for inner bean
2. occupy memory for same reference (waste of memory)
Sol :
<ref -------=" "/> tag will be used.
-- local (within XML file)
-- Parent (other XML)
-- Bean(both)
--------------private List data;
}
2. constructor (spring)
3. interface (struts 2.*)
--------------------- PART 7 IOC-------------Type of coupling
1.Tight (one class object into another class object by using new operator)
no suitable. effect on existing component.so need to again develope.
2.Loose()
Not effect on existing component.
To implement Loose coupling:1.need to follow POJO(plain old java object) and POJI(plain old java interface)
concept
jourany (I) -->
Travller(c) -->
{
publice vechial v;
}
Vechial(I)-->
car(c) --> int/string (POJO)
motercycle -->int(POJO)
****** Create 2 XML file for this *********
1. Vechial
2. Jounany (used object class)
How to import Both Xml file

import both class sperately as we do.


but in second (used/child)
beanfactory factory1= new xmlbeanfactory(res1,factory)
NOTE :: first create inner bean than outer bean.

********************** PART 10 *****************


Dependency in form of Collection :Four Type of Collection suport by Spring
1.Set
2.List
3.Map(key,value) (Most need tag)
4.property(key,value)(Not any tag)
1. <set>
2. <list>
3 <map>
<entry>
4.<props>
<prop>
all present in java.util Package
MAP:-->
private map<string,Integer> var_name;
setter method((map<string,Integer> var_name);
printf method :-->
{
Set s =var_name.entryset(); {get the keys value}
Itrator is =s.iterator();
While(is.hasnext())
{
Map.entry me =(Map.entry)it.next();
s.o.p(me.getkey() + me.getvalue());
}
}
}
}

{Map(I).entry(Nested Class)}

******************** PART 13 ********************


[2] Constructor Injection :
<constructor-arg>
Note : When setler and constructor both present in single then setler override c
onstructor.
****************** PART 14 **************************
Disadvantage:

[1] if multiple constructor / multiple parameter constructor present in Bean cla


ss then
then multiple reference of same constructor will create .waste of memory.
[2] Circular dependency problem :unresolved problem
Two class and each need other class object.
Soluation : go for selter injection for one class.
Spring will create mock(empty) object using default consturctor when it called.
********************* PART 15 ******************
Bean Autowiring :
Directly place inner bean into outer bean.
(atribute) AutoWire :
1. By name
2. by type
3. constructor
4. Autodetect
5. none(default/disable mode)
********************* PART 16 *******************
3] constructor
constructor of class need
[4] Autodetect
if constructor then work according if not then by type it will work.
******************** PART 17 *******************
anotation in auto wiring
[1] @autowired :
if we don't use autowire atribute then we use it.
-- At setler level we use it(above it){ Acting as a by type}
-- At constructor level {Acting as a constructor}
-- if single reference of inner bean then no problem
****** Multiple reference of inner bean****
ambiguty error
Solution
[2] @Qualifier("ob_name")
If both anotation used then acting as a by name.
NOTE : For this we want to use advance container.
Differenent ;
1. suport all anotation
2. no need too load XML file sperate
3. object create early.
**** init_lazy = false; *******
Advance container :

package : org.springframework.context.*
[1] Applicationcontext (I)
package : org.springframework.context.support.*
-- classpathxmlapplicationcontext (C) : same location
-- filesystemxmlapplicationcontext (C) : different location
-- xmlwebapplicationcontext (C) : Automatically active by spring controller call
ed dispitcher
After loading
Object o = aa.getbean("");
**************************** PART 18 ********************
Bean Validation : by default(disable) not verified all properties by container.
if not asign properties value then default value will asign
To enable it : along with bean config we use 1 atribute
<dependency-check = ""> having 4 value
1. sample (only primative verify)
2. objects (only objective / Collections)
3. all (for Both)
4. no(default)
*************************** PART 19 ********************
Drawback :
[1] If we have large number of primative type vaiable.{Use simple}
So we need to config all the properties
-- But we want only few need to check , this is not possible
Soluation : remove dependency and take
@Requried(I)
Public void setPro_name(type var)
{
this.var=var.
}
************************* PART 20 ***********************
Life cycle of Bean:
Doesn't existing State (initial)
|
bean inig
|
bean intiatited
|
providing the service
|
destroy the object
|
doesn't existing State
For this life cycle need to implment 2 interface
Package : org.springframework.bean.factory.*
[1] InitializingBean (I)

public void afterPropertiesSet()


{
/**** Automatically called by spring container *****/
}
[2] DisposableBean(I)
public void destory()
{
/**** Automatically called by spring container *****/
/**** to call this need to close the container *******/
/*** for this
ApplicationContext(I)
|implement
ConfigureableApplicationContext(C)
******/
container_ob.close(); must be call at the end.
}
Both are life cycle method.
No need to call method, Container will call it.
Public class c_name implements I1,I2
{
NOTE : this also suport Advance container.
No need to call method, Container will call it.
--------------------------------------------If implement pridefined API it will heavyweight component , Reduce performance.
Solution :
[A] use Xml tag
{B]
two Anotation used for this
[1]@postconstruct
[2]@predestory
*** @Overridge :
******************* PART 21 ****************
JDBC dsiadvantages :
[3] Duplicate Code (boilar Plate code)
[4] Some error Code will be generate (ORA-652)
Overcome This Problem :
Entity Beans
Disadvantage
[1] heavywieght
[2] More XML file

Overcome :
Spring with JDBC
To get connection object :javax.sql.Datasource(I)
org.springFrameWork.jdbc.datasource.*
--> DriverManagerDataSource(C)
IN Small Scale Applications
Four Property
[1] driverClassName = "driver_class_name"
[2] url = "jdbc:oracle:thin@localhost:1521:serviceid"
[3] username
[4] password
org.apache.commons.dbcp.*
--> BasicDataSource(C)
IN Large Scale / Production Applications
To perform database relate operation 2 centelized class(Template class):
org.springFrameWork.jdbc.core.*
1. JdbcTemplate(predifiend)
org.springFrameWork.jdbc.object.*
2. StoredProcedure
Having internal process and some method .
1. Public Void Excute(); (DDL operation) ("inside pass Query")
2. Public int Update(); (DML operation)
3. Query(); (DQL Operation)(select)
1.QueryforList();
2.QueryForint();
3.QueryForlong();
4.QueryForObject();
************ PART 2 JDBC*********
Number of class config
1. Connection
2. JDBC template
3. Bussiness Class
Number of jar :
1.spring.jar
2.common-logging.jar
3.ojdbc14.jar
global_name
Drawback :
1. Persitance logic is less.( both business and data access logic same)
2. Passing Static value not dynamic.
************ PART 4 JDBC *****************
Soluation :
Separte implement Both Logic (DAO (Data access Logic)Design patteren)s
interface EmpDAO
{
public int intialemp(Employee e)

}
Employee with property with seter and getter method.
Public class Bus_log
{
private EmpDAO dao;
seter/getter method
}
Public class per_log implments EmpDAO
{
private JdbcTemplate jt
seter method;
implement of all method
Store all value as Object array.
Object [] ob ={,,};
[1]
int k = jt.update("insert into t_name values(?,?,?,?)",ob)
[2]
List l = jt.QueryList(select * from t_name)
Iterator it = l.Iterator();
While(it.hasnext())
{
s.o.p(it.next());
}
[3]
int k = jt.Update("update t_name set c_name = ? where c_name = ?", ob)
Number of Class config
1. connection
2. jdbc
3. m_Class

************** PART 7 JDBC *************


Problem : Direct Hitting Database - profermance are decrease.
Soluation : Stored Proc.
Package : ore,springframework.jdbc.object.*
To call Stored Proc : extend class from StoredProcedure(C)
Class A extends StoredProcedure
{
A(DataSource ds)
{
Super(ds,proc_name);
/*Method present in SP(C)
For Input Parameter*/
[1] declarePrameter (new sqlparameter("name_col",TYPE.INTEGER))
For output Parameter
[2]declarePrameter (new sqloutparameter("","")

}
Public void call_proc(int )
{
MAP imp = new HashMap();
imp.put("var_name",inp)
MAP omp = excute(imp);
object o1 = omp.get("out_col")
o1.toString()
Integer i.intValue();
}
}
}

***************************** SPRING J2EE PART 1 *********************


1. TimerService : Time when Start , Stop.
For this 2 Thread will implement
[A] Public class Task1 Entends TimerTask {java.util.*}
{
Public void run()
{
s.o.p();
}
}
[B]
import java.util.*;
import java.io.*;
Public class Task2 extends TimerTask
{
Public Void run()
{
try
{
Filewriter foo = new FileWriter(".txt",true)
foo.write(new data())
s.o.p
foo.close();
}
Catch(expection e)
{
s.o.p
}
}
}

Clinet Application :only loading

[2] RMI service : (remote method service)


Distrbute Programing (RMI , Socket/): 2 diff Object run into Different JVM then
it will req.
IF 2 object and 1 JVM then not Req.
For this we need to develop Helper class , this is problem development side.
Soluation : RMI (automatically create helper class)
For RMI Application
1. interface
2. class
3. server
Public interface i1 remote(java.remote.*)
{
}

import java.rmi.*
import java.rmi.server.*
Public class c1 extends UniCastremoteObject (**Clcas not allowed duplicate URL)
Implements i1
Public String (String uname) throws RemoteException
{
}
}
**** server application
import java.rmi.*
import java.net.*
Public class fs1
{
publice static void main()
{
c1 ob1 = new c1();
Naming.rebind("rmi:localhost:1099/tester",ob1)
s.o.p(start)
}
}
javac *.java
rmic c1 -->firstimpl.stud.class(helper class)
Start rmiregister
java fs1

Вам также может понравиться