Browse Source
Postgres requires the non standard type "FLOAT8" for "DOUBLE". This is accomplished by making the conversion dependent on the dialect. This required a new JdbcDialect interface in order to keep the JDBC annotation out of the relational module. Closes #1033 Original pull request: #1037.pull/1064/head
12 changed files with 222 additions and 17 deletions
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.jdbc.core.dialect; |
||||
|
||||
import java.sql.JDBCType; |
||||
|
||||
import org.springframework.data.relational.core.dialect.ArrayColumns; |
||||
|
||||
/** |
||||
* {@link org.springframework.data.relational.core.dialect.ArrayColumns} that offer JDBC specific functionality. |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 2.3 |
||||
*/ |
||||
public interface JdbcArrayColumns extends ArrayColumns { |
||||
|
||||
JdbcArrayColumns UNSUPPORTED = new JdbcArrayColumns() { |
||||
@Override |
||||
public boolean isSupported() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public Class<?> getArrayType(Class<?> userType) { |
||||
throw new UnsupportedOperationException("Array types not supported"); |
||||
} |
||||
|
||||
@Override |
||||
public String getSqlTypeRepresentation(JDBCType jdbcType) { |
||||
throw new UnsupportedOperationException("Array types not supported"); |
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* The appropriate SQL type as a String which should be used to represent the given {@link JDBCType} in an |
||||
* {@link java.sql.Array}. Defaults to the name of the argument. |
||||
* |
||||
* @param jdbcType the {@link JDBCType} value representing the type that should be stored in the |
||||
* {@link java.sql.Array}. Must not be {@literal null}. |
||||
* @return the appropriate SQL type as a String which should be used to represent the given {@link JDBCType} in an |
||||
* {@link java.sql.Array}. Guaranteed to be not {@literal null}. |
||||
*/ |
||||
default String getSqlTypeRepresentation(JDBCType jdbcType) { |
||||
return jdbcType.getName(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
/* |
||||
* 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.jdbc.core.dialect; |
||||
|
||||
import org.springframework.data.relational.core.dialect.Dialect; |
||||
|
||||
/** |
||||
* {@link org.springframework.data.relational.core.dialect.ArrayColumns} that offer JDBC specific functionality. |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 2.3 |
||||
*/ |
||||
public interface JdbcDialect extends Dialect { |
||||
|
||||
/** |
||||
* Returns the JDBC specific array support object that describes how array-typed columns are supported by this |
||||
* dialect. |
||||
* |
||||
* @return the JDBC specific array support object that describes how array-typed columns are supported by this |
||||
* dialect. |
||||
*/ |
||||
@Override |
||||
JdbcArrayColumns getArraySupport(); |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -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.jdbc.core.dialect; |
||||
|
||||
import java.sql.JDBCType; |
||||
|
||||
import org.springframework.data.relational.core.dialect.PostgresDialect; |
||||
|
||||
/** |
||||
* JDBC specific Postgres Dialect. |
||||
* |
||||
* @author Jens Schauder |
||||
* @since 2.3 |
||||
*/ |
||||
public class JdbcPostgresDialect extends PostgresDialect implements JdbcDialect { |
||||
|
||||
public static final JdbcPostgresDialect INSTANCE = new JdbcPostgresDialect(); |
||||
private static final JdbcPostgresArrayColumns ARRAY_COLUMNS = new JdbcPostgresArrayColumns(); |
||||
|
||||
@Override |
||||
public JdbcArrayColumns getArraySupport() { |
||||
return ARRAY_COLUMNS; |
||||
} |
||||
|
||||
static class JdbcPostgresArrayColumns extends PostgresArrayColumns implements JdbcArrayColumns { |
||||
@Override |
||||
public String getSqlTypeRepresentation(JDBCType jdbcType) { |
||||
return jdbcType == JDBCType.DOUBLE ? "FLOAT8" : jdbcType.getName(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue