31
What's new in Java EE 7? Java User Group Berlin Brandenburg 04.12.2013 Dirk Weil, GEDOPLAN GmbH

JUG Berlin Brandenburg: What's new in Java EE 7?

Embed Size (px)

DESCRIPTION

Vortrag auf der Java User Group berlin Brandenbuirg 4.12.2013

Citation preview

Page 1: JUG Berlin Brandenburg: What's new in Java EE 7?

What's new in Java EE 7?

Java User Group Berlin Brandenburg

04.12.2013

Dirk Weil, GEDOPLAN GmbH

Page 2: JUG Berlin Brandenburg: What's new in Java EE 7?

Dirk Weil

CEO of GEDOPLAN GmbH, Bielefeld, Germany

Java EE since 1998

Conceptual design

and implementation

Talks

Training

Books & articles

Power Workshop Java EE 7 2

Page 3: JUG Berlin Brandenburg: What's new in Java EE 7?

Java EE

What's new in Java EE 7? 3

1.2

1.3

1.4

5 6

7

1.1

1.0 1998

2001

2002

2006 2010

2013

Annotations

CDI

Page 4: JUG Berlin Brandenburg: What's new in Java EE 7?

Java EE 7

What's new in Java EE 7? 4

Web Profile?

Java

EE

Pla

t-

form

Java Platform, Enterprise Edition 7 Java EE JSR 342

Java API for WebSocket JSR 356

Java API for JSON Processing JSON-P JSR 353

Java Servlet 3.1 Servlet JSR 340

JavaServer Faces 2.2 JSF JSR 344

Expression Language 3.0 EL JSR 341

JavaServer Pages 2.3 JSP JSR 245

Standard Tag Library for JavaServer Pages 1.2 JSTL JSR 52

Batch Applications for the Java Platform Batch JSR 352

Concurrency Utilities for Java EE 1.0 JSR 236

Contexts and Dependency Injection for Java 1.1 CDI JSR 346

Dependency Injection for Java 1.0 JSR 330

Bean Validation 1.1 BV JSR 349

Enterprise JavaBeans 3.2 EJB JSR 345

Interceptors 1.2 JSR 318

Java EE Connector Architecture 1.7 JCA JSR 322

Java Persistence 2.1 JPA JSR 338

Common Annotations for the Java Platform 1.2 JSR 250

Java Message Service API 2.0 JMS JSR 343

Java Transaction API 1.2 JTA JSR 907

JavaMail 1.5 Mail JSR 919

Java API for RESTful Web Services 2.0 JAX-RS JSR 339

Implementing Enterprise Web Services 1.3 JSR 109

Java API for XML-Based Web Services 2.2 JAX-WS JSR 224

Web Services Metadata for the Java Platform JSR 181

Java API for XML-Based RPC 1.1 (Optional) JAX-RPC JSR 101

Java APIs for XML Messaging 1.3 JSR 67

Java API for XML Registries 1.0 JAXR JSR 93

Java Authentication Service Provider Interface for Containers 1.1 JSR 196

Java Authorization Contract for Containers 1.5 JACC JSR 115

Java EE Application Deployment 1.2  (Optional) JSR 88

J2EE Management 1.1 JSR 77

Debugging Support for Other Languages 1.0 JSR 45

Java Architecture for XML Binding 2.2 JAXB JSR 222

Java API for XML Processing 1.3 JAXP JSR 206

Java Database Connectivity 4.0 JDBC JSR 221

Java Management Extensions 2.0 JMX JSR 003

JavaBeans Activation Framework 1.1 JAF JSR 925

Streaming API for XML 1.0 StAX JSR 173

Specification

Java

EE-

rela

ted

Spe

cs in

Jav

a SE

Man

age

me

nt

and

Se

curi

ty

Tech

no

logi

es

We

b S

erv

ice

s

Tech

no

logi

es

Ente

rpri

se A

pp

lica

tio

n T

ech

no

logi

es

We

b A

pp

lica

tio

n

Tech

no

logi

es

JSF 2.2

JPA 2.1

CDI 1.1

JAX-RS 2.0

Page 5: JUG Berlin Brandenburg: What's new in Java EE 7?

JavaServer Faces 2.2

Big Ticket Features

Faces Flows

Resource Library Contracts

HTML 5 Friendly Markup

Stateless Views

Several minor enhancements

What's new in Java EE 7? 5

Page 6: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: Faces Flows

Combination of various views

Internal navigation

Dedicated entry and return views

"Subroutine"

Embeddable

Flow scoped values

and beans

What's new in Java EE 7? 6

