Address some issues identified by FindBugs.
This commit is contained in:
parent
01a458a7f6
commit
09a7fbc405
9 changed files with 67 additions and 32 deletions
|
@ -4,7 +4,6 @@ import com.google.common.base.Optional;
|
|||
|
||||
public class DropMaterializedView extends Drop {
|
||||
|
||||
private final String itemType = "MATERIALIZED VIEW";
|
||||
private Optional<String> keyspaceName = Optional.absent();
|
||||
private String itemName;
|
||||
private boolean ifExists = true;
|
||||
|
@ -31,7 +30,7 @@ public class DropMaterializedView extends Drop {
|
|||
|
||||
@Override
|
||||
public String buildInternal() {
|
||||
StringBuilder dropStatement = new StringBuilder("DROP " + itemType + " ");
|
||||
StringBuilder dropStatement = new StringBuilder("DROP MATERIALIZED VIEW ");
|
||||
if (ifExists) {
|
||||
dropStatement.append("IF EXISTS ");
|
||||
}
|
||||
|
|
|
@ -150,8 +150,8 @@ public abstract class AbstractEntityDraft<E> implements Drafted<E> {
|
|||
Map<String, Object> combined;
|
||||
if (entityMap != null && entityMap.size() > 0) {
|
||||
combined = new HashMap<String, Object>(entityMap.size());
|
||||
for (String key : entityMap.keySet()) {
|
||||
combined.put(key, entityMap.get(key));
|
||||
for (Map.Entry<String, Object> e : entityMap.entrySet()) {
|
||||
combined.put(e.getKey(), e.getValue());
|
||||
}
|
||||
} else {
|
||||
combined = new HashMap<String, Object>(backingMap.size());
|
||||
|
|
|
@ -124,10 +124,10 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
|||
String database = "";
|
||||
if (databaseTime.size() > 0) {
|
||||
List<String> dbt = new ArrayList<>(databaseTime.size());
|
||||
for (String name : databaseTime.keySet()) {
|
||||
double t = databaseTime.get(name) / 1000.0;
|
||||
for (Map.Entry<String, Double> dt : databaseTime.entrySet()) {
|
||||
double t = dt.getValue() / 1000.0;
|
||||
d += t;
|
||||
dbt.add(String.format("%s took %,.3fms %,2.2f%%", name, t, (t / e) * 100.0));
|
||||
dbt.add(String.format("%s took %,.3fms %,2.2f%%", dt.getKey(), t, (t / e) * 100.0));
|
||||
}
|
||||
double fd = (d / e) * 100.0;
|
||||
database = String.format(", %d quer%s (%,.3fms %,2.2f%% - %s)", databaseLookups,
|
||||
|
@ -293,12 +293,13 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
|||
parent.cacheMisses += cacheMisses;
|
||||
parent.databaseLookups += databaseLookups;
|
||||
parent.cacheLookupTime += cacheLookupTime;
|
||||
for (String name : databaseTime.keySet()) {
|
||||
for (Map.Entry<String, Double> dt : databaseTime.entrySet()) {
|
||||
String name = dt.getKey();
|
||||
if (parent.databaseTime.containsKey(name)) {
|
||||
double t = parent.databaseTime.get(name);
|
||||
parent.databaseTime.put(name, t + databaseTime.get(name));
|
||||
parent.databaseTime.put(name, t + dt.getValue());
|
||||
} else {
|
||||
parent.databaseTime.put(name, databaseTime.get(name));
|
||||
parent.databaseTime.put(name, dt.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -335,8 +335,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
return uow.begin();
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new HelenusException(
|
||||
String.format("Unable to instantiate {} as a UnitOfWork.", unitOfWorkClass.getSimpleName()), e);
|
||||
throw new HelenusException(String.format("Unable to instantiate %s as a UnitOfWork.", unitOfWorkClass.getSimpleName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -698,6 +697,9 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
case UDT :
|
||||
execute(SchemaUtil.dropUserType(entity), true);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new HelenusException("Unknown entity type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,10 +167,6 @@ public final class SchemaUtil {
|
|||
throw new HelenusMappingException("expected view entity " + entity);
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
throw new HelenusMappingException("no entity or table to select data");
|
||||
}
|
||||
|
||||
List<HelenusPropertyNode> props = new ArrayList<HelenusPropertyNode>();
|
||||
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
.forEach(p -> props.add(p));
|
||||
|
|
|
@ -8,7 +8,7 @@ public class CacheUtil {
|
|||
|
||||
public static List<String[]> combinations(List<String> items) {
|
||||
int n = items.size();
|
||||
if (n > 20 || n < 0)
|
||||
if (n > 20)
|
||||
throw new IllegalArgumentException(n + " is out of range");
|
||||
long e = Math.round(Math.pow(2, n));
|
||||
List<String[]> out = new ArrayList<String[]>((int) e - 1);
|
||||
|
|
|
@ -44,13 +44,10 @@ public final class StatementColumnValuePreparer implements ColumnValuePreparer {
|
|||
|
||||
HelenusValidator.INSTANCE.validate(prop, value);
|
||||
|
||||
if (value != null) {
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(repository);
|
||||
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(repository);
|
||||
|
||||
if (converter.isPresent()) {
|
||||
value = converter.get().apply(value);
|
||||
}
|
||||
if (converter.isPresent()) {
|
||||
value = converter.get().apply(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
|
@ -111,13 +111,17 @@ public final class ValueProviderMap implements Map<String, Object> {
|
|||
|
||||
@Override
|
||||
public Set<java.util.Map.Entry<String, Object>> entrySet() {
|
||||
throwShouldNeverCall("entrySet()");
|
||||
return null;
|
||||
return entity.getOrderedProperties()
|
||||
.stream()
|
||||
.map(p -> {
|
||||
return new ValueProviderMap.Entry<String, Object>(p.getPropertyName(),
|
||||
valueProvider.getColumnValue(source, -1, p, immutable));
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private void throwShouldNeverCall(String methodName) {
|
||||
private static void throwShouldNeverCall(String methodName) {
|
||||
throw new HelenusMappingException(String.format(
|
||||
"the method {} should never be called on an instance of a Helenus ValueProviderMap", methodName));
|
||||
"the method %s should never be called on an instance of a Helenus ValueProviderMap", methodName));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,6 +129,15 @@ public final class ValueProviderMap implements Map<String, Object> {
|
|||
return source.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = source.hashCode();
|
||||
result = 31 * result + valueProvider.hashCode();
|
||||
result = 31 * result + entity.hashCode();
|
||||
result = 31 * result + (immutable ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
|
@ -135,10 +148,37 @@ public final class ValueProviderMap implements Map<String, Object> {
|
|||
Map that = (Map) o;
|
||||
if (this.size() != that.size())
|
||||
return false;
|
||||
for (String key : this.keySet())
|
||||
if (!this.get(key).equals(that.get(key)))
|
||||
for (Map.Entry<String, Object> e : this.entrySet())
|
||||
if (!e.getValue().equals(that.get(e.getKey())))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Entry<K, V> implements Map.Entry<K, V> {
|
||||
|
||||
private final K key;
|
||||
private final V value;
|
||||
|
||||
public Entry(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
throwShouldNeverCall("Entry.setValue()");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,9 +173,9 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.uncached()
|
||||
.sync().orElse(null);
|
||||
|
||||
Assert.assertNotEquals(w5, w2); // Not the same instance
|
||||
Assert.assertTrue(w2.equals(w5)); // But they have the same values
|
||||
Assert.assertFalse(w5.equals(w2)); // TODO(gburd): should also work
|
||||
Assert.assertNotEquals(w5, w2); // Not the same instance,
|
||||
Assert.assertTrue(w2.equals(w5)); // but they have the same values,
|
||||
Assert.assertFalse(w5.equals(w2)); // regardless of the order when comparing.
|
||||
Assert.assertEquals(w5.name(), "Bill");
|
||||
|
||||
uow.commit().andThen(() -> {
|
||||
|
|
Loading…
Reference in a new issue