-
Notifications
You must be signed in to change notification settings - Fork 346
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 Postgres UUID arrays using JDBC.
We now use Postgres' JDBC drivers TypeInfoCache to register and determine array types including support for UUID. Closes #1567
- Loading branch information
Showing
6 changed files
with
217 additions
and
3 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
7 changes: 7 additions & 0 deletions
7
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/package-info.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,7 @@ | ||
/** | ||
* JDBC-specific Dialect implementations. | ||
*/ | ||
@NonNullApi | ||
package org.springframework.data.jdbc.core.dialect; | ||
|
||
import org.springframework.lang.NonNullApi; |
64 changes: 64 additions & 0 deletions
64
.../src/test/java/org/springframework/data/jdbc/core/convert/DefaultJdbcTypeFactoryTest.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,64 @@ | ||
/* | ||
* Copyright 2023 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.jdbc.core.convert; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.sql.Array; | ||
import java.sql.SQLException; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.postgresql.core.BaseConnection; | ||
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect; | ||
import org.springframework.jdbc.core.ConnectionCallback; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
|
||
/** | ||
* Unit tests for {@link DefaultJdbcTypeFactory}. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class DefaultJdbcTypeFactoryTest { | ||
|
||
@Mock JdbcOperations operations; | ||
@Mock BaseConnection connection; | ||
|
||
@Test // GH-1567 | ||
void shouldProvidePostgresArrayType() throws SQLException { | ||
|
||
DefaultJdbcTypeFactory sut = new DefaultJdbcTypeFactory(operations, JdbcPostgresDialect.INSTANCE.getArraySupport()); | ||
|
||
when(operations.execute(any(ConnectionCallback.class))).thenAnswer(invocation -> { | ||
|
||
ConnectionCallback callback = invocation.getArgument(0, ConnectionCallback.class); | ||
return callback.doInConnection(connection); | ||
}); | ||
|
||
UUID uuids[] = new UUID[] { UUID.randomUUID(), UUID.randomUUID() }; | ||
when(connection.createArrayOf("uuid", uuids)).thenReturn(mock(Array.class)); | ||
Array array = sut.createArray(uuids); | ||
|
||
assertThat(array).isNotNull(); | ||
} | ||
|
||
} |