<?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.owrawww.domain.mapper.UserMapper">

    <resultMap id="userResultMap" type="com.owrawww.domain.User">
        <id     property="id"       column="id"/>
        <result property="username" column="username"/>
        <result property="password" column="password"/>
        <result property="role"     column="role"/>
        <result property="email"    column="email"/>
        <result property="enabled"  column="enabled"/>
    </resultMap>

    <select id="findByUsername" parameterType="string" resultMap="userResultMap">
        SELECT id, username, password, role, email, enabled
          FROM users
         WHERE username = #{username}
    </select>

    <select id="findAll" resultMap="userResultMap">
        SELECT id, username, password, role, email, enabled
          FROM users
         ORDER BY id ASC
    </select>

    <insert id="insert" parameterType="com.owrawww.domain.User" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO users (username, password, role, email, enabled)
        VALUES (#{username}, #{password}, #{role}, #{email}, #{enabled})
    </insert>

    <update id="update" parameterType="com.owrawww.domain.User">
        UPDATE users
           SET password = #{password},
               role     = #{role},
               email    = #{email},
               enabled  = #{enabled}
         WHERE id = #{id}
    </update>

    <delete id="deleteById" parameterType="long">
        DELETE FROM users WHERE id = #{id}
    </delete>

</mapper>
