Skip to content

Commit

Permalink
[hibernate#1732] Fix to support array Types
Browse files Browse the repository at this point in the history
  • Loading branch information
blafond committed Dec 1, 2023
1 parent 40d08dd commit e07755d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.InputStream;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
Expand All @@ -18,6 +19,7 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
Expand All @@ -35,6 +37,9 @@

import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.engine.jdbc.ClobProxy;
import org.hibernate.reactive.logging.impl.Log;
import org.hibernate.reactive.logging.impl.LoggerFactory;
import org.hibernate.type.descriptor.jdbc.JdbcType;

import io.vertx.core.buffer.Buffer;
import io.vertx.sqlclient.Row;
Expand All @@ -50,7 +55,7 @@
* {@code ResultSet} to read values from Vert.x's {@code RowSet}.
*/
public class ResultSetAdaptor implements ResultSet {

Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
private final RowIterator<Row> iterator;
private final RowSet<Row> rows;
private Row row;
Expand Down Expand Up @@ -748,6 +753,70 @@ public Array getArray(int columnIndex) {
throw new UnsupportedOperationException();
}

public Array getArray(int columnIndex, JdbcType elementJdbcType) {
Object[] objects = (Object[]) row.getValue( columnIndex - 1 );
wasNull = objects == null;
if ( objects == null ) {
return null;
}
return new Array() {
@Override
public String getBaseTypeName() throws SQLException {
return elementJdbcType.getFriendlyName();
}

@Override
public int getBaseType() throws SQLException {
return elementJdbcType.getJdbcTypeCode();
}

@Override
public Object getArray() throws SQLException {
return objects;
}

@Override
public Object getArray(Map<String, Class<?>> map) throws SQLException {
throw LOG.notYetImplemented();
}

@Override
public Object getArray(long l, int i) throws SQLException {
return null;
}

@Override
public Object getArray(long l, int i, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException( "array of maps is not yet supported" );
}

@Override
public ResultSet getResultSet() throws SQLException {
return null;
}

@Override
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
return null;
}

@Override
public ResultSet getResultSet(long l, int i) throws SQLException {
return null;
}

@Override
public ResultSet getResultSet(long l, int i, Map<String, Class<?>> map) throws SQLException {
return null;
}

@Override
public void free() throws SQLException {

}
};
}

@Override
public Object getObject(String columnLabel, Map<String, Class<?>> map) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.sql.Types;

import org.hibernate.HibernateException;
import org.hibernate.reactive.adaptor.impl.ResultSetAdaptor;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
Expand Down Expand Up @@ -111,12 +112,18 @@ public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaTypeDescriptor)
return new BasicExtractor<>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getArray( paramIndex ), options );
return javaTypeDescriptor.wrap(
( (ResultSetAdaptor) rs ).getArray( paramIndex, elementJdbcType ),
options
);
}

@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( statement.getArray( index ), options );
return javaTypeDescriptor.wrap(
( (ResultSetAdaptor) statement ).getArray( index, elementJdbcType ),
options
);
}

@Override
Expand Down

0 comments on commit e07755d

Please sign in to comment.