JDBCCommitQueries extends JDBCQueriesHelper implements CommitQueries { @Override public String commitInsertionStatement(int projectId, Commit commit, GitDiff diff) { logger.trace("[" + projectId + "] Inserting commit: " + commit.sha + " - ordinal: " + commit.ordinal + " - diff: " + diff + " - time: " + commit.date); String commitMessage = escapeStringEntry(commit.message); String mergedCommit = commit.getParentCount() >= 2 ? "(" + idFromShaQuery(projectId, commit.getParent(1).sha) + ")" : null; String developerQuery = developerQueries.idFromEmailQuery(commit.authorEmail); return "INSERT INTO commit_entry (project_id, developer_id, sha1, ordinal, date, " + "additions, deletions, files_changed, message, merged_commit_id, in_detector) VALUES ('" + projectId + "', (" + developerQuery + "), '" + commit.sha + "', " + commit.ordinal + ", '" + commit.date.toString() + "', " + diff.getAddition() + ", " + diff.getDeletion() + ", " + diff.getChangedFiles() + ", $$ " + commitMessage + " $$, " + mergedCommit + ", " + commit.isInPaprika() + ") ON CONFLICT DO NOTHING;"; } JDBCCommitQueries(DeveloperQueries developerQueries); @Override String commitInsertionStatement(int projectId, Commit commit, GitDiff diff); @Override String idFromShaQuery(int projectId, String sha); @Override String shaFromOrdinalQuery(int projectId, int ordinal); @Override String idFromShaQuery(int projectId, String sha, boolean paprikaOnly); @Override String shaFromOrdinalQuery(int projectId, int ordinal, boolean paprikaOnly); @Override String lastProjectCommitShaQuery(int projectId); @Override String lastProjectCommitShaQuery(int projectId, boolean paprikaOnly); @Override String fileRenameInsertionStatement(int projectId, String commitSha, GitRename rename); @Override String mergedCommitIdQuery(int projectId, Commit commit); @Override String projectIdFromShaQuery(String sha); @Override String updateCommitSizeQuery(int projectId, String tempTable); @Override String fileChangedInsertionStatement(int projectId, String commitSha, GitChangedFile changedFile);  }
@Test public void testCommitInsertionStatement() { long count = 0; Commit commit = generateCommit("sha", 1); executeSuccess(queries.commitInsertionStatement(projectId, commit, GitDiff.EMPTY)); assertEquals(++count, getCommitCount()); int secondProjectID = createProject("anotherProject"); executeSuccess(queries.commitInsertionStatement(secondProjectID, commit, GitDiff.EMPTY)); assertEquals(++count, getCommitCount()); Commit anotherSha = generateCommit("anotherSha", commit.ordinal + 1); executeSuccess(queries.commitInsertionStatement(projectId, anotherSha, GitDiff.EMPTY)); assertEquals(++count, getCommitCount()); Commit anotherMessage = generateCommit("thirdSha", anotherSha.ordinal + 1, "test $$ subString $$ ^$ should ' \" work any way $$ for sure @&é\"'(§è!çà' $"); executeSuccess(queries.commitInsertionStatement(projectId, anotherMessage, GitDiff.EMPTY)); assertEquals(++count, getCommitCount()); executeNothinhDone(queries.commitInsertionStatement(projectId, commit, GitDiff.EMPTY)); assertEquals(count, getCommitCount()); }