-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
2,490 additions
and
575 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
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
79 changes: 79 additions & 0 deletions
79
data-jdbc/src/main/java/io/micronaut/data/jdbc/mapper/JdbcTuple.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,79 @@ | ||
/* | ||
* Copyright 2017-2024 original 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 io.micronaut.data.jdbc.mapper; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.convert.ConversionService; | ||
import jakarta.persistence.Tuple; | ||
import jakarta.persistence.TupleElement; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* An implementation of {@link Tuple}. | ||
* | ||
* @author Denis Stepanov | ||
* @since 4.10 | ||
*/ | ||
@Internal | ||
final class JdbcTuple implements Tuple { | ||
|
||
private final ConversionService conversionService; | ||
private final Object[] values; | ||
private final Map<String, Integer> aliasToPosition; | ||
|
||
public JdbcTuple(ConversionService conversionService, Object[] values, Map<String, Integer> aliasToPosition) { | ||
this.conversionService = conversionService; | ||
this.values = values; | ||
this.aliasToPosition = aliasToPosition; | ||
} | ||
|
||
@Override | ||
public <X> X get(TupleElement<X> tupleElement) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public <X> X get(String alias, Class<X> type) { | ||
return conversionService.convertRequired(get(alias), type); | ||
} | ||
|
||
@Override | ||
public Object get(String alias) { | ||
return get(aliasToPosition.get(alias)); | ||
} | ||
|
||
@Override | ||
public <X> X get(int i, Class<X> type) { | ||
return conversionService.convertRequired(get(i), type); | ||
} | ||
|
||
@Override | ||
public Object get(int i) { | ||
return values[i]; | ||
} | ||
|
||
@Override | ||
public Object[] toArray() { | ||
return values; | ||
} | ||
|
||
@Override | ||
public List<TupleElement<?>> getElements() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
data-jdbc/src/main/java/io/micronaut/data/jdbc/mapper/JdbcTupleMapper.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,80 @@ | ||
/* | ||
* Copyright 2017-2024 original 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 io.micronaut.data.jdbc.mapper; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.convert.ConversionService; | ||
import io.micronaut.core.util.CollectionUtils; | ||
import io.micronaut.data.exceptions.DataAccessException; | ||
import io.micronaut.data.runtime.mapper.sql.SqlTypeMapper; | ||
import jakarta.persistence.Tuple; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
/** | ||
* A mapper of {@link Tuple}. | ||
* | ||
* @author Denis Stepanov | ||
* @since 4.10 | ||
*/ | ||
@Internal | ||
public final class JdbcTupleMapper implements SqlTypeMapper<ResultSet, Tuple> { | ||
|
||
private final ConversionService conversionService; | ||
|
||
public JdbcTupleMapper(ConversionService conversionService) { | ||
this.conversionService = conversionService; | ||
} | ||
|
||
@Override | ||
public boolean hasNext(ResultSet resultSet) { | ||
try { | ||
return resultSet.next(); | ||
} catch (SQLException e) { | ||
throw new DataAccessException("Failed to move the result set: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public Tuple map(ResultSet rs, Class<Tuple> type) throws DataAccessException { | ||
try { | ||
ResultSetMetaData metaData = rs.getMetaData(); | ||
Object[] values = new Object[metaData.getColumnCount()]; | ||
Map<String, Integer> aliasToPosition = CollectionUtils.newHashMap(values.length); | ||
for (int i = 0; i < values.length; i++) { | ||
values[i] = rs.getObject(i + 1); | ||
String alias = metaData.getColumnName(i + 1); | ||
aliasToPosition.put(alias, i); | ||
} | ||
return new JdbcTuple(conversionService, values, aliasToPosition); | ||
} catch (SQLException e) { | ||
throw new DataAccessException("Failed to read the result set: " + e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public Object read(ResultSet object, String name) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public ConversionService getConversionService() { | ||
return conversionService; | ||
} | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
data-jdbc/src/test/java/io/micronaut/data/jdbc/h2/H2AsyncBookRepository.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,25 @@ | ||
/* | ||
* Copyright 2017-2024 original 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 io.micronaut.data.jdbc.h2; | ||
|
||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
import io.micronaut.data.tck.repositories.BookAsyncRepository; | ||
import io.micronaut.data.tck.repositories.PersonAsyncRepository; | ||
|
||
@JdbcRepository(dialect = Dialect.H2) | ||
public interface H2AsyncBookRepository extends BookAsyncRepository { | ||
} |
Oops, something went wrong.