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

org.hibernate.loader.custom.ScalarResultColumnProcessor Maven / Gradle / Ivy

There is a newer version: 6.5.0.CR2
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.loader.custom;

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

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.Type;

/**
 * Represents a scalar result within the custom query
 *
 * @author Steve Ebersole
 */
public class ScalarResultColumnProcessor implements ResultColumnProcessor {
	private int position = -1;
	private String alias;
	private Type type;

	public ScalarResultColumnProcessor(int position) {
		this.position = position;
	}

	public ScalarResultColumnProcessor(String alias, Type type) {
		this.alias = alias;
		this.type = type;
	}

	@Override
	public void performDiscovery(JdbcResultMetadata metadata, List types, List aliases) throws SQLException {
		if ( alias == null ) {
			alias = metadata.getColumnName( position );
		}
		else if ( position < 0 ) {
			position = metadata.resolveColumnPosition( alias );
		}
		if ( type == null ) {
			type = metadata.getHibernateType( position );
		}
		types.add( type );
		aliases.add( alias );
	}

	@Override
	public Object extract(Object[] data, ResultSet resultSet, SharedSessionContractImplementor session)
			throws SQLException, HibernateException {
		return type.nullSafeGet( resultSet, alias, session, null );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy