我有一个简单的结构,我注意到更新数据库中的记录需要很长时间才能执行。
这就是我的数据类的定义方式:
public static final String TILE_MAP_UNIQUE_ID_FIELD_NAME = "tileMap_unique_id";
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
int tileMap_unique_id;
public static final String TILE_MAP_LEVEL_ID_FIELD_NAME = "tileMap_level_id";
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
String tileMap_level_id;
public static final String COLUMN_FIELD_NAME = "column";
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
long column;
public static final String ROW_FIELD_NAME = "row";
@DatabaseField (uniqueIndexName = "unique_tileMapCache", canBeNull = false)
long row;
public static final String IMAGE_DATA_FIELD_NAME = "image_data";
@DatabaseField (dataType = DataType.BYTE_ARRAY, index = true, canBeNull = false)
byte[] image_data;
public static final String IMAGE_DATA_LENGHT_FIELD_NAME = "image_data_lenght";
@DatabaseField (index = true, canBeNull = false)
int image_data_lenght;
public static final String DATE_CREATED_FIELD_NAME = "date_created";
@DatabaseField(index = true, canBeNull = false)
Date date_created;
public static final String DATE_LAST_ACCESSED_FIELD_NAME = "date_last_accessed";
@DatabaseField(index = true, canBeNull = false)
Date date_last_accessed;
public static final String ACCESSED_COUNTER = "accessed_counter";
@DatabaseField(index = true, canBeNull = false)
int accessed_counter;
这是我的应用程序中某处的更新语句:
Dao<TileMapCacheData, Integer> updateTileMapCacheDataDao = dbHelper.getTileMapCacheDataDao();
UpdateBuilder<TileMapCacheData, Integer> updateBuilder = updateTileMapCacheDataDao.updateBuilder();
updateBuilder.updateColumnValue(TileMapCacheData.DATE_LAST_ACCESSED_FIELD_NAME, new Date());
updateBuilder.updateColumnValue(TileMapCacheData.ACCESSED_COUNTER, record.accessed_counter + 1);
updateBuilder.where()
.eq(TileMapCacheData.TILE_MAP_UNIQUE_ID_FIELD_NAME, tileMap.getUniqueId())
.and()
.eq(TileMapCacheData.TILE_MAP_LEVEL_ID_FIELD_NAME, tileMap.getLevelId(tileImage.tile.level))
.and()
.eq(TileMapCacheData.COLUMN_FIELD_NAME, tileImage.tile.column)
.and()
.eq(TileMapCacheData.ROW_FIELD_NAME, tileImage.tile.row);
updateTileMapCacheDataDao.update(updateBuilder.prepare());
SQL 如下所示:
UPDATE `tilemapcachedata` SET `date_last_accessed` = ? ,`accessed_counter` = 11 WHERE (((`tileMap_unique_id` = -1902272760 AND `tileMap_level_id` = '5' ) AND `column` = 24 ) AND `row` = -6 )
有没有人看到问题出在哪里?.update() 需要几秒钟,它应该立即执行。
任何想法都会很棒。