This commit is contained in:
Greg Burd 2017-11-07 23:01:43 -05:00
parent eb22e3c72e
commit a198989a76
7 changed files with 39 additions and 25 deletions

View file

@ -51,20 +51,27 @@ public class CacheUtil {
})
.collect(Collectors.toList()));
// TODO(gburd): rework so as to not generate the combinations at all rather than filter
facets = facets.stream()
.filter(f -> !f.fixed())
.filter(f -> !f.alone() || !f.combined())
.collect(Collectors.toList());
for (Facet facet : facets) {
if (facet.fixed()) continue;
if (facet.alone() && facet.combined() && true) continue;
combinations = combinations
.stream()
.filter(combo -> {
for (String c : combo) {
// When used alone, this facet is not distinct so don't use it as a key.
if (facet.alone() == false && c.equals(facet.name())) {
// When used alone, this facet is not distinct so don't use it as a key.
if (combo.length == 1) {
if (!facet.alone() && combo[0].startsWith(facet.name() + "==")) {
return false;
}
// Don't use this facet in combination with others to create keys.
if (facet.combined() == false && c.split("==")[0].equals(facet.name())) {
return false;
} else {
if (!facet.combined()) {
for (String c : combo) {
// Don't use this facet in combination with others to create keys.
if (c.startsWith(facet.name() + "==")) {
return false;
}
}
}
}
return true;

View file

@ -91,7 +91,7 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
queryExecutionTimeout,
queryTimeoutUnits,
showValues,
false);
isSessionCacheable());
// Transform the query result set into the desired shape.
result = transform(resultSet);

View file

@ -92,7 +92,7 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
queryExecutionTimeout,
queryTimeoutUnits,
showValues,
false);
isSessionCacheable());
// Transform the query result set into the desired shape.
resultStream = transform(resultSet);

View file

@ -57,7 +57,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
protected String alternateTableName = null;
protected boolean isCacheable = false;
protected boolean implmentsEntityType = false;
protected boolean implementsEntityType = false;
@SuppressWarnings("unchecked")
public SelectOperation(AbstractSessionOperations sessionOperations) {
@ -94,7 +94,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
.forEach(p -> this.props.add(p));
this.isCacheable = entity.isCacheable();
this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class);
this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class);
}
public SelectOperation(
@ -112,7 +112,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
.forEach(p -> this.props.add(p));
this.isCacheable = entity.isCacheable();
this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class);
this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class);
}
public SelectOperation(AbstractSessionOperations sessionOperations, Function<Row, E> rowMapper,
@ -125,7 +125,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
HelenusEntity entity = props[0].getEntity();
this.isCacheable = entity.isCacheable();
this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class);
this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class);
}
public CountOperation count() {
@ -272,19 +272,17 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
+ prop.getEntity().getMappingInterface());
}
if (cached && implmentsEntityType) {
if (cached && implementsEntityType) {
switch (prop.getProperty().getColumnType()) {
case PARTITION_KEY:
case CLUSTERING_COLUMN:
break;
default:
if (entity.equals(prop.getEntity())) {
if (prop.getNext().isPresent()) {
columnName = Iterables.getLast(prop).getColumnName().toCql(true);
if (!prop.getProperty().getDataType().isCollectionType()) {
selection.writeTime(columnName).as(CacheUtil.writeTimeKey(columnName));
selection.ttl(columnName).as(CacheUtil.ttlKey(columnName));
}
if (!prop.getProperty().getDataType().isCollectionType()) {
columnName = prop.getProperty().getColumnName().toCql(false);
selection.ttl(columnName).as('"' + CacheUtil.ttlKey(columnName) + '"');
selection.writeTime(columnName).as('"' + CacheUtil.writeTimeKey(columnName) + '"');
}
}
break;

View file

@ -117,8 +117,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
if (iface.getDeclaredAnnotation(MaterializedView.class) == null) {
facetsBuilder.add(new Facet("table", name.toCql()).setFixed());
} else {
facetsBuilder.add(
new Facet("table", Helenus.entity(iface.getInterfaces()[0]).getName().toCql())
facetsBuilder.add(new Facet("table", Helenus.entity(iface.getInterfaces()[0]).getName().toCql())
.setFixed());
}
for (HelenusProperty prop : orderedProps) {
@ -150,7 +149,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
}
facet = new UnboundFacet(props, validator.alone(), validator.combined());
} else {
facet = new UnboundFacet(prop);
facet = new UnboundFacet(prop, validator.alone(), validator.combined());
}
facetsBuilder.add(facet);
break;

View file

@ -314,6 +314,15 @@ public final class MappingUtil {
}
}
public static boolean extendsInterface(Class<?> clazz, Class<?> iface) {
Class<?>[] interfaces = clazz.getInterfaces();
for (Class<?> i : interfaces) {
if (i == iface)
return true;
}
return false;
}
private static void rethrow(Throwable cause) throws CloneNotSupportedException {
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;

View file

@ -381,8 +381,9 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
uow.commit();
committedAt = uow.committedAt();
}
// 'c' is distinct, but not on it's own so this should miss cache
w4 = session.<Widget>select(Widget.class)
.where(widget::id, eq(key))
.where(widget::c, eq(w3.c()))
.single()
.sync()
.orElse(null);