我开始使用Android Room而且我遇到了一些麻烦。
我有一个包含7个订单的ArrayList,当我调用insertAll(List orders)时 只有4个订单插入数据库。
如何调试插入查询以查找阻塞内容?
由于
答案 0 :(得分:13)
Room执行的调用不同步,因此可能在执行
时执行List<Order> myOrders = mDb.getOrderDao().getAll()
它仍在插入订单。
试试这个
@Dao
public interface OrderDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long insertOrder(Order order);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAllOrders(List<Order> order);
@Query("SELECT * FROM orders")
List<Order> getAll();
}
@Entity(tableName = TABLE_NAME)
public class Order {
public static final String TABLE_NAME = "orders";
@PrimaryKey (autoGenerate = true)
private int id;
@SerializedName("order_number")
@ColumnInfo(name = "order_number")
private String orderNumber;
}
// Call
mDb.getOrderDao().insertAllOrders(orders);
Log.d(TAG, "inserted all");
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
@Override
public void run() {
List<Order> myOrders = mDb.getOrderDao().getAll();
Log.d(TAG, "Orders nr = " + myOrders.size());
}
});
答案 1 :(得分:1)
必须添加OnConflict属性。
@echo off
Title Welcome Screen with DJ Buzz Radio by Hackoo 2017
mode con cols=64 lines=35 & color 0A
REM You can change the variable PeriodTime as you needs here is set to (120 seconds = 2 minutes) as example
Set "PeriodTime=120"
Call :Stop_Radio
Call :Play_DJ_Buzz_Radio
echo(
cls
:::
::: __ __ _______ ___ ___ _______
::: | | | || || | | | | |
::: | |_| || ___|| | | | | _ |
::: | || |___ | | | | | | | |
::: | || ___|| |___ | |___ | |_| |
::: | _ || |___ | || || |
::: |__| |__||_______||_______||_______||_______|
:::
::: _ _,---._
::: ,-',' `-.___
::: /-;' `._
::: /\/ ._ _,'o \
::: ( /\ _,--'\,','"`. )
::: |\ ,'o \' //\
::: | \ / ,--'""`-.
::: : \_ _/ ,-' `-._
::: \ `--' / )
::: `. \`._ ,' ________,','
::: .--` ,' ,--` __\___,;'
::: \`.,-- ,' ,`_)--' /`.,'
::: \( ; | | ) (`-/
::: `--'| |) |-/
::: | | | | |
::: | | |,.,-. | |_
::: | `./ / )---` )
::: _| / ,', ,-'
::: ,'|_( /-<._,' |--,
::: | `--'---. \/ \
::: | / \ /\ \
::: ,-^---._ | \ / \ \
::: ,-' \----' \/ \--`.
::: / \ \ \
:::
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
>NUL TIMEOUT /T %PeriodTime% /NOBREAK & Call :Stop_Radio & exit
::**************************************************************
:Play_DJ_Buzz_Radio
Taskkill /IM "wscript.exe" /F >nul 2>&1
Set vbsfile=%temp%\DJBuzzRadio.vbs
Set "URL=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx"
Call:Play %URL% %vbsfile%
Start %vbsfile%
Exit /b
::**************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000
echo End Sub
)>%~2
exit /b
::**************************************************************
:Stop_Radio
Taskkill /IM "wscript.exe" /F >nul 2>&1
::**************************************************************