org.itsallcode.jdbc.resultset.generic.ColumnValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-jdbc Show documentation
Show all versions of simple-jdbc Show documentation
Library to simplify using JDBC
package org.itsallcode.jdbc.resultset.generic;
/**
* Represents a generic column value.
*
* @param type column type
* @param value column value
*/
public record ColumnValue(ColumnType type, Object value) {
/**
* Get the column value cast to the given type.
*
* @param type expected type
* @param result type
* @return value of the given type
*/
public T getValue(final Class type) {
return cast(type);
}
/**
* Get the column value as a string.
*
* @return column value as string
*/
public String getString() {
return cast(String.class);
}
private T cast(final Class type) {
return type.cast(this.value);
}
}