Skip to content

Commit 9b88b08

Browse files
Added basic working sql queries
1 parent 1fc4c0f commit 9b88b08

14 files changed

Lines changed: 223 additions & 343 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>spring-data-eclipse-store-root</artifactId>
9-
<version>2.1.0-SNAPSHOT</version>
9+
<version>2.1.1-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<organization>

spring-data-eclipse-store-benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>software.xdev</groupId>
77
<artifactId>spring-data-eclipse-store-root</artifactId>
8-
<version>2.1.0-SNAPSHOT</version>
8+
<version>2.1.1-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>spring-data-eclipse-store-benchmark</artifactId>

spring-data-eclipse-store-demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>spring-data-eclipse-store-root</artifactId>
10-
<version>2.1.0-SNAPSHOT</version>
10+
<version>2.1.1-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>spring-data-eclipse-store-demo</artifactId>

spring-data-eclipse-store-jpa/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>software.xdev</groupId>
99
<artifactId>spring-data-eclipse-store-root</artifactId>
10-
<version>2.1.0-SNAPSHOT</version>
10+
<version>2.1.1-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>spring-data-eclipse-store-jpa</artifactId>

spring-data-eclipse-store/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@
169169
<groupId>com.googlecode.cqengine</groupId>
170170
<artifactId>cqengine</artifactId>
171171
<version>3.6.0</version>
172+
<exclusions>
173+
<exclusion>
174+
<artifactId>kryo</artifactId>
175+
<groupId>com.esotericsoftware</groupId>
176+
</exclusion>
177+
<exclusion>
178+
<artifactId>kryo-serializers</artifactId>
179+
<groupId>de.javakaffee</groupId>
180+
</exclusion>
181+
<exclusion>
182+
<artifactId>sqlite-jdbc</artifactId>
183+
<groupId>org.xerial</groupId>
184+
</exclusion>
185+
</exclusions>
172186
</dependency>
173187

174188
<dependency>
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
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+
*/
116
package software.xdev.spring.data.eclipse.store.repository.query;
217

3-
import java.lang.reflect.Method;
418
import java.util.Objects;
519

6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
8-
import org.springframework.data.repository.query.Parameters;
920
import org.springframework.data.repository.query.QueryMethod;
1021
import org.springframework.data.repository.query.RepositoryQuery;
11-
import org.springframework.data.util.TypeInformation;
1222

1323
import software.xdev.spring.data.eclipse.store.core.EntityListProvider;
1424
import software.xdev.spring.data.eclipse.store.repository.query.antlr.HSqlQueryExecutor;
@@ -17,35 +27,24 @@
1727

1828
public class HSqlQueryProvider<T> implements RepositoryQuery
1929
{
20-
private static final Logger LOG = LoggerFactory.getLogger(HSqlQueryProvider.class);
21-
22-
// private final PartTree tree;
23-
private final Parameters<?, ?> parameters;
24-
private final EntityListProvider entityListProvider;
25-
private final Class<T> domainClass;
26-
private final TypeInformation<?> typeInformation;
27-
private final WorkingCopier<T> copier;
28-
private final QueryMethod queryMethod;
2930
private final HSqlQueryExecutor executor;
3031
private final String sqlValue;
32+
private final QueryMethod queryMethod;
3133

3234
public HSqlQueryProvider(
3335
final String sqlValue,
3436
final QueryMethod queryMethod,
35-
final Method method,
3637
final Class<T> domainClass,
3738
final EntityListProvider entityListProvider,
3839
final WorkingCopier<T> copier
3940
)
4041
{
41-
Objects.requireNonNull(method);
4242
this.queryMethod = queryMethod;
43-
this.domainClass = Objects.requireNonNull(domainClass);
44-
this.entityListProvider = Objects.requireNonNull(entityListProvider);
45-
this.typeInformation = TypeInformation.fromReturnTypeOf(method);
46-
this.parameters = queryMethod.getParameters();
47-
this.copier = Objects.requireNonNull(copier);
48-
this.executor = new HSqlQueryExecutor(this.domainClass, this.entityListProvider);
43+
this.executor = new HSqlQueryExecutor(
44+
Objects.requireNonNull(domainClass),
45+
Objects.requireNonNull(entityListProvider),
46+
copier
47+
);
4948
this.sqlValue = sqlValue;
5049
}
5150

@@ -58,6 +57,6 @@ public Object execute(final Object[] parameters)
5857
@Override
5958
public QueryMethod getQueryMethod()
6059
{
61-
return null;
60+
return this.queryMethod;
6261
}
6362
}

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
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+
*/
116
package software.xdev.spring.data.eclipse.store.repository.query.antlr;
217