Page 7: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: Faces Flows

Various flow definitions

Simple, directory-based

Flow descriptor

CDI Producer

Location

Web app root

Library JAR

META-INF/flows

What's new in Java EE 7? 7

Page 8: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: Resource Library Contracts

Encapsulation of templates, images, CSS, JS

Subdirectory of

WebappRoot/contracts

Library JAR

META-INF/contracts

8 What's new in Java EE 7?

Page 9: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: Resource Library Contracts

Activation

f:view

faces-config.xml

What's new in Java EE 7? 9

<faces-config version="2.2" …>

<application>

<resource-library-contracts>

<contract-mapping>

<url-pattern>*</url-pattern>

<contracts>jugbb</contracts>

</contract-mapping>

</resource-library-contracts>

<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:f="http://java.sun.com/jsf/core" …>

<f:view contracts="default">

Page 10: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: HTML 5 Friendly Markup

Passthrough elements:

Use HTML 5 tags with JSF attributes

Passthrough attributes:

Use JSF tags with HTML 5 attributes

<input jsf:id="email" jsf:value="#{demoModel.email}“

type="email" name="email" size="40" required="required"/>

<h:inputText id="nights" value="#{demoModel.nights}" >

<f:passThroughAttribute name="type" value="number" />

<f:passThroughAttribute name="size" value="40" />

</h:inputText>

What's new in Java EE 7? 10

Page 11: JUG Berlin Brandenburg: What's new in Java EE 7?

JSF 2.2: More Changes

Stateless Views

<f:view transient="true">

UIData supports Collection

@ViewScoped

javax.faces.bean deprecated in next version

(@ManagedBean etc.)

What's new in Java EE 7? 11

Page 12: JUG Berlin Brandenburg: What's new in Java EE 7?

Java Persistence API 2.1

Converter

JPQL & Criteria Query Enhancements

CDI Injection in Entity Listener

DDL Handling

Entity Graphs

What's new in Java EE 7? 12

Page 13: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: Converter

@Convert

Explicit type / value mapping

replaces „User Types“ etc.

generalizes @Enumerated, @Temporal

What's new in Java EE 7? 13

