All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jdbc.converter.SqlArrayToJavaArrayConverter Maven / Gradle / Ivy

package org.simpleflatmapper.jdbc.converter;


import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.converter.ContextualConverter;
import org.simpleflatmapper.reflect.Getter;

import java.sql.Array;
import java.sql.ResultSet;
import java.util.List;

public class SqlArrayToJavaArrayConverter implements ContextualConverter {
    private final T[] emptyArray;

    private final SqlArrayToListConverter sqlArrayToListConverter;

    @SuppressWarnings("unchecked")
    public SqlArrayToJavaArrayConverter(Class elementType, Getter getter) {
        this.emptyArray = (T[]) java.lang.reflect.Array.newInstance(elementType, 0);
        this.sqlArrayToListConverter = new SqlArrayToListConverter(getter);
    }

    @Override
    public T[] convert(Array in, Context context) throws Exception {
        List list = sqlArrayToListConverter.convert(in, context);
        return list != null ? list.toArray(emptyArray) : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy