com.luna.common.repository.UserRepository.java Source code

Java tutorial

Introduction

Here is the source code for com.luna.common.repository.UserRepository.java

Source

/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.luna.common.repository;

import com.luna.common.entity.SchoolType;
import com.luna.common.entity.Sex;
import com.luna.common.entity.User;
import org.springframework.context.annotation.Profile;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * <p></p>
 * <p>User: Zhang Kaitao
 * <p>Date: 13-1-14 ?2:18
 * <p>Version: 1.0
 */
public interface UserRepository extends BaseRepository<User, Long>, JpaSpecificationExecutor<User> {

    @Modifying
    @Query("update BaseInfo bi set bi.realname=?1 where bi.user.id=?2")
    public void updateRealname(String realname, Long userId);

    @Modifying
    @Query("update BaseInfo bi set bi.realname=:realname where bi.user.id=:userId")
    public void updateRealnameWithNamedParam(@Param("realname") String realname, @Param("userId") Long userId);

    @Modifying
    @Query("delete from BaseInfo bi where bi.user.id=?1")
    public void deleteBaseInfoByUser(Long userId);

    /**
     * ? ?
     *
     * @param username
     * @return
     */
    public User findByUsername(String username);

    /**
     * ? ?
     *
     * @param sex
     * @return
     */
    public User findByBaseInfoSex(Sex sex);

    public Page<User> findByBaseInfoSex(Sex sex, Pageable pageable);

    public List<User> findByBaseInfoSex(Sex sex, Sort sort);

    /**
     * ?  and
     *
     * @param sex
     * @param type
     * @return
     */
    @Query("select u from User u, BaseInfo bi, SchoolInfo si where bi.user=u and si.user=u and bi.sex=?1 and si.type=?2")
    public User findByBaseInfoSexAndShcoolInfoSetType(Sex sex, SchoolType type);

}