Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
JUG Berlin Brandenburg: What's new in Java EE 7?
1. What's new in Java EE 7?
Java User Group Berlin Brandenburg
04.12.2013
Dirk Weil, GEDOPLAN GmbH
2. 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
4. Java EE-related
Specs in Java SE
Management
and Security
Technologies
Web Services
Technologies
Enterprise Application Technologies
Web Application
Technologies
Java EE
Platform
Java EE 7
What's new in Java EE 7?
Specification
Java Platform, Enterprise Edition 7
Java API for WebSocket
Java API for JSON Processing
Java Servlet 3.1
JavaServer Faces 2.2
Expression Language 3.0
JavaServer Pages 2.3
Standard Tag Library for JavaServer Pages 1.2
Batch Applications for the Java Platform
Concurrency Utilities for Java EE 1.0
Contexts and Dependency Injection for Java 1.1
Dependency Injection for Java 1.0
Bean Validation 1.1
Enterprise JavaBeans 3.2
Interceptors 1.2
Java EE Connector Architecture 1.7
Java Persistence 2.1
Common Annotations for the Java Platform 1.2
Java Message Service API 2.0
Java Transaction API 1.2
JavaMail 1.5
Java API for RESTful Web Services 2.0
Implementing Enterprise Web Services 1.3
Java API for XML-Based Web Services 2.2
Web Services Metadata for the Java Platform
Java API for XML-Based RPC 1.1 (Optional)
Java APIs for XML Messaging 1.3
Java API for XML Registries 1.0
Java Authentication Service Provider Interface for Containers 1.1
Java Authorization Contract for Containers 1.5
Java EE Application Deployment 1.2 (Optional)
J2EE Management 1.1
Debugging Support for Other Languages 1.0
Java Architecture for XML Binding 2.2
Java API for XML Processing 1.3
Java Database Connectivity 4.0
Java Management Extensions 2.0
JavaBeans Activation Framework 1.1
Streaming API for XML 1.0
Web Profile?
Java EE JSR 342
JSR 356
JSR 353
JSR 340
JSR 344
JSR 341
JSR 245
JSR 52
JSR 352
JSR 236
CDI
JSR 346
JSR 330
BV
JSR 349
EJB
JSR 345
JSR 318
JCA
JSR 322
JPA
JSR 338
JSR 250
JMS
JSR 343
JTA
JSR 907
Mail
JSR 919
JAX-RS JSR 339
JSR 109
JAX-WS JSR 224
JSR 181
JAX-RPC JSR 101
JSR 67
JAXR
JSR 93
JSR 196
JACC
JSR 115
JSR 88
JSR 77
JSR 45
JAXB
JSR 222
JAXP
JSR 206
JDBC
JSR 221
JMX
JSR 003
JAF
JSR 925
StAX
JSR 173
JSON-P
Servlet
JSF
EL
JSP
JSTL
Batch
JSF 2.2
CDI 1.1
JPA 2.1
JAX-RS 2.0
4
5. 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
6. 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
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
8. JSF 2.2: Resource Library Contracts
Encapsulation of templates, images, CSS, JS
Subdirectory of
WebappRoot/contracts
Library JAR
META-INF/contracts
What's new in Java EE 7?
8
10. JSF 2.2: HTML 5 Friendly Markup
Passthrough elements:
Use HTML 5 tags with JSF attributes
<input jsf:id="email" jsf:value="#{demoModel.email}“
type="email" name="email" size="40" required="required"/>
Passthrough attributes:
Use JSF tags with HTML 5 attributes
<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
11. 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
12. 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
13. JPA 2.1: Converter
@Convert
Explicit type / value mapping
replaces „User Types“ etc.
generalizes @Enumerated, @Temporal
@Entity
public class Country
{
@Convert(converter = YesNoConverter.class)
private boolean expired;
What's new in Java EE 7?
13
14. JPA 2.1: Converter
@Converter
declares converter
can be auto-applied (autoApply = true)
@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");
What's new in Java EE 7?
14
15. JPA 2.1: JPQL & Criteria Query Enhancements
ON: Join filter
select p.name, count(b)
from Publisher p
left join p.books b
on b.bookType = BookType.PAPERBACK
group by p.name
TREAT: Downcast (includes filter)
select s from StorageLocation s
where treat(s.product as Book).bookType = BookType.HARDCOVER
FUNCTION: Call DB function
select c from Customer c
where function('hasGoodCredit', c.balance, c.creditLimit)
What's new in Java EE 7?
15
16. JPA 2.1: JPQL & Criteria Query Enhancements
Bulk Update/Delete for Criteria Query
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();
Stored Procedure Queries
StoredProcedureQuery query
= entityManager.createStoredProcedureQuery("findMissingProducts");
What's new in Java EE 7?
16
17. JPA 2.1: CDI Injection in Entity Listener
public class CountryListener {
@Inject
private AuditService auditService;
@PreUpdate
public void preUpdate(Object entity) {
this.auditService.logUpdate(entity);
}
@Entity
@EntityListeners(CountryListener.class)
public class Country {
What's new in Java EE 7?
17
18. JPA 2.1: DDL Handling
Create and/or drop db tables
Based on entity meta data (mapping)
SQL script
Data load script
<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" />
What's new in Java EE 7?
18
19. JPA 2.1: DDL Handling
Write create and/or drop scripts
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);
What's new in Java EE 7?
19
20. JPA 2.1: Entity Graphs
Declaration of lazy attributes to be loaded
@Entity
@NamedEntityGraph(name = "Publisher_books",
attributeNodes = @NamedAttributeNode(value = "books")))
public class Publisher
{
…
@OneToMany(mappedBy = "publisher", fetch = FetchType.LAZY)
private List<Book> books;
find parameter or query hint
fetchgraph: Fetch entity graph attributes only
loadgraph: Fetch eager attributes also
TypedQuery<Publisher> query = entityManager.createQuery(…);
query.setHint("javax.persistence.fetchgraph", "Publisher_books");
What's new in Java EE 7?
20
21. 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
22. CDI 1.1: Bean Discovery
Discovery mode: all, annotated, none
Exclusion filter: Class or package
<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>
What's new in Java EE 7?
22
23. CDI 1.1: Global Enablement of Interceptors etc.
@Priority
Interceptors & decorators
global enablement
Order
@TraceCall
@Interceptor
@Priority(Interceptor.Priority.APPLICATION + 1)
public class TraceCallInterceptor
{
Alternatives
Global activation of alternative with highest priority
What's new in Java EE 7?
23
24. CDI 1.1: Constructor Interception
@TraceCall @Interceptor @Priority(…)
public class TraceCallInterceptor
{
@AroundConstruct
public Object traceConstructorCall(InvocationContext ic)
throws Exception
{
…
}
@AroundInvoke
public Object traceMethodCall(InvocationContext ic)
throws Exception
{
…
}
What's new in Java EE 7?
24
25. CDI 1.1: Transaction Support
Platform global transaction interceptor @Transactional
TX modes like EJB TX attributes
@Transactional(value = TxType.REQUIRED,
dontRollbackOn={HarmlessException.class})
public void insert(Cocktail cocktail)
{
CDI scope @TransactionScoped
What's new in Java EE 7?
25
26. CDI 1.1: Bean Validation for Parameters and Return Values
@NotNull
public List<Questionnaire> createPoll(@Min(10) int
{
What's new in Java EE 7?
size)
26
27. Restful Webservices (JAX-RS)
Out-of-the-Box
JSON Support
@Path("country")
@Produces(MediaType.APPLICATION_JSON)
public class CountryResource
{
@GET
public List<Country> getAll()
{
…
Client API
Client client = ClientBuilder.newClient();
WebTarget target = client.target(“http://.../country/DE");
Country country = target.request(MediaType.APPLICATION_XML)
.get(Country.class);
What's new in Java EE 7?
27