Fixed issue with null Integer id return value

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
master
Andrew DeMaria 9 years ago
parent 3213b3f115
commit 6f54dc05d5
  1. 6
      libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java
  2. 7
      libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java

@ -86,7 +86,11 @@ public class PlayerDao extends AbstractDao {
* @param player The player to create.
*/
public synchronized void createPlayer(Player player) {
int id = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class) + 1;
Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class);
if(existingMax == null) {
existingMax = 0;
}
int id = existingMax + 1;
player.setId(String.valueOf(id));
String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")";
update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(),

@ -82,8 +82,11 @@ public class TranscodingDao extends AbstractDao {
* @param transcoding The transcoding to create.
*/
public synchronized void createTranscoding(Transcoding transcoding) {
int id = getJdbcTemplate().queryForObject("select max(id) + 1 from transcoding2", Integer.class);
transcoding.setId(id);
Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from transcoding2", Integer.class);
if(existingMax == null) {
existingMax = 0;
}
transcoding.setId(existingMax + 1);
String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")";
update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(),
transcoding.getTargetFormat(), transcoding.getStep1(),

Loading…
Cancel
Save