/** * Create the underlying {@link JTransaction} for a new transaction. * * <p> * The implementation in {@link PermazenTransactionManager} just delegates to * {@link Permazen#createTransaction(boolean, ValidationMode, Map)} using this instance's configured * settings for validation mode and allowing new schema versions. * * @param options transaction options * @return newly created {@link JTransaction} * @throws DatabaseException if an error occurs */ protected JTransaction createTransaction(Map<String, Object> options) { return this.jdb.createTransaction(this.allowNewSchema, this.validationMode, options); }
/** * Create a new transaction. * * <p> * Convenience method; equivalent to: * <blockquote><pre> * {@link #createTransaction(boolean, ValidationMode, Map) createTransaction}(allowNewSchema, validationMode, null) * </pre></blockquote> * * @param allowNewSchema whether creating a new schema version is allowed * @param validationMode the {@link ValidationMode} to use for the new transaction * @return the newly created transaction * @throws io.permazen.core.InvalidSchemaException if the schema does not match what's recorded in the * database for the schema version provided to the constructor * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is false * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is true, but the schema is incompatible * with one or more previous schemas alread recorded in the database (i.e., the same storage ID is used * incompatibly between schema versions) * @throws io.permazen.core.InconsistentDatabaseException if inconsistent or invalid meta-data is detected in the database * @throws IllegalArgumentException if {@code validationMode} is null */ public JTransaction createTransaction(boolean allowNewSchema, ValidationMode validationMode) { return this.createTransaction(allowNewSchema, validationMode, null); }
/** * Create a new transaction. * * <p> * Convenience method; equivalent to: * <blockquote><pre> * {@link #createTransaction(boolean, ValidationMode, Map) createTransaction}(true, {@link ValidationMode#AUTOMATIC}, null) * </pre></blockquote> * * @return the newly created transaction * @throws io.permazen.core.InvalidSchemaException if the schema does not match what's recorded in the * database for the schema version provided to the constructor * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is false * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is true, but the schema is incompatible * with one or more previous schemas alread recorded in the database (i.e., the same storage ID is used * incompatibly between schema versions) * @throws io.permazen.core.InconsistentDatabaseException if inconsistent or invalid meta-data is detected in the database */ public JTransaction createTransaction() { return this.createTransaction(true, ValidationMode.AUTOMATIC, null); }
/** * Create a new transaction using an already-opened {@link KVTransaction}. * * <p> * This does not invoke {@link JTransaction#setCurrent JTransaction.setCurrent()}: the caller is responsible * for doing that if necessary. However, this method does arrange for * {@link JTransaction#setCurrent JTransaction.setCurrent}{@code (null)} to be invoked as soon as the * returned transaction is committed (or rolled back), assuming {@link JTransaction#getCurrent} returns the * {@link JTransaction} returned here at that time. * * @param kvt already opened key/value store transaction * @param allowNewSchema whether creating a new schema version is allowed * @param validationMode the {@link ValidationMode} to use for the new transaction * @return the newly created transaction * @throws io.permazen.core.InvalidSchemaException if the schema does not match what's recorded in the * database for the schema version provided to the constructor * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is false * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is true, but the schema is incompatible * with one or more previous schemas alread recorded in the database (i.e., the same storage ID is used * incompatibly between schema versions) * @throws io.permazen.core.InconsistentDatabaseException if inconsistent or invalid meta-data is detected in the database * @throws IllegalArgumentException if {@code kvt} or {@code validationMode} is null */ public JTransaction createTransaction(KVTransaction kvt, boolean allowNewSchema, ValidationMode validationMode) { return this.createTransaction( this.db.createTransaction(kvt, this.getSchemaModel(), this.configuredVersion, allowNewSchema), validationMode); }
/** * Create a new transaction with key/value transaction options. * * <p> * This does not invoke {@link JTransaction#setCurrent JTransaction.setCurrent()}: the caller is responsible * for doing that if necessary. However, this method does arrange for * {@link JTransaction#setCurrent JTransaction.setCurrent}{@code (null)} to be invoked as soon as the * returned transaction is committed (or rolled back), assuming {@link JTransaction#getCurrent} returns the * {@link JTransaction} returned here at that time. * * @param allowNewSchema whether creating a new schema version is allowed * @param validationMode the {@link ValidationMode} to use for the new transaction * @param kvoptions optional {@link io.permazen.kv.KVDatabase}-specific transaction options; may be null * @return the newly created transaction * @throws io.permazen.core.InvalidSchemaException if the schema does not match what's recorded in the * database for the schema version provided to the constructor * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is false * @throws io.permazen.core.InvalidSchemaException if the schema version provided to the constructor * is not recorded in the database and {@code allowNewSchema} is true, but the schema is incompatible * with one or more previous schemas alread recorded in the database (i.e., the same storage ID is used * incompatibly between schema versions) * @throws io.permazen.core.InconsistentDatabaseException if inconsistent or invalid meta-data is detected in the database * @throws IllegalArgumentException if {@code validationMode} is null */ public JTransaction createTransaction(boolean allowNewSchema, ValidationMode validationMode, Map<String, ?> kvoptions) { return this.createTransaction( this.db.createTransaction(this.getSchemaModel(), this.configuredVersion, allowNewSchema, kvoptions), validationMode); }
/** * 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(); } }
final JTransaction jtx = this.lookupPermazen().createTransaction(this.allowNewSchema, this.validationMode);
if (this.schemaVersion != 0) this.jdb.setConfiguredVersion(this.schemaVersion); final JTransaction jtx = this.jdb.createTransaction(this.allowNewSchema, this.validationMode != null ? this.validationMode : ValidationMode.AUTOMATIC, options); JTransaction.setCurrent(jtx);