JDBCLog extends JDBCBase implements Log { @Override public synchronized @Nullable LogEntry getFirst() throws StorageException { try { return executeQuery("SELECT * FROM entries WHERE log_index=(SELECT MIN(log_index) FROM ENTRIES)", new StatementWithReturnBlock<LogEntry>() { @Override public @Nullable LogEntry use(PreparedStatement statement) throws Exception { return withResultSet(statement, new ResultSetBlock<LogEntry>() { @Override public LogEntry use(ResultSet resultSet) throws Exception { if (!resultSet.next()) { return null; } return newLogEntryFromDatabaseRow( mapDatabaseTypeToLogEntryType(resultSet.getInt("type")), resultSet.getLong("log_index"), resultSet.getLong("term"), resultSet.getBytes("data")); } }); } }); } catch (Exception e) { throw new StorageException("fail get last log entry", e); } } JDBCLog(String url, String username, @Nullable String password, CommandSerializer commandSerializer, CommandDeserializer commandDeserializer); synchronized void setupCustomCommandSerializerAndDeserializer(CommandSerializer commandSerializer, CommandDeserializer commandDeserializer); @Override @Nullable LogEntry get(final long logIndex); @Override synchronized @Nullable LogEntry getFirst(); @Override synchronized @Nullable LogEntry getLast(); @Override synchronized void put(final LogEntry logEntry); @Override synchronized void truncate(final long index);  }
@Test public void shouldReturnNullWhenGetFirstIsCalledOnEmptyTable() throws StorageException { assertThat(jdbcLog.getFirst(), nullValue()); }