View Javadoc
1   package net.avcompris.examples.users3.dao.impl;
2   
3   import static net.avcompris.commons3.dao.DbTable.Type.BOOLEAN;
4   import static net.avcompris.commons3.dao.DbTable.Type.INTEGER;
5   import static net.avcompris.commons3.dao.DbTable.Type.TIMESTAMP_WITH_TIMEZONE;
6   import static net.avcompris.commons3.dao.DbTable.Type.VARCHAR;
7   import static net.avcompris.commons3.dao.DbTablesUtils.column;
8   
9   import java.util.Arrays;
10  
11  import net.avcompris.commons3.dao.DbTable;
12  import net.avcompris.commons3.dao.DbTablesUtils.Column;
13  
14  public enum DbTables implements DbTable {
15  
16  	CORRELATIONS( //
17  			column("correlation_id") //
18  					.type(VARCHAR) //
19  					.size(255) //
20  					.notNull() //
21  					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
22  					.primaryKey() //
23  					.build(), //
24  			column("created_at") //
25  					.type(TIMESTAMP_WITH_TIMEZONE) //
26  					.notNull() //
27  					.build()),
28  
29  	USERS( //
30  			column("username") //
31  					.type(VARCHAR) //
32  					.size(255) //
33  					.notNull() //
34  					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
35  					.primaryKey() //
36  					.build(), //
37  			column("rolename") //
38  					.type(VARCHAR) //
39  					.size(255) //
40  					.regexp("[A-Z]+(_[A-Z0-9_])*") //
41  					.notNull() //
42  					.index() //
43  					.build(),
44  			column("preferred_lang") //
45  					.type(VARCHAR) //
46  					.size(10) //
47  					.regexp("[a-z]+") //
48  					.nullable() //
49  					.index() //
50  					.build(),
51  			column("preferred_timezone") //
52  					.type(VARCHAR) //
53  					.size(10) //
54  					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
55  					.nullable() //
56  					.index() //
57  					.build(),
58  			column("enabled") //
59  					.type(BOOLEAN) //
60  					.notNull() //
61  					.index() //
62  					.build(),
63  			column("created_at") //
64  					.type(TIMESTAMP_WITH_TIMEZONE) //
65  					.notNull() //
66  					.build(), //
67  			column("updated_at") //
68  					.type(TIMESTAMP_WITH_TIMEZONE) //
69  					.notNull() //
70  					.build(), //
71  			column("revision") //
72  					.type(INTEGER) //
73  					.notNull() //
74  					.build(), //
75  			column("last_active_at") //
76  					.type(TIMESTAMP_WITH_TIMEZONE) //
77  					.nullable() //
78  					.build()),
79  
80  	AUTH( //
81  			column("username") //
82  					.type(VARCHAR) //
83  					.size(255) //
84  					.notNull() //
85  					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
86  					.primaryKey() //
87  					.refKey(USERS, "username", true) //
88  					.build(), //
89  			column("password_salt") //
90  					.type(VARCHAR) //
91  					.size(255) //
92  					.notNull() //
93  					.regexp("[a-zA-Z0-9]*") //
94  					.build(),
95  			column("password_hash") //
96  					.type(VARCHAR) //
97  					.size(255) //
98  					.notNull() //
99  					.regexp("[a-zA-Z0-9]*") //
100 					.build()),
101 
102 	AUTH_SESSIONS( //
103 			column("user_session_id") //
104 					.type(VARCHAR) //
105 					.size(255) //
106 					.notNull() //
107 					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
108 					.primaryKey() //
109 					.build(), //
110 			column("username") //
111 					.type(VARCHAR) //
112 					.size(255) //
113 					.notNull() //
114 					.regexp("[a-zA-Z]+[a-zA-Z0-9-_]*") //
115 					.refKey(USERS, "username", true) //
116 					.build(), //
117 			column("created_at") //
118 					.type(TIMESTAMP_WITH_TIMEZONE) //
119 					.notNull() //
120 					.build(), //
121 			column("updated_at") //
122 					.type(TIMESTAMP_WITH_TIMEZONE) //
123 					.notNull() //
124 					.build(), //
125 			column("expires_at") //
126 					.type(TIMESTAMP_WITH_TIMEZONE) //
127 					.notNull() //
128 					.build(), //
129 			column("expired_at") //
130 					.type(TIMESTAMP_WITH_TIMEZONE) //
131 					.nullable() //
132 					.build());
133 
134 	private final Column[] columns;
135 
136 	private DbTables(final Column... columns) {
137 
138 		this.columns = columns;
139 	}
140 
141 	@Override
142 	public Column[] columns() {
143 
144 		return Arrays.copyOf(columns, columns.length);
145 	}
146 }