package org.hibernate.result.internal;
import java.sql.ResultSet;
import java.util.List;
import java.util.function.Supplier;
import javax.enterprise.inject.spi.Producer;
import org.hibernate.result.ResultSetOutput;
class ResultSetOutputImpl implements ResultSetOutput {
private final Supplier<List> resultSetSupplier;
public ResultSetOutputImpl(List results) {
this.resultSetSupplier = () -> results;
}
public ResultSetOutputImpl(Supplier<List> resultSetSupplier) {
this.resultSetSupplier = resultSetSupplier;
}
@Override
public boolean isResultSet() {
return true;
}
@Override
@SuppressWarnings("unchecked")
public List getResultList() {
return resultSetSupplier.get();
}
@Override
public Object getSingleResult() {
final List results = getResultList();
if ( results == null || results.isEmpty() ) {
return null;
}
else {
return results.get( 0 );
}
}
}