<commit_before>package com.comsysto.shop.repository.order.impl;

import com.comsysto.common.repository.AbstractRepositoryImpl;
import com.comsysto.shop.repository.order.api.OrderRepository;
import com.comsysto.shop.repository.order.model.Order;
import com.comsysto.shop.repository.user.api.UserRepository;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author zutherb
 */
@Repository("orderRepository")
public class OrderRepositoryImpl extends AbstractRepositoryImpl<Order> implements OrderRepository {

    private UserRepository userRepository;

    @Autowired
    public OrderRepositoryImpl(@Qualifier("mongoTemplate") MongoOperations mongoOperations,
                               @Qualifier("userRepository") UserRepository userRepository) {
        super(mongoOperations, Order.class);
        this.userRepository = userRepository;
    }

    @Override
    public List<Order> findAll(int limit, int offset, Sort sort) {
        Query query = new Query();
        applySortAndPagination(query, limit, offset, sort);
        return mongoOperations.find(query, Order.class);
    }

    @Override
    public List<Order> findInRange(Date fromDate, Date toDate, int limit, int offset, Sort sort) {
        Criteria criteria = Criteria.where("orderDate").gte(fromDate).lte(toDate);
        Query query = Query.query(criteria);
        applySortAndPagination(query, limit, offset, sort);
        return mongoOperations.find(query, Order.class);
    }

    @Override
    public Order findFirstOrder() {
        Query query = Query.query(Criteria.where("orderDate").exists(true));
        query.with(new Sort(Sort.Direction.ASC, "orderDate"));
        return mongoOperations.findOne(query, Order.class);
    }

    @Override
    public Order findLastOrder() {
        Query query = Query.query(Criteria.where("orderDate").exists(true));
        query.with(new Sort(Sort.Direction.DESC, "orderDate"));
        return mongoOperations.findOne(query, Order.class);
    }

    @Override
    public long countInRange(Date fromDate, Date toDate) {
        Criteria criteria = Criteria.where("orderDate").gte(fromDate).lte(toDate);
        Query query = Query.query(criteria);
        return mongoOperations.count(query, Order.class);
    }

    @Override
    public Order findByOrderId(long orderId) {
        Criteria criteria = Criteria.where("orderId").is(orderId);
        Query query = Query.query(criteria);<commit_msg>using static import for queries now<commit_after>package com.comsysto.shop.repository.order.impl;

import com.comsysto.common.repository.AbstractRepositoryImpl;
import com.comsysto.shop.repository.order.api.OrderRepository;
import com.comsysto.shop.repository.order.model.Order;
import com.comsysto.shop.repository.user.api.UserRepository;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;

/**
 * @author zutherb
 */
@Repository("orderRepository")
public class OrderRepositoryImpl extends AbstractRepositoryImpl<Order> implements OrderRepository {

    private UserRepository userRepository;

    @Autowired
    public OrderRepositoryImpl(@Qualifier("mongoTemplate") MongoOperations mongoOperations,
                               @Qualifier("userRepository") UserRepository userRepository) {
        super(mongoOperations, Order.class);
        this.userRepository = userRepository;
    }

    @Override
    public List<Order> findAll(int limit, int offset, Sort sort) {
        Query query = new Query();
        applySortAndPagination(query, limit, offset, sort);
        return mongoOperations.find(query, Order.class);
    }

    @Override
    public List<Order> findInRange(Date fromDate, Date toDate, int limit, int offset, Sort sort) {
        Query query = query(where("orderDate").gte(fromDate).lte(toDate));
        applySortAndPagination(query, limit, offset, sort);
        return mongoOperations.find(query, Order.class);
    }

    @Override
    public Order findFirstOrder() {
        Query query = query(where("orderDate").exists(true));
        query.with(new Sort(Sort.Direction.ASC, "orderDate"));
        return mongoOperations.findOne(query, Order.class);
    }

    @Override
    public Order findLastOrder() {
        Query query = query(where("orderDate").exists(true));
        query.with(new Sort(Sort.Direction.DESC, "orderDate"));
        return mongoOperations.findOne(query, Order.class);
    }

    @Override
    public long countInRange(Date fromDate, Date toDate) {
        Query query = query(where("orderDate").gte(fromDate).lte(toDate));
        return mongoOperations.count(query, Order.class);
    }

    @Override
    public Order findByOrderId(long orderId) {
        Query query = query(where("orderId").is(orderId));
{'fraction_non_alphanumeric': 0.10916489738145789, 'fraction_numerical': 0.0, 'mean_word_length': 4.042818911685995, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7665785', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1569, 'n_words': 307}