Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
What's new in Java EE 7
1. What's new in Java EE 7?
Expertenkreis Java
19.09.2013, GEDOPLAN
Dirk Weil, GEDOPLAN GmbH
2. 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
3. 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
4. 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
5. 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
5What'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
6. 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
7. JPA 2.1: Converter
7What'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;
8. 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)
9. 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");
10. JPA 2.1: CDI Injection in Entity Listener
10What'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 {
11. 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" />
12. JPA 2.1: DDL Handling
Write create and/or drop scripts
12What'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);
13. 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
13What'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");
14. 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
15. 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>
16. 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
{
17. CDI 1.1: Constructor Interception
17What'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
{
…
}
18. 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)
{
19. CDI 1.1: Bean Validation for Parameters and Return Values
19What's new in Java EE 7?
@NotNull
public List<Fragebogen> createUmfrage(@Min(10) int personenZahl)
{