package com.timgroup.eventstore.mysql;

import com.timgroup.eventstore.api.EventReader;
import com.timgroup.eventstore.api.Position;
import com.timgroup.eventstore.api.ResolvedEvent;

import java.util.stream.Stream;

import static java.lang.String.format;
import static java.util.stream.StreamSupport.stream;

public class BasicMysqlEventReader implements EventReader {
    private final ConnectionProvider connectionProvider;
    private final String tableName;

    public BasicMysqlEventReader(ConnectionProvider connectionProvider, String tableName) {
        this.connectionProvider = connectionProvider;
        this.tableName = tableName;
    }

    @Override
    public Stream<ResolvedEvent> readAllForwards() {
        return readAllForwards(new BasicMysqlEventStorePosition(-1));
    }

    @Override
    public Stream<ResolvedEvent> readAllForwards(Position positionExclusive) {
        BasicMysqlEventStorePosition basicMysqlEventStorePosition = (BasicMysqlEventStorePosition) positionExclusive;

        EventSpliterator spliterator = new EventSpliterator(connectionProvider,
                format("select position, timestamp, stream_category, stream_id, event_number, event_type, data, metadata " +
                        "from %s where position > %s order by position asc", tableName, basicMysqlEventStorePosition.value));

        return stream(spliterator, false).onClose(spliterator::close);
    }
}

@@ -175,16 +175,78 @@
 edEvent;
+%0Aimport com.timgroup.eventstore.memory.JavaInMemoryEventStore;
 %0A%0Aimport
@@ -425,16 +425,131 @@
 eader %7B%0A
+    private static final BasicMysqlEventStorePosition EMPTY_STORE_POSITION = new BasicMysqlEventStorePosition(-1);%0A
     priv
@@ -925,44 +925,28 @@
 rds(
-new BasicMysqlEventStorePosition(-1)
+EMPTY_STORE_POSITION
 );%0A 
@@ -1495,16 +1495,16 @@
 lue));%0A%0A
-
         
@@ -1571,11 +1571,105 @@
 );%0A    %7D
+%0A%0A    public static Position emptyStorePosition() %7B%0A        return EMPTY_STORE_POSITION;%0A    %7D
 %0A%7D%0A

add emptyStorePosition() method to basic mysql event reader