Skip to content

Commit

Permalink
- use UPSERT for website links as well
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed May 25, 2018
1 parent 82cc570 commit d53522e
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions src/main/java/mSearch/daten/DatenFilm.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,31 +265,6 @@ public void setDescription(final String desc) {
}
}

private void writeDescriptionToDatabase(String desc) {
try (Connection connection = PooledDatabaseConnection.getInstance().getConnection();
PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO description VALUES (?,?)");
PreparedStatement updateStatement = connection.prepareStatement("UPDATE description SET desc=? WHERE id =?")
) {
String cleanedDesc = cleanDescription(desc, arr[FILM_THEMA], getTitle());
cleanedDesc = StringUtils.replace(cleanedDesc, "\n", "<br />");

updateStatement.setString(1, cleanedDesc);
updateStatement.setInt(2, databaseFilmNumber);
updateStatement.executeUpdate();

insertStatement.setInt(1, databaseFilmNumber);
insertStatement.setString(2, cleanedDesc);
insertStatement.execute();


} catch (SQLIntegrityConstraintViolationException ignored) {
//this will happen in UPSERT operation
} catch (SQLException ex) {
logger.error(ex);
}

}

public String getWebsiteLink() {
String res;

Expand Down Expand Up @@ -332,15 +307,48 @@ public void setWebsiteLink(String link) {

private void writeWebsiteLinkToDatabase(String link) {
try (Connection connection = PooledDatabaseConnection.getInstance().getConnection();
PreparedStatement statement = connection.prepareStatement("INSERT INTO website_links VALUES (?,?)")) {
statement.setInt(1, databaseFilmNumber);
statement.setString(2, link);
statement.executeUpdate();
PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO website_links VALUES (?,?)");
PreparedStatement updateStatement = connection.prepareStatement("UPDATE website_links SET link=? WHERE id=?")) {

updateStatement.setString(1, link);
updateStatement.setInt(2, databaseFilmNumber);
updateStatement.executeUpdate();

insertStatement.setInt(1, databaseFilmNumber);
insertStatement.setString(2, link);
insertStatement.executeUpdate();
} catch (SQLIntegrityConstraintViolationException ignored) {
} catch (SQLException ex) {
logger.error(ex);
}
}

private void writeDescriptionToDatabase(String desc) {
try (Connection connection = PooledDatabaseConnection.getInstance().getConnection();
PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO description VALUES (?,?)");
PreparedStatement updateStatement = connection.prepareStatement("UPDATE description SET desc=? WHERE id =?")
) {
String cleanedDesc = cleanDescription(desc, arr[FILM_THEMA], getTitle());
cleanedDesc = StringUtils.replace(cleanedDesc, "\n", "<br />");

updateStatement.setString(1, cleanedDesc);
updateStatement.setInt(2, databaseFilmNumber);
updateStatement.executeUpdate();

insertStatement.setInt(1, databaseFilmNumber);
insertStatement.setString(2, cleanedDesc);
insertStatement.execute();


} catch (SQLIntegrityConstraintViolationException ignored) {
//this will happen in UPSERT operation
} catch (SQLException ex) {
logger.error(ex);
}

}


private String cleanDescription(String s, String thema, String titel) {
// die Beschreibung auf x Zeichen beschränken

Expand Down

0 comments on commit d53522e

Please sign in to comment.