The three data modules' docs were in Italian, so the synchronization contract added in the previous commit went in as Italian too, to match its file. English is the project's language for docs, comments and READMEs alike, and a file half in each is worse than either — so all three are translated, not just the new section. Content is otherwise unchanged, except the "synchronizations run on commit/rollback" line in the two backend READMEs, which was vague before and is now accurate about which hook sees the session/connection still bound, pointing at flash-ext-data-core's README for the full contract. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2.9 KiB
2.9 KiB
flash-ext-data-hibernate
Hibernate backend for flash-ext-data-core.
Purpose
This module implements TxManager on top of a SessionFactory and provides a Hibernate-centric
repository base class.
How to use it
1. Create the manager
SessionFactory sessionFactory = ...;
HibernateTxManager txManager = new HibernateTxManager(sessionFactory);
DataExtension extension = new DataExtension(txManager);
2. Install the extension in Flash
The extension registers Tx and TxManager in the FlashContext. Class-based handlers annotated
with @Transactional are wrapped automatically.
3. Define a repository
public final class UserRepository extends HibernateRepository<User, Long> {
public UserRepository(Tx tx) {
super(tx, User.class);
}
}
With the query/spec model you can expose reusable fields as constants:
public final class UserRepository extends HibernateRepository<User, Long> {
public static final SpecBuilder.FieldSpec<User, String> EMAIL = SpecBuilder.field("u.email");
public static final SpecBuilder.FieldSpec<User, Boolean> ACTIVE = SpecBuilder.field("u.active");
public UserRepository(Tx tx) {
super(tx, User.class);
}
public Optional<User> findByEmail(String email) {
return findOne(EMAIL.eq(email));
}
}
Domain-specific queries can use the base class helpers:
public List<User> findByEmailDomain(String domain) {
return findMany("from User u where u.email like :email", q ->
q.setParameter("email", "%@" + domain)
);
}
How it works underneath
- The current transaction is represented by
HibernateTxStatus. - The resource exposed to the core is a
Session. Tx.resource(Session.class)retrieves theSessionfrom the current context.REQUIRES_NEWsuspends the active status and opens a newSession.NOT_SUPPORTEDsuspends the active transaction and continues with no session bound.
Repository base class
HibernateRepository provides:
findById,findAll,findPage,findOnesave,update,delete,saveAll- bulk
deleteAll(Spec<T>)andupdateAll(Spec<T>, T) - HQL helpers:
hql(...),hqlMutate(...)
Concrete classes only have to implement domain queries, never the transactional plumbing.
Transactional semantics
REQUIRED: join, or open a new transaction.REQUIRES_NEW: suspend the current context.SUPPORTS: join if a transaction exists, otherwise no-op.NOT_SUPPORTED: suspend and continue without a transaction.MANDATORY: fail if there is no transaction.
Notes
- The
Sessionis closed when a new transaction ends. - Synchronizations registered in a transaction fire when that transaction completes:
beforeCommitwhile it is still active and theSessionstill bound, the post-completion hooks once it is unbound. Seeflash-ext-data-core/docs/README.mdfor the full contract. - This backend is meant to be used through the base class, not directly.