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

org.nutz.dao.impl.sql.callback.EntityCallback Maven / Gradle / Ivy

Go to download

Nutz, which is a collections of lightweight frameworks, each of them can be used independently

There is a newer version: 1.r.72
Show newest version
package org.nutz.dao.impl.sql.callback;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.nutz.dao.FieldFilter;
import org.nutz.dao.FieldMatcher;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.dao.sql.SqlContext;
import org.nutz.lang.Lang;

public abstract class EntityCallback implements SqlCallback {

    public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
        Entity en = sql.getEntity();
        if (null == en)
            throw Lang.makeThrow("SQL without entity : %s", sql.toString());
        FieldMatcher fmh = sql.getContext().getFieldMatcher();
        if (null == fmh)
            sql.getContext().setFieldMatcher(FieldFilter.get(en.getType()));
        return process(rs, en, sql.getContext());
    }

    protected abstract Object process(ResultSet rs, Entity entity, SqlContext context)
            throws SQLException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy