Search in sources :

Example 1 with HintsAwareExtractor

use of com.ctrip.platform.dal.dao.helper.HintsAwareExtractor in project dal by ctripcorp.

the class DalDirectClient method query.

@Override
public List<?> query(String sql, StatementParameters parameters, final DalHints hints, final List<DalResultSetExtractor<?>> extractors) throws SQLException {
    ConnectionAction<List<?>> action = new ConnectionAction<List<?>>() {

        @Override
        public List<?> execute() throws Exception {
            conn = getConnection(hints, this);
            preparedStatement = createPreparedStatement(conn, sql, parameters, hints);
            List<Object> result = new ArrayList<>();
            DalWatcher.beginExecute();
            preparedStatement.execute();
            for (DalResultSetExtractor<?> extractor : extractors) {
                ResultSet resultSet = preparedStatement.getResultSet();
                Object partResult;
                if (extractor instanceof HintsAwareExtractor)
                    partResult = ((DalResultSetExtractor) ((HintsAwareExtractor) extractor).extractWith(hints)).extract(resultSet);
                else
                    partResult = extractor.extract(resultSet);
                result.add(partResult);
                preparedStatement.getMoreResults();
            }
            DalWatcher.endExectue();
            return result;
        }
    };
    action.populate(DalEventEnum.QUERY, sql, parameters);
    return doInConnection(action, hints);
}
Also used : HintsAwareExtractor(com.ctrip.platform.dal.dao.helper.HintsAwareExtractor) DalResultSetExtractor(com.ctrip.platform.dal.dao.DalResultSetExtractor) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DalResultSetExtractor (com.ctrip.platform.dal.dao.DalResultSetExtractor)1 HintsAwareExtractor (com.ctrip.platform.dal.dao.helper.HintsAwareExtractor)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1