Skip to content

Commit

Permalink
Merge branch 'jdk8'
Browse files Browse the repository at this point in the history
# Conflicts:
#	swing/framework-model-tools/src/main/java/is/codion/swing/framework/model/tools/metadata/SchemaPacker.java
  • Loading branch information
bjorndarri committed Jan 8, 2024
2 parents fb089c1 + 2c09880 commit 150d848
Show file tree
Hide file tree
Showing 46 changed files with 359 additions and 181 deletions.
18 changes: 17 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
Codion Change Log
==================

## 0.17.23-SNAPSHOT
## 0.17.23
### is.codion.common.core
- LocaleDateTimePattern.timePattern() now returns Optional.
### is.codion.common.db
- AbstractDatabase, transaction isolation now a final field, instead of using the configuration value directly.
- AbstractDatabase, login timeout now set in a static initializer block, instead of during connection creation.
- Database.connectionPool(username) now throws IllegalArgumentException in case no connection pool is available for the given username.
- ResultPacker.get() no longer allowed to return null.
### is.codion.common.model
- ColumnConditionModel.setEqualValues() no longer accepts null values.
### is.codion.common.rmi
- SerializationWhitelist.writeToFile() improved a bit, javadocs fixed.
- SerializationWhitelist no longer public, refactored.
### is.codion.framework.domain
- EntityDefinition.orderBy() and selectQuery() now return Optional.
- AttributeDefinition.mnemonic() now primitive based, with 0 replacing null for no mnemonic.
- AbstractAttributeDefinition.validateItems() now returns an unmodifiable copy of the item list, minor refactoring.
### is.codion.framework.model
- EntityTableConditionModel.setEqualConditionValues() no longer accepts null values.
### is.codion.swing.common.model
- DefaultFilteredTableModel.DefaultSummaryValueProvider format no longer nullable.
- FilteredComboBoxModel.setItems() no longer accepts null.
### is.codion.swing.common.ui
- KeyboardShortcuts.copy() added.
- CalendarPanel.Builder added, replaces factory methods
Expand All @@ -23,6 +38,7 @@ Codion Change Log
- EntityComboBox.KeyboardShortcut moved to EntityComboBoxPanel, EntityComboBoxPanel.Builder.keyStroke() added for configuring keyboard shortcuts on an instance basis.
- TabbedPanelLayout.Builder.keyboardShortcut() renamed keyStroke() for consistency.
- EntityEditComponentPanel.selectInputComponent() bug fixed, now does nothing instead of throwing exception when no input components are selectable.
- TabbedPanelLayout.defaultKeyStroke() bug fixed, incorrect key used for RESIZE_RIGHT.

## 0.17.22
### is.codion.swing.common.core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -55,8 +56,8 @@ private DefaultLocaleDateTimePattern(DefaultBuilder builder) {
}

