com.buschmais.xo.impl.proxy.query.property.GetMethod Maven / Gradle / Ivy
The newest version!
package com.buschmais.xo.impl.proxy.query.property;
import java.util.Map;
import com.buschmais.xo.api.XOException;
import com.buschmais.xo.impl.proxy.query.RowProxyMethod;
public class GetMethod implements RowProxyMethod {
private final String name;
private final Class> type;
public GetMethod(String name, Class> type) {
this.name = name;
this.type = type;
}
@Override
public Object invoke(Map entity, Object instance, Object[] args) {
if (!entity.containsKey(name)) {
throw new XOException("Query result does not contain column '" + name + "'");
}
Object value = entity.get(name);
return value != null ? type.cast(value) : null;
}
}