JSR-303 (“Bean Validation”) ActionScript3 framework for form validation
validation framework is a specific adaptation of the JSR-303 (Bean Validation) specification to Flex: like its Java counterpart, it relies on validation annotations placed on bean properties and provides an engine API that lets you validate your forms without writing by hand a specific validator for each of your input fields
code generation tools provided by GraniteDS so that when you write your Java entity bean with validation annotations, they are automatically replicated in your ActionScript3 beans
problem with LCDS is mainly that it promotes a strict “client / server” architecture, with – roughly speaking – a heavy Flex client application connected to a server almost reduced to a database frontend
big majority of these organizations use BlazeDS, a free and open-source subset of LCDS
need more advanced mechanisms than just Remoting start looking for open-source libraries to enable deeper integrations with the Java business layer, and GraniteDS is for sure the most popular project
“Flex Data Services” (now renamed to “Live Cycle Data Services”)
Interceptor classes and methods are defined using metadata annotations, or in the deployment
descriptor of the application containing the interceptors and target classes
Interceptor Metadata Annotations
AroundInvoke
AroundTimeout
PostConstruct
PreDestroy
Interceptor classes must have a public,
no-argument constructor
just don't hard-code this eager loading behavior by using jpa's FetchType.EAGER when annotating the entity beans
if you do, you force all clients of said entity beans to *always* eager fetch everything, even if the client doesn't want/need the full depth/breadth of the object graph
to eager load the relations when needed, try fetch joins (see item 5)
instead of, say, attaching validation 'behavior' directly on, but still decoupled from domain classes themselves (eg. validation rule annotations on jpa entity beans)
Fully polymorphic behavior is available, but there is no annotation support for any mappings.
Hibernate supports fully polymorphic behavior. It provides extra support for any association mappings to an inheritance hierarchy mapped with implicit polymorphism.
inner class Builder is in charge of creating Customer instances
mandatory fields – either primitive (e.g. id) or annotated with @NotNull (e.g. lastName) – are part of the builder's constructor
all optional fields setter methods on the builder are provided
newly created Customer instance is validated using the Validator#validate() method
impossible to retrieve an invalid Customer instance
extract the validation routine into a base class:
abstract class AbstractBuilder<T>
T build() throws ConstraintViolationException
protected abstract T buildInternal();
private static Validator validator
Concrete builder classes have to
extend AbstractBuilder
must implement the buildInternal() method:
Builder extends AbstractBuilder<Customer>
@Override
protected Customer buildInternal()
Implementing the Builder Pattern using the Bean Validation API
variation of the Builder design pattern for instantiating objects with multiple optional attributes.
this pattern frees you from providing multiple constructors with the different optional attributes as parameters (hard to maintain and hard to read for clients)
or providing setter methods for the optional attributes
(require objects to be mutable, can leave objects in inconsistent state)
GraniteDS introduces an ActionsScript3 implementation of the Bean Validation specification and provides code generation
tools integration so that your Java constraint annotations are reproduced in your AS3 beans
All entities marked as [Managed] are considered as corresponding to Hibernate/JPA managed entities on the server
It is highly recommended to use JPA optimistic locking in a multi-tier environment (@Version annotation
In conclusion, the recommended approach to avoid any kind of subtle problems is to have a real uid property which will be persisted
in the database
but is not a primary key for efficiency concerns
Here all loaded collections of the Person object will be uninitialized so uperson contains only the minimum of data
to correctly merge your changes in the server persistence context
Tide uses the client data tracking (the same used for dirty checking, see below) to determine which parts of the graph
need to be sent.
Dirty Checking and Conflict Handling
Data Validation
Tide integrates with Hibernate Validator 3.x and the Bean Validation API (JSR 303) implementations, and propagate the server validation errors to the client
UI components
highly recommended to use JPA optimistic locking in a multi-tier environment (@Version annotation)
Tip
The easiest and recommended way for getting Tide enabled managed entities is to generate them from Java classes with Gas3 or the GDS Eclipse builder using
the tide="true" option.
In a typical Flex/app server/database application, an entity lives in three layers:
the Flex client
the Hibernate/JPA persistence context
the database
only invariant is the id.
id reliably links the different existing versions of the entity in the three layers
Entity–attribute–value model (EAV) is a data model to describe entities where the number of attributes (properties, parameters) that can be used to describe them is potentially vast, but the number that will actually apply to a given entity is relatively modest
also known as object–attribute–value model, vertical database model and open schema
In an EAV data model, each attribute-value pair is a fact describing an entity, and a row in an EAV table stores a single fact
EAV tables are often described as "long and skinny": "long" refers to the number of rows, "skinny" to the few columns
Data is recorded as three columns:
The entity: the item being described.
The attribute or parameter: a foreign key into a table of attribute definitions. At the very least, the attribute definitions table would contain the following columns: an attribute ID, attribute name, description, data type, and columns assisting input validation
The value of the attribute
Row modeling, where facts about something (in this case, a sales transaction) are recorded as multiple rows rather than multiple columns
differences between row modeling and EAV (which may be considered a generalization of row-modeling) are:
A row-modeled table is homogeneous in the facts that it describes
The data type of the value column/s in a row-modeled table is pre-determined by the nature of the facts it records. By contrast, in an EAV table, the conceptual data type of a value in a particular row depend on the attribute in that row
In the EAV table itself, this is just an attribute ID, a foreign key into an Attribute Definitions table
The Attribute
The Value
Coercing all values into strings
larger systems use separate EAV tables for each data type (including binary large objects, "BLOBS"), with the metadata for a given attribute identifying the EAV table in which its data will be stored
Where an EAV system is implemented through RDF, the RDF Schema language may conveniently be used to express such metadata
access to metadata must be restricted, and an audit trail of accesses and changes put into place to deal with situations where multiple individuals have metadata access
quality of the annotation and documentation within the metadata (i.e., the narrative/explanatory text in the descriptive columns of the metadata sub-schema) must be much higher, in order to facilitate understanding by various members of the development team.
Attribute metadata
Validation metadata include data type, range of permissible values or membership in a set of values, regular expression match, default value, and whether the value is permitted to be null
Presentation metadata: how the attribute is to be displayed to the user
Grouping metadata: Attributes are typically presented as part of a higher-order group, e.g., a specialty-specific form. Grouping metadata includes information such as the order in which attributes are presented
Why is the constructor invoked twice when a normal scoped bean is created?
What you see is the instantiation of two objects: one is the actual bean instance, the other one is the proxy. Both likely invoke the default constructor.
That's why it's generally considered a bad idea to do initialization in class construction code. Instead, when using managed beans (objects managed by the EE container) to perform initialisation in a @PostConstruct or @Inject annotated method.
one of the most important value
propositions for frameworks like Spring has been the ability to easily extend the framework or
integrate third-party solutions
SPI allows you to register your own beans, custom scopes, stereotypes, interceptors and
decorators with CDI even if is it not included in the automatic scanning process (such as perhaps
registering Spring beans as CDI beans), programmatically looking up CDI beans and injecting them
into your own objects (such as injecting CDI beans into Spring beans) and adding/overriding
annotation-metadata from other sources (such as from a database or property file)
SPI can be
segmented into three parts. Interfaces like Bean, Interceptor and
Decorator model container meta-data (there are a few other meta-data interfaces such as
ObserverMethod, Producer, InjectionTarget, InjectionPoint,
AnnotatedType, AnnotatedMethod, etc). Each meta-data object encapsulates
everything that the CDI container needs to know about the meta-data type
JPA 2.0, still contains only a subset of the features supported by many database vendors
features not supported in JP QL.
performance required by an application is to replace the JP QL query with a hand-optimized SQL version. This may be a simple restructuring of the query that the persistence provider was generating, or it may be a vendor-specific version that leverages query hints and features specific to a particular database.
recommend avoiding SQL initially if possible and then introducing it only when necessary
benefits of SQL query support is that it uses the same Query interface used for JP QL queries. With some small exceptions that will be described later, all the Query interface operations discussed in previous chapters apply equally to both JP QL and SQL queries.
keep application code consistent because it needs to concern itself only with the EntityManager and Query interfaces.
An unfortunate result of adding the TypedQuery interface in JPA 2.0 is that the createNativeQuery() method was already defined in JPA 1.0 to accept a SQL string and a result class and return an untyped Query interface
consequence is that when the createNativeQuery() method is called with a result class argument one might mistakenly think it will produce a TypedQuery, like createQuery() and createNamedQuery() do when a result class is passed in.
@NamedNativeQuery
resultClass=Employee.class
The fact that the named query was defined using SQL instead of JP QL is not important to the caller
SQL Result Set Mapping
JPA provides SQL result set mappings to handle these scenarios
A SQL result set mapping is defined using the @SqlResultSetMapping annotation. It may be placed on an entity class and consists of a name (unique within the persistence unit) and one or more entity and column mappings.
expected result type and therefore received an instance of TypedQuery that is bound to the expected type. By qualifying the result type in this way, the getResultList() and getSingleResult() methods return the correct types without the need for casting.
Defining a Class for Use in a Constructor Expression
public EmpMenu(String employeeName, String departmentName)
List<EmpMenu>
NEW example.EmpMenu(" +
"e.name, e.department.name)
EmpMenu.class
createNamedQuery() can return a TypedQuery whereas the createNativeQuery() method returns an untyped Query