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

org.simpleflatmapper.jdbc.impl.getter.UndefinedDateResultSetGetter Maven / Gradle / Ivy

package org.simpleflatmapper.jdbc.impl.getter;

import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.map.getter.ContextualGetter;
import org.simpleflatmapper.reflect.Getter;

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

public final class UndefinedDateResultSetGetter implements
		Getter, ContextualGetter {
	private final int column;
	
	public UndefinedDateResultSetGetter(final int column) {
		this.column = column;
	}

	public Date get(final ResultSet target) throws SQLException {
		Object o = target.getObject(column);
		if (o == null) {
			return null;
			
		}
		if (o instanceof Date) {
			return (Date)o;
		} else if (o instanceof Number) {
			return new Date(((Number) o).longValue());
		}
		
		throw new SQLException("Expected date, cannot convert " + o  + " to date");
	}

	@Override
	public Date get(ResultSet resultSet, Context context) throws Exception {
		return get(resultSet);
	}

    @Override
    public String toString() {
        return "UndefinedDateResultSetGetter{" +
                "property=" + column +
                '}';
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy