Java EE 6 Teknolojilerine Giriş

Hakan Uygun (hakan.uygun@ozguryazilim.com.tr)

İçerik

Anahtar Kelimeler

Standartlar

Java'nın Kısa Tarihi

Kurumsal Uygulama Gerekleri

Çözüm Yöntemleri

Katmanlı Mimari

Java EE Profilleri

Java Paketleri

Uygulama Sunucuları

Web Uygulama Çatıları

Geliştirme Araçları

Java Web Teknolojileri

Web Tekolojileri Tarihi

Servlet 3.0

    
    		
<web-fragment>
	<servlet>
    	<servlet-name>myFrameworkServlet</servlet-name>
        <servlet-class>myFramework.myServlet</servlet-class>
	</servlet>
</web-fragment>
    		
    
    	

JSF Nedir?

JSF 2.0

JSF Örneği

    
    
    <xml version="1.0" encoding="UTF-8"?>
           <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:ui="http://java.sun.com/jsf/facelets">
   <head>
           <title>Guess Number JSF Application</title>
   </head>
   <body>
      <h:form>
       <h2>Hi. My name is Duke. I am thinking of a number from <b>
              <h:outputText value="#{UserNumberBean.minimum}"/> to
              &nbsp;&nbsp;<b>
       <h:outputText value="#{UserNumberBean.maximum}"/>.
       <p>Can you guess it ?</p>
       <h:graphicImage id="waveImg" url="/wave.med.gif" />
       <h:inputText id="userNo"
             value="#{UserNumberBean.userNumber}">
          converterMessage="#{ErrMsg.userNoConvert}">
       <f:validateLongRange
             minimum="#{UserNumberBean.minimum}"
             maximum="#{UserNumberBean.maximum}"/>
       </h:inputText>
       <h:commandButton id="submit"
             action="success" value="submit" />
       <h:message showSummary="true" showDetail="false"
                  style="color: red;
                   font-family: 'New Century Schoolbook', serif;
                   font-style: oblique;
                   text-decoration: overline"
                   id="errors1"
                   for="userNo"/>
       </h2>
      </h:form>
   </body>
   </html>
    
    
    
    

JSF Örnek Sonuç

ManagedBean

    
    
    
@ManagedBean(name="userBean")
@RequestScoped
public class UserBean {
      private String name;
      public String getName() {
        return name;
      }
      public void setName(String name) {
        this.name = name;
      }
      public UserBean() {}
}
    
    
    
    

JSF Scope

Expression Language ( EL )

Bileşen Kütüphaneleri

JAX-WS

		
		
@WebService(endpointInterface = "juma.mohammad.Greeting")
public class GreetingImpl implements Greeting {
 
  @WebMethod
  public String sayHello(String name) {
    return "Hello, Welcom to jax-ws " + name;
  }
}
		
		
		
		

JAX-RS

    
    
@Path ("items")
@Produces (MediaType.APPLICATION_XML)
Public class ItemsResource {
	@Context UriInfo uriInfo;
   @GET
   Items listItems() {
   		Return Allitems();
   }
   @POST
   @Consumes (MediaType.APPLICATION_XML)
   Public Response create(Item item) throws ItemCreationException {
           ...
   }
   ...
}
    
    
    
    

Kalıcılık Katmanı

Object-Relational Map ( ORM )

ORM-0 : JDBC

ORM-1 : Veri Erişim Katmanı

DAL : Data Access Layer

ORM-2 : Kod Üretici

ORM-3 : ORM

Java Persistance API ( JPA )

JPA Örnek

    
    
@Entity
@Table(name="ACCOUNT")
public class Account extends AuditBase implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE,generator="genericSeq")
    @Column(name="ID")
    private Long id;
    
    @Column(name="ACCOUNT_TYPE")
    @Enumerated(EnumType.ORDINAL)
    private AccountType accountType;
    
    @Column(name="CODE", length=20, nullable=false, unique=true) 
    @NotNull
    @Length(max=20, min=1)
    private String code;
    
    @Column(name="NAME", length=50) 
    @Length(max=50, min=1)
    private String name;
 
 .....
}
    
    
    
    

Temel Kurallar

EntityManager

EntityManager Örnek

    
    
@PersistanceContext
EntityManager em;
Account acc = em.find(Account.class, 1L);
acc.setCode(“010101”);
em.merge(acc);

//Sorgu
em.createQuery(“select c from Account c”)
     .getResults();
    
    
    
    
    

Criteria API

    
EntityManager em = ... ;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = cb.createQuery(Employee.class);
Root<Employee> emp = cq.from(Employee.class);
cq.select(emp);
cq.where(cb.equal(emp.get(Employee_.lastName), "Smith"));
TypedQuery<Employee> query = em.createQuery(cq);
List<Employee> rows = query.getResultList();
    
    
    
    

İş Kuralları Katmanı

Enterprise Java Bean ( EJB )

EJB 3.1

EJB Örnek

    
    
    
@Stateful
Class public HelloAction implements Serializable{

	public String sayHello( String name ){
		return “Hello “ + name;
	}
}

//Kullanım
@Ejb
HelloAction hello;
    
    
    
    
    
    

Context Dependency Injection

CDI Örnek

    
    
    
@Stateful
@SessionScoped
@Model
public class Login {
      @Inject Credentials credentials;
      @Inject EntityManager userDatabase;
      private User user;

      @RolesAllowed("user")
      @Produces @LoggedIn User getCurrentUser() {
         ...
      }
}
    
    
    
    
    
    

CDI - Weld

Qualifier

    
    
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface Informal {}
    
    
    
    

Producer Method

    
    
    
private int maxNumber = 100;
...
@Produces @MaxNumber int getMaxNumber() {
return maxNumber;
}

----------
//Kullanım Biçimi
@Inject @MaxNumber Instance<Integer> randomInt;
    
    
    
    

JBoss Seam 3

Sorular