Fix a few things.
This commit is contained in:
parent
c025dc35a7
commit
39a8643103
6 changed files with 32 additions and 33 deletions
|
@ -245,18 +245,19 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
Either<Object, List<Facet>> deletedObjectFacets = Either.right(facets);
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
Optional<Object> optionalValue = cacheLookup(facets);
|
||||
|
||||
for (Facet facet : facets) {
|
||||
if (!facet.fixed()) {
|
||||
String columnKey = facet.name() + "==" + facet.value();
|
||||
// mark the value identified by the facet to `deleted`
|
||||
cache.put(tableName, columnKey, deletedObjectFacets);
|
||||
}
|
||||
}
|
||||
|
||||
// Now, look for other row/col pairs that referenced the same object, mark them
|
||||
// `deleted` if the cache had a value before we added the deleted marker objects.
|
||||
if (optionalValue.isPresent()) {
|
||||
Object value = optionalValue.get();
|
||||
|
||||
for (Facet facet : facets) {
|
||||
if (!facet.fixed()) {
|
||||
String columnKey = facet.name() + "==" + facet.value();
|
||||
// mark the value identified by the facet to `deleted`
|
||||
cache.put(tableName, columnKey, deletedObjectFacets);
|
||||
}
|
||||
}
|
||||
// look for other row/col pairs that referenced the same object, mark them
|
||||
// `deleted`
|
||||
cache
|
||||
.columnKeySet()
|
||||
.forEach(
|
||||
|
@ -326,13 +327,6 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
}
|
||||
}
|
||||
|
||||
// log.record(txn::provisionalCommit)
|
||||
// examine log for conflicts in read-set and write-set between begin and
|
||||
// provisional commit
|
||||
// if (conflict) { throw new ConflictingUnitOfWorkException(this) }
|
||||
// else return function so as to enable commit.andThen(() -> { do something iff
|
||||
// commit was successful; })
|
||||
|
||||
if (canCommit) {
|
||||
committed = true;
|
||||
aborted = false;
|
||||
|
|
|
@ -151,8 +151,8 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
if (isSessionCacheable()) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cachedResult = (E) sessionOps.checkCache(tableName, facets);
|
||||
Class<?> iface = MappingUtil.getMappingInterface(cachedResult);
|
||||
if (cachedResult != null) {
|
||||
Class<?> iface = MappingUtil.getMappingInterface(cachedResult);
|
||||
try {
|
||||
if (Drafted.class.isAssignableFrom(iface)) {
|
||||
result = Optional.of(cachedResult);
|
||||
|
|
|
@ -157,8 +157,8 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
if (isSessionCacheable()) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cachedResult = (E) sessionOps.checkCache(tableName, facets);
|
||||
Class<?> iface = MappingUtil.getMappingInterface(cachedResult);
|
||||
if (cachedResult != null) {
|
||||
Class<?> iface = MappingUtil.getMappingInterface(cachedResult);
|
||||
E result = null;
|
||||
try {
|
||||
if (Drafted.class.isAssignableFrom(iface)) {
|
||||
|
|
|
@ -38,7 +38,6 @@ import net.helenus.support.HelenusException;
|
|||
import net.helenus.support.HelenusMappingException;
|
||||
import net.helenus.support.Immutables;
|
||||
|
||||
|
||||
public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateOperation<E>> {
|
||||
|
||||
private final Map<Assignment, BoundFacet> assignments = new HashMap<>();
|
||||
|
@ -787,13 +786,14 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
@Override
|
||||
public E sync() throws TimeoutException {
|
||||
E result = super.sync();
|
||||
if (entity.isCacheable()) {
|
||||
if (result != null && entity.isCacheable()) {
|
||||
if (draft != null) {
|
||||
sessionOps.updateCache(draft, bindFacetValues());
|
||||
adjustTtlAndWriteTime(draft);
|
||||
adjustTtlAndWriteTime((MapExportable) result);
|
||||
sessionOps.updateCache(result, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
sessionOps.updateCache(pojo, bindFacetValues());
|
||||
adjustTtlAndWriteTime((MapExportable) pojo);
|
||||
sessionOps.updateCache(pojo, bindFacetValues());
|
||||
} else {
|
||||
sessionOps.cacheEvict(bindFacetValues());
|
||||
}
|
||||
|
@ -807,16 +807,18 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
return sync();
|
||||
}
|
||||
E result = super.sync(uow);
|
||||
if (draft != null) {
|
||||
adjustTtlAndWriteTime(draft);
|
||||
if (result != null) {
|
||||
if (draft != null) {
|
||||
adjustTtlAndWriteTime(draft);
|
||||
}
|
||||
if (entity != null && MapExportable.class.isAssignableFrom(entity.getMappingInterface())) {
|
||||
adjustTtlAndWriteTime((MapExportable) result);
|
||||
cacheUpdate(uow, result, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
adjustTtlAndWriteTime((MapExportable) pojo);
|
||||
cacheUpdate(uow, (E) pojo, bindFacetValues());
|
||||
return (E) pojo;
|
||||
}
|
||||
cacheUpdate(uow, result, bindFacetValues());
|
||||
} else if (pojo != null) {
|
||||
cacheUpdate(uow, (E) pojo, bindFacetValues());
|
||||
adjustTtlAndWriteTime((MapExportable) pojo);
|
||||
return (E) pojo;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,6 @@ public class EntityDraftBuilderTest extends AbstractEmbeddedCassandraTest {
|
|||
Supply s2 =
|
||||
session
|
||||
.<Supply>update(s1.update())
|
||||
.and(supply::region, eq(region))
|
||||
.prepend(supply::suppliers, "Pignose Supply, LLC.")
|
||||
.sync();
|
||||
|
||||
|
|
|
@ -264,8 +264,13 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
Assert.assertEquals(w1, w2);
|
||||
|
||||
// This should remove the object from the session cache.
|
||||
session.<Widget>update(w2).set(widget::name, "Bill").where(widget::id, eq(key)).sync(uow);
|
||||
w3 =
|
||||
session.<Widget>update(w2).set(widget::name, "Bill").where(widget::id, eq(key)).sync(uow);
|
||||
session
|
||||
.<Widget>update(w2)
|
||||
.set(widget::name, w1.name())
|
||||
.where(widget::id, eq(key))
|
||||
.sync(uow);
|
||||
|
||||
// Fetch from session cache will cache miss (as it was updated) and trigger a SELECT.
|
||||
w4 = session.<Widget>select(widget).where(widget::id, eq(key)).single().sync().orElse(null);
|
||||
|
@ -284,7 +289,6 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
|
||||
Assert.assertTrue(w5.equals(w2));
|
||||
Assert.assertTrue(w2.equals(w5));
|
||||
Assert.assertEquals(w5.name(), "Bill");
|
||||
|
||||
uow.commit()
|
||||
.andThen(
|
||||
|
|
Loading…
Reference in a new issue