add source comments
@@ -6,9 +6,19 @@ | ||
6 | 6 | import java.sql.SQLException; |
7 | 7 | import java.util.Date; |
8 | 8 | |
9 | +/** | |
10 | + * Util for estoc db | |
11 | + */ | |
9 | 12 | public class DbmUtil { |
10 | 13 | private static final Object[] EMPTY_ARRAY = new Object[0]; |
11 | 14 | |
15 | + /** | |
16 | + * to csv string | |
17 | + * @param objects | |
18 | + * @param sep Object separator | |
19 | + * @param quote quoting String | |
20 | + * @return string | |
21 | + */ | |
12 | 22 | public static String toCommaString(Object[] objects, String sep, String quote) { |
13 | 23 | String qstr = ""; |
14 | 24 | if (quote != null) { |
@@ -24,6 +34,15 @@ | ||
24 | 34 | return sb.toString(); |
25 | 35 | } |
26 | 36 | |
37 | + | |
38 | + /** | |
39 | + * fill to TableObject from ResultSet | |
40 | + * @param <T> Class | |
41 | + * @param clz Table object | |
42 | + * @param result ResultSet | |
43 | + * @return filled object | |
44 | + * @throws SQLException | |
45 | + */ | |
27 | 46 | public static <T> T fillData(Class<T> clz, ResultSet result) throws SQLException { |
28 | 47 | try { |
29 | 48 | T instance = clz.newInstance(); |
@@ -46,6 +65,13 @@ | ||
46 | 65 | } |
47 | 66 | } |
48 | 67 | |
68 | + | |
69 | + /** | |
70 | + * Set value to Field | |
71 | + * @param obj target object | |
72 | + * @param info target column | |
73 | + * @param val set value | |
74 | + */ | |
49 | 75 | public static void setVlaueToField(Object obj, ColumnInfo info, Object val) { |
50 | 76 | String setter = getSetterName(info.getName()); |
51 | 77 | try { |
@@ -61,6 +87,12 @@ | ||
61 | 87 | } |
62 | 88 | } |
63 | 89 | |
90 | + /** | |
91 | + * Get value from Filed | |
92 | + * @param obj target object | |
93 | + * @param info target column | |
94 | + * @return filed value | |
95 | + */ | |
64 | 96 | public static Object getVlaueFromField(Object obj, ColumnInfo info) { |
65 | 97 | String getter = getGetterName(info.getName()); |
66 | 98 | Object rtn = null; |
@@ -13,15 +13,33 @@ | ||
13 | 13 | import estoc.dbm.annotate.Column; |
14 | 14 | import estoc.dbm.annotate.Table; |
15 | 15 | |
16 | +/** | |
17 | + * Table access class <br> | |
18 | + * create, drop | |
19 | + */ | |
16 | 20 | public abstract class TableAccess { |
17 | 21 | private final static Logger LOG = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); |
18 | 22 | |
23 | + /** | |
24 | + * Drop table | |
25 | + * @param clz Table class | |
26 | + * @throws SQLException | |
27 | + */ | |
19 | 28 | public abstract void drop(Class<?> clz) throws SQLException; |
20 | 29 | |
30 | + /** | |
31 | + * Create table | |
32 | + * @param clz Table class | |
33 | + * @throws SQLException | |
34 | + */ | |
21 | 35 | public abstract void create(Class<?> clz) throws SQLException; |
22 | 36 | |
23 | 37 | private final Connection connection; |
24 | 38 | |
39 | + /** | |
40 | + * constructor | |
41 | + * @param connection JDBC connection | |
42 | + */ | |
25 | 43 | public TableAccess(Connection connection) { |
26 | 44 | try { |
27 | 45 | if (connection == null || connection.isClosed()) { |
@@ -1,9 +1,31 @@ | ||
1 | 1 | package estoc.dbm; |
2 | 2 | |
3 | +/** | |
4 | + * Define supported database types | |
5 | + */ | |
3 | 6 | public enum DbType { |
7 | + /** | |
8 | + * H2<br> | |
9 | + * http://www.h2database.com/html/main.html | |
10 | + */ | |
4 | 11 | H2, |
12 | + /** | |
13 | + * Derby within JDK | |
14 | + */ | |
5 | 15 | Derby, |
16 | + /** | |
17 | + * Postgresql<br> | |
18 | + * http://www.postgresql.org/ | |
19 | + */ | |
6 | 20 | Postgresql, |
21 | + /** | |
22 | + * Mysql<br> | |
23 | + * http://www.mysql.com/ | |
24 | + */ | |
7 | 25 | Mysql, |
26 | + /** | |
27 | + * Oracle<br> | |
28 | + * http://www.oracle.com/ | |
29 | + */ | |
8 | 30 | Oracle |
9 | 31 | } |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * auto increment column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface AutoInc { |
@@ -6,7 +6,8 @@ | ||
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | 8 | /** |
9 | - * Pkとの併用はできません | |
9 | + * time stamp column | |
10 | + * this can't use with <see>Pk</see> | |
10 | 11 | */ |
11 | 12 | @Retention(RetentionPolicy.RUNTIME) |
12 | 13 | @Target(ElementType.FIELD) |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * unique column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface Unique { |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * index column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface Index { |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * Class as Table | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.TYPE) |
10 | 13 | public @interface Table { |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * primary key column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface Pk { |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * not null column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface NotNull { |
@@ -5,6 +5,9 @@ | ||
5 | 5 | import java.lang.annotation.RetentionPolicy; |
6 | 6 | import java.lang.annotation.Target; |
7 | 7 | |
8 | +/** | |
9 | + * Field as Table column | |
10 | + */ | |
8 | 11 | @Retention(RetentionPolicy.RUNTIME) |
9 | 12 | @Target(ElementType.FIELD) |
10 | 13 | public @interface Column { |
@@ -2,12 +2,46 @@ | ||
2 | 2 | |
3 | 3 | import java.sql.SQLException; |
4 | 4 | |
5 | +/** | |
6 | + * Data access class <br> | |
7 | + * ex. select, delete, insert, update | |
8 | + */ | |
5 | 9 | public interface DataAccess { |
10 | + | |
11 | + | |
12 | + /** | |
13 | + * Select the record | |
14 | + * @param <T> Class | |
15 | + * @param clz Table object | |
16 | + * @param pk conditions | |
17 | + * @return selected record or null if record not found | |
18 | + * @throws SQLException | |
19 | + */ | |
6 | 20 | public abstract <T> T select(Class<T> clz, Object... params) throws SQLException; |
7 | 21 | |
22 | + /** | |
23 | + * Delete the record | |
24 | + * @param obj TableClass | |
25 | + * @return true: if success, false:faild | |
26 | + * @throws SQLException | |
27 | + */ | |
8 | 28 | public abstract boolean delete(Object obj) throws SQLException; |
9 | 29 | |
30 | + /** | |
31 | + * Insert the record | |
32 | + * @param <T> Class | |
33 | + * @param obj Table object | |
34 | + * @return inserted record | |
35 | + * @throws SQLException | |
36 | + */ | |
10 | 37 | public abstract <T> T insert(T obj) throws SQLException; |
11 | 38 | |
39 | + /** | |
40 | + * Update the record | |
41 | + * @param <T> Class | |
42 | + * @param obj Table object | |
43 | + * @return updated record | |
44 | + * @throws SQLException | |
45 | + */ | |
12 | 46 | public abstract <T> T update(T obj) throws SQLException; |
13 | 47 | } |
\ No newline at end of file |
@@ -2,9 +2,16 @@ | ||
2 | 2 | |
3 | 3 | import java.sql.Connection; |
4 | 4 | |
5 | +/** | |
6 | + * Database accesser factory | |
7 | + */ | |
5 | 8 | public class AccessManager { |
6 | 9 | private final DbType dbType; |
7 | 10 | |
11 | + /** | |
12 | + * constructor | |
13 | + * @param dbType the type of Database | |
14 | + */ | |
8 | 15 | public AccessManager(DbType dbType) { |
9 | 16 | if (dbType == null) { |
10 | 17 | throw new IllegalArgumentException(); |
@@ -12,6 +19,11 @@ | ||
12 | 19 | this.dbType = dbType; |
13 | 20 | } |
14 | 21 | |
22 | + /** | |
23 | + * get DataAccess object | |
24 | + * @param connection JDBC connection | |
25 | + * @return | |
26 | + */ | |
15 | 27 | public DataAccess getDataAccess(Connection connection) { |
16 | 28 | SqlCreatorImpl creator = new SqlCreatorImpl(); |
17 | 29 | switch (dbType) { |
@@ -31,6 +43,11 @@ | ||
31 | 43 | } |
32 | 44 | } |
33 | 45 | |
46 | + /** | |
47 | + * get TableAccess object | |
48 | + * @param connection | |
49 | + * @return | |
50 | + */ | |
34 | 51 | public TableAccess getTableAccess(Connection connection) { |
35 | 52 | TableAccess tableAccess = null; |
36 | 53 | switch (dbType) { |
@@ -1,8 +1,8 @@ | ||
1 | 1 | <?xml version="1.0" encoding="Shift_JIS"?> |
2 | 2 | |
3 | -<project name="javahelloant" default="jar" basedir="."> | |
3 | +<project name="estocdb" default="jar" basedir="."> | |
4 | 4 | |
5 | - <property name="release.version" value="0.3"/> | |
5 | + <property name="release.version" value="0.4"/> | |
6 | 6 | |
7 | 7 | <!-- property --> |
8 | 8 | <property name="src.dir" value="src"/> |