を反復しようとしForeignCollection<OrderItems>
ます。これはeager
に設定すると機能true
しますが、lazy オプションはまだ機能しません。
まず、私が作る
OrderDataSource orderDS = new OrderDataSource(getAppContext());
ws.Order order = orderDS.convertToWS(mOrder,ws.Order.class);
orderDS.close();
どこでclose()
データベース接続を閉じconvertToWS()
て繰り返します。
の一部convertToWS()
:
Iterator<OrderItem> itr = order.getOrderItems().iterator();
while (itr.hasNext())
{
OrderItem orderItem = itr.next();
...
}
メソッド close は、から戻った後に呼び出されconvertToWS()
ます。convertToWS()
私はどんな問題でも他のオブジェクトを扱います。
CloseableIterator
私も使用してブロックで閉じようとしましfinally
たが、成功しませんでした。これを期待して、接続を閉じません。
例外:
02-17 02:21:43.094: E/AndroidRuntime(4820): FATAL EXCEPTION: main
02-17 02:21:43.094: E/AndroidRuntime(4820): java.lang.IllegalStateException: database /data/data/my_app/databases/my_db (conn# 0) already closed
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2082)
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1556)
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1538)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:162)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:57)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.stmt.SelectIterator.<init>(SelectIterator.java:55)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:232)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java:933)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java:531)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java:526)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java:74)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java:60)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java:50)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:45)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:26)
02-17 02:21:43.094: E/AndroidRuntime(4820): at orders.OrderDataSource.convertToWS(OrderDataSource.java:409)
02-17 02:21:43.094: E/AndroidRuntime(4820): at fragments.OrderDetailFragment.sendOrder(OrderDetailFragment.java:419)
02-17 02:21:43.094: E/AndroidRuntime(4820): at fragments.OrderDetailFragment.doPositiveClick(OrderDetailFragment.java:347)
02-17 02:21:43.094: E/AndroidRuntime(4820): at ui.dialogfragments.AlertDialogFragment$1.onClick(AlertDialogFragment.java:54)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.os.Looper.loop(Looper.java:137)
02-17 02:21:43.094: E/AndroidRuntime(4820): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-17 02:21:43.094: E/AndroidRuntime(4820): at java.lang.reflect.Method.invokeNative(Native Method)
02-17 02:21:43.094: E/AndroidRuntime(4820): at java.lang.reflect.Method.invoke(Method.java:511)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-17 02:21:43.094: E/AndroidRuntime(4820): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-17 02:21:43.094: E/AndroidRuntime(4820): at dalvik.system.NativeStart.main(Native Method)