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

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy