fixed issue #808

This commit is contained in:
Jeremy Long
2017-07-17 06:40:39 -04:00
parent 2ab92a940b
commit 91b1d5cbde

View File

@@ -324,7 +324,7 @@ public final class CveDB implements AutoCloseable {
*/ */
private void prepareStatements() throws DatabaseException { private void prepareStatements() throws DatabaseException {
for (PreparedStatementCveDb key : values()) { for (PreparedStatementCveDb key : values()) {
final PreparedStatement preparedStatement; PreparedStatement preparedStatement = null;
try { try {
final String statementString = statementBundle.getString(key.name()); final String statementString = statementBundle.getString(key.name());
if (key == INSERT_VULNERABILITY || key == INSERT_CPE) { if (key == INSERT_VULNERABILITY || key == INSERT_CPE) {
@@ -332,12 +332,18 @@ public final class CveDB implements AutoCloseable {
} else { } else {
preparedStatement = connection.prepareStatement(statementString); preparedStatement = connection.prepareStatement(statementString);
} }
} catch (SQLException | MissingResourceException exception) { } catch (SQLException ex) {
throw new DatabaseException(exception); throw new DatabaseException(ex);
} catch (MissingResourceException ex) {
if (!ex.getMessage().contains("key MERGE_PROPERTY")) {
throw new DatabaseException(ex);
} }
}
if (preparedStatement != null) {
preparedStatements.put(key, preparedStatement); preparedStatements.put(key, preparedStatement);
} }
} }
}
/** /**
* Closes all prepared statements. * Closes all prepared statements.
@@ -357,6 +363,9 @@ public final class CveDB implements AutoCloseable {
* @throws SQLException thrown if a SQL Exception occurs * @throws SQLException thrown if a SQL Exception occurs
*/ */
private synchronized PreparedStatement getPreparedStatement(PreparedStatementCveDb key) throws SQLException { private synchronized PreparedStatement getPreparedStatement(PreparedStatementCveDb key) throws SQLException {
if (!preparedStatements.containsKey(key)) {
return null;
}
final PreparedStatement preparedStatement = preparedStatements.get(key); final PreparedStatement preparedStatement = preparedStatements.get(key);
preparedStatement.clearParameters(); preparedStatement.clearParameters();
return preparedStatement; return preparedStatement;
@@ -495,13 +504,13 @@ public final class CveDB implements AutoCloseable {
*/ */
public synchronized void saveProperty(String key, String value) { public synchronized void saveProperty(String key, String value) {
clearCache(); clearCache();
try {
try { try {
final PreparedStatement mergeProperty = getPreparedStatement(MERGE_PROPERTY); final PreparedStatement mergeProperty = getPreparedStatement(MERGE_PROPERTY);
if (mergeProperty != null) {
mergeProperty.setString(1, key); mergeProperty.setString(1, key);
mergeProperty.setString(2, value); mergeProperty.setString(2, value);
mergeProperty.executeUpdate(); mergeProperty.executeUpdate();
} catch (SQLException e) { } else {
// No Merge statement, so doing an Update/Insert... // No Merge statement, so doing an Update/Insert...
final PreparedStatement updateProperty = getPreparedStatement(UPDATE_PROPERTY); final PreparedStatement updateProperty = getPreparedStatement(UPDATE_PROPERTY);
updateProperty.setString(1, value); updateProperty.setString(1, value);