-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Oracle's R2DBC driver.
We support Oracle's experimental R2DBC driver by providing a dialect including bind markers. Since the driver is not yet available from Maven Central and it requires module-path support for ServiceLoader discovery, we need to apply a few workarounds including absence check for our integration tests. See #230
- Loading branch information
Showing
13 changed files
with
646 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/org/springframework/data/r2dbc/dialect/OracleDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2021 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.r2dbc.dialect; | ||
|
||
import org.springframework.r2dbc.core.binding.BindMarkersFactory; | ||
|
||
/** | ||
* An SQL dialect for Oracle. | ||
* | ||
* @author Mark Paluch | ||
* @since 1.2.6 | ||
*/ | ||
public class OracleDialect extends org.springframework.data.relational.core.dialect.OracleDialect | ||
implements R2dbcDialect { | ||
|
||
/** | ||
* Singleton instance. | ||
*/ | ||
public static final OracleDialect INSTANCE = new OracleDialect(); | ||
|
||
private static final BindMarkersFactory NAMED = BindMarkersFactory.named(":", "P", 32, | ||
OracleDialect::filterBindMarker); | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.data.r2dbc.dialect.Dialect#getBindMarkersFactory() | ||
*/ | ||
@Override | ||
public BindMarkersFactory getBindMarkersFactory() { | ||
return NAMED; | ||
} | ||
|
||
private static String filterBindMarker(CharSequence input) { | ||
|
||
StringBuilder builder = new StringBuilder(); | ||
|
||
for (int i = 0; i < input.length(); i++) { | ||
|
||
char ch = input.charAt(i); | ||
|
||
// ascii letter or digit | ||
if (Character.isLetterOrDigit(ch) && ch < 127) { | ||
builder.append(ch); | ||
} | ||
} | ||
|
||
if (builder.length() == 0) { | ||
return ""; | ||
} | ||
|
||
return "_" + builder; | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/springframework/data/r2dbc/core/OracleDatabaseClientIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2018-2021 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.r2dbc.core; | ||
|
||
import io.r2dbc.spi.ConnectionFactory; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import org.springframework.data.r2dbc.testing.EnabledOnClass; | ||
import org.springframework.data.r2dbc.testing.ExternalDatabase; | ||
import org.springframework.data.r2dbc.testing.OracleTestSupport; | ||
|
||
/** | ||
* Integration tests for {@link DatabaseClient} against Oracle. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
@EnabledOnClass("oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl") | ||
public class OracleDatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests { | ||
|
||
@RegisterExtension public static final ExternalDatabase database = OracleTestSupport.database(); | ||
|
||
@Override | ||
protected DataSource createDataSource() { | ||
return OracleTestSupport.createDataSource(database); | ||
} | ||
|
||
@Override | ||
protected ConnectionFactory createConnectionFactory() { | ||
return OracleTestSupport.createConnectionFactory(database); | ||
} | ||
|
||
@Override | ||
protected String getCreateTableStatement() { | ||
return OracleTestSupport.CREATE_TABLE_LEGOSET; | ||
} | ||
|
||
@Override | ||
@Disabled("https://github.com/oracle/oracle-r2dbc/issues/9") | ||
public void executeSelectNamedParameters() {} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/org/springframework/data/r2dbc/dialect/OracleDialectUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2021 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.r2dbc.dialect; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.r2dbc.core.binding.BindMarker; | ||
import org.springframework.r2dbc.core.binding.BindMarkers; | ||
|
||
/** | ||
* Unit tests for {@link OracleDialect}. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
class OracleDialectUnitTests { | ||
|
||
@Test // gh-230 | ||
void shouldUseNamedPlaceholders() { | ||
|
||
BindMarkers bindMarkers = OracleDialect.INSTANCE.getBindMarkersFactory().create(); | ||
|
||
BindMarker first = bindMarkers.next(); | ||
BindMarker second = bindMarkers.next("'foo!bar"); | ||
|
||
assertThat(first.getPlaceholder()).isEqualTo(":P0"); | ||
assertThat(second.getPlaceholder()).isEqualTo(":P1_foobar"); | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
...java/org/springframework/data/r2dbc/repository/OracleR2dbcRepositoryIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2019-2021 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.r2dbc.repository; | ||
|
||
import io.r2dbc.spi.ConnectionFactory; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan.Filter; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.FilterType; | ||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; | ||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; | ||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; | ||
import org.springframework.data.r2dbc.testing.EnabledOnClass; | ||
import org.springframework.data.r2dbc.testing.ExternalDatabase; | ||
import org.springframework.data.r2dbc.testing.OracleTestSupport; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
/** | ||
* Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against Oracle. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration | ||
@EnabledOnClass("oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl") | ||
public class OracleR2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests { | ||
|
||
@RegisterExtension public static final ExternalDatabase database = OracleTestSupport.database(); | ||
|
||
@Configuration | ||
@EnableR2dbcRepositories(considerNestedRepositories = true, | ||
includeFilters = @Filter(classes = OracleLegoSetRepository.class, type = FilterType.ASSIGNABLE_TYPE)) | ||
static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration { | ||
|
||
@Bean | ||
@Override | ||
public ConnectionFactory connectionFactory() { | ||
return OracleTestSupport.createConnectionFactory(database); | ||
} | ||
} | ||
|
||
@Override | ||
protected DataSource createDataSource() { | ||
return OracleTestSupport.createDataSource(database); | ||
} | ||
|
||
@Override | ||
protected ConnectionFactory createConnectionFactory() { | ||
return OracleTestSupport.createConnectionFactory(database); | ||
} | ||
|
||
@Override | ||
protected String getCreateTableStatement() { | ||
return OracleTestSupport.CREATE_TABLE_LEGOSET_WITH_ID_GENERATION; | ||
} | ||
|
||
@Override | ||
protected Class<? extends LegoSetRepository> getRepositoryInterfaceType() { | ||
return OracleLegoSetRepository.class; | ||
} | ||
|
||
interface OracleLegoSetRepository extends LegoSetRepository { | ||
|
||
@Override | ||
@Query("SELECT name FROM legoset") | ||
Flux<Named> findAsProjection(); | ||
|
||
@Override | ||
@Query("SELECT * FROM legoset WHERE manual = :manual") | ||
Mono<LegoSet> findByManual(int manual); | ||
|
||
@Override | ||
@Query("SELECT id FROM legoset") | ||
Flux<Integer> findAllIds(); | ||
} | ||
} |
Oops, something went wrong.