Skip to content

Commit 0ad7f77

Browse files
Create Test infrastructure for HsqlTests
1 parent d573021 commit 0ad7f77

5 files changed

Lines changed: 283 additions & 3 deletions

File tree

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/HSqlQueryProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.springframework.data.repository.query.Parameters;
99
import org.springframework.data.repository.query.QueryMethod;
1010
import org.springframework.data.repository.query.RepositoryQuery;
11-
import org.springframework.data.repository.query.parser.PartTree;
1211
import org.springframework.data.util.TypeInformation;
1312

1413
import software.xdev.spring.data.eclipse.store.core.EntityListProvider;
@@ -20,7 +19,7 @@ public class HSqlQueryProvider<T> implements RepositoryQuery
2019
{
2120
private static final Logger LOG = LoggerFactory.getLogger(HSqlQueryProvider.class);
2221

23-
private final PartTree tree;
22+
// private final PartTree tree;
2423
private final Parameters<?, ?> parameters;
2524
private final EntityListProvider entityListProvider;
2625
private final Class<T> domainClass;
@@ -42,7 +41,7 @@ public HSqlQueryProvider(
4241
this.queryMethod = queryMethod;
4342
this.domainClass = Objects.requireNonNull(domainClass);
4443
this.entityListProvider = Objects.requireNonNull(entityListProvider);
45-
this.tree = new PartTree(method.getName(), domainClass);
44+
// this.tree = new PartTree(method.getName(), domainClass);
4645
this.typeInformation = TypeInformation.fromReturnTypeOf(method);
4746
this.parameters = queryMethod.getParameters();
4847
this.copier = Objects.requireNonNull(copier);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.hsql;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
20+
import java.util.Arrays;
21+
import java.util.Calendar;
22+
import java.util.List;
23+
import java.util.stream.Stream;
24+
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.Arguments;
28+
import org.junit.jupiter.params.provider.MethodSource;
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.test.context.ContextConfiguration;
31+
32+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations;
33+
34+
35+
@IsolatedTestAnnotations
36+
@ContextConfiguration(classes = {HsqlTestConfiguration.class})
37+
class HsqlTest
38+
{
39+
@Autowired
40+
private MyEntityRepository repository;
41+
42+
@Autowired
43+
private HsqlTestConfiguration configuration;
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.hsql;
17+
18+
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
19+
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.context.annotation.Configuration;
22+
23+
import software.xdev.spring.data.eclipse.store.integration.TestConfiguration;
24+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
25+
26+
27+
@Configuration
28+
@EnableEclipseStoreRepositories
29+
public class HsqlTestConfiguration extends TestConfiguration
30+
{
31+
@Autowired
32+
protected HsqlTestConfiguration(
33+
final EclipseStoreProperties defaultEclipseStoreProperties,
34+
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider)
35+
{
36+
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.hsql;
2+
3+
import java.time.LocalDate;
4+
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.GenerationType;
7+
import jakarta.persistence.Id;
8+
9+
10+
public class MyEntity
11+
{
12+
@Id
13+
@GeneratedValue(strategy = GenerationType.AUTO)
14+
private Long id;
15+
16+
private String name;
17+
18+
private int age;
19+
20+
private LocalDate creationDate;
21+
22+
private boolean active;
23+
24+
private Object otherEntity;
25+
26+
public MyEntity()
27+
{
28+
}
29+
30+
public MyEntity(
31+
final Long id,
32+
final String name,
33+
final int age,
34+
final LocalDate creationDate,
35+
final boolean active,
36+
final Object otherEntity)
37+
{
38+
this.id = id;
39+
this.name = name;
40+
this.age = age;
41+
this.creationDate = creationDate;
42+
this.active = active;
43+
this.otherEntity = otherEntity;
44+
}
45+
46+
public Long getId()
47+
{
48+
return this.id;
49+
}
50+
51+
public void setId(final Long id)
52+
{
53+
this.id = id;
54+
}
55+
56+
public String getName()
57+
{
58+
return this.name;
59+
}
60+
61+
public void setName(final String name)
62+
{
63+
this.name = name;
64+
}
65+
66+
public int getAge()
67+
{
68+
return this.age;
69+
}
70+
71+
public void setAge(final int age)
72+
{
73+
this.age = age;
74+
}
75+
76+
public LocalDate getCreationDate()
77+
{
78+
return this.creationDate;
79+
}
80+
81+
public void setCreationDate(final LocalDate creationDate)
82+
{
83+
this.creationDate = creationDate;
84+
}
85+
86+
public boolean isActive()
87+
{
88+
return this.active;
89+
}
90+
91+
public void setActive(final boolean active)
92+
{
93+
this.active = active;
94+
}
95+
96+
public Object getOtherEntity()
97+
{
98+
return this.otherEntity;
99+
}
100+
101+
public void setOtherEntity(final Object otherEntity)
102+
{
103+
this.otherEntity = otherEntity;
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.hsql;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
6+
import org.springframework.data.repository.ListCrudRepository;
7+
8+
import software.xdev.spring.data.eclipse.store.repository.Query;
9+
10+
11+
public interface MyEntityRepository extends ListCrudRepository<MyEntity, Long>
12+
{
13+
// 1. Simple Select
14+
@Query("SELECT e FROM MyEntity e")
15+
List<MyEntity> findAllEntities();
16+
17+
// 2. Select with a where clause
18+
@Query("SELECT e FROM MyEntity e WHERE e.name = ?1")
19+
List<MyEntity> findByName(String name);
20+
21+
// 3. Select with multiple where clauses
22+
@Query("SELECT e FROM MyEntity e WHERE e.name = ?1 AND e.age > ?2")
23+
List<MyEntity> findByNameAndAgeGreaterThan(String name, int age);
24+
25+
// 4. Select with order by
26+
@Query("SELECT e FROM MyEntity e ORDER BY e.age DESC")
27+
List<MyEntity> findAllOrderByAgeDesc();
28+
29+
// 5. Select with limit
30+
@Query(value = "SELECT e FROM MyEntity e ORDER BY e.age DESC")
31+
List<MyEntity> findTop5ByOrderByAgeDesc();
32+
33+
// 6. Select with distinct
34+
@Query("SELECT DISTINCT e.name FROM MyEntity e")
35+
List<String> findDistinctNames();
36+
37+
// 7. Select with join
38+
@Query("SELECT e FROM MyEntity e JOIN e.otherEntity o WHERE o.id = ?1")
39+
List<MyEntity> findByOtherEntityId(Long otherEntityId);
40+
41+
// 8. Select with group by
42+
@Query("SELECT e.name, COUNT(e) FROM MyEntity e GROUP BY e.name")
43+
List<Object[]> countByName();
44+
45+
// 9. Select with having
46+
@Query("SELECT e.name, COUNT(e) FROM MyEntity e GROUP BY e.name HAVING COUNT(e) > ?1")
47+
List<Object[]> countByNameHavingMoreThan(long count);
48+
49+
// 10. Select with subquery
50+
@Query("SELECT e FROM MyEntity e WHERE e.age = (SELECT MAX(e2.age) FROM MyEntity e2)")
51+
MyEntity findEntityWithMaxAge();
52+
53+
// 11. Select with IN clause
54+
@Query("SELECT e FROM MyEntity e WHERE e.name IN ?1")
55+
List<MyEntity> findByNameIn(List<String> names);
56+
57+
// 12. Select with LIKE clause
58+
@Query("SELECT e FROM MyEntity e WHERE e.name LIKE %?1%")
59+
List<MyEntity> findByNameContaining(String keyword);
60+
61+
// 13. Select with native query
62+
@Query(value = "SELECT * FROM my_entity WHERE name = ?1")
63+
List<MyEntity> findByNameNative(String name);
64+
65+
// 14. Select with date comparison
66+
@Query("SELECT e FROM MyEntity e WHERE e.creationDate > ?1")
67+
List<MyEntity> findByCreationDateAfter(LocalDate date);
68+
69+
// 15. Select with between clause
70+
@Query("SELECT e FROM MyEntity e WHERE e.age BETWEEN ?1 AND ?2")
71+
List<MyEntity> findByAgeBetween(int startAge, int endAge);
72+
73+
// 16. Select with boolean condition
74+
@Query("SELECT e FROM MyEntity e WHERE e.active = true")
75+
List<MyEntity> findAllActive();
76+
77+
// 17. Select with is null condition
78+
@Query("SELECT e FROM MyEntity e WHERE e.otherEntity IS NULL")
79+
List<MyEntity> findWhereOtherEntityIsNull();
80+
81+
// 18. Select with is not null condition
82+
@Query("SELECT e FROM MyEntity e WHERE e.otherEntity IS NOT NULL")
83+
List<MyEntity> findWhereOtherEntityIsNotNull();
84+
85+
// TODO
86+
// 19. Select with a custom projection
87+
// @Query("SELECT new com.example.demo.dto.MyEntityDTO(e.name, e.age) FROM MyEntity e")
88+
// List<MyEntityDTO> findAllAsDTO();
89+
90+
// 20. Select with function
91+
@Query("SELECT e FROM MyEntity e WHERE FUNCTION('YEAR', e.creationDate) = ?1")
92+
List<MyEntity> findByCreationYear(int year);
93+
}

0 commit comments

Comments
 (0)