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

com.vladmihalcea.hibernate.type.basic.PostgreSQLCITextType Maven / Gradle / Ivy

There is a newer version: 2.21.1
Show newest version
package com.vladmihalcea.hibernate.type.basic;

import com.vladmihalcea.hibernate.type.ImmutableType;
import com.vladmihalcea.hibernate.type.util.Configuration;
import org.hibernate.engine.spi.SharedSessionContractImplementor;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

/**
 * Maps a {@link String} object type to a PostgreSQL citext
 * column type.
 *
 * @author Sergei Portnov
 */
public class PostgreSQLCITextType extends ImmutableType {

    public static final PostgreSQLCITextType INSTANCE = new PostgreSQLCITextType();

    public PostgreSQLCITextType() {
        super(String.class);
    }

    public PostgreSQLCITextType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) {
        super(String.class, new Configuration(typeBootstrapContext.getConfigurationSettings()));
    }

    @Override
    public int getSqlType() {
        return Types.OTHER;
    }

    @Override
    protected String get(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException {
        Object value = rs.getObject(position);
        return value == null ? null : value.toString();
    }

    @Override
    protected void set(PreparedStatement st, String value, int index, SharedSessionContractImplementor session) throws SQLException {
        st.setObject(index, value, Types.OTHER);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy