@Override public Value evaluate(ParseSession session) { return new ConstValue(JTransaction.getCurrent().get(id)); }
/** * Reload this container after the transaction open in the current thread successfully commits. * * <p> * Does nothing if the current transaction fails or this instance is not {@link #connect}'ed. * * @throws IllegalStateException if there is no {@link JTransaction} associated with the current thread */ public void reloadAfterCommit() { JTransaction.getCurrent().getTransaction().addCallback(new Transaction.CallbackAdapter() { @Override public void afterCommit() { if (ReloadableJObjectContainer.this.vaadinSession == null) return; ReloadableJObjectContainer.this.vaadinSession.access(() -> { if (ReloadableJObjectContainer.this.vaadinSession != null) ReloadableJObjectContainer.this.reload(); }); } }); } }
/** * Perform the given action within a new {@link JTransaction}. * * <p> * The implementation in {@link JObjectContainer} performs {@code action} within a new read-only transaction. * Note that {@code action} should be idempotent because the transaction will be retried if needed. * * @param action the action to perform */ protected void doInTransaction(Runnable action) { final JTransaction jtx = this.jdb.createTransaction(false, ValidationMode.DISABLED); jtx.getTransaction().setReadOnly(true); try { jtx.performAction(action); } finally { jtx.commit(); } }
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().queryIndex(objectType, fieldName, valueTypes[0]); } };
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().getAll((Class<?>)obj); } };
@Override public void afterCompletion(boolean committed) { final JTransaction current; try { current = JTransaction.getCurrent(); } catch (IllegalStateException e) { return; } if (current == this.jtx) JTransaction.setCurrent(null); }
final JTransaction jtx = JTransaction.getCurrent(); final ObjId id = this.jobj.getObjId(); final JObject target = this.create ? (JObject)jtx.create(this.jclass) : jtx.get(id); jtx.validate(); } catch (ValidationException e) { Notification.show("Validation failed", e.getMessage(), Notification.Type.ERROR_MESSAGE); jtx.getTransaction().setRollbackOnly(); return false; jtx.getTransaction().addCallback(new Transaction.CallbackAdapter() { @Override public void afterCommit() {
JTransaction.getCurrent(); throw new IllegalStateException("a JTransaction is already associated with the current thread"); } catch (IllegalStateException e) { jtx.getTransaction().setReadOnly(true); final int timeout = attr.getTimeout(); if (timeout != TransactionAttribute.TIMEOUT_DEFAULT) { try { jtx.getTransaction().setTimeout(timeout * 1000L); } catch (UnsupportedOperationException e) { JTransaction.setCurrent(jtx); filterChain.doFilter(request, response); success = true; } catch (Throwable t) { if (attr.rollbackOn(t) || jtx.getTransaction().isRollbackOnly()) jtx.rollback(); else jtx.commit(); Throwables.propagateIfPossible(t, ServletException.class, IOException.class); throw new RuntimeException(t); } finally { JTransaction.setCurrent(null); if (success) { if (jtx.getTransaction().isRollbackOnly()) jtx.rollback(); else jtx.commit();
@Override public boolean isRollbackOnly() { return this.jtx != null && this.jtx.getTransaction().isRollbackOnly(); }
/** * Reattach the given {@link JObject} to the current transaction if it's associated with a stale transaction. */ public static JObject refresh(JObject jobj) { return !jobj.getTransaction().isValid() ? JTransaction.getCurrent().get(jobj) : jobj; }
@RetryTransaction @Transactional("permazenGuiTransactionManager") private JObject doCopyForEdit(ObjId id) { // Find object final JTransaction jtx = JTransaction.getCurrent(); final JObject jobj = jtx.get(id); if (!jobj.exists()) return null; // Copy out object and its dependencies return this.objectChooser.getJObjectContainer().copyWithRelated(jobj, jtx.getSnapshotTransaction(), new CopyState()); }
/** * Like {@link JTransaction#getCurrent}, but returns null instead of throwing {@link IllegalStateException}. * * @return the transaction associated with the current thread, or null if there is none */ protected JTransaction getCurrent() { try { return JTransaction.getCurrent(); } catch (IllegalStateException e) { return null; } }
/** * "Snapshot" constructor for when the destination transaction is the "snapshot" transaction of the transaction * associated with the current thread and no copy cascade is needed * * <p> * This is a convenience constructor, equivalent to: * <blockquote><code> * ChangeCopier(JTransaction.getCurrent().getSnapshotTransaction()) * </code></blockquote> * * @throws IllegalStateException if this is not a snapshot instance and there is no {@link JTransaction} * associated with the current thread */ public ChangeCopier() { this(JTransaction.getCurrent().getSnapshotTransaction()); }
case PERMAZEN: if (commit && !this.tx.isRollbackOnly()) JTransaction.getCurrent().commit(); else JTransaction.getCurrent().rollback(); break; case CORE_API:
private void cleanupTx(SessionMode mode) { if (mode.compareTo(SessionMode.PERMAZEN) >= 0) { try { JTransaction.getCurrent().rollback(); } catch (IllegalStateException e) { // ignore } JTransaction.setCurrent(null); } if (mode.compareTo(SessionMode.CORE_API) >= 0) { if (this.tx != null) this.tx.rollback(); this.tx = null; } if (mode.compareTo(SessionMode.KEY_VALUE) >= 0) { if (this.kvt != null) this.kvt.rollback(); this.kvt = null; } }
@Override public JObject convertToModel(ObjId id, Class<? extends JObject> targetType, Locale locale) { if (id == null) return null; return this.jtx.get(id); } }
final ObjId id = this.getObjId(); final JTransaction jtx = this.getTransaction(); final ObjIdSet ids = jtx.cascadeFindAll(id, cascadeName, recursionLimit); final CopyState copyState = clone ? new CopyState(dest.createClones(ids)) : new CopyState(); jtx.copyTo(dest, copyState, ids); return dest.get(copyState.getDestinationId(id));
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().queryListElementIndex(objectType, fieldName, valueTypes[0]); } };
this.revalidate(Collections.singleton(id)); this.doConvertAndSetField(id, oldField0, this.tx.getDatabase().getFieldTypeRegistry().getFieldType(TypeToken.of(long.class)), newField, oldValue, jfield.upgradeConversion); this.convertAndSetField(id, oldField, newField, oldValue, jfield.upgradeConversion); (storageId, oldValue) -> this.convertOldVersionValue(id, oldObjType.getField(storageId), oldValue)); jobj = this.get(id);
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().queryMapValueIndex(objectType, fieldName, valueTypes[0], valueTypes[1]); } };