Formatting.
This commit is contained in:
parent
a600c0bd23
commit
fe47531984
6 changed files with 61 additions and 9 deletions
|
@ -235,7 +235,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab
|
|||
}
|
||||
} else {
|
||||
value = valueMap.get(prop.getPropertyName());
|
||||
binder.setValueForProperty(prop, value.toString());
|
||||
if (value != null) binder.setValueForProperty(prop, value.toString());
|
||||
}
|
||||
}
|
||||
if (binder.isBound()) {
|
||||
|
|
|
@ -165,6 +165,14 @@ public final class SchemaUtil {
|
|||
}
|
||||
}
|
||||
|
||||
if (p.size() == 0 && c.size() == 0)
|
||||
return "{"
|
||||
+ properties
|
||||
.stream()
|
||||
.map(HelenusProperty::getPropertyName)
|
||||
.collect(Collectors.joining(", "))
|
||||
+ "}";
|
||||
|
||||
return "("
|
||||
+ ((p.size() > 1) ? "(" + String.join(", ", p) + ")" : p.get(0))
|
||||
+ ((c.size() > 0)
|
||||
|
|
|
@ -31,6 +31,7 @@ import net.helenus.mapping.annotation.*;
|
|||
import net.helenus.mapping.validator.DistinctValidator;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public final class HelenusMappingEntity implements HelenusEntity {
|
||||
|
||||
|
@ -128,7 +129,24 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
for (ConstraintValidator<?, ?> constraint :
|
||||
MappingUtil.getValidators(prop.getGetterMethod())) {
|
||||
if (constraint.getClass().isAssignableFrom(DistinctValidator.class)) {
|
||||
UnboundFacet facet = new UnboundFacet(prop);
|
||||
DistinctValidator validator = (DistinctValidator) constraint;
|
||||
String[] values = validator.value();
|
||||
UnboundFacet facet;
|
||||
if (values != null && values.length >= 1 && !(StringUtils.isBlank(values[0]))) {
|
||||
List<HelenusProperty> props = new ArrayList<HelenusProperty>(values.length + 1);
|
||||
props.add(prop);
|
||||
for (String value : values) {
|
||||
for (HelenusProperty p : orderedProps) {
|
||||
String name = p.getPropertyName();
|
||||
if (name.equals(value) && !name.equals(prop.getPropertyName())) {
|
||||
props.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
facet = new UnboundFacet(props);
|
||||
} else {
|
||||
facet = new UnboundFacet(prop);
|
||||
}
|
||||
facetsBuilder.add(facet);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -228,10 +228,11 @@ public final class Constraints {
|
|||
public @interface Distinct {
|
||||
|
||||
/**
|
||||
* User defined Enum to further restrict the items in the set.
|
||||
* User defined list of properties that combine with this one to result in a distinct
|
||||
* combination in the table.
|
||||
*
|
||||
* @return Java
|
||||
*/
|
||||
Class<? extends Enum> value() default Enum.class;
|
||||
String[] value() default "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,20 @@ import net.helenus.mapping.annotation.Constraints;
|
|||
public final class DistinctValidator
|
||||
implements ConstraintValidator<Constraints.Distinct, CharSequence> {
|
||||
|
||||
private Constraints.Distinct annotation;
|
||||
|
||||
@Override
|
||||
public void initialize(Constraints.Distinct constraintAnnotation) {}
|
||||
public void initialize(Constraints.Distinct constraintAnnotation) {
|
||||
annotation = constraintAnnotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
|
||||
// TODO(gburd): if there is an Enum type supplied, check that value is valid
|
||||
// Enum.name()
|
||||
// TODO(gburd): check that the list contains valid property names.
|
||||
return true;
|
||||
}
|
||||
|
||||
public String[] value() {
|
||||
return annotation == null ? null : annotation.value();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,13 @@ interface Widget {
|
|||
UUID id();
|
||||
|
||||
@Index
|
||||
@Constraints.Distinct()
|
||||
@Constraints.Distinct
|
||||
String name();
|
||||
|
||||
@Constraints.Distinct(value = {"b"})
|
||||
String a();
|
||||
|
||||
String b();
|
||||
}
|
||||
|
||||
public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
||||
|
@ -74,6 +79,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync();
|
||||
|
||||
try (UnitOfWork uow = session.begin()) {
|
||||
|
@ -118,6 +125,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key1)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync(uow1);
|
||||
|
||||
try (UnitOfWork uow2 = session.begin(uow1)) {
|
||||
|
@ -138,6 +147,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key2)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync(uow2);
|
||||
|
||||
uow2.commit()
|
||||
|
@ -151,7 +162,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
w4 =
|
||||
session
|
||||
.<Widget>select(widget)
|
||||
.where(widget::id, eq(key2))
|
||||
.where(widget::a, eq(w3.a()))
|
||||
.and(widget::b, eq(w3.b()))
|
||||
.single()
|
||||
.sync(uow1)
|
||||
.orElse(null);
|
||||
|
@ -175,6 +187,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync(uow);
|
||||
|
||||
// This should read from the database and return a Widget.
|
||||
|
@ -209,6 +223,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync();
|
||||
|
||||
try (UnitOfWork uow = session.begin()) {
|
||||
|
@ -271,6 +287,8 @@ public class UnitOfWorkTest extends AbstractEmbeddedCassandraTest {
|
|||
.<Widget>insert(widget)
|
||||
.value(widget::id, key)
|
||||
.value(widget::name, RandomString.make(20))
|
||||
.value(widget::a, RandomString.make(10))
|
||||
.value(widget::b, RandomString.make(10))
|
||||
.sync();
|
||||
|
||||
try (UnitOfWork uow = session.begin()) {
|
||||
|
|
Loading…
Reference in a new issue