Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions bindings/java/src/org/sleuthkit/datamodel/HostAddressManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ private HostAddress newHostAddress(HostAddress.HostAddressType type, String addr
}

String normalizedAddress = getNormalizedAddress(address);
// This prevents orphaned objects and ensures we return the existing valid object.
Optional<HostAddress> existingAddr = getHostAddress(addressType, normalizedAddress, connection);
if (existingAddr.isPresent()) {
return existingAddr.get();
}
try {

// TODO: need to get the correct parent obj id.
Expand All @@ -220,17 +225,8 @@ private HostAddress newHostAddress(HostAddress.HostAddressType type, String addr

long objId = db.addObject(parentObjId, objTypeId, connection);

/*
* A conflict clause is used improve performance related to
* exception handling in the database.
*/
String hostAddressInsertSQL;
if (db.getDatabaseType() == TskData.DbType.POSTGRESQL) {
hostAddressInsertSQL = "INSERT INTO tsk_host_addresses(id, address_type, address) VALUES (?, ?, ?) ON CONFLICT DO NOTHING"; //NON-NLS
} else {
hostAddressInsertSQL = "INSERT OR IGNORE INTO tsk_host_addresses(id, address_type, address) VALUES (?, ?, ?)"; //NON-NLS
}

String hostAddressInsertSQL = "INSERT INTO tsk_host_addresses(id, address_type, address) VALUES (?, ?, ?) "; //NON-NLS

PreparedStatement preparedStatement = connection.getPreparedStatement(hostAddressInsertSQL, Statement.RETURN_GENERATED_KEYS);

preparedStatement.clearParameters();
Expand Down