@Override public boolean isRollbackOnly() { return this.jtx != null && this.jtx.getTransaction().isRollbackOnly(); }
@Override void importPlain(ImportContext context, Object obj, ObjId id) { // Read POJO property final Object value; try { value = obj.getClass().getMethod(this.getter.getName()).invoke(obj); } catch (Exception e) { return; } // Auto-convert any Number final long count; if (value instanceof Number) count = ((Number)value).longValue(); else return; // Set counter value context.getTransaction().getTransaction().writeCounterField(id, this.storageId, count, true); }
@Override @SuppressWarnings("unchecked") void importPlain(ImportContext context, Object obj, ObjId id) { // Get POJO value final Object value; try { value = obj.getClass().getMethod(this.getter.getName()).invoke(obj); } catch (Exception e) { return; } final Object coreValue = this.importCoreValue(context, value); // Set field core API value context.getTransaction().getTransaction().writeSimpleField(id, this.storageId, coreValue, true); }
@Override @SuppressWarnings("unchecked") void importPlain(ImportContext context, Object obj, ObjId id) { // Get POJO collection final Collection<?> objCollection; try { objCollection = (Collection<?>)obj.getClass().getMethod(this.getter.getName()).invoke(obj); } catch (Exception e) { return; } if (objCollection == null) return; // Get JCollectionField collection final Collection<Object> coreCollection = (Collection<Object>)this.readCoreCollection( context.getTransaction().getTransaction(), id); // Copy values over coreCollection.clear(); for (Object value : objCollection) coreCollection.add(this.elementField.importCoreValue(context, value)); }
@Override @SuppressWarnings("unchecked") void importPlain(ImportContext context, Object obj, ObjId id) { // Get POJO map final Map<?, ?> objMap; try { objMap = (Map<?, ?>)obj.getClass().getMethod(this.getter.getName()).invoke(obj); } catch (Exception e) { return; } if (objMap == null) return; // Get core API map final Map<Object, Object> coreMap = (Map<Object, Object>)context.getTransaction().getTransaction().readMapField( id, this.storageId, true); // Copy key/value pairs over coreMap.clear(); for (Map.Entry<?, ?> entry : objMap.entrySet()) { coreMap.put( this.keyField.importCoreValue(context, entry.getKey()), this.valueField.importCoreValue(context, entry.getValue())); } }
@Override void exportPlain(ExportContext context, ObjId id, Object obj) { // Find setter method final Method objSetter; try { objSetter = Util.findJFieldSetterMethod(obj.getClass(), obj.getClass().getMethod(this.getter.getName())); } catch (Exception e) { return; } // Get field value final Object value = this.exportCoreValue(context, context.getTransaction().getTransaction().readSimpleField(id, this.storageId, true)); // Set POJO value try { objSetter.invoke(obj, value); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("failed to invoke setter method " + objSetter, e); } }
/** * Configure a new transaction. * * <p> * The implementation in {@link PermazenTransactionManager} sets the transaction's timeout and read-only properties. * * @param jtx transaction to configure * @param txDef transaction definition * @throws DatabaseException if an error occurs */ protected void configureTransaction(JTransaction jtx, TransactionDefinition txDef) { // Set name //jtx.setName(txDef.getName()); // Set read-only if (txDef.isReadOnly()) jtx.getTransaction().setReadOnly(true); // Set lock timeout final int timeout = this.determineTimeout(txDef); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { try { jtx.getTransaction().setTimeout(timeout * 1000L); } catch (UnsupportedOperationException e) { if (this.logger.isDebugEnabled()) this.logger.debug("setting non-default timeout of " + timeout + "sec not supported by underlying transaction"); } } }
/** * 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(); }); } }); } }
final Map<?, ?> coreMap = context.getTransaction().getTransaction().readMapField(id, this.storageId, true);
final Collection<?> coreCollection = this.readCoreCollection(context.getTransaction().getTransaction(), id);
final long count = context.getTransaction().getTransaction().readCounterField(id, this.storageId, true);
@Override protected Long getContentLength(JObject jobj, MediaType contentType) { return KVStoreHttpMessageConverter.getKVStoreContentLength(jobj.getTransaction().getTransaction().getKVTransaction()); }
@Override protected void doSetRollbackOnly(DefaultTransactionStatus status) { // Is there a transaction? if (!status.hasTransaction()) return; // Get transaction final JTransaction jtx = ((TxWrapper)status.getTransaction()).getJTransaction(); if (jtx == null) throw new NoTransactionException("no current JTransaction exists"); // Set rollback only if (this.logger.isTraceEnabled()) this.logger.trace("marking Permazen transaction " + jtx + " for rollback-only"); jtx.getTransaction().setRollbackOnly(); }
@Override protected void registerAfterCompletionWithExistingTransaction(Object txObj, List<TransactionSynchronization> synchronizations) { // Get transaction final JTransaction jtx = ((TxWrapper)txObj).getJTransaction(); if (jtx == null) throw new NoTransactionException("no current JTransaction exists"); // Add synchronizations final Transaction tx = jtx.getTransaction(); for (TransactionSynchronization synchronization : synchronizations) tx.addCallback(new TransactionSynchronizationCallback(synchronization)); }
@Override protected void writeInternal(JObject jobj, HttpOutputMessage output) throws IOException { output.getHeaders().setContentType(this.getDefaultContentType(jobj)); KVStoreHttpMessageConverter.writeKVStore(jobj.getTransaction().getTransaction().getKVTransaction(), output); } }
/** * 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(); } }
jtx.getTransaction().setReadOnly(true); final int timeout = attr.getTimeout(); if (timeout != TransactionAttribute.TIMEOUT_DEFAULT) { try { jtx.getTransaction().setTimeout(timeout * 1000L); } catch (UnsupportedOperationException e) { success = true; } catch (Throwable t) { if (attr.rollbackOn(t) || jtx.getTransaction().isRollbackOnly()) jtx.rollback(); else JTransaction.setCurrent(null); if (success) { if (jtx.getTransaction().isRollbackOnly()) jtx.rollback(); else
this.doInTransaction(() -> { final JTransaction jtx = JTransaction.getCurrent(); final CloseableKVStore snapshot = jtx.getTransaction().getKVTransaction().mutableSnapshot(); jtx.getTransaction().addCallback(new Transaction.CallbackAdapter() { @Override public void afterCompletion(boolean committed) {
private String getTypeName(JObject jobj) { return jobj.getTransaction().getTransaction().getSchemas() .getVersion(jobj.getSchemaVersion()).getObjType(jobj.getObjId().getStorageId()).getName(); } }
} 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() {