Review related fixes.

This commit is contained in:
Greg Burd 2018-01-15 11:28:04 -05:00
parent 3554b7ecb5
commit 26c67e391a
5 changed files with 21 additions and 13 deletions

View file

@ -5,7 +5,7 @@ import com.datastax.driver.core.querybuilder.Select;
public class CreateMaterializedView extends Create { public class CreateMaterializedView extends Create {
private String viewName; private final String viewName;
private Select.Where selection; private Select.Where selection;
private String primaryKey; private String primaryKey;
private String clustering; private String clustering;

View file

@ -33,6 +33,6 @@ public abstract class AbstractAuditedEntityDraft<E> extends AbstractEntityDraft<
} }
public Date createdAt() { public Date createdAt() {
return (Date) get("createdAt", Date.class); return get("createdAt", Date.class);
} }
} }

View file

@ -1,8 +1,6 @@
package net.helenus.core; package net.helenus.core;
import com.google.common.primitives.Primitives; import com.google.common.primitives.Primitives;
import java.io.Serializable;
import java.util.*;
import net.helenus.core.reflect.DefaultPrimitiveTypes; import net.helenus.core.reflect.DefaultPrimitiveTypes;
import net.helenus.core.reflect.Drafted; import net.helenus.core.reflect.Drafted;
import net.helenus.core.reflect.MapExportable; import net.helenus.core.reflect.MapExportable;
@ -10,6 +8,14 @@ import net.helenus.mapping.HelenusProperty;
import net.helenus.mapping.MappingUtil; import net.helenus.mapping.MappingUtil;
import org.apache.commons.lang3.SerializationUtils; import org.apache.commons.lang3.SerializationUtils;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
public abstract class AbstractEntityDraft<E> implements Drafted<E> { public abstract class AbstractEntityDraft<E> implements Drafted<E> {
private final MapExportable entity; private final MapExportable entity;

View file

@ -56,7 +56,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
protected int databaseLookups = 0; protected int databaseLookups = 0;
protected Stopwatch elapsedTime; protected Stopwatch elapsedTime;
protected Map<String, Double> databaseTime = new HashMap<>(); protected Map<String, Double> databaseTime = new HashMap<>();
protected double cacheLookupTime = 0.0; protected double cacheLookupTimeMSecs = 0.0;
private List<CommitThunk> commitThunks = new ArrayList<CommitThunk>(); private List<CommitThunk> commitThunks = new ArrayList<CommitThunk>();
private List<CommitThunk> abortThunks = new ArrayList<CommitThunk>(); private List<CommitThunk> abortThunks = new ArrayList<CommitThunk>();
private List<CompletableFuture<?>> asyncOperationFutures = new ArrayList<CompletableFuture<?>>(); private List<CompletableFuture<?>> asyncOperationFutures = new ArrayList<CompletableFuture<?>>();
@ -84,7 +84,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
@Override @Override
public void addCacheLookupTime(Stopwatch amount) { public void addCacheLookupTime(Stopwatch amount) {
cacheLookupTime += amount.elapsed(TimeUnit.MICROSECONDS); cacheLookupTimeMSecs += amount.elapsed(TimeUnit.MICROSECONDS);
} }
@Override @Override
@ -137,7 +137,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
public String logTimers(String what) { public String logTimers(String what) {
double e = (double) elapsedTime.elapsed(TimeUnit.MICROSECONDS) / 1000.0; double e = (double) elapsedTime.elapsed(TimeUnit.MICROSECONDS) / 1000.0;
double d = 0.0; double d = 0.0;
double c = cacheLookupTime / 1000.0; double c = cacheLookupTimeMSecs / 1000.0;
double fc = (c / e) * 100.0; double fc = (c / e) * 100.0;
String database = ""; String database = "";
if (databaseTime.size() > 0) { if (databaseTime.size() > 0) {
@ -154,7 +154,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
databaseLookups, (databaseLookups > 1) ? "ies" : "y", d, fd, String.join(", ", dbt)); databaseLookups, (databaseLookups > 1) ? "ies" : "y", d, fd, String.join(", ", dbt));
} }
String cache = ""; String cache = "";
if (cacheLookupTime > 0) { if (cacheLookupTimeMSecs > 0) {
int cacheLookups = cacheHits + cacheMisses; int cacheLookups = cacheHits + cacheMisses;
cache = cache =
String.format( String.format(
@ -162,7 +162,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
cacheLookups, cacheLookups > 1 ? "s" : "", c, fc, cacheHits, cacheMisses); cacheLookups, cacheLookups > 1 ? "s" : "", c, fc, cacheHits, cacheMisses);
} }
String da = ""; String da = "";
if (databaseTime.size() > 0 || cacheLookupTime > 0) { if (databaseTime.size() > 0 || cacheLookupTimeMSecs > 0) {
double dat = d + c; double dat = d + c;
double daf = (dat / e) * 100; double daf = (dat / e) * 100;
da = da =
@ -386,7 +386,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
parent.cacheHits += cacheHits; parent.cacheHits += cacheHits;
parent.cacheMisses += cacheMisses; parent.cacheMisses += cacheMisses;
parent.databaseLookups += databaseLookups; parent.databaseLookups += databaseLookups;
parent.cacheLookupTime += cacheLookupTime; parent.cacheLookupTimeMSecs += cacheLookupTimeMSecs;
for (Map.Entry<String, Double> dt : databaseTime.entrySet()) { for (Map.Entry<String, Double> dt : databaseTime.entrySet()) {
String name = dt.getKey(); String name = dt.getKey();
if (parent.databaseTime.containsKey(name)) { if (parent.databaseTime.containsKey(name)) {
@ -398,6 +398,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
} }
} }
} }
// TODO(gburd): hopefully we'll be able to detect conflicts here and so we'd want to...
// else { // else {
// Constructor<T> ctor = clazz.getConstructor(conflictExceptionClass); // Constructor<T> ctor = clazz.getConstructor(conflictExceptionClass);
// T object = ctor.newInstance(new Object[] { String message }); // T object = ctor.newInstance(new Object[] { String message });
@ -435,6 +436,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
uow.abortThunks.clear(); uow.abortThunks.clear();
}); });
// TODO(gburd): when we integrate the transaction support we'll need to...
// log.record(txn::abort) // log.record(txn::abort)
// cache.invalidateSince(txn::start time) // cache.invalidateSince(txn::start time)
} }
@ -472,8 +474,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
@Override @Override
public void close() throws E { public void close() throws E {
// Closing a AbstractUnitOfWork will abort iff we've not already aborted or // Closing a AbstractUnitOfWork will abort iff we've not already aborted or committed this unit of work.
// committed this unit of work.
if (aborted == false && committed == false) { if (aborted == false && committed == false) {
abort(); abort();
} }

View file

@ -15,8 +15,9 @@
*/ */
package net.helenus.core; package net.helenus.core;
import com.datastax.driver.core.querybuilder.Clause;
import java.util.Objects; import java.util.Objects;
import com.datastax.driver.core.querybuilder.Clause;
import net.helenus.core.reflect.HelenusPropertyNode; import net.helenus.core.reflect.HelenusPropertyNode;
import net.helenus.mapping.MappingUtil; import net.helenus.mapping.MappingUtil;
import net.helenus.mapping.value.ColumnValuePreparer; import net.helenus.mapping.value.ColumnValuePreparer;