@Override
public String timePattern() {
return timePattern;
public Optional<String> timePattern() {
return Optional.ofNullable(timePattern);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Optional;

/**
* Specifies a locale sensitive numerical date format pattern.
Expand Down Expand Up @@ -52,7 +53,7 @@ public interface LocaleDateTimePattern {
/**
* @return the time part of this format, null if none is available
*/
String timePattern();
Optional<String> timePattern();

/**
* @return the date part of this format using the default Locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void locale() {
Locale iceland = new Locale("is", "IS");
Locale us = new Locale("en", "US");

assertEquals("HH:mm", pattern.timePattern());
assertEquals("HH:mm", pattern.timePattern().orElseThrow(IllegalStateException::new));
assertEquals("dd-MM-yyyy", pattern.datePattern(iceland));
assertEquals("MM-dd-yyyy", pattern.datePattern(us));
assertEquals("dd-MM-yyyy HH:mm", pattern.dateTimePattern(iceland));
Expand All @@ -49,7 +49,7 @@ void locale() {
.yearTwoDigits()
.hoursMinutesSeconds()
.build();
assertEquals("HH:mm:ss", pattern.timePattern());
assertEquals("HH:mm:ss", pattern.timePattern().orElseThrow(IllegalStateException::new));
assertEquals("dd.MM.yy", pattern.datePattern(iceland));
assertEquals("MM.dd.yy", pattern.datePattern(us));
assertEquals("dd.MM.yy HH:mm:ss", pattern.dateTimePattern(iceland));
Expand All @@ -61,7 +61,7 @@ void locale() {
.hoursMinutesSecondsMilliseconds()
.build();

assertEquals("HH:mm:ss.SSS", pattern.timePattern());
assertEquals("HH:mm:ss.SSS", pattern.timePattern().orElseThrow(IllegalStateException::new));
assertEquals("dd/MM/yyyy", pattern.datePattern(iceland));
assertEquals("MM/dd/yyyy", pattern.datePattern(us));
assertEquals("dd/MM/yyyy HH:mm:ss.SSS", pattern.dateTimePattern(iceland));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,19 @@ public final void createConnectionPool(ConnectionPoolFactory connectionPoolFacto
connectionPools.put(poolUser.username().toLowerCase(), connectionPoolFactory.createConnectionPool(this, poolUser));
}

@Override
public final boolean containsConnectionPool(String username) {
return connectionPools.containsKey(requireNonNull(username).toLowerCase());
}

@Override
public final ConnectionPoolWrapper connectionPool(String username) {
return connectionPools.get(requireNonNull(username, "username").toLowerCase());
ConnectionPoolWrapper connectionPoolWrapper = connectionPools.get(requireNonNull(username, "username").toLowerCase());
if (connectionPoolWrapper == null) {
throw new IllegalArgumentException("No connection pool available for user: " + username);
}

return connectionPoolWrapper;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,16 @@ enum Operation {
*/
void createConnectionPool(ConnectionPoolFactory connectionPoolFactory, User poolUser) throws DatabaseException;

/**
* @param username the username
* @return true if a connection pool exists for the given username
*/
boolean containsConnectionPool(String username);

/**
* @param username the username
* @return the connection pool for the given user, null if none exists
* @throws IllegalArgumentException in case no connection pool exists for the given user
*/
ConnectionPoolWrapper connectionPool(String username);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ default List<T> pack(ResultSet resultSet) throws SQLException {
}

/**
* Fetches a single instance from the given result set, assumes {@link ResultSet#next()} has been called
* Fetches a single instance from the given result set, assuming {@link ResultSet#next()} has been called
* @param resultSet the result set
* @return the instance fetched from the ResultSet, null if the item should not be included for some reason
* @return the instance fetched from the ResultSet
* @throws SQLException in case of failure
*/
T get(ResultSet resultSet) throws SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import is.codion.common.db.database.Database.Operation;
import is.codion.common.db.exception.DatabaseException;
import is.codion.common.db.pool.ConnectionPoolFactory;
import is.codion.common.user.User;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -85,6 +86,17 @@ void transactionIsolation() throws DatabaseException, SQLException {
Database.TRANSACTION_ISOLATION.set(null);
}

@Test
void connectionPool() throws DatabaseException {
Database db = new TestDatabase();
db.createConnectionPool(ConnectionPoolFactory.instance(), User.parse("scott:tiger"));
assertTrue(db.containsConnectionPool("ScotT"));
assertThrows(IllegalArgumentException.class, () -> db.connectionPool("john"));
assertNotNull(db.connectionPool("scott"));
db.closeConnectionPool("scott");
assertFalse(db.containsConnectionPool("ScotT"));
}

private static final class TestDatabase extends AbstractDatabase {

private TestDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String description() {
T getEqualValue();

/**
* @param values the values to set
* @param values the values to set, an empty Collection for none
*/
void setEqualValues(Collection<T> values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import java.text.Format;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;

import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -123,7 +122,7 @@ public T getEqualValue() {

@Override
public void setEqualValues(Collection<T> values) {
equalValues.set(values == null ? Collections.emptySet() : new HashSet<>(values));
equalValues.set(requireNonNull(values));
}

@Override
Expand Down Expand Up @@ -186,7 +185,7 @@ public State autoEnable() {
@Override
public void clear() {
enabled.set(false);
setEqualValues(null);
setEqualValues(emptyList());
setUpperBound(null);
setLowerBound(null);
operator.set(Operator.EQUAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void multiConditionString() {

Collection<String> strings = asList("abc", "def");
conditionModel.setEqualValues(strings);
assertThrows(NullPointerException.class, () -> conditionModel.setEqualValues(null));

assertTrue(conditionModel.getEqualValues().containsAll(strings));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import is.codion.framework.domain.entity.attribute.ForeignKey;
import is.codion.framework.domain.entity.attribute.ForeignKeyDefinition;
import is.codion.framework.domain.entity.condition.Condition;
import is.codion.framework.domain.entity.query.SelectQuery;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1530,10 +1529,11 @@ private static void verifyColumnIsSelectable(ColumnDefinition<?> columnDefinitio
if (columnDefinition.aggregate()) {
throw new UnsupportedOperationException("Selecting column values is not implemented for aggregate function values");
}
SelectQuery selectQuery = entityDefinition.selectQuery();
if (selectQuery != null && selectQuery.columns() != null) {
throw new UnsupportedOperationException("Selecting column values is not implemented for entities with custom column clauses");
}
entityDefinition.selectQuery().ifPresent(selectQuery -> {
if (selectQuery.columns() != null) {
throw new UnsupportedOperationException("Selecting column values is not implemented for entities with custom column clauses");
}
});
}

private static void closeSilently(AutoCloseable closeable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,7 @@ Builder select(Select select, boolean setWhereClause) {
}

Builder entitySelectQuery() {
SelectQuery selectQuery = definition.selectQuery();
if (selectQuery != null) {
if (selectQuery.columns() != null) {
columns(selectQuery.columns());
selectedColums = defaultSelectColumns();
columnsClauseFromSelectQuery = true;
}
else {
columns(defaultColumnsClause());
}
from(selectQuery.from());
where(selectQuery.where());
orderBy(selectQuery.orderBy());
groupBy(selectQuery.groupBy());
having(selectQuery.having());
}

definition.selectQuery().ifPresent(this::fromSelectQuery);
return this;
}

Expand Down Expand Up @@ -253,6 +237,22 @@ private void setColumns(Select select) {
}
}

private void fromSelectQuery(SelectQuery selectQuery) {
if (selectQuery.columns() != null) {
columns(selectQuery.columns());
selectedColums = defaultSelectColumns();
columnsClauseFromSelectQuery = true;
}
else {
columns(defaultColumnsClause());
}
from(selectQuery.from());
where(selectQuery.where());
orderBy(selectQuery.orderBy());
groupBy(selectQuery.groupBy());
having(selectQuery.having());
}

private String from() {
if (from == null) {
return forUpdate ? definition.tableName() : definition.selectTableName();
Expand Down Expand Up @@ -291,9 +291,9 @@ private String defaultColumnsClause() {
private String groupByClause() {
return groupByClauseCache.computeIfAbsent(definition.entityType(), type ->
definition.columns().definitions().stream()
.filter(ColumnDefinition::groupBy)
.map(ColumnDefinition::expression)
.collect(Collectors.joining(", ")));
.filter(ColumnDefinition::groupBy)
.map(ColumnDefinition::expression)
.collect(Collectors.joining(", ")));
}

private String columnsClause(List<ColumnDefinition<?>> columnDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public boolean optimisticLocking() {
}

@Override
public OrderBy orderBy() {
return orderBy;
public Optional<OrderBy> orderBy() {
return Optional.ofNullable(orderBy);
}

@Override
Expand All @@ -322,8 +322,8 @@ public String selectTableName() {
}

@Override
public SelectQuery selectQuery() {
return selectQuery;
public Optional<SelectQuery> selectQuery() {
return Optional.ofNullable(selectQuery);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;

Expand Down Expand Up @@ -115,19 +116,19 @@ public interface EntityDefinition {
boolean optimisticLocking();

/**
* @return the default order by clause to use when querying entities of this type, null if none is available
* @return the default order by clause to use when querying entities of this type, an empty Optional if none is available
*/
OrderBy orderBy();
Optional<OrderBy> orderBy();

/**
* @return the name of the table to use when selecting entities of this type
*/
String selectTableName();

/**
* @return the select query to use when selecting entities of this type, may be null
* @return the select query to use when selecting entities of this type, an empty Optional if none is available
*/
SelectQuery selectQuery();
Optional<SelectQuery> selectQuery();

/**
* @return the object responsible for providing toString values for this entity type
Expand Down
Loading

0 comments on commit 150d848

Please sign in to comment.