-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTransactionTokenMapper.java
More file actions
77 lines (65 loc) · 2.73 KB
/
TransactionTokenMapper.java
File metadata and controls
77 lines (65 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.example.mybatis;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
/**
* An article on these annotations can be found at:
* http://loianegroner.com/2011/02/getting-started-with-ibatis-mybatis-annotations/
* <p/>
* Notice how the SQL statements are broken up into more readable multiple strings.
* myBatis automatically adds spaces, but otherwise the statements are the same.
*/
public interface TransactionTokenMapper {
/**
* In this example, the DDL is invoked during the test setup. It would be easy to envision using this kind
* of functionality to both intialize the database for test purposes as well as validating the bindings. For
* example, a standard schema() method and a validate() method, called as part of the factory setup.
*/
@Update("create table trans_token (id bigserial primary key, trans_id varchar, token_id varchar)")
void schema();
@Select({
"select * from trans_token where id = #{id}"
})
@Results({
@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
@Result(column = "trans_id", property = "transaction", jdbcType = JdbcType.VARCHAR),
@Result(column = "token_id", property = "token", jdbcType = JdbcType.VARCHAR)
})
TransactionToken getById(long id);
/**
* Note the use of the options annotation to tell myBatis to put the returned id
* into the object when the object is successfully inserted.
*/
@Insert({
"insert into trans_token (trans_id, token_id)",
"values (#{transaction}, #{token})"
})
@Options(useGeneratedKeys = true, keyProperty = "id")
int insert(TransactionToken record);
@Select("select count(*) from trans_token")
long count();
@Delete({
"delete from trans_token where id = #{id}"
})
void deleteById(TransactionToken token);
@Delete({
"delete from trans_token where trans_id = #{transaction}"
})
void deleteByTransaction(TransactionToken token);
@Update({
"update trans_token",
"set trans_id = #{transaction},",
"token_id = #{token}",
"where id = #{id}"
})
int update(TransactionToken record);
@Select({
"select id, trans_id, token_id",
"from trans_token where trans_id = #{transaction}"
})
@Results({
@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
@Result(column = "trans_id", property = "transaction", jdbcType = JdbcType.VARCHAR),
@Result(column = "token_id", property = "token", jdbcType = JdbcType.VARCHAR)
})
TransactionToken selectByTransaction(String transaction);
}