tds.assessment.repositories.impl.GradesQueryRepositoryImpl.java Source code

Java tutorial

Introduction

Here is the source code for tds.assessment.repositories.impl.GradesQueryRepositoryImpl.java

Source

/***************************************************************************************************
 * Copyright 2017 Regents of the University of California. Licensed under the Educational
 * Community License, Version 2.0 (the license?); you may not use this file except in
 * compliance with the License. You may obtain a copy of the license at
 *
 * https://opensource.org/licenses/ECL-2.0
 *
 * Unless required under applicable law or agreed to in writing, software distributed under the
 * License is distributed in an AS IS? BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for specific language governing permissions
 * and limitations under the license.
 **************************************************************************************************/

package tds.assessment.repositories.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import java.util.List;

import tds.assessment.repositories.GradesQueryRepository;

@Repository
public class GradesQueryRepositoryImpl implements GradesQueryRepository {
    private final NamedParameterJdbcTemplate jdbcTemplate;

    @Autowired
    public GradesQueryRepositoryImpl(final NamedParameterJdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<String> findGrades(final String assessmentKey) {
        final SqlParameterSource parameters = new MapSqlParameterSource("key", assessmentKey);
        final String SQL = "SELECT \n" + "   grade \n" + "FROM \n" + "   setoftestgrades \n" + "WHERE \n"
                + "   _fk_adminsubject = :key \n" + "ORDER BY \n" + "   CAST(grade AS SIGNED)";

        return jdbcTemplate.queryForList(SQL, parameters, String.class);
    }
}