LoginSignup
1
1

More than 5 years have passed since last update.

ORMLiteは、(デフォルトでは)beginTransactionNonExclusive(またはbeginTransactionWithListenerNonExclusive)が実行できない

Posted at

かなり驚いたのでメモ。

ORMLiteの4.48で確認したが、1年以上更新されていないので、恐らく今後とも同じ仕様だろう。
結論から言うと、ORMLiteはマルチスレッドでは使わない方がいい。
ORMLiteはトランザクション管理にTransactionManagerクラスを使用している。
まず、このクラスにはトランザクションの種類を指定するパラメータが存在しない。

そして使用しているコネクションの実態は、AndroidDatabaseConnectionのインスタンスだ。
このクラスの中でtransactionを開始しているのは以下の通りだ。

java

    public void setAutoCommit(boolean autoCommit) {
        /*
         * Sqlite does not support auto-commit. The various JDBC drivers seem to implement it with the use of a
         * transaction. That's what we are doing here.
         */
        if (autoCommit) {
            if (db.inTransaction()) {
                db.setTransactionSuccessful();
                db.endTransaction();
            }
        } else {
            if (!db.inTransaction()) {
                db.beginTransaction();
            }
        }
    }

    public Savepoint setSavePoint(String name) throws SQLException {
        try {
            db.beginTransaction();
            logger.trace("{}: save-point set with name {}", this, name);
            return new OurSavePoint(name);
        } catch (android.database.SQLException e) {
            throw SqlExceptionUtil.create("problems beginning transaction " + name, e);
        }
    }

見ての通り、beginTransactionNonExclusiveやbeginTransactionWithListenerNonExclusiveは存在しない。
そもそも、ライブラリのソース内に一度も出てこない。

これはちょっとまずい。ORMLiteは非同期で動作するのに全く向いていないんじゃないだろうか。
つか、俺の開発どうしよう。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1