Cleanup.
This commit is contained in:
parent
eb22e3c72e
commit
a198989a76
7 changed files with 39 additions and 25 deletions
|
@ -51,20 +51,27 @@ public class CacheUtil {
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
// TODO(gburd): rework so as to not generate the combinations at all rather than filter
|
// 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) {
|
for (Facet facet : facets) {
|
||||||
if (facet.fixed()) continue;
|
|
||||||
if (facet.alone() && facet.combined() && true) continue;
|
|
||||||
combinations = combinations
|
combinations = combinations
|
||||||
.stream()
|
.stream()
|
||||||
.filter(combo -> {
|
.filter(combo -> {
|
||||||
for (String c : combo) {
|
// When used alone, this facet is not distinct so don't use it as a key.
|
||||||
// When used alone, this facet is not distinct so don't use it as a key.
|
if (combo.length == 1) {
|
||||||
if (facet.alone() == false && c.equals(facet.name())) {
|
if (!facet.alone() && combo[0].startsWith(facet.name() + "==")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Don't use this facet in combination with others to create keys.
|
} else {
|
||||||
if (facet.combined() == false && c.split("==")[0].equals(facet.name())) {
|
if (!facet.combined()) {
|
||||||
return false;
|
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;
|
return true;
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
||||||
queryExecutionTimeout,
|
queryExecutionTimeout,
|
||||||
queryTimeoutUnits,
|
queryTimeoutUnits,
|
||||||
showValues,
|
showValues,
|
||||||
false);
|
isSessionCacheable());
|
||||||
|
|
||||||
// Transform the query result set into the desired shape.
|
// Transform the query result set into the desired shape.
|
||||||
result = transform(resultSet);
|
result = transform(resultSet);
|
||||||
|
|
|
@ -92,7 +92,7 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
||||||
queryExecutionTimeout,
|
queryExecutionTimeout,
|
||||||
queryTimeoutUnits,
|
queryTimeoutUnits,
|
||||||
showValues,
|
showValues,
|
||||||
false);
|
isSessionCacheable());
|
||||||
|
|
||||||
// Transform the query result set into the desired shape.
|
// Transform the query result set into the desired shape.
|
||||||
resultStream = transform(resultSet);
|
resultStream = transform(resultSet);
|
||||||
|
|
|
@ -57,7 +57,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
||||||
|
|
||||||
protected String alternateTableName = null;
|
protected String alternateTableName = null;
|
||||||
protected boolean isCacheable = false;
|
protected boolean isCacheable = false;
|
||||||
protected boolean implmentsEntityType = false;
|
protected boolean implementsEntityType = false;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SelectOperation(AbstractSessionOperations sessionOperations) {
|
public SelectOperation(AbstractSessionOperations sessionOperations) {
|
||||||
|
@ -94,7 +94,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
||||||
.forEach(p -> this.props.add(p));
|
.forEach(p -> this.props.add(p));
|
||||||
|
|
||||||
this.isCacheable = entity.isCacheable();
|
this.isCacheable = entity.isCacheable();
|
||||||
this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class);
|
this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectOperation(
|
public SelectOperation(
|
||||||
|
@ -112,7 +112,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
||||||
.forEach(p -> this.props.add(p));
|
.forEach(p -> this.props.add(p));
|
||||||
|
|
||||||
this.isCacheable = entity.isCacheable();
|
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,
|
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();
|
HelenusEntity entity = props[0].getEntity();
|
||||||
this.isCacheable = entity.isCacheable();
|
this.isCacheable = entity.isCacheable();
|
||||||
this.implmentsEntityType = entity.getMappingInterface().getClass().isAssignableFrom(Entity.class);
|
this.implementsEntityType = MappingUtil.extendsInterface(entity.getMappingInterface(), Entity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CountOperation count() {
|
public CountOperation count() {
|
||||||
|
@ -272,19 +272,17 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
||||||
+ prop.getEntity().getMappingInterface());
|
+ prop.getEntity().getMappingInterface());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cached && implmentsEntityType) {
|
if (cached && implementsEntityType) {
|
||||||
switch (prop.getProperty().getColumnType()) {
|
switch (prop.getProperty().getColumnType()) {
|
||||||
case PARTITION_KEY:
|
case PARTITION_KEY:
|
||||||
case CLUSTERING_COLUMN:
|
case CLUSTERING_COLUMN:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (entity.equals(prop.getEntity())) {
|
if (entity.equals(prop.getEntity())) {
|
||||||
if (prop.getNext().isPresent()) {
|
if (!prop.getProperty().getDataType().isCollectionType()) {
|
||||||
columnName = Iterables.getLast(prop).getColumnName().toCql(true);
|
columnName = prop.getProperty().getColumnName().toCql(false);
|
||||||
if (!prop.getProperty().getDataType().isCollectionType()) {
|
selection.ttl(columnName).as('"' + CacheUtil.ttlKey(columnName) + '"');
|
||||||
selection.writeTime(columnName).as(CacheUtil.writeTimeKey(columnName));
|
selection.writeTime(columnName).as('"' + CacheUtil.writeTimeKey(columnName) + '"');
|
||||||
selection.ttl(columnName).as(CacheUtil.ttlKey(columnName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -117,8 +117,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
||||||
if (iface.getDeclaredAnnotation(MaterializedView.class) == null) {
|
if (iface.getDeclaredAnnotation(MaterializedView.class) == null) {
|
||||||
facetsBuilder.add(new Facet("table", name.toCql()).setFixed());
|
facetsBuilder.add(new Facet("table", name.toCql()).setFixed());
|
||||||
} else {
|
} else {
|
||||||
facetsBuilder.add(
|
facetsBuilder.add(new Facet("table", Helenus.entity(iface.getInterfaces()[0]).getName().toCql())
|
||||||
new Facet("table", Helenus.entity(iface.getInterfaces()[0]).getName().toCql())
|
|
||||||
.setFixed());
|
.setFixed());
|
||||||
}
|
}
|
||||||
for (HelenusProperty prop : orderedProps) {
|
for (HelenusProperty prop : orderedProps) {
|
||||||
|
@ -150,7 +149,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
||||||
}
|
}
|
||||||
facet = new UnboundFacet(props, validator.alone(), validator.combined());
|
facet = new UnboundFacet(props, validator.alone(), validator.combined());
|
||||||
} else {
|
} else {
|
||||||
facet = new UnboundFacet(prop);
|
facet = new UnboundFacet(prop, validator.alone(), validator.combined());
|
||||||
}
|
}
|
||||||
facetsBuilder.add(facet);
|
facetsBuilder.add(facet);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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 {
|
private static void rethrow(Throwable cause) throws CloneNotSupportedException {
|
||||||
if (cause instanceof RuntimeException) {
|
if (cause instanceof RuntimeException) {
|
||||||
throw (RuntimeException) cause;
|
throw (RuntimeException) cause;
|
||||||
|
|
|
@ -381,8 +381,9 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
||||||
uow.commit();
|
uow.commit();
|
||||||
committedAt = uow.committedAt();
|
committedAt = uow.committedAt();
|
||||||
}
|
}
|
||||||
|
// 'c' is distinct, but not on it's own so this should miss cache
|
||||||
w4 = session.<Widget>select(Widget.class)
|
w4 = session.<Widget>select(Widget.class)
|
||||||
.where(widget::id, eq(key))
|
.where(widget::c, eq(w3.c()))
|
||||||
.single()
|
.single()
|
||||||
.sync()
|
.sync()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
Loading…
Reference in a new issue