What's new in Java EE 7
-
Upload
gedoplan -
Category
Technology
-
view
318 -
download
5
description
Transcript of What's new in Java EE 7
What's new in Java EE 7?
Expertenkreis Java
19.09.2013, GEDOPLAN
Dirk Weil, GEDOPLAN GmbH
JavaServer Faces 2.2
Big Ticket Features
Faces Flows
Resource Library Contracts
HTML 5 Friendly Markup
Stateless Views
Other Changes
UIData supports Collection
@ViewScoped
javax.faces.bean deprecated in next version
What's new in Java EE 7? 2
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? 3
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? 4
JSF 2.2: Resource Library Contracts
Encapsulation of templates, images, CSS and JS files
Subdir of
WebappRoot/contracts
Library JAR META-INF/contracts
Activation in faces-config.xml or view attributes
5 What's new in Java EE 7?
<resource-library-contracts> <contract-mapping> <url-pattern>*</url-pattern> <contracts>siteLayout</contracts> </contract-mapping> </resource-library-contracts>
siteLayout/ topNav_template.xhtml leftNav_foo.xhtml styles.css script.js background.png
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? 6
JPA 2.1: Converter
7 What's new in Java EE 7?
@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");
@Entity public class Country { @Convert(converter = YesNoConverter.class) private boolean expired;
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? 8
select p.name, count(b) from Publisher p left join p.books b on b.bookType = BookType.PAPERBACK group by p.name
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)
JPA 2.1: JPQL & Criteria Query Enhancements
Bulk Update/Delete for Criteria Query
Stored Procedure Queries
What's new in Java EE 7? 9
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");
JPA 2.1: CDI Injection in Entity Listener
10 What's new in Java EE 7?
public class CountryListener { @Inject private AuditService auditService; @PreUpdate public void preUpdate(Object entity) { this.auditService.logUpdate(entity); }
@Entity @EntityListeners(CountryListener.class) public class Country {
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? 11
<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" />
JPA 2.1: DDL Handling
Write create and/or drop scripts
12 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);
JPA 2.1: Entity Graphs
Declaration of lazy attributes to be loaded by find or query
find parameter or query hint
fetchgraph: Fetch entity graph attributes only
loadgraph: Fetch eager attributes also
13 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");
CDI 1.1
Enhanced bean discovery
Global enablement of interceptors, decorators, alternatives
Constructor interception
@TransactionScoped
@Transactional
Bean Validation for method parameters and return values
What's new in Java EE 7? 14
CDI 1.1: Bean Discovery
Discovery mode: all, annotated, none
Exclusion filter: Class or package
What's new in Java EE 7? 15
<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>
CDI 1.1: Global Enablement of Interceptors etc.
@Priority
Global enablement and ordering of interceptors & decorators
Global activation of alternative with highest priority
What's new in Java EE 7? 16
@One @Interceptor @Priority(Interceptor.Priority.APPLICATION + 1) public class OneInterceptor {
CDI 1.1: Constructor Interception
17 What's new in Java EE 7?
@Interceptor public class TraceCallInterceptor { @AroundConstruct public Object traceConstructorCall(InvocationContext ic) throws Exception { … } @AroundInvoke public Object traceMethodCall(InvocationContext ic) throws Exception { … }
CDI 1.1: @Transactional & @TransactionScoped
Platform global transaction interceptor @Transactional
TX modes like EJB TX attributes
CDI scope @TransactionScoped
What's new in Java EE 7? 18
@Transactional(value = TxType.REQUIRED, dontRollbackOn={HarmlessException.class}) public void insert(Cocktail cocktail) {
CDI 1.1: Bean Validation for Parameters and Return Values
19 What's new in Java EE 7?
@NotNull public List<Fragebogen> createUmfrage(@Min(10) int personenZahl) {
More new things
Websockets
JAX-RS
JSON
Standardized Client
Concurrency Utilities
Batch
JMS
20 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.Alpha4
21 What's new in Java EE 7?
Schön, dass Sie da waren!
Unserer nächster Termin:
21.11.2013: Testen im EE-Umfeld – Seien Sie feige!