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