Catch all exceptions in OsuDB. (fixes #41)

Also added checks for missing audioFilename fields.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-08 20:26:37 -04:00
parent 400f9395e7
commit 40476d4f31
2 changed files with 112 additions and 80 deletions

View File

@ -575,6 +575,10 @@ public class OsuParser {
ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false); ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false);
} }
// no associated audio file?
if (osu.audioFilename == null)
return null;
// if no custom colors, use the default color scheme // if no custom colors, use the default color scheme
if (osu.combo == null) if (osu.combo == null)
osu.combo = Utils.DEFAULT_COMBO; osu.combo = Utils.DEFAULT_COMBO;

View File

@ -33,6 +33,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.newdawn.slick.util.Log;
/** /**
* Handles connections and queries with the cached beatmap database. * Handles connections and queries with the cached beatmap database.
*/ */
@ -247,7 +249,11 @@ public class OsuDB {
// batch insert // batch insert
for (OsuFile osu : batch) { for (OsuFile osu : batch) {
setStatementFields(insertStmt, osu); try {
setStatementFields(insertStmt, osu);
} catch (SQLException e) {
Log.error(String.format("Failed to insert map '%s' into database.", osu.getFile().getPath()), e);
}
insertStmt.addBatch(); insertStmt.addBatch();
} }
int[] results = insertStmt.executeBatch(); int[] results = insertStmt.executeBatch();
@ -281,45 +287,51 @@ public class OsuDB {
*/ */
private static void setStatementFields(PreparedStatement stmt, OsuFile osu) private static void setStatementFields(PreparedStatement stmt, OsuFile osu)
throws SQLException { throws SQLException {
stmt.setString(1, osu.getFile().getParentFile().getName()); try {
stmt.setString(2, osu.getFile().getName()); stmt.setString(1, osu.getFile().getParentFile().getName());
stmt.setLong(3, osu.getFile().lastModified()); stmt.setString(2, osu.getFile().getName());
stmt.setInt(4, osu.beatmapID); stmt.setLong(3, osu.getFile().lastModified());
stmt.setInt(5, osu.beatmapSetID); stmt.setInt(4, osu.beatmapID);
stmt.setString(6, osu.title); stmt.setInt(5, osu.beatmapSetID);
stmt.setString(7, osu.titleUnicode); stmt.setString(6, osu.title);
stmt.setString(8, osu.artist); stmt.setString(7, osu.titleUnicode);
stmt.setString(9, osu.artistUnicode); stmt.setString(8, osu.artist);
stmt.setString(10, osu.creator); stmt.setString(9, osu.artistUnicode);
stmt.setString(11, osu.version); stmt.setString(10, osu.creator);
stmt.setString(12, osu.source); stmt.setString(11, osu.version);
stmt.setString(13, osu.tags); stmt.setString(12, osu.source);
stmt.setInt(14, osu.hitObjectCircle); stmt.setString(13, osu.tags);
stmt.setInt(15, osu.hitObjectSlider); stmt.setInt(14, osu.hitObjectCircle);
stmt.setInt(16, osu.hitObjectSpinner); stmt.setInt(15, osu.hitObjectSlider);
stmt.setFloat(17, osu.HPDrainRate); stmt.setInt(16, osu.hitObjectSpinner);
stmt.setFloat(18, osu.circleSize); stmt.setFloat(17, osu.HPDrainRate);
stmt.setFloat(19, osu.overallDifficulty); stmt.setFloat(18, osu.circleSize);
stmt.setFloat(20, osu.approachRate); stmt.setFloat(19, osu.overallDifficulty);
stmt.setFloat(21, osu.sliderMultiplier); stmt.setFloat(20, osu.approachRate);
stmt.setFloat(22, osu.sliderTickRate); stmt.setFloat(21, osu.sliderMultiplier);
stmt.setInt(23, osu.bpmMin); stmt.setFloat(22, osu.sliderTickRate);
stmt.setInt(24, osu.bpmMax); stmt.setInt(23, osu.bpmMin);
stmt.setInt(25, osu.endTime); stmt.setInt(24, osu.bpmMax);
stmt.setString(26, osu.audioFilename.getName()); stmt.setInt(25, osu.endTime);
stmt.setInt(27, osu.audioLeadIn); stmt.setString(26, osu.audioFilename.getName());
stmt.setInt(28, osu.previewTime); stmt.setInt(27, osu.audioLeadIn);
stmt.setByte(29, osu.countdown); stmt.setInt(28, osu.previewTime);
stmt.setString(30, osu.sampleSet); stmt.setByte(29, osu.countdown);
stmt.setFloat(31, osu.stackLeniency); stmt.setString(30, osu.sampleSet);
stmt.setByte(32, osu.mode); stmt.setFloat(31, osu.stackLeniency);
stmt.setBoolean(33, osu.letterboxInBreaks); stmt.setByte(32, osu.mode);
stmt.setBoolean(34, osu.widescreenStoryboard); stmt.setBoolean(33, osu.letterboxInBreaks);
stmt.setBoolean(35, osu.epilepsyWarning); stmt.setBoolean(34, osu.widescreenStoryboard);
stmt.setString(36, osu.bg); stmt.setBoolean(35, osu.epilepsyWarning);
stmt.setString(37, osu.timingPointsToString()); stmt.setString(36, osu.bg);
stmt.setString(38, osu.breaksToString()); stmt.setString(37, osu.timingPointsToString());
stmt.setString(39, osu.comboToString()); stmt.setString(38, osu.breaksToString());
stmt.setString(39, osu.comboToString());
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**
@ -392,10 +404,14 @@ public class OsuDB {
String name = rs.getString(2); String name = rs.getString(2);
OsuFile osu = m.get(name); OsuFile osu = m.get(name);
if (osu != null) { if (osu != null) {
if ((flag & LOAD_NONARRAY) > 0) try {
setOsuFileFields(rs, osu); if ((flag & LOAD_NONARRAY) > 0)
if ((flag & LOAD_ARRAY) > 0) setOsuFileFields(rs, osu);
setOsuFileArrayFields(rs, osu); if ((flag & LOAD_ARRAY) > 0)
setOsuFileArrayFields(rs, osu);
} catch (SQLException e) {
Log.error(String.format("Failed to load map '%s/%s' from database.", parent, name), e);
}
if (++count >= size) if (++count >= size)
break; break;
} }
@ -414,39 +430,45 @@ public class OsuDB {
* @throws SQLException * @throws SQLException
*/ */
private static void setOsuFileFields(ResultSet rs, OsuFile osu) throws SQLException { private static void setOsuFileFields(ResultSet rs, OsuFile osu) throws SQLException {
osu.beatmapID = rs.getInt(4); try {
osu.beatmapSetID = rs.getInt(5); osu.beatmapID = rs.getInt(4);
osu.title = OsuParser.getDBString(rs.getString(6)); osu.beatmapSetID = rs.getInt(5);
osu.titleUnicode = OsuParser.getDBString(rs.getString(7)); osu.title = OsuParser.getDBString(rs.getString(6));
osu.artist = OsuParser.getDBString(rs.getString(8)); osu.titleUnicode = OsuParser.getDBString(rs.getString(7));
osu.artistUnicode = OsuParser.getDBString(rs.getString(9)); osu.artist = OsuParser.getDBString(rs.getString(8));
osu.creator = OsuParser.getDBString(rs.getString(10)); osu.artistUnicode = OsuParser.getDBString(rs.getString(9));
osu.version = OsuParser.getDBString(rs.getString(11)); osu.creator = OsuParser.getDBString(rs.getString(10));
osu.source = OsuParser.getDBString(rs.getString(12)); osu.version = OsuParser.getDBString(rs.getString(11));
osu.tags = OsuParser.getDBString(rs.getString(13)); osu.source = OsuParser.getDBString(rs.getString(12));
osu.hitObjectCircle = rs.getInt(14); osu.tags = OsuParser.getDBString(rs.getString(13));
osu.hitObjectSlider = rs.getInt(15); osu.hitObjectCircle = rs.getInt(14);
osu.hitObjectSpinner = rs.getInt(16); osu.hitObjectSlider = rs.getInt(15);
osu.HPDrainRate = rs.getFloat(17); osu.hitObjectSpinner = rs.getInt(16);
osu.circleSize = rs.getFloat(18); osu.HPDrainRate = rs.getFloat(17);
osu.overallDifficulty = rs.getFloat(19); osu.circleSize = rs.getFloat(18);
osu.approachRate = rs.getFloat(20); osu.overallDifficulty = rs.getFloat(19);
osu.sliderMultiplier = rs.getFloat(21); osu.approachRate = rs.getFloat(20);
osu.sliderTickRate = rs.getFloat(22); osu.sliderMultiplier = rs.getFloat(21);
osu.bpmMin = rs.getInt(23); osu.sliderTickRate = rs.getFloat(22);
osu.bpmMax = rs.getInt(24); osu.bpmMin = rs.getInt(23);
osu.endTime = rs.getInt(25); osu.bpmMax = rs.getInt(24);
osu.audioFilename = new File(osu.getFile().getParentFile(), OsuParser.getDBString(rs.getString(26))); osu.endTime = rs.getInt(25);
osu.audioLeadIn = rs.getInt(27); osu.audioFilename = new File(osu.getFile().getParentFile(), OsuParser.getDBString(rs.getString(26)));
osu.previewTime = rs.getInt(28); osu.audioLeadIn = rs.getInt(27);
osu.countdown = rs.getByte(29); osu.previewTime = rs.getInt(28);
osu.sampleSet = OsuParser.getDBString(rs.getString(30)); osu.countdown = rs.getByte(29);
osu.stackLeniency = rs.getFloat(31); osu.sampleSet = OsuParser.getDBString(rs.getString(30));
osu.mode = rs.getByte(32); osu.stackLeniency = rs.getFloat(31);
osu.letterboxInBreaks = rs.getBoolean(33); osu.mode = rs.getByte(32);
osu.widescreenStoryboard = rs.getBoolean(34); osu.letterboxInBreaks = rs.getBoolean(33);
osu.epilepsyWarning = rs.getBoolean(35); osu.widescreenStoryboard = rs.getBoolean(34);
osu.bg = OsuParser.getDBString(rs.getString(36)); osu.epilepsyWarning = rs.getBoolean(35);
osu.bg = OsuParser.getDBString(rs.getString(36));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**
@ -456,9 +478,15 @@ public class OsuDB {
* @throws SQLException * @throws SQLException
*/ */
private static void setOsuFileArrayFields(ResultSet rs, OsuFile osu) throws SQLException { private static void setOsuFileArrayFields(ResultSet rs, OsuFile osu) throws SQLException {
osu.timingPointsFromString(rs.getString(37)); try {
osu.breaksFromString(rs.getString(38)); osu.timingPointsFromString(rs.getString(37));
osu.comboFromString(rs.getString(39)); osu.breaksFromString(rs.getString(38));
osu.comboFromString(rs.getString(39));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**