Skip to content

Commit

Permalink
Merge branch 'jdk8'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorndarri committed Sep 10, 2023
2 parents 53bfe56 + 553e9da commit c3ee99f
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 109 deletions.
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9573,4 +9573,7 @@
FilteredModel.AbstractRefresher.fireRefreshEvent() and fireRefreshFailedEvent() renamed refreshEvent() and refreshFailedEvent()
DatabaseConnection.selectInteger() and selectLong() removed, now only handles transaction control
AbstractQueriedKeyGenerator refactored
KeyGenerator.increment() implementation removed
KeyGenerator.increment() implementation removed
AllCondition now interface, moved to Condition, renamed All
ColumnDefinition.resultPacker() removed, related refactoring
ColumnDefinition.toColumnValue() replaced with valueConverter()
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -192,7 +191,7 @@ public boolean equals(Object object) {

@Override
public int hashCode() {
int result = Objects.hash(methodName);
int result = methodName.hashCode();
result = 31 * result + Arrays.hashCode(parameterTypes);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ final class DefaultColumnConditionModel<C, T> implements ColumnConditionModel<C,
private final Value<T> equalValue = equalValues.value();
private final Value<T> upperBoundValue = Value.value();
private final Value<T> lowerBoundValue = Value.value();
private final Value<Operator> operatorValue = Value.value(Operator.EQUAL, Operator.EQUAL);
private final Value<Operator> operator = Value.value(Operator.EQUAL, Operator.EQUAL);
private final Event<?> conditionChangedEvent = Event.event();

private final State caseSensitiveState;
private final Value<AutomaticWildcard> automaticWildcardValue;
private final State caseSensitive;
private final Value<AutomaticWildcard> automaticWildcard;
private final char wildcard;

private final State autoEnableState;
private final State enabledState = State.state();
private final State lockedState = State.state();
private final State autoEnable;
private final State enabled = State.state();
private final State locked = State.state();

private final C columnIdentifier;
private final Class<T> columnClass;
Expand All @@ -53,15 +53,15 @@ private DefaultColumnConditionModel(DefaultBuilder<C, T> builder) {
this.wildcard = builder.wildcard;
this.format = builder.format;
this.dateTimePattern = builder.dateTimePattern;
this.automaticWildcardValue = Value.value(builder.automaticWildcard, AutomaticWildcard.NONE);
this.caseSensitiveState = State.state(builder.caseSensitive);
this.autoEnableState = State.state(builder.autoEnable);
this.enabledState.addValidator(value -> checkLock());
this.automaticWildcard = Value.value(builder.automaticWildcard, AutomaticWildcard.NONE);
this.caseSensitive = State.state(builder.caseSensitive);
this.autoEnable = State.state(builder.autoEnable);
this.enabled.addValidator(value -> checkLock());
this.equalValues.addValidator(value -> checkLock());
this.upperBoundValue.addValidator(value -> checkLock());
this.lowerBoundValue.addValidator(value -> checkLock());
this.operatorValue.addValidator(this::validateOperator);
this.operatorValue.addValidator(value -> checkLock());
this.operator.addValidator(this::validateOperator);
this.operator.addValidator(value -> checkLock());
bindEvents();
}

Expand All @@ -72,7 +72,7 @@ public C columnIdentifier() {

@Override
public State caseSensitive() {
return caseSensitiveState;
return caseSensitive;
}

@Override
Expand All @@ -87,7 +87,7 @@ public String dateTimePattern() {

@Override
public State locked() {
return lockedState;
return locked;
}

@Override
Expand Down Expand Up @@ -139,7 +139,7 @@ public T getLowerBound() {

@Override
public Value<Operator> operator() {
return operatorValue;
return operator;
}

@Override
Expand All @@ -154,31 +154,31 @@ public char wildcard() {

@Override
public State enabled() {
return enabledState;
return enabled;
}

@Override
public Value<AutomaticWildcard> automaticWildcard() {
return automaticWildcardValue;
return automaticWildcard;
}

@Override
public State autoEnable() {
return autoEnableState;
return autoEnable;
}

@Override
public void clear() {
enabledState.set(false);
enabled.set(false);
setEqualValues(null);
setUpperBound(null);
setLowerBound(null);
operatorValue.set(Operator.EQUAL);
operator.set(Operator.EQUAL);
}

@Override
public boolean accepts(Comparable<T> columnValue) {
return !enabledState.get() || valueAccepted(columnValue);
return !enabled.get() || valueAccepted(columnValue);
}

@Override
Expand Down Expand Up @@ -207,7 +207,7 @@ public void removeChangeListener(Runnable listener) {
}

private boolean valueAccepted(Comparable<T> comparable) {
switch (operatorValue.get()) {
switch (operator.get()) {
case EQUAL:
return isEqual(comparable);
case NOT_EQUAL:
Expand All @@ -229,7 +229,7 @@ private boolean valueAccepted(Comparable<T> comparable) {
case NOT_BETWEEN:
return isNotBetween(comparable);
default:
throw new IllegalArgumentException("Undefined operator: " + operatorValue.get());
throw new IllegalArgumentException("Undefined operator: " + operator.get());
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ private boolean isEqualWildcard(String value) {
}

String valueToTest = value;
if (!caseSensitiveState.get()) {
if (!caseSensitive.get()) {
equalValue = equalValue.toUpperCase();
valueToTest = valueToTest.toUpperCase();
}
Expand Down Expand Up @@ -420,7 +420,7 @@ private T addAutomaticWildcard(T bound) {
if (!(bound instanceof String)) {
return bound;
}
switch (operatorValue.get()) {
switch (operator.get()) {
//wildcard only used for EQUAL and NOT_EQUAL
case EQUAL:
case NOT_EQUAL:
Expand All @@ -431,7 +431,7 @@ private T addAutomaticWildcard(T bound) {
}

private String addAutomaticWildcard(String value) {
switch (automaticWildcardValue.get()) {
switch (automaticWildcard.get()) {
case PREFIX_AND_POSTFIX:
return wildcard + value + wildcard;
case PREFIX:
Expand All @@ -448,19 +448,19 @@ private void bindEvents() {
equalValues.addListener(autoEnableListener);
upperBoundValue.addListener(autoEnableListener);
lowerBoundValue.addListener(autoEnableListener);
operatorValue.addListener(autoEnableListener);
autoEnableState.addListener(autoEnableListener);
operator.addListener(autoEnableListener);
autoEnable.addListener(autoEnableListener);
equalValues.addListener(conditionChangedEvent);
upperBoundValue.addListener(conditionChangedEvent);
lowerBoundValue.addListener(conditionChangedEvent);
operatorValue.addListener(conditionChangedEvent);
enabledState.addListener(conditionChangedEvent);
caseSensitiveState.addListener(conditionChangedEvent);
automaticWildcardValue.addListener(conditionChangedEvent);
operator.addListener(conditionChangedEvent);
enabled.addListener(conditionChangedEvent);
caseSensitive.addListener(conditionChangedEvent);
automaticWildcard.addListener(conditionChangedEvent);
}

private void checkLock() {
if (lockedState.get()) {
if (locked.get()) {
throw new IllegalStateException("Condition model for column identified by " + columnIdentifier + " is locked");
}
}
Expand All @@ -475,28 +475,28 @@ private final class AutoEnableListener implements Runnable {

@Override
public void run() {
if (autoEnableState.get()) {
switch (operatorValue.get()) {
if (autoEnable.get()) {
switch (operator.get()) {
case EQUAL:
case NOT_EQUAL:
enabledState.set(equalValues.isNotEmpty());
enabled.set(equalValues.isNotEmpty());
break;
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
enabledState.set(upperBoundValue.isNotNull());
enabled.set(upperBoundValue.isNotNull());
break;
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
enabledState.set(lowerBoundValue.isNotNull());
enabled.set(lowerBoundValue.isNotNull());
break;
case BETWEEN:
case BETWEEN_EXCLUSIVE:
case NOT_BETWEEN:
case NOT_BETWEEN_EXCLUSIVE:
enabledState.set(lowerBoundValue.isNotNull() && upperBoundValue.isNotNull());
enabled.set(lowerBoundValue.isNotNull() && upperBoundValue.isNotNull());
break;
default:
throw new IllegalStateException("Unknown operator: " + operatorValue.get());
throw new IllegalStateException("Unknown operator: " + operator.get());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@
*/
final class DefaultColumnSummaryModel<T extends Number> implements ColumnSummaryModel {

private final Value<Summary> summaryValue = Value.value(ColumnSummary.NONE, ColumnSummary.NONE);
private final Value<String> summaryTextValue = Value.value();
private final State lockedState = State.state();
private final Value<Summary> summary = Value.value(ColumnSummary.NONE, ColumnSummary.NONE);
private final Value<String> summaryText = Value.value();
private final State locked = State.state();
private final SummaryValueProvider<T> valueProvider;
private final List<Summary> summaries = asList(ColumnSummary.values());

DefaultColumnSummaryModel(SummaryValueProvider<T> valueProvider) {
this.valueProvider = requireNonNull(valueProvider);
this.summaryValue.addValidator(summary -> {
if (lockedState.get()) {
this.summary.addValidator(summary -> {
if (locked.get()) {
throw new IllegalStateException("Summary model is locked");
}
});
this.valueProvider.addListener(this::updateSummary);
this.summaryValue.addListener(this::updateSummary);
this.summary.addListener(this::updateSummary);
}

@Override
public State locked() {
return lockedState;
return locked;
}

@Override
public Value<Summary> summary() {
return summaryValue;
return summary;
}

@Override
Expand All @@ -53,11 +53,11 @@ public List<Summary> summaries() {

@Override
public ValueObserver<String> summaryText() {
return summaryTextValue.observer();
return summaryText.observer();
}

private void updateSummary() {
summaryTextValue.set(summary().get().summary(valueProvider));
summaryText.set(summary().get().summary(valueProvider));
}

static final class DefaultSummaryValues<T extends Number> implements ColumnSummaryModel.SummaryValues<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public interface Condition {
*/
String toString(EntityDefinition definition);

/**
* A condition specifying all entities of a given type.
*/
interface All extends Condition {}

/**
* An interface encapsulating a combination of Condition instances,
* that should be either AND'ed or OR'ed together in a query context
Expand All @@ -91,7 +96,7 @@ interface Combination extends Condition {
* @return a Condition specifying all entities of the given type
*/
static Condition all(EntityType entityType) {
return new AllCondition(entityType);
return new DefaultAllCondition(entityType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;

public final class AllCondition extends AbstractCondition implements Serializable {
final class DefaultAllCondition extends AbstractCondition implements Condition.All, Serializable {

private static final long serialVersionUID = 1;

AllCondition(EntityType entityType) {
DefaultAllCondition(EntityType entityType) {
super(entityType, emptyList(), emptyList());
}

Expand All @@ -31,15 +31,15 @@ public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof AllCondition)) {
if (!(object instanceof All)) {
return false;
}
AllCondition that = (AllCondition) object;
All that = (All) object;
return Objects.equals(entityType(), that.entityType());
}

@Override
public int hashCode() {
return Objects.hash(entityType());
return entityType().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public <T> List<T> select(Column<T> column, Select select) throws DatabaseExcept
try {
statement = prepareStatement(selectQuery);
resultSet = executeStatement(statement, selectQuery, combinedCondition, entityDefinition);
List<T> result = columnDefinition.resultPacker().pack(resultSet);
List<T> result = resultPacker(columnDefinition).pack(resultSet);
commitIfTransactionIsNotOpen();

return result;
Expand Down Expand Up @@ -1348,6 +1348,10 @@ private static List<ColumnDefinition<?>> columnDefinitions(EntityDefinition enti
.collect(toList());
}

private static <T> ResultPacker<T> resultPacker(ColumnDefinition<T> columnDefinition) {
return resultSet -> columnDefinition.get(resultSet, 1);
}

private static void setParameterValues(PreparedStatement statement, List<ColumnDefinition<?>> statementColumns,
List<?> statementValues) throws SQLException {
if (statementValues.isEmpty()) {
Expand All @@ -1365,7 +1369,7 @@ private static void setParameterValues(PreparedStatement statement, List<ColumnD

private static void setParameterValue(PreparedStatement statement, ColumnDefinition<Object> columnDefinition,
Object value, int parameterIndex) throws SQLException {
Object columnValue = columnDefinition.toColumnValue(value, statement);
Object columnValue = columnDefinition.valueConverter().toColumnValue(value, statement);
try {
if (columnValue == null) {
statement.setNull(parameterIndex, columnDefinition.columnType());
Expand Down Expand Up @@ -1442,7 +1446,7 @@ private static String createValueString(List<?> values, List<ColumnDefinition<?>
Object columnValue;
String stringValue;
try {
columnValue = columnDefinition.toColumnValue(value, null);
columnValue = columnDefinition.valueConverter().toColumnValue(value, null);
stringValue = String.valueOf(value);
}
catch (SQLException e) {
Expand Down
Loading

0 comments on commit c3ee99f

Please sign in to comment.