mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-26 11:01:44 +01:00
Replaced update or insert property logic with merge property logic.
This commit is contained in:
@@ -258,12 +258,10 @@ public class CveDB {
|
|||||||
* @param props a collection of properties
|
* @param props a collection of properties
|
||||||
*/
|
*/
|
||||||
void saveProperties(Properties props) {
|
void saveProperties(Properties props) {
|
||||||
PreparedStatement updateProperty = null;
|
PreparedStatement mergeProperty = null;
|
||||||
PreparedStatement insertProperty = null;
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
updateProperty = getConnection().prepareStatement(statementBundle.getString("UPDATE_PROPERTY"));
|
mergeProperty = getConnection().prepareStatement(statementBundle.getString("MERGE_PROPERTY"));
|
||||||
insertProperty = getConnection().prepareStatement(statementBundle.getString("INSERT_PROPERTY"));
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.warn("Unable to save properties to the database");
|
LOGGER.warn("Unable to save properties to the database");
|
||||||
LOGGER.debug("Unable to save properties to the database", ex);
|
LOGGER.debug("Unable to save properties to the database", ex);
|
||||||
@@ -273,20 +271,16 @@ public class CveDB {
|
|||||||
final String key = entry.getKey().toString();
|
final String key = entry.getKey().toString();
|
||||||
final String value = entry.getValue().toString();
|
final String value = entry.getValue().toString();
|
||||||
try {
|
try {
|
||||||
updateProperty.setString(1, value);
|
mergeProperty.setString(1, key);
|
||||||
updateProperty.setString(2, key);
|
mergeProperty.setString(2, value);
|
||||||
if (updateProperty.executeUpdate() == 0) {
|
mergeProperty.executeUpdate();
|
||||||
insertProperty.setString(1, key);
|
|
||||||
insertProperty.setString(2, value);
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.warn("Unable to save property '{}' with a value of '{}' to the database", key, value);
|
LOGGER.warn("Unable to save property '{}' with a value of '{}' to the database", key, value);
|
||||||
LOGGER.debug("", ex);
|
LOGGER.debug("", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DBUtils.closeStatement(updateProperty);
|
DBUtils.closeStatement(mergeProperty);
|
||||||
DBUtils.closeStatement(insertProperty);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,38 +291,25 @@ public class CveDB {
|
|||||||
* @param value the property value
|
* @param value the property value
|
||||||
*/
|
*/
|
||||||
void saveProperty(String key, String value) {
|
void saveProperty(String key, String value) {
|
||||||
PreparedStatement updateProperty = null;
|
PreparedStatement mergeProperty = null;
|
||||||
PreparedStatement insertProperty = null;
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
updateProperty = getConnection().prepareStatement(statementBundle.getString("UPDATE_PROPERTY"));
|
mergeProperty = getConnection().prepareStatement(statementBundle.getString("MERGE_PROPERTY"));
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.warn("Unable to save properties to the database");
|
LOGGER.warn("Unable to save properties to the database");
|
||||||
LOGGER.debug("Unable to save properties to the database", ex);
|
LOGGER.debug("Unable to save properties to the database", ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
updateProperty.setString(1, value);
|
mergeProperty.setString(1, key);
|
||||||
updateProperty.setString(2, key);
|
mergeProperty.setString(2, value);
|
||||||
if (updateProperty.executeUpdate() == 0) {
|
mergeProperty.executeUpdate();
|
||||||
try {
|
|
||||||
insertProperty = getConnection().prepareStatement(statementBundle.getString("INSERT_PROPERTY"));
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
LOGGER.warn("Unable to save properties to the database");
|
|
||||||
LOGGER.debug("Unable to save properties to the database", ex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
insertProperty.setString(1, key);
|
|
||||||
insertProperty.setString(2, value);
|
|
||||||
insertProperty.execute();
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LOGGER.warn("Unable to save property '{}' with a value of '{}' to the database", key, value);
|
LOGGER.warn("Unable to save property '{}' with a value of '{}' to the database", key, value);
|
||||||
LOGGER.debug("", ex);
|
LOGGER.debug("", ex);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DBUtils.closeStatement(updateProperty);
|
DBUtils.closeStatement(mergeProperty);
|
||||||
DBUtils.closeStatement(insertProperty);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ SELECT_VULNERABILITY=SELECT id, description, cwe, cvssScore, cvssAccessVector, c
|
|||||||
SELECT_VULNERABILITY_ID=SELECT id FROM vulnerability WHERE cve = ?
|
SELECT_VULNERABILITY_ID=SELECT id FROM vulnerability WHERE cve = ?
|
||||||
SELECT_PROPERTIES=SELECT id, value FROM properties
|
SELECT_PROPERTIES=SELECT id, value FROM properties
|
||||||
SELECT_PROPERTY=SELECT id, value FROM properties WHERE id = ?
|
SELECT_PROPERTY=SELECT id, value FROM properties WHERE id = ?
|
||||||
INSERT_PROPERTY=INSERT INTO properties (id, value) VALUES (?, ?)
|
MERGE_PROPERTY=MERGE INTO properties (id, value) KEY(id) VALUES(?, ?)
|
||||||
UPDATE_PROPERTY=UPDATE properties SET value = ? WHERE id = ?
|
|
||||||
DELETE_PROPERTY=DELETE FROM properties WHERE id = ?
|
DELETE_PROPERTY=DELETE FROM properties WHERE id = ?
|
||||||
|
|
||||||
DELETE_UNUSED_DICT_CPE=DELETE FROM cpeEntry WHERE dictionaryEntry=true AND id NOT IN (SELECT cpeEntryId FROM software)
|
DELETE_UNUSED_DICT_CPE=DELETE FROM cpeEntry WHERE dictionaryEntry=true AND id NOT IN (SELECT cpeEntryId FROM software)
|
||||||
|
|||||||
Reference in New Issue
Block a user