/** * 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; } }
private static boolean isCurrentJTransaction() { try { JTransaction.getCurrent(); return true; } catch (IllegalStateException e) { return false; } }
@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); }
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().queryListElementIndex(objectType, fieldName, valueTypes[0]); } };
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().queryMapValueIndex(objectType, fieldName, valueTypes[0], valueTypes[1]); } };
/** * Get the open {@link JTransaction} currently associated with this instance. * * <p> * This method just invokes {@link JTransaction#getCurrent} and returns the result. * * @return the open {@link JTransaction} in which to do work * @throws IllegalStateException if {@link #performSessionAction performSessionAction()} is not currently being invoked * @throws IllegalStateException if this instance is not in mode {@link SessionMode#PERMAZEN} */ public JTransaction getJTransaction() { Preconditions.checkState(this.mode.hasPermazen(), "Permazen not available in " + this.mode + " mode"); return JTransaction.getCurrent(); }
/** * Apply this change to the transaction associated with the current thread. * * <p> * This is a convenience method, equivalent to: * <blockquote><code> * apply(JTransaction.getCurrent()) * </code></blockquote> * * @throws IllegalStateException if there is no {@link JTransaction} associated with the current thread */ public void apply() { this.apply(JTransaction.getCurrent()); }
@Override public Object get(ParseSession session) { return JTransaction.getCurrent().getAll(jclass.getType()); } };
@Override public Value evaluate(ParseSession session) { return new ConstValue(JTransaction.getCurrent().get(id)); }
@RetryTransaction @Transactional("permazenGuiTransactionManager") private JObject doCreateForEdit() { return (JObject)JTransaction.getCurrent().getSnapshotTransaction().create(this.jclass); }
/** * 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 boolean doDelete(ObjId id) { final boolean deleted = JTransaction.getCurrent().get(id).delete(); if (deleted) this.objectChooser.getJObjectContainer().reloadAfterCommit(); return deleted; }
private void reloadInTransaction() { // Get objects from subclass Iterator<? extends JObject> jobjs = this.queryForObjects(); // Copy objects (and their related object friends) into a snapshot transaction final SnapshotJTransaction snapshotTx = JTransaction.getCurrent().createSnapshotTransaction(ValidationMode.DISABLED); final CopyState copyState = new CopyState(); jobjs = Iterators.transform(jobjs, jobj -> this.copyWithRelated(jobj, snapshotTx, copyState)); // Now actually load the objects this.load(jobjs); }
@RetryTransaction @Transactional("permazenGuiTransactionManager") private boolean canUpgrade(ObjId id) { final JObject jobj = JTransaction.getCurrent().get(id); return jobj.exists() && jobj.getSchemaVersion() != this.jdb.getActualVersion(); }
@Override public Object get(ParseSession session) { return session.getMode().hasPermazen() ? JTransaction.getCurrent().getAll(Object.class) : session.getTransaction().getAll(); } };
@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()); }
@Override public Object get(ParseSession session) { if (session.getMode().hasPermazen()) return JTransaction.getCurrent().queryIndex(storageId); else return session.getTransaction().queryIndex(storageId); } };
@Override public Value apply(ParseSession session, Object params) { final ParamInfo info = (ParamInfo)params; final int storageId = info.getStorageId(); final Node version = info.getVersion(); // Create object final Transaction tx = session.getTransaction(); final ObjId id = version != null ? tx.create(storageId, version.evaluate(session).checkIntegral(session, "create()")) : tx.create(storageId); return new ConstValue(session.getMode().hasPermazen() ? JTransaction.getCurrent().get(id) : id); }