@Entity public class Country { @Convert(converter = YesNoConverter.class) private boolean expired;

Page 14: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: Converter

@Converter

declares converter

can be auto-applied (autoApply = true)

What's new in Java EE 7? 14

@Converter public class YesNoConverter implements AttributeConverter<Boolean, String> { public String convertToDatabaseColumn(Boolean fieldValue) { if (fieldValue == null) return null; return fieldValue ? "Y" : "N"; } public Boolean convertToEntityAttribute(String columnValue) { if (columnValue == null) return null; return columnValue.equals("Y");

Page 15: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: JPQL & Criteria Query Enhancements

ON: Join filter

TREAT: Downcast (includes filter)

FUNCTION: Call DB function

What's new in Java EE 7? 15

select s from StorageLocation s where treat(s.product as Book).bookType = BookType.HARDCOVER

select c from Customer c where function('hasGoodCredit', c.balance, c.creditLimit)

select p.name, count(b) from Publisher p left join p.books b on b.bookType = BookType.PAPERBACK group by p.name

Page 16: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: JPQL & Criteria Query Enhancements

Bulk Update/Delete for Criteria Query

Stored Procedure Queries

16 What's new in Java EE 7?

CriteriaUpdate<Product> criteriaUpdate = criteriaBuilder.createCriteriaUpdate(Product.class); Root<Product> p = criteriaUpdate.from(Product.class); Path<Number> price = p.get(Product_.price); criteriaUpdate.set(price, criteriaBuilder.prod(price, 1.03)); entityManager.createQuery(criteriaUpdate).executeUpdate();

StoredProcedureQuery query = entityManager.createStoredProcedureQuery("findMissingProducts");

Page 17: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: CDI Injection in Entity Listener

What's new in Java EE 7? 17

public class CountryListener { @Inject private AuditService auditService; @PreUpdate public void preUpdate(Object entity) { this.auditService.logUpdate(entity); }

@Entity @EntityListeners(CountryListener.class) public class Country {

Page 18: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: DDL Handling

Create and/or drop db tables

Based on entity meta data (mapping)

SQL script

Data load script

What's new in Java EE 7? 18

<persistence … > <persistence-unit name="test"> … <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create" /> <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/create.sql" /> <property name="javax.persistence.schema-generation.create-source" value="metadata-then-script" /> <property name="javax.persistence.sql-load-script-source" value="META-INF/sqlLoad.sql" />

Page 19: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: DDL Handling

Write create and/or drop scripts

19 What's new in Java EE 7?

Writer createWriter = …; // File, String … Map<String, Object> properties = new HashMap<>(); properties.put("javax.persistence.schema-generation.scripts.action", "create"); properties.put("javax.persistence.schema-generation.scripts.create-target", createWriter); Persistence.generateSchema("test", properties);

Page 20: JUG Berlin Brandenburg: What's new in Java EE 7?

JPA 2.1: Entity Graphs

Declaration of lazy attributes to be loaded

find parameter or query hint

fetchgraph: Fetch entity graph attributes only

loadgraph: Fetch eager attributes also

20 What's new in Java EE 7?

@Entity

@NamedEntityGraph(name = "Publisher_books",

attributeNodes = @NamedAttributeNode(value = "books")))

public class Publisher

{

@OneToMany(mappedBy = "publisher", fetch = FetchType.LAZY)

private List<Book> books;

TypedQuery<Publisher> query = entityManager.createQuery(…);

query.setHint("javax.persistence.fetchgraph", "Publisher_books");

Page 21: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1

Enhanced bean discovery

Global enablement of interceptors, decorators, alternatives

Constructor interception

Transaction support

Validation for parameters and return values

What's new in Java EE 7? 21

Page 22: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1: Bean Discovery

Discovery mode: all, annotated, none

Exclusion filter: Class or package

What's new in Java EE 7? 22

<beans … bean-discovery-mode="all" version="1.1"> <scan> <exclude name="de.gedoplan.….sub1.beans.DiscoverableBean12"/> <exclude name="de.gedoplan.….sub1.beans.excluded.**"/> <exclude name="de.gedoplan.….dummy.**"> <if-system-property name="NO_DUMMY" value="true" /> </exclude> </scan> </beans>

Page 23: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1: Global Enablement of Interceptors etc.

@Priority

Interceptors & decorators

global enablement

Order

Alternatives

Global activation of alternative with highest priority

What's new in Java EE 7? 23

@TraceCall

@Interceptor

@Priority(Interceptor.Priority.APPLICATION + 1)

public class TraceCallInterceptor

{

Page 24: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1: Constructor Interception

What's new in Java EE 7? 24

@TraceCall @Interceptor @Priority(…)

public class TraceCallInterceptor

{

@AroundConstruct

public Object traceConstructorCall(InvocationContext ic)

throws Exception

{

}

@AroundInvoke

public Object traceMethodCall(InvocationContext ic)

throws Exception

{

}

Page 25: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1: Transaction Support

Platform global transaction interceptor @Transactional

TX modes like EJB TX attributes

CDI scope @TransactionScoped

What's new in Java EE 7? 25

@Transactional(value = TxType.REQUIRED, dontRollbackOn={HarmlessException.class}) public void insert(Cocktail cocktail) {

Page 26: JUG Berlin Brandenburg: What's new in Java EE 7?

CDI 1.1: Bean Validation for Parameters and Return Values

What's new in Java EE 7? 26

@NotNull

public List<Questionnaire> createPoll(@Min(10) int size) {

Page 27: JUG Berlin Brandenburg: What's new in Java EE 7?

Restful Webservices (JAX-RS)

Out-of-the-Box

JSON Support

Client API

What's new in Java EE 7? 27

@Path("country")

@Produces(MediaType.APPLICATION_JSON)

public class CountryResource

{

@GET

public List<Country> getAll()

{

Client client = ClientBuilder.newClient();

WebTarget target = client.target(“http://.../country/DE");

Country country = target.request(MediaType.APPLICATION_XML)

.get(Country.class);

Page 28: JUG Berlin Brandenburg: What's new in Java EE 7?

More new things

Websockets

Concurrency Utilities

Batch

JMS

28 What's new in Java EE 7?

Page 29: JUG Berlin Brandenburg: What's new in Java EE 7?

Platforms

GlassFish 4

Reference implementation

Stable version: 4.0

Promoted build: 4.0.1 b03

WildFly 8

Formerly known as JBoss AS

Current version: 8.0.0.Beta1

29 What's new in Java EE 7?

Page 30: JUG Berlin Brandenburg: What's new in Java EE 7?

Links

Sample Project

https://github.com/dirkweil/whatsNewInJavaEe7

Java EE Blog

http://javaeeblog.wordpress.com/

Consulting

http://www.gedoplan.de

[email protected]

Training

http://www.ips-it-schulungen.de/

What's new in Java EE 7? 30

Page 31: JUG Berlin Brandenburg: What's new in Java EE 7?

Schön, dass Sie da waren!

[email protected]