/
JdbcConverter.java
69 lines (63 loc) · 2.73 KB
/
JdbcConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright 2019-2020 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 java.sql.ResultSet;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
/**
* A {@link JdbcConverter} is responsible for converting for values to the native relational representation and vice
* versa.
*
* @author Jens Schauder
* @since 1.1
*/
public interface JdbcConverter extends RelationalConverter {
/**
* Convert a property value into a {@link JdbcValue} that contains the converted value and information how to bind it
* to JDBC parameters.
*
* @param value a value as it is used in the object model. May be {@code null}.
* @param type {@link TypeInformation} into which the value is to be converted. Must not be {@code null}.
* @param sqlType the type constant from {@link java.sql.Types} to be used if non is specified by a converter.
* @return The converted value wrapped in a {@link JdbcValue}. Guaranteed to be not {@literal null}.
*/
JdbcValue writeJdbcValue(@Nullable Object value, Class<?> type, int sqlType);
/**
* Read the current row from {@link ResultSet} to an {@link RelationalPersistentEntity#getType() entity}.
*
* @param entity the persistent entity type.
* @param resultSet the {@link ResultSet} to read from.
* @param key primary key.
* @param <T>
* @return
*/
<T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key);
/**
* Read the current row from {@link ResultSet} to an {@link PersistentPropertyPathExtension#getActualType() entity}.
*
* @param path path to the owning property.
* @param resultSet the {@link ResultSet} to read from.
* @param identifier entity identifier.
* @param key primary key.
* @param <T>
* @return
*/
<T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key);
}