SQLEntrys should be sorted by their timestamp

There's no guarantee that events are inserted into the events-log
plugin's database in the same order as the events were created by
gerrit. Hence always sort them by the event creation timestamp which is
the same order SQL queries created by SQLQueryMaker are using.

Change-Id: Ia44b11049b7c09adc9610971c5a8cecd1fd0b05e
diff --git a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
index 30643ff..d0a6af4 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
@@ -208,7 +208,6 @@
       while (rs.next()) {
         entries.add(
             new SQLEntry(
-                databaseDialect,
                 rs.getString(PROJECT_ENTRY),
                 rs.getTimestamp(DATE_ENTRY),
                 rs.getString(EVENT_ENTRY),
@@ -225,7 +224,6 @@
       while (rs.next()) {
         SQLEntry entry =
             new SQLEntry(
-                databaseDialect,
                 rs.getString(PROJECT_ENTRY),
                 rs.getTimestamp(DATE_ENTRY),
                 rs.getString(EVENT_ENTRY),
diff --git a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntry.java b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntry.java
index 38bc8bc..b853eef 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntry.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntry.java
@@ -18,24 +18,18 @@
 import java.util.Objects;
 
 class SQLEntry implements Comparable<SQLEntry> {
-  private SQLDialect dialect;
   private String name;
   private Timestamp timestamp;
   private String event;
   private Object id;
 
-  SQLEntry(SQLDialect dialect, String name, Timestamp timestamp, String event, Object id) {
-    this.dialect = dialect;
+  SQLEntry(String name, Timestamp timestamp, String event, Object id) {
     this.name = name;
     this.timestamp = timestamp;
     this.event = event;
     this.id = id;
   }
 
-  public SQLDialect getDialect() {
-    return dialect;
-  }
-
   public String getName() {
     return name;
   }
@@ -50,12 +44,7 @@
 
   @Override
   public int compareTo(SQLEntry o) {
-    switch (dialect) {
-      case SPANNER:
-        return timestamp.compareTo(o.timestamp);
-      default:
-        return Integer.compare((int) id, (int) o.id);
-    }
+    return timestamp.compareTo(o.timestamp);
   }
 
   @Override
diff --git a/src/test/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntryTest.java b/src/test/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntryTest.java
index 2fe12da..0c1064f 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntryTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLEntryTest.java
@@ -35,31 +35,15 @@
   @Before
   public void setUp() {
     Timestamp timestamp = new Timestamp(NOW);
-    entry1 = new SQLEntry(SQLDialect.H2, "name1", timestamp, "event1", Integer.MAX_VALUE);
-    entry2 = new SQLEntry(SQLDialect.H2, "name2", timestamp, "event2", Integer.MIN_VALUE);
-    entry3 = new SQLEntry(SQLDialect.H2, "name3", timestamp, "event3", 0);
-    entry4 = new SQLEntry(SQLDialect.H2, "name4", timestamp, "event4", Integer.MAX_VALUE);
-    entry5 =
-        new SQLEntry(
-            SQLDialect.SPANNER,
-            "name5",
-            timestamp,
-            "event1",
-            "b54e6b86-7686-4c3e-a4e4-8edd60ae328e");
-    entry6 =
-        new SQLEntry(
-            SQLDialect.SPANNER,
-            "name6",
-            timestamp,
-            "event2",
-            "0ebc1d7f-5888-45d8-8cd1-244eda611a38");
-    entry7 =
-        new SQLEntry(
-            SQLDialect.SPANNER,
-            "name7",
-            timestamp,
-            "event2",
-            "0ebc1d7f-5888-45d8-8cd1-244eda611a38");
+    Timestamp past = new Timestamp(0);
+    Timestamp future = new Timestamp(NOW + 60000);
+    entry1 = new SQLEntry("name1", future, "event1", Integer.MAX_VALUE);
+    entry2 = new SQLEntry("name2", past, "event2", Integer.MIN_VALUE);
+    entry3 = new SQLEntry("name3", timestamp, "event3", 0);
+    entry4 = new SQLEntry("name4", future, "event4", Integer.MAX_VALUE);
+    entry5 = new SQLEntry("name5", timestamp, "event1", "b54e6b86-7686-4c3e-a4e4-8edd60ae328e");
+    entry6 = new SQLEntry("name6", timestamp, "event2", "0ebc1d7f-5888-45d8-8cd1-244eda611a38");
+    entry7 = new SQLEntry("name7", timestamp, "event2", "0ebc1d7f-5888-45d8-8cd1-244eda611a38");
   }
 
   @Test
@@ -69,7 +53,7 @@
 
   @Test
   public void testGetTimestamp() throws Exception {
-    assertThat(entry1.getTimestamp()).isEqualTo(new Timestamp(NOW));
+    assertThat(entry3.getTimestamp()).isEqualTo(new Timestamp(NOW));
   }
 
   @Test
@@ -79,8 +63,8 @@
 
   @Test
   public void testCompareTo() throws Exception {
-    assertThat(entry1.compareTo(entry2)).isEqualTo(1);
-    assertThat(entry2.compareTo(entry1)).isEqualTo(-1);
+    assertThat(entry3.compareTo(entry2)).isEqualTo(1);
+    assertThat(entry3.compareTo(entry1)).isEqualTo(-1);
   }
 
   @SuppressWarnings("unlikely-arg-type")