@@ -161,6 +161,53 @@ default void persistBatch(List<?> entries) {
161161 "Atomic batch insert (persistBatch) is not supported by '%s' persistence backend" , getPersistenceType ()));
162162 }
163163
164+ /**
165+ * Reports whether {@link #executeInTransaction(String, TransactionCallback)} and
166+ * {@link #findForUpdate(Class, Object)} are supported for entries stored under {@code primaryKey}.
167+ * Only the SQL backend supports them; a hybrid entry manager returns the capability of the backend
168+ * that the DN maps to.
169+ *
170+ * @param primaryKey DN (or base DN) of the entries the transaction will read and write
171+ * @return {@code true} when transactions are supported for that DN
172+ */
173+ default boolean isTransactionSupported (String primaryKey ) {
174+ return false ;
175+ }
176+
177+ /**
178+ * Runs {@code callback} in ONE database transaction. Every read and write this entry manager performs
179+ * on the calling thread while the callback runs joins the transaction. The transaction commits when
180+ * the callback returns normally and rolls back when it throws; the exception is rethrown unchanged
181+ * when it is a {@link RuntimeException}, otherwise it is wrapped in an
182+ * {@link io.jans.orm.exception.EntryPersistenceException}.
183+ *
184+ * <p>A nested call on the same thread joins the outer transaction (no savepoints): the outer call
185+ * decides commit or rollback. Writes that a hybrid entry manager routes to a different backend than
186+ * {@code primaryKey} are not part of the transaction.</p>
187+ *
188+ * @param primaryKey DN (or base DN) that selects the backend
189+ * @param callback unit of work
190+ * @return result of the callback
191+ * @throws io.jans.orm.exception.UnsupportedOperationException the backend has no transactions
192+ */
193+ default <T > T executeInTransaction (String primaryKey , TransactionCallback <T > callback ) {
194+ throw new io .jans .orm .exception .UnsupportedOperationException (String .format (
195+ "Transactions are not supported by '%s' persistence backend" , getPersistenceType ()));
196+ }
197+
198+ /**
199+ * Reads one entry and locks its row until the current transaction ends ({@code SELECT ... FOR UPDATE}).
200+ * Must be called inside {@link #executeInTransaction(String, TransactionCallback)}.
201+ *
202+ * @return the entry, or {@code null} when it does not exist
203+ * @throws io.jans.orm.exception.UnsupportedOperationException the backend has no row locks
204+ * @throws IllegalStateException called outside a transaction
205+ */
206+ default <T > T findForUpdate (Class <T > entryClass , Object primaryKey ) {
207+ throw new io .jans .orm .exception .UnsupportedOperationException (String .format (
208+ "Row locks are not supported by '%s' persistence backend" , getPersistenceType ()));
209+ }
210+
164211 /**
165212 * Reads entries by DN. Backends with a native implementation (SQL) read them in one round trip
166213 * per table; the default implementation works on every backend and reads one DN at a time, so
0 commit comments