Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Marvel example #31

Merged
merged 8 commits into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ target
.DS_Store
Thumbs.db
*.swp
*.bak
*.bak
marvel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected final <R extends PaginatedCacheDataSource<K, V>> void addPaginatedCach
*
* @param page Page to be retrieved
*/
public PaginatedCollection<V> getPage(Page page) {
public PaginatedCollection<V> getPage(Page page) throws Exception {
return getPage(page, ReadPolicy.READ_ALL);
}

Expand All @@ -62,7 +62,7 @@ public PaginatedCollection<V> getPage(Page page) {
* @param page Page to be retrieved
* @param policy Specifies how the value is going to be retrieved.
*/
public PaginatedCollection<V> getPage(Page page, ReadPolicy policy) {
public PaginatedCollection<V> getPage(Page page, ReadPolicy policy) throws Exception {
PaginatedCollection<V> values = null;

if (policy.useCache()) {
Expand All @@ -80,7 +80,7 @@ public PaginatedCollection<V> getPage(Page page, ReadPolicy policy) {
return values;
}

protected PaginatedCollection<V> getPaginatedValuesFromCaches(Page page) {
protected PaginatedCollection<V> getPaginatedValuesFromCaches(Page page) throws Exception {
PaginatedCollection<V> values = null;

for (PaginatedCacheDataSource<K, V> cacheDataSource : paginatedCacheDataSources) {
Expand All @@ -99,7 +99,7 @@ protected PaginatedCollection<V> getPaginatedValuesFromCaches(Page page) {
return values;
}

protected PaginatedCollection<V> getPaginatedValuesFromReadables(Page page) {
protected PaginatedCollection<V> getPaginatedValuesFromReadables(Page page) throws Exception {
PaginatedCollection<V> values = null;

for (PaginatedReadableDataSource<V> readable : paginatedReadableDataSources) {
Expand All @@ -113,7 +113,8 @@ protected PaginatedCollection<V> getPaginatedValuesFromReadables(Page page) {
return values;
}

protected void populatePaginatedCaches(Page page, PaginatedCollection<V> values) {
protected void populatePaginatedCaches(Page page, PaginatedCollection<V> values)
throws Exception {
for (PaginatedCacheDataSource<K, V> cacheDataSource : paginatedCacheDataSources) {
cacheDataSource.addOrUpdatePage(page, values.getItems(), values.hasMore());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class RosieRepository<K, V extends Identifiable<K>>
/**
* {@link ReadableDataSource#getByKey(Object)}
*/
@Override public V getByKey(K key) {
@Override public V getByKey(K key) throws Exception {
return getByKey(key, ReadPolicy.READ_ALL);
}

Expand All @@ -70,7 +70,7 @@ public class RosieRepository<K, V extends Identifiable<K>>
*
* @param policy Specifies how the value is going to be retrieved.
*/
public V getByKey(K key, ReadPolicy policy) {
public V getByKey(K key, ReadPolicy policy) throws Exception {
validateKey(key);

V value = null;
Expand All @@ -93,7 +93,7 @@ public V getByKey(K key, ReadPolicy policy) {
/**
* {@link ReadableDataSource#getAll()}
*/
@Override public Collection<V> getAll() {
@Override public Collection<V> getAll() throws Exception {
return getAll(ReadPolicy.READ_ALL);
}

Expand All @@ -102,7 +102,7 @@ public V getByKey(K key, ReadPolicy policy) {
*
* @param policy Specifies how the value is going to be retrieved.
*/
public Collection<V> getAll(ReadPolicy policy) {
public Collection<V> getAll(ReadPolicy policy) throws Exception {
Collection<V> values = null;

if (policy.useCache()) {
Expand All @@ -123,7 +123,7 @@ public Collection<V> getAll(ReadPolicy policy) {
/**
* {@link WriteableDataSource#addOrUpdate(Identifiable)}
*/
@Override public V addOrUpdate(V value) {
@Override public V addOrUpdate(V value) throws Exception {
return addOrUpdate(value, WritePolicy.WRITE_ALL);
}

Expand All @@ -132,7 +132,7 @@ public Collection<V> getAll(ReadPolicy policy) {
*
* @param policy Specifies how the value is going to be stored.
*/
public V addOrUpdate(V value, WritePolicy policy) {
public V addOrUpdate(V value, WritePolicy policy) throws Exception {
validateValue(value);

V updatedValue = null;
Expand All @@ -155,11 +155,11 @@ public V addOrUpdate(V value, WritePolicy policy) {
/**
* {@link WriteableDataSource#addOrUpdateAll(Collection)}
*/
@Override public Collection<V> addOrUpdateAll(Collection<V> values) {
@Override public Collection<V> addOrUpdateAll(Collection<V> values) throws Exception {
return addOrUpdateAll(values, WritePolicy.WRITE_ALL);
}

public Collection<V> addOrUpdateAll(Collection<V> values, WritePolicy policy) {
public Collection<V> addOrUpdateAll(Collection<V> values, WritePolicy policy) throws Exception {
validateValues(values);

Collection<V> updatedValues = null;
Expand All @@ -182,7 +182,7 @@ public Collection<V> addOrUpdateAll(Collection<V> values, WritePolicy policy) {
/**
* {@link WriteableDataSource#deleteByKey(Object)}
*/
@Override public void deleteByKey(K key) {
@Override public void deleteByKey(K key) throws Exception {
for (WriteableDataSource<K, V> writeableDataSource : writeableDataSources) {
writeableDataSource.deleteByKey(key);
}
Expand All @@ -195,7 +195,7 @@ public Collection<V> addOrUpdateAll(Collection<V> values, WritePolicy policy) {
/**
* {@link WriteableDataSource#deleteAll()}
*/
@Override public void deleteAll() {
@Override public void deleteAll() throws Exception {
for (WriteableDataSource<K, V> writeableDataSource : writeableDataSources) {
writeableDataSource.deleteAll();
}
Expand All @@ -205,7 +205,7 @@ public Collection<V> addOrUpdateAll(Collection<V> values, WritePolicy policy) {
}
}

private V getValueFromCaches(K id) {
private V getValueFromCaches(K id) throws Exception {
V value = null;

for (CacheDataSource<K, V> cacheDataSource : cacheDataSources) {
Expand All @@ -224,7 +224,7 @@ private V getValueFromCaches(K id) {
return value;
}

private Collection<V> getValuesFromCaches() {
private Collection<V> getValuesFromCaches() throws Exception {
Collection<V> values = null;

for (CacheDataSource<K, V> cacheDataSource : cacheDataSources) {
Expand All @@ -243,7 +243,7 @@ private Collection<V> getValuesFromCaches() {
return values;
}

private V getValueFromReadables(K key) {
private V getValueFromReadables(K key) throws Exception {
V value = null;

for (ReadableDataSource<K, V> readableDataSource : readableDataSources) {
Expand All @@ -257,7 +257,7 @@ private V getValueFromReadables(K key) {
return value;
}

protected Collection<V> getValuesFromReadables() {
protected Collection<V> getValuesFromReadables() throws Exception {
Collection<V> values = null;

for (ReadableDataSource<K, V> readableDataSource : readableDataSources) {
Expand All @@ -271,13 +271,13 @@ protected Collection<V> getValuesFromReadables() {
return values;
}

private void populateCaches(V value) {
private void populateCaches(V value) throws Exception {
for (CacheDataSource<K, V> cacheDataSource : cacheDataSources) {
cacheDataSource.addOrUpdate(value);
}
}

protected void populateCaches(Collection<V> values) {
protected void populateCaches(Collection<V> values) throws Exception {
for (CacheDataSource<K, V> cacheDataSource : cacheDataSources) {
cacheDataSource.addOrUpdateAll(values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
*/
public class EmptyCacheDataSource<K, V extends Identifiable<K>> implements CacheDataSource<K, V> {

@Override public V getByKey(K key) {
@Override public V getByKey(K key) throws Exception {
return null;
}

@Override public Collection<V> getAll() {
@Override public Collection<V> getAll() throws Exception {
return null;
}

@Override public V addOrUpdate(V value) {
@Override public V addOrUpdate(V value) throws Exception {
return null;
}

@Override public Collection<V> addOrUpdateAll(Collection<V> values) {
@Override public Collection<V> addOrUpdateAll(Collection<V> values) throws Exception {
return null;
}

@Override public void deleteByKey(K key) {
@Override public void deleteByKey(K key) throws Exception {

}

@Override public void deleteAll() {
@Override public void deleteAll() throws Exception {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*/
public class EmptyReadableDataSource<K, V> implements ReadableDataSource<K, V> {

@Override public V getByKey(K key) {
@Override public V getByKey(K key) throws Exception {
return null;
}

@Override public Collection<V> getAll() {
@Override public Collection<V> getAll() throws Exception {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public interface ReadableDataSource<K, V> {
* @param key The key that uniquely identifies the requested value.
* @return The value associated to the provided key or null if there is not any.
*/
V getByKey(K key);
V getByKey(K key) throws Exception;

/**
* Returns all the values available in the data source or null if the operation does not make
* sense in the context of the data source.
*
* @return A collection of values or null if the operation is not implemented by this data source.
*/
Collection<V> getAll();
Collection<V> getAll() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ public interface WriteableDataSource<K, V extends Identifiable<K>> {
* @param value The value to be persisted.
* @return The value after its addition or update.
*/
V addOrUpdate(V value);
V addOrUpdate(V value) throws Exception;

/**
* Add or updates all the provided values into this data source.
*
* @param values A collection of values to be added or persisted.
* @return The values that has been persisted.
*/
Collection<V> addOrUpdateAll(Collection<V> values);
Collection<V> addOrUpdateAll(Collection<V> values) throws Exception;

/**
* Deletes a value given its associated key.
*
* @param key The key that uniquely identifies the value to be deleted.
*/
void deleteByKey(K key);
void deleteByKey(K key) throws Exception;

/**
* Delete all the values stored in this data source.
*/
void deleteAll();
void deleteAll() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public class EmptyPaginatedCacheDataSource<K, V extends Identifiable<K>>
return false;
}

@Override public PaginatedCollection<V> getPage(Page page) {
@Override public PaginatedCollection<V> getPage(Page page) throws Exception {
return null;
}

@Override
public PaginatedCollection<V> addOrUpdatePage(Page page, Collection<V> values, boolean hasMore) {
public PaginatedCollection<V> addOrUpdatePage(Page page, Collection<V> values, boolean hasMore) throws Exception {
return null;
}

@Override public void deleteAll() {
@Override public void deleteAll() throws Exception {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public interface PaginatedReadableDataSource<V> {
*
* @param page page to be retrieved
*/
PaginatedCollection<V> getPage(Page page);
PaginatedCollection<V> getPage(Page page) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public interface PaginatedWriteableDataSource<K, V extends Identifiable<K>> {
* @param values Collection of values to be stored
* @param hasMore True whether the persisted page has more elements
*/
PaginatedCollection<V> addOrUpdatePage(Page page, Collection<V> values, boolean hasMore);
PaginatedCollection<V> addOrUpdatePage(Page page, Collection<V> values, boolean hasMore)
throws Exception;

/**
* Deletes all the pages stored in this data source.
*/
void deleteAll();
void deleteAll() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ private PaginatedCollection<AnyRepositoryValue> givenCacheDataSourceReturnsNonVa
}

private PaginatedCollection<AnyRepositoryValue> givenCacheDataSourceReturnsValues(Page page,
boolean areValidValues) {
boolean areValidValues) throws Exception {
PaginatedCollection<AnyRepositoryValue> values = getSomeValues(page);
when(cacheDataSource.getPage(page)).thenReturn(values);
when(cacheDataSource.isValid(any(AnyRepositoryValue.class))).thenReturn(areValidValues);
return values;
}

private PaginatedCollection<AnyRepositoryValue> givenReadableDataSourceReturnsValues(Page page) {
private PaginatedCollection<AnyRepositoryValue> givenReadableDataSourceReturnsValues(Page page)
throws Exception {
PaginatedCollection<AnyRepositoryValue> values = getSomeValues(page);
when(readableDataSource.getPage(page)).thenReturn(values);
return values;
Expand Down
Loading