001package org.lanyonm.playground.persistence;
002
003import java.util.List;
004
005import org.apache.ibatis.annotations.Delete;
006import org.apache.ibatis.annotations.Insert;
007import org.apache.ibatis.annotations.Select;
008import org.apache.ibatis.annotations.Update;
009import org.lanyonm.playground.domain.Todo;
010
011/**
012 * @author lanyonm
013 */
014public interface TodoMapper {
015
016        /**
017         * @return all rows from the 'todos' table
018         */
019        @Select("SELECT id, title, dateCreated, dateModified FROM todos")
020        public List<Todo> getAllTodos();
021
022        /**
023         * @param id
024         * @return the corresponding {@link Todo}
025         */
026        @Select("SELECT * FROM todos WHERE ID = #{id}")
027        public Todo getTodo(int id);
028
029        /**
030         * @param todo the {@link Todo} to add
031         * @return the number of new rows inserted
032         */
033        @Insert("INSERT INTO todos (title, dateCreated) VALUES (#{title}, #{dateCreated})")
034        public int insertTodo(Todo todo);
035
036        /**
037         * @param todo the {@link Todo} to update
038         * @return the number of rows altered
039         */
040        @Update("UPDATE todos SET title = #{title}, dateModified = #{dateModified} WHERE id = #{id}")
041        public int updateTodo(Todo todo);
042
043        /**
044         * @param todo
045         * @return the number of rows deleted
046         */
047        @Delete("DELETE FROM todos WHERE id = #{id}")
048        public int deleteTodo(Todo todo);
049}