18+
import java.time.LocalDate;
19+
import java.time.format.DateTimeFormatter;
320
import java.util.Collection;
21+
import java.util.List;
422
import java.util.Map;
523
import java.util.TreeMap;
624
import java.util.stream.Collectors;
@@ -14,41 +32,45 @@
1432

1533
import software.xdev.spring.data.eclipse.store.core.EntityListProvider;
1634
import software.xdev.spring.data.eclipse.store.repository.access.AccessHelper;
35+
import software.xdev.spring.data.eclipse.store.repository.support.copier.working.WorkingCopier;
1736

1837

1938
public class HSqlQueryExecutor<T>
2039
{
2140
private final SQLParser<T> parser;
2241
private final EntityListProvider entityListProvider;
2342
private final Class<T> domainClass;
43+
private final WorkingCopier<T> copier;
2444

25-
public HSqlQueryExecutor(final Class<T> domainClass, final EntityListProvider entityListProvider)
45+
public HSqlQueryExecutor(
46+
final Class<T> domainClass,
47+
final EntityListProvider entityListProvider,
48+
final WorkingCopier<T> copier)
2649
{
2750
this.domainClass = domainClass;
2851
this.parser = SQLParser.forPojoWithAttributes(domainClass, this.createAttributes(domainClass));
2952
this.entityListProvider = entityListProvider;
53+
this.copier = copier;
3054
}
3155

32-
public Object execute(final String sqlValue, final Object[] parameters)
56+
public List<T> execute(final String sqlValue, final Object[] parameters)
3357
{
3458
final IndexedCollection<T> entities = new ConcurrentIndexedCollection<>();
3559
entities.addAll(this.entityListProvider.getEntityProvider(this.domainClass).toCollection());
3660
final String sqlStringWithReplacedValues = this.replacePlaceholders(sqlValue, parameters);
3761
final ResultSet<T> retrieve = this.parser.retrieve(entities, sqlStringWithReplacedValues);
38-
return retrieve.stream().toList();
62+
final List<T> results = retrieve.stream().toList();
63+
return this.copier.copy(results);
3964
}
4065

41-
private String replacePlaceholders(String sqlValue, final Object[] parameters)
66+
private String replacePlaceholders(final String sqlValue, final Object[] parameters)
4267
{
68+
String stringWithReplacedValues = sqlValue;
4369
// Replace positional placeholders with actual parameter values
4470
for(int i = 0; i < parameters.length; i++)
4571
{
4672
final String placeholder = "\\?" + (i + 1);
4773
String value = parameters[i].toString();
48-
if(parameters[i] instanceof String)
49-
{
50-
value = "'" + value + "'";
51-
}
5274
if(parameters[i] instanceof final Collection collection)
5375
{
5476
value =
@@ -57,9 +79,13 @@ private String replacePlaceholders(String sqlValue, final Object[] parameters)
5779
.collect(Collectors.joining(", ", "(", ")"))
5880
.toString();
5981
}
60-
sqlValue = sqlValue.replaceAll(placeholder, value);
82+
if(parameters[i] instanceof final LocalDate localDate)
83+
{
84+
value = localDate.format(DateTimeFormatter.ofPattern("YYYY-MM-dd"));
85+
}
86+
stringWithReplacedValues = stringWithReplacedValues.replaceAll(placeholder, value);
6187
}
62-
return sqlValue;
88+
return stringWithReplacedValues;
6389
}
6490

6591
private <O> Map<String, ? extends Attribute<O, ?>> createAttributes(final Class<O> domainClass)

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/EclipseStoreQueryLookupStrategy.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public RepositoryQuery resolveQuery(
7676
return this.createHSqlQueryProvider(
7777
queryAnnotation.value(),
7878
metadata.getDomainType(),
79-
queryMethod,
80-
method
79+
queryMethod
8180
);
8281
}
8382

@@ -121,14 +120,12 @@ private <T> RepositoryQuery createStringBasedEclipseStoreQueryProvider(
121120
private <T> RepositoryQuery createHSqlQueryProvider(
122121
final String sqlString,
123122
final Class<T> domainType,
124-
final QueryMethod queryMethod,
125-
final Method method
123+
final QueryMethod queryMethod
126124
)
127125
{
128126
return new HSqlQueryProvider<>(
129127
sqlString,
130128
queryMethod,
131-
method,
132129
domainType,
133130
this.storage,
134131
this.workingCopierCreator.createWorkingCopier(domainType, this.storage)

0 commit comments

Comments
 (0)