| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| <mapper namespace="com.example.g8backend.mapper.PeerMapper"> |
| |
| <select id="getPeerByPK" parameterType="map" resultType="com.example.g8backend.entity.Peer"> |
| SELECT * FROM peers |
| WHERE peer_id = #{peerId} and info_hash = #{infoHash} and passkey = #{passkey} |
| </select> |
| |
| <select id="getPeerByInfoHashAndPeerId" parameterType="map" resultType="com.example.g8backend.entity.Peer"> |
| SELECT * FROM peers |
| WHERE info_hash = #{infoHash} and peer_id = #{peerId} |
| </select> |
| |
| <select id="selectAllInfoHashesWithPeers" resultType="String"> |
| SELECT DISTINCT info_hash FROM peers |
| </select> |
| |
| <select id="countRecentActivity" resultType="Long" parameterType="String"> |
| SELECT COUNT(*) FROM torrents |
| WHERE info_hash = #{infoHash} |
| AND upload_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) |
| </select> |
| |
| |
| <select id="selectByInfoHashList" parameterType="list" resultType="com.example.g8backend.entity.Torrent"> |
| SELECT * FROM torrents |
| WHERE info_hash IN |
| <foreach collection="infoHashes" item="item" open="(" separator="," close=")"> |
| #{item} |
| </foreach> |
| </select> |
| |
| |
| <update id="updatePeer" parameterType="map"> |
| UPDATE peers |
| SET uploaded = #{uploaded}, downloaded = #{downloaded} |
| WHERE peer_id = #{peerId} and info_hash = #{infoHash} and passkey = #{passkey} |
| </update> |
| |
| </mapper> |