Skip to content

Commit 606e368

Browse files
authored
IGNITE-23951 Spring Data JDBC support for Ignite (#4968)
1 parent 29af723 commit 606e368

File tree

16 files changed

+1575
-0
lines changed

16 files changed

+1575
-0
lines changed

gradle/libs.versions.toml

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ tree-sitter-sql = "gh-pages-a"
8585
tree-sitter-hocon = "master-a"
8686
otel = "1.45.0"
8787
spring-boot = "3.4.1"
88+
spring-data = "3.4.0"
8889

8990
#Tools
9091
pmdTool = "6.55.0"
@@ -275,3 +276,4 @@ opentelemetry-exporter-otlp = { module = "io.opentelemetry:opentelemetry-exporte
275276
spring-boot = { module = "org.springframework.boot:spring-boot", version.ref = "spring-boot" }
276277
spring-boot-autoconfigure = { module = "org.springframework.boot:spring-boot-autoconfigure", version.ref = "spring-boot" }
277278
spring-boot-test = { module = "org.springframework.boot:spring-boot-test", version.ref = "spring-boot" }
279+
spring-data-jdbc = { module = "org.springframework.data:spring-data-jdbc", version.ref = "spring-data"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
apply from: "$rootDir/buildscripts/java-core.gradle"
19+
apply from: "$rootDir/buildscripts/publishing.gradle"
20+
apply from: "$rootDir/buildscripts/java-junit5.gradle"
21+
22+
description = "spring-data-ignite"
23+
24+
java {
25+
sourceCompatibility = JavaVersion.VERSION_17
26+
targetCompatibility = JavaVersion.VERSION_17
27+
}
28+
29+
dependencies {
30+
implementation project(':ignite-client')
31+
implementation project(":ignite-jdbc")
32+
implementation libs.spring.boot
33+
implementation libs.spring.boot.autoconfigure
34+
implementation libs.spring.data.jdbc
35+
36+
testImplementation libs.spring.boot.test
37+
testImplementation libs.assertj.core
38+
testImplementation testFixtures(project(':ignite-runner'))
39+
testImplementation testFixtures(project(':ignite-core'))
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.data;
19+
20+
import java.util.Collections;
21+
import java.util.Set;
22+
import org.springframework.data.relational.core.dialect.AbstractDialect;
23+
import org.springframework.data.relational.core.dialect.ArrayColumns;
24+
import org.springframework.data.relational.core.dialect.LimitClause;
25+
import org.springframework.data.relational.core.dialect.LockClause;
26+
import org.springframework.data.relational.core.sql.IdentifierProcessing;
27+
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
28+
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
29+
import org.springframework.data.relational.core.sql.LockOptions;
30+
import org.springframework.util.Assert;
31+
import org.springframework.util.ClassUtils;
32+
33+
/**
34+
* Implementation of Ignite-specific dialect.
35+
*/
36+
public class IgniteDialect extends AbstractDialect {
37+
38+
/**
39+
* Singleton instance.
40+
*/
41+
public static final IgniteDialect INSTANCE = new IgniteDialect();
42+
43+
private IgniteDialect() {}
44+
45+
private static final LimitClause LIMIT_CLAUSE = new LimitClause() {
46+
@Override
47+
public String getLimit(long limit) {
48+
return "LIMIT " + limit;
49+
}
50+
51+
@Override
52+
public String getOffset(long offset) {
53+
return "OFFSET " + offset;
54+
}
55+
56+
@Override
57+
public String getLimitOffset(long limit, long offset) {
58+
return String.format("OFFSET %d ROWS FETCH FIRST %d ROWS ONLY", offset, limit);
59+
}
60+
61+
@Override
62+
public Position getClausePosition() {
63+
return Position.AFTER_ORDER_BY;
64+
}
65+
};
66+
67+
static class IgniteArrayColumns implements ArrayColumns {
68+
@Override
69+
public boolean isSupported() {
70+
return true;
71+
}
72+
73+
@Override
74+
public Class<?> getArrayType(Class<?> userType) {
75+
Assert.notNull(userType, "Array component type must not be null");
76+
77+
return ClassUtils.resolvePrimitiveIfNecessary(userType);
78+
}
79+
}
80+
81+
@Override
82+
public LimitClause limit() {
83+
return LIMIT_CLAUSE;
84+
}
85+
86+
static final LockClause LOCK_CLAUSE = new LockClause() {
87+
88+
@Override
89+
public String getLock(LockOptions lockOptions) {
90+
return "";
91+
}
92+
93+
@Override
94+
public Position getClausePosition() {
95+
return Position.AFTER_ORDER_BY;
96+
}
97+
};
98+
99+
@Override
100+
public LockClause lock() {
101+
return LOCK_CLAUSE;
102+
}
103+
104+
private final IgniteArrayColumns arrayColumns = new IgniteArrayColumns();
105+
106+
@Override
107+
public ArrayColumns getArraySupport() {
108+
return arrayColumns;
109+
}
110+
111+
@Override
112+
public IdentifierProcessing getIdentifierProcessing() {
113+
return IdentifierProcessing.create(Quoting.ANSI, LetterCasing.UPPER_CASE);
114+
}
115+
116+
@Override
117+
public Set<Class<?>> simpleTypes() {
118+
return Collections.emptySet();
119+
}
120+
121+
@Override
122+
public boolean supportsSingleQueryLoading() {
123+
return false;
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.data;
19+
20+
import java.util.Optional;
21+
import org.springframework.data.jdbc.repository.config.DialectResolver;
22+
import org.springframework.data.relational.core.dialect.Dialect;
23+
import org.springframework.jdbc.core.JdbcOperations;
24+
25+
/**
26+
* Provider for Ignite-specific dialect.
27+
*/
28+
public class IgniteDialectProvider implements DialectResolver.JdbcDialectProvider {
29+
30+
@Override public Optional<Dialect> getDialect(JdbcOperations operations) {
31+
return Optional.of(IgniteDialect.INSTANCE);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.data.jdbc.repository.config.DialectResolver$JdbcDialectProvider=org.apache.ignite.data.IgniteDialectProvider

0 commit comments

Comments
 (0)