Fixed issue with null Integer id return value

Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
master
Andrew DeMaria 9 years ago
parent bd42e92928
commit 196fdf63ba
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  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. * @param player The player to create.
*/ */
public synchronized void createPlayer(Player player) { 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)); player.setId(String.valueOf(id));
String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")";
update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(), 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. * @param transcoding The transcoding to create.
*/ */
public synchronized void createTranscoding(Transcoding transcoding) { public synchronized void createTranscoding(Transcoding transcoding) {
int id = getJdbcTemplate().queryForObject("select max(id) + 1 from transcoding2", Integer.class); Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from transcoding2", Integer.class);
transcoding.setId(id); if(existingMax == null) {
existingMax = 0;
}
transcoding.setId(existingMax + 1);
String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")";
update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(), update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(),
transcoding.getTargetFormat(), transcoding.getStep1(), transcoding.getTargetFormat(), transcoding.getStep1(),

Loading…
Cancel
Save