Fix PRIMARY KEY constraint handling in auction import
- Handle both auction_id and URL constraint failures
- Add fallback UPDATE by URL when INSERT fails
- Properly catch and log constraint violations without propagating
- Fixes import errors on server with duplicate auctions
Former-commit-id: 80b9841aee
This commit is contained in:
@@ -481,6 +481,9 @@ public class DatabaseService {
|
|||||||
} else {
|
} else {
|
||||||
log.debug("Updated existing auction by URL: {}", auction.url());
|
log.debug("Updated existing auction by URL: {}", auction.url());
|
||||||
}
|
}
|
||||||
|
} catch (SQLException updateEx) {
|
||||||
|
// UPDATE also failed - log and swallow the exception
|
||||||
|
log.warn("Failed to update auction by URL ({}): {}", auction.url(), updateEx.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -844,8 +847,12 @@ public class DatabaseService {
|
|||||||
}
|
}
|
||||||
upsertAuction(auction);
|
upsertAuction(auction);
|
||||||
imported.add(auction);
|
imported.add(auction);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// SQLException should be handled by upsertAuction, but if it propagates here, log it
|
||||||
|
log.warn("Failed to import auction (SQL error): {}", e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Failed to import auction: " + e.getMessage());
|
// Other exceptions (parsing errors, etc)
|
||||||
|
log.warn("Failed to import auction (parsing error): {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user