// Path: myeslib-util/src/main/java/org/myeslib/util/EventSourcingMagicHelper.java
// @SneakyThrows
// static public void applyEventsOn(List<? extends Event> events, AggregateRoot instance)  {
//    MultiMethod mm = MultiMethod.getMultiMethod(instance.getClass(), "on");
//    for (Event event : events) {
// 	  mm.invoke(instance, event);
//    }
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/AggregateRoot.java
// public interface AggregateRoot extends Serializable {
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/Event.java
// public interface Event extends Serializable {
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/AggregateRootHistory.java
// @SuppressWarnings("serial")
// @Data
// public class AggregateRootHistory implements Serializable {
// 
// 	private final List<UnitOfWork> unitsOfWork;
// 	private final Set<UnitOfWork> persisted;
// 
// 	public AggregateRootHistory() {
// 		this.unitsOfWork = new LinkedList<>();
// 		this.persisted = new LinkedHashSet<>();
// 	}
// 
// 	public List<Event> getAllEvents() {
//        return getEventsAfterUntil(0, Long.MAX_VALUE);
// 	}
// 
// 	public List<Event> getEventsAfterUntil(long afterVersion, long untilVersion){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() > afterVersion && t.getVersion() <= untilVersion){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public List<Event> getEventsUntil(long version){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() <= version){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public Long getLastVersion() {
// 		return unitsOfWork.size()==0 ? 0 : unitsOfWork.get(unitsOfWork.size()-1).getVersion();
// 	}
// 
// 	public void add(final UnitOfWork transaction) {
// 		checkNotNull(transaction);
// 		unitsOfWork.add(transaction);
// 	}
// 
// 	public UnitOfWork getLastUnitOfWork() {
// 		return unitsOfWork.get(unitsOfWork.size()-1);
// 	}
// 
//     public List<UnitOfWork> getPendingOfPersistence() {
//         return Lists.newLinkedList(Sets.difference(Sets.newLinkedHashSet(unitsOfWork), persisted));
//     }
// 
//     public void markAsPersisted(UnitOfWork uow) {
//         checkArgument(unitsOfWork.contains(uow), "unitOfWork must be part of this AggregateRootHistory in order to be marked as persisted");
//         persisted.add(uow);
//     }
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/Snapshot.java
// @SuppressWarnings("serial")
// @Value
// public class Snapshot<A extends AggregateRoot> implements Serializable {
// 	
// 	private A aggregateInstance;
// 	private Long version;
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/storage/SnapshotReader.java
// public interface SnapshotReader<K, A extends AggregateRoot> {
// 	
// 	public Snapshot<A> get(final K id) ;
// 
// }
// 
// Path: myeslib-util/src/main/java/org/myeslib/util/jdbi/AggregateRootHistoryReaderDao.java
// public interface AggregateRootHistoryReaderDao<K> {
// 
// 	AggregateRootHistory get(K id);
// 	
// }


import static com.google.common.base.Preconditions.checkNotNull;
import static org.myeslib.util.EventSourcingMagicHelper.applyEventsOn;
import java.util.List;
import java.util.Map;
import org.myeslib.core.AggregateRoot;
import org.myeslib.core.Event;
import org.myeslib.core.data.AggregateRootHistory;
import org.myeslib.core.data.Snapshot;
import org.myeslib.core.storage.SnapshotReader;
import org.myeslib.util.jdbi.AggregateRootHistoryReaderDao;
import com.google.common.base.Function;
import com.google.inject.Inject;
package org.myeslib.jdbi.storage;





public class JdbiSnapshotReader<K, A extends AggregateRoot> implements SnapshotReader<K, A> {
    
