use of java.sql.Timestamp in project languagetool by languagetool-org.
the class MatchDatabase method list.
List<StoredWikipediaRuleMatch> list() throws SQLException {
try (PreparedStatement prepSt = conn.prepareStatement("SELECT * FROM feed_matches");
ResultSet resultSet = prepSt.executeQuery()) {
List<StoredWikipediaRuleMatch> result = new ArrayList<>();
while (resultSet.next()) {
String ruleId = resultSet.getString("rule_id");
String ruleSubId = resultSet.getString("rule_sub_id");
String ruleDescription = resultSet.getString("rule_description");
String ruleMessage = resultSet.getString("rule_message");
String errorContext = resultSet.getString("error_context");
String title = resultSet.getString("title");
Date editDate = new Date(resultSet.getTimestamp("edit_date").getTime());
Timestamp fixTimeStamp = resultSet.getTimestamp("fix_date");
Date fixDate = fixTimeStamp != null ? new Date(resultSet.getTimestamp("fix_date").getTime()) : null;
long diffId = resultSet.getLong("diff_id");
long fixDiffId = resultSet.getLong("fix_diff_id");
result.add(new StoredWikipediaRuleMatch(ruleId, ruleSubId, ruleDescription, ruleMessage, errorContext, title, editDate, fixDate, diffId, fixDiffId));
}
return result;
}
}
use of java.sql.Timestamp in project languagetool by languagetool-org.
the class MatchDatabase method updateRuleMatchDate.
private void updateRuleMatchDate(String tableName, Language language, Date date) {
String updateSql = "UPDATE " + tableName + " SET check_date = ? WHERE language_code = ?";
try (PreparedStatement updateSt = conn.prepareStatement(updateSql)) {
updateSt.setTimestamp(1, new Timestamp(date.getTime()));
updateSt.setString(2, language.getShortCode());
int affected = updateSt.executeUpdate();
if (affected == 0) {
String insertSql = "INSERT INTO " + tableName + " (language_code, check_date) VALUES (?, ?)";
try (PreparedStatement insertSt = conn.prepareStatement(insertSql)) {
insertSt.setString(1, language.getShortCode());
insertSt.setTimestamp(2, new Timestamp(date.getTime()));
insertSt.execute();
}
}
} catch (SQLException e) {
throw new RuntimeException("Could not store date for " + language + " to database, table " + tableName, e);
}
}
use of java.sql.Timestamp in project languagetool by languagetool-org.
the class MatchDatabase method add.
void add(WikipediaRuleMatch ruleMatch) {
String sql = "INSERT INTO feed_matches " + "(title, language_code, rule_id, rule_sub_id, rule_description, rule_message, rule_category, error_context, edit_date, diff_id) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement prepSt = conn.prepareStatement(sql)) {
prepSt.setString(1, StringUtils.abbreviate(ruleMatch.getTitle(), 255));
prepSt.setString(2, ruleMatch.getLanguage().getShortCode());
prepSt.setString(3, ruleMatch.getRule().getId());
if (ruleMatch.getRule() instanceof AbstractPatternRule) {
prepSt.setString(4, ((AbstractPatternRule) ruleMatch.getRule()).getSubId());
} else {
prepSt.setString(4, null);
}
prepSt.setString(5, StringUtils.abbreviate(ruleMatch.getRule().getDescription(), 255));
prepSt.setString(6, StringUtils.abbreviate(ruleMatch.getMessage(), 255));
if (ruleMatch.getRule().getCategory() != null) {
prepSt.setString(7, StringUtils.abbreviate(ruleMatch.getRule().getCategory().getName(), 255));
} else {
prepSt.setString(7, "<no category>");
}
prepSt.setString(8, StringUtils.abbreviate(ruleMatch.getErrorContext(), 500));
prepSt.setTimestamp(9, new Timestamp(ruleMatch.getEditDate().getTime()));
prepSt.setLong(10, ruleMatch.getDiffId());
prepSt.execute();
} catch (SQLException e) {
if (e.toString().contains("Incorrect string value")) {
// Let's accept this - i.e. not crash - for now:
// See http://stackoverflow.com/questions/1168036/ and http://stackoverflow.com/questions/10957238/
System.err.println("Could not add rule match " + ruleMatch + " to database - stacktrace follows:");
e.printStackTrace();
} else {
throw new RuntimeException("Could not add rule match " + ruleMatch + " to database", e);
}
}
}
use of java.sql.Timestamp in project languagetool by languagetool-org.
the class MatchDatabase method markedFixed.
/**
* @return the number of affected rows, thus {@code 0} means the error was not found in the database
*/
int markedFixed(WikipediaRuleMatch ruleMatch) {
String sql = "UPDATE feed_matches SET fix_date = ?, fix_diff_id = ? WHERE language_code = ? AND title = ? AND rule_id = ? AND error_context = ?";
try (PreparedStatement prepSt = conn.prepareStatement(sql)) {
prepSt.setTimestamp(1, new Timestamp(ruleMatch.getEditDate().getTime()));
prepSt.setLong(2, ruleMatch.getDiffId());
prepSt.setString(3, ruleMatch.getLanguage().getShortCode());
prepSt.setString(4, ruleMatch.getTitle());
// I'm not sure whether we should also consider the sub id...
prepSt.setString(5, ruleMatch.getRule().getId());
prepSt.setString(6, ruleMatch.getErrorContext());
return prepSt.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException("Could not mark rule match " + ruleMatch + " as fixed in database", e);
}
}
use of java.sql.Timestamp in project jOOQ by jOOQ.
the class TableRecordImpl method addRecordTimestamp.
/**
* Set an updated timestamp value to a store query
*/
final Timestamp addRecordTimestamp(StoreQuery<?> store) {
Timestamp result = null;
if (isTimestampOrVersionAvailable()) {
TableField<R, ?> timestamp = getTable().getRecordTimestamp();
if (timestamp != null) {
// Use Timestamp locally, to provide maximum precision
result = new Timestamp(System.currentTimeMillis());
addValue(store, timestamp, result);
}
}
return result;
}
Aggregations