Browse Source
The major ones are: * directly construct joins * remove multiple places of duplication * naming * documentation See #574 Original pull request #1957pull/2077/head
36 changed files with 926 additions and 619 deletions
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
/* |
||||
* Copyright 2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.relational.core.mapping; |
||||
|
||||
import java.util.Map; |
||||
import java.util.TreeMap; |
||||
|
||||
import org.springframework.data.relational.core.sql.SqlIdentifier; |
||||
|
||||
/** |
||||
* A builder for {@link AggregatePath.ColumnInfos} instances. |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 4.0 |
||||
*/ |
||||
class ColumInfosBuilder { |
||||
|
||||
private final AggregatePath basePath; |
||||
private final Map<AggregatePath, AggregatePath.ColumnInfo> columnInfoMap = new TreeMap<>(); |
||||
|
||||
/** |
||||
* Start construction with just the {@literal basePath} which all other paths are build upon. |
||||
* |
||||
* @param basePath must not be null. |
||||
*/ |
||||
ColumInfosBuilder(AggregatePath basePath) { |
||||
this.basePath = basePath; |
||||
} |
||||
|
||||
/** |
||||
* Adds a {@link AggregatePath.ColumnInfo} to the {@link AggregatePath.ColumnInfos} under construction. |
||||
* |
||||
* @param path referencing the {@literal ColumnInfo}. |
||||
* @param name of the column. |
||||
* @param alias alias for the column. |
||||
*/ |
||||
void add(AggregatePath path, SqlIdentifier name, SqlIdentifier alias) { |
||||
add(path, new AggregatePath.ColumnInfo(name, alias)); |
||||
} |
||||
|
||||
/** |
||||
* Adds a {@link AggregatePath.ColumnInfo} to the {@link AggregatePath.ColumnInfos} under construction. |
||||
* |
||||
* @param property referencing the {@literal ColumnInfo}. |
||||
* @param name of the column. |
||||
* @param alias alias for the column. |
||||
*/ |
||||
void add(RelationalPersistentProperty property, SqlIdentifier name, SqlIdentifier alias) { |
||||
add(basePath.append(property), name, alias); |
||||
} |
||||
|
||||
/** |
||||
* Adds a {@link AggregatePath.ColumnInfo} to the {@link AggregatePath.ColumnInfos} under construction. |
||||
* |
||||
* @param path the path referencing the {@literal ColumnInfo} |
||||
* @param columnInfo the {@literal ColumnInfo} added. |
||||
*/ |
||||
void add(AggregatePath path, AggregatePath.ColumnInfo columnInfo) { |
||||
columnInfoMap.put(path.subtract(basePath), columnInfo); |
||||
} |
||||
|
||||
/** |
||||
* Build the final {@link AggregatePath.ColumnInfos} instance. |
||||
* |
||||
* @return a {@literal ColumnInfos} instance containing all the added {@link AggregatePath.ColumnInfo} instances. |
||||
*/ |
||||
AggregatePath.ColumnInfos build() { |
||||
return new AggregatePath.ColumnInfos(basePath, columnInfoMap); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright 2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.relational.core.mapping; |
||||
|
||||
import org.assertj.core.api.AbstractAssert; |
||||
|
||||
/** |
||||
* Custom AssertJ assertions for {@link AggregatePath} instances |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 4.0 |
||||
*/ |
||||
public class AggregatePathAssertions extends AbstractAssert<AggregatePathAssertions, AggregatePath> { |
||||
|
||||
/** |
||||
* Constructor taking the actual {@link AggregatePath} to assert over. |
||||
* |
||||
* @param actual |
||||
*/ |
||||
public AggregatePathAssertions(AggregatePath actual) { |
||||
super(actual, AggregatePathAssertions.class); |
||||
} |
||||
|
||||
/** |
||||
* Entry point for creating assertions for AggregatePath. |
||||
*/ |
||||
public static AggregatePathAssertions assertThat(AggregatePath actual) { |
||||
return new AggregatePathAssertions(actual); |
||||
} |
||||
|
||||
/** |
||||
* Assertion method comparing the path of the actual AggregatePath with the provided String representation of a path |
||||
* in dot notation. Note that the assertion does not test the root entity type of the AggregatePath. |
||||
*/ |
||||
public AggregatePathAssertions hasPath(String expectedPath) { |
||||
isNotNull(); |
||||
|
||||
if (!actual.toDotPath().equals(expectedPath)) { // Adjust this condition based on your AggregatePath's path logic
|
||||
failWithMessage("Expected path to be <%s> but was <%s>", expectedPath, actual.toString()); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* assertion testing if the actual path is a root path. |
||||
*/ |
||||
public AggregatePathAssertions isRoot() { |
||||
isNotNull(); |
||||
|
||||
if (!actual.isRoot()) { |
||||
failWithMessage("Expected AggregatePath to be root path, but it was not"); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* assertion testing if the actual path is NOT a root path. |
||||
*/ |
||||
public AggregatePathAssertions isNotRoot() { |
||||
isNotNull(); |
||||
|
||||
if (actual.isRoot()) { |
||||
failWithMessage("Expected AggregatePath not to be root path, but it was."); |
||||
} |
||||
return this; |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.relational.core.mapping; |
||||
|
||||
import java.util.function.Consumer; |
||||
|
||||
import org.assertj.core.api.SoftAssertions; |
||||
import org.assertj.core.api.SoftAssertionsProvider; |
||||
|
||||
/** |
||||
* Soft assertions for {@link AggregatePath} instances. |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 4.0 |
||||
*/ |
||||
public class AggregatePathSoftAssertions extends SoftAssertions { |
||||
|
||||
/** |
||||
* Entry point for assertions. The default {@literal assertThat} can't be used, since it collides with {@link SoftAssertions#assertThat(Iterable)} |
||||
*/ |
||||
public AggregatePathAssertions assertAggregatePath(AggregatePath actual) { |
||||
return proxy(AggregatePathAssertions.class, AggregatePath.class, actual); |
||||
} |
||||
|
||||
static void assertAggregatePathsSoftly(Consumer<AggregatePathSoftAssertions> softly) { |
||||
SoftAssertionsProvider.assertSoftly(AggregatePathSoftAssertions.class, softly); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue