Skip to content

Commit 2e4006e

Browse files
Denzel CodeDenzel Code
authored andcommitted
Code documentation added
1 parent ec64696 commit 2e4006e

27 files changed

Lines changed: 490 additions & 49 deletions

src/main/java/advancedsql/ISQL.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,38 @@
1111

1212
public interface ISQL {
1313

14+
/**
15+
* Prepare SQL query.
16+
* @param query Query object that you want to prepare.
17+
* @return A PreparedStatement object.
18+
* @throws SQLException Exception when something goes wrong.
19+
*/
1420
PreparedStatement prepare(IQuery query) throws SQLException;
1521

22+
/**
23+
* Get access to a table object to modify information.
24+
* @param name Name of the table.
25+
* @return A Table object which allows you to execute SQL query's.
26+
*/
1627
ITable table(String name);
1728

29+
/**
30+
* Get connection state.
31+
* @return true if connected, false if not.
32+
*/
1833
boolean isConnected();
1934

35+
/**
36+
* @return Connection Object.
37+
*/
2038
Connection getConnection();
2139

40+
/**
41+
* Convert a ResultSet into a list.
42+
* @param resultSet Result set
43+
* @return Returns a list of map with the column name and value.
44+
* @throws SQLException Exception when something goes wrong.
45+
*/
2246
static List<Map<String, Object>> convertResultSetToList(ResultSet resultSet) throws SQLException {
2347
ResultSetMetaData metaData = resultSet.getMetaData();
2448

@@ -37,6 +61,12 @@ static List<Map<String, Object>> convertResultSetToList(ResultSet resultSet) thr
3761
return list;
3862
}
3963

64+
/**
65+
* Set statement parameters.
66+
* @param statement Statement to modify.
67+
* @param execute Parameters to assign.
68+
* @throws SQLException Exception when something goes wrong.
69+
*/
4070
static void setStatementParameters(PreparedStatement statement, List<Object> execute) throws SQLException {
4171
for (int i = 0; i < execute.size(); i++) {
4272
Object value = execute.get(i);

src/main/java/advancedsql/MySQL.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88

99
public class MySQL extends SQL {
1010

11+
/**
12+
* Create MySQL connection.
13+
* Do not worry about creating the database, AdvancedSQL takes care of it for you.
14+
* @param host MySQL server host.
15+
* @param port MySQL server port.
16+
* @param username MySQL server username.
17+
* @param password MySQL server password.
18+
* @param database MySQL server database. If not exists AdvancedSQL creates it for you.
19+
* @throws SQLException Exception when something goes wrong.
20+
*/
1121
public MySQL(String host, int port, String username, String password, String database) throws SQLException {
1222
try {
1323
Class.forName("com.mysql.cj.jdbc.Driver");

src/main/java/advancedsql/query/Alter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ public Alter(ITable table) {
1616
super(table);
1717
}
1818

19+
/**
20+
* @return "Drop" Object that allows you to specify the columns that you want to drop.
21+
*/
1922
public advancedsql.query.action.Drop drop() {
2023
return drop;
2124
}
2225

26+
/**
27+
* @return "Modify" Object that allows you to specify the columns that you want to modify.
28+
*/
2329
public advancedsql.query.action.Modify modify() {
2430
return modify;
2531
}
2632

33+
/**
34+
* @return "Add" Object that allows you to specify the columns that you want to add.
35+
*/
2736
public advancedsql.query.action.Add add() {
2837
return add;
2938
}

src/main/java/advancedsql/query/ExecuteQuery.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public PreparedStatement executePrepare() throws SQLException {
2424
return this.prepare;
2525
}
2626

27+
/**
28+
* @return A Map of the first result found.
29+
* @throws SQLException Exception when something goes wrong.
30+
*/
2731
public Map<String, Object> fetch() throws SQLException {
2832
this.limit(1);
2933

@@ -48,16 +52,29 @@ public Map<String, Object> fetch() throws SQLException {
4852
return map;
4953
}
5054

55+
/**
56+
* @return ResultSet of all the results found.
57+
* @throws SQLException Exception when something goes wrong.
58+
*/
5159
public ResultSet fetchAll() throws SQLException {
5260
return execute();
5361
}
5462

63+
/**
64+
* @return A List of all the results found.
65+
* @throws SQLException Exception when something goes wrong.
66+
*/
5567
public List<Map<String, Object>> fetchAllAsList() throws SQLException {
5668
ResultSet resultSet = this.fetchAll();
5769

5870
return ISQL.convertResultSetToList(resultSet);
5971
}
6072

73+
/**
74+
* Execute query.
75+
* @return A ResultSet of all the results found.
76+
* @throws SQLException Exception when something goes wrong.
77+
*/
6178
public ResultSet execute() throws SQLException {
6279
return this.executeQuery();
6380
}

src/main/java/advancedsql/query/ExecuteStatement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public PreparedStatement executePrepare() throws SQLException {
1818
return this.prepare;
1919
}
2020

21+
/**
22+
* Execute query.
23+
* @return A boolean.
24+
* @throws SQLException Exception when something goes wrong.
25+
*/
2126
public Boolean execute() throws SQLException {
2227
return this.executeStatement();
2328
}

src/main/java/advancedsql/query/ExecuteUpdate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public PreparedStatement executePrepare() throws SQLException {
2020
return this.prepare;
2121
}
2222

23+
/**
24+
* Execute the query.
25+
* @return An integer.
26+
* @throws SQLException Exception when something goes wrong.
27+
*/
2328
public int execute() throws SQLException {
2429
return this.executeUpdate();
2530
}

src/main/java/advancedsql/query/IQuery.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,69 @@
66

77
public interface IQuery {
88

9+
/**
10+
* Specify what values will be affected for example:
11+
* query.where("first_name = ? AND last_name = ?", "Denzel", "Code");
12+
* @param where Where statement.
13+
* @param execute Values of the statement.
14+
* @return Query object.
15+
*/
916
IQuery where(String where, Object... execute);
1017

18+
/**
19+
* Specify what values will be affected for example:
20+
* query.where("first_name = 'Denzel' AND last_name = 'Code'");
21+
* @param where Where statement.
22+
* @return Query object.
23+
*/
1124
IQuery where(String where);
1225

26+
/**
27+
* Execute query and return a boolean.
28+
* Recommended for: CREATE, ALTER, DROP, TRUNCATE.
29+
* @return boolean.
30+
* @throws SQLException Exception when something goes wrong.
31+
*/
1332
Boolean executeStatement() throws SQLException;
1433

34+
/**
35+
* Execute query and return an integer.
36+
* Recommended for: INSERT, UPDATE, DELETE.
37+
* @return integer.
38+
* @throws SQLException Exception when something goes wrong.
39+
*/
1540
int executeUpdate() throws SQLException;
1641

42+
/**
43+
* Execute query and return a ResultSet.
44+
* Recommended for: SELECT, SHOW.
45+
* @return ResultSet.
46+
* @throws SQLException Exception when something goes wrong.
47+
*/
1748
ResultSet executeQuery() throws SQLException;
1849

50+
/**
51+
* Execute query and return a PreparedStatement.
52+
* Recommended for: General.
53+
* @return PreparedStatement.
54+
* @throws SQLException Exception when something goes wrong.
55+
*/
1956
PreparedStatement executePrepare() throws SQLException;
2057

58+
/**
59+
* Get PreparedStatement of the query.
60+
* This just works if you already executed the query.
61+
* @return PreparedStatement.
62+
*/
63+
PreparedStatement getPrepare();
64+
65+
/**
66+
* @return String representation of the Query.
67+
*/
2168
String toQuery();
69+
70+
/**
71+
* @return String representation of the Query.
72+
*/
73+
String toString();
2274
}

src/main/java/advancedsql/query/Insert.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ public Insert(ITable table) {
2020
public Insert(ITable table, Map<String, Object> fields) {
2121
super(table);
2222

23-
this.setFields(fields);
23+
this.fields(fields);
2424
}
2525

26-
public Insert setField(String field, Object value) {
26+
/**
27+
* Columns and values that you want to insert.
28+
* @param field Column name
29+
* @param value Row value
30+
* @return Query object.
31+
*/
32+
public Insert field(String field, Object value) {
2733
this.fields.add(field);
2834

2935
this.values.add(value);
@@ -33,20 +39,17 @@ public Insert setField(String field, Object value) {
3339
return this;
3440
}
3541

36-
public Insert field(String field, Object value) {
37-
return this.setField(field, value);
38-
}
39-
40-
public Insert setFields(Map<String, Object> values) {
41-
for (Map.Entry<String, Object> entry: values.entrySet()) this.setField(entry.getKey(), entry.getValue());
42+
/**
43+
* Columns and values that you want to insert.
44+
* @param values Map
45+
* @return Query object.
46+
*/
47+
public Insert fields(Map<String, Object> values) {
48+
for (Map.Entry<String, Object> entry: values.entrySet()) this.field(entry.getKey(), entry.getValue());
4249

4350
return this;
4451
}
4552

46-
public Insert fields(Map<String, Object> values) {
47-
return this.setFields(values);
48-
}
49-
5053
@Override
5154
public String toQuery() {
5255
StringBuilder query = new StringBuilder("INSERT INTO " + this.table + " (");

src/main/java/advancedsql/query/Query.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@ public Query(ITable table) {
3232
this.table = table.getName();
3333
}
3434

35-
public T setLimit(int limit) {
35+
/**
36+
* Assign the limit of rows to be affected.
37+
* @param limit Limit amount.
38+
* @return Query object.
39+
*/
40+
public T limit(int limit) {
3641
this.limit = limit;
3742

3843
return (T)this;
3944
}
4045

41-
public T limit(int limit) {
42-
return this.setLimit(limit);
43-
}
44-
46+
/**
47+
* @return Limit of rows to be affected.
48+
*/
4549
public int getLimit() {
4650
return this.limit;
4751
}

0 commit comments

Comments
 (0)