	@Inject
	public JdbiSnapshotReader(
			Map<K, Snapshot<A>> lastSnapshotMap,
// Path: myeslib-util/src/main/java/org/myeslib/util/EventSourcingMagicHelper.java
// @SneakyThrows
// static public void applyEventsOn(List<? extends Event> events, AggregateRoot instance)  {
//    MultiMethod mm = MultiMethod.getMultiMethod(instance.getClass(), "on");
//    for (Event event : events) {
// 	  mm.invoke(instance, event);
//    }
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/AggregateRoot.java
// public interface AggregateRoot extends Serializable {
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/Event.java
// public interface Event extends Serializable {
// 	
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/AggregateRootHistory.java
// @SuppressWarnings("serial")
// @Data
// public class AggregateRootHistory implements Serializable {
// 
// 	private final List<UnitOfWork> unitsOfWork;
// 	private final Set<UnitOfWork> persisted;
// 
// 	public AggregateRootHistory() {
// 		this.unitsOfWork = new LinkedList<>();
// 		this.persisted = new LinkedHashSet<>();
// 	}
// 
// 	public List<Event> getAllEvents() {
//        return getEventsAfterUntil(0, Long.MAX_VALUE);
// 	}
// 
// 	public List<Event> getEventsAfterUntil(long afterVersion, long untilVersion){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() > afterVersion && t.getVersion() <= untilVersion){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public List<Event> getEventsUntil(long version){
// 		List<Event> events = new LinkedList<>();
// 		for (UnitOfWork t : unitsOfWork) {
// 			if (t.getVersion() <= version){
// 				for (Event event : t.getEvents()) {
// 					events.add(event);
// 				}
// 			}
// 		}
// 		return events;
// 	}
// 	
// 	public Long getLastVersion() {
// 		return unitsOfWork.size()==0 ? 0 : unitsOfWork.get(unitsOfWork.size()-1).getVersion();
// 	}
// 
// 	public void add(final UnitOfWork transaction) {
// 		checkNotNull(transaction);
// 		unitsOfWork.add(transaction);
// 	}
// 
// 	public UnitOfWork getLastUnitOfWork() {
// 		return unitsOfWork.get(unitsOfWork.size()-1);
// 	}
// 
//     public List<UnitOfWork> getPendingOfPersistence() {
//         return Lists.newLinkedList(Sets.difference(Sets.newLinkedHashSet(unitsOfWork), persisted));
//     }
// 
//     public void markAsPersisted(UnitOfWork uow) {
//         checkArgument(unitsOfWork.contains(uow), "unitOfWork must be part of this AggregateRootHistory in order to be marked as persisted");
//         persisted.add(uow);
//     }
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/data/Snapshot.java
// @SuppressWarnings("serial")
// @Value
// public class Snapshot<A extends AggregateRoot> implements Serializable {
// 	
// 	private A aggregateInstance;
// 	private Long version;
// 
// }
// 
// Path: myeslib-core/src/main/java/org/myeslib/core/storage/SnapshotReader.java
// public interface SnapshotReader<K, A extends AggregateRoot> {
// 	
// 	public Snapshot<A> get(final K id) ;
// 
// }
// 
// Path: myeslib-util/src/main/java/org/myeslib/util/jdbi/AggregateRootHistoryReaderDao.java
// public interface AggregateRootHistoryReaderDao<K> {
// 
// 	AggregateRootHistory get(K id);
// 	
// }


// Path: myeslib-jdbi/src/main/java/org/myeslib/jdbi/storage/JdbiSnapshotReader.java
import static com.google.common.base.Preconditions.checkNotNull;
import static org.myeslib.util.EventSourcingMagicHelper.applyEventsOn;
import java.util.List;
import java.util.Map;
import org.myeslib.core.AggregateRoot;
import org.myeslib.core.Event;
import org.myeslib.core.data.AggregateRootHistory;
import org.myeslib.core.data.Snapshot;
import org.myeslib.core.storage.SnapshotReader;
import org.myeslib.util.jdbi.AggregateRootHistoryReaderDao;
import com.google.common.base.Function;
import com.google.inject.Inject;

package org.myeslib.jdbi.storage;





public class JdbiSnapshotReader<K, A extends AggregateRoot> implements SnapshotReader<K, A> {
    
	@Inject
	public JdbiSnapshotReader(
			Map<K, Snapshot<A>> lastSnapshotMap,
			AggregateRootHistoryReaderDao<K> arReader,