Skip to content

Commit 9692339

Browse files
Denzel CodeDenzel Code
authored andcommitted
Documentation and Action abstraction.
1 parent 07197ea commit 9692339

12 files changed

Lines changed: 292 additions & 56 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/advancedsql/MySQL.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,16 @@
66

77
public class MySQL extends SQL {
88

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

23-
this.connect(host, port, username, password, database);
13+
this.connect(host, port, username, password, database, attributes);
2414
} catch (SQLException e) {
2515
if (e.getErrorCode() == 1049) {
2616
createDatabase(host, port, username, password, database);
2717

28-
connect(host, port, username, password, database);
18+
connect(host, port, username, password, database, attributes);
2919

3020
return;
3121
}
@@ -38,14 +28,28 @@ public MySQL(String host, int port, String username, String password, String dat
3828
}
3929
}
4030

41-
private void connect(String host, int port, String username, String password, String database) throws SQLException {
42-
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", username, password);
31+
/**
32+
* Create MySQL connection.
33+
* Do not worry about creating the database, AdvancedSQL takes care of it for you.
34+
* @param host MySQL server host.
35+
* @param port MySQL server port.
36+
* @param username MySQL server username.
37+
* @param password MySQL server password.
38+
* @param database MySQL server database. If not exists AdvancedSQL creates it for you.
39+
* @throws SQLException Exception when something goes wrong.
40+
*/
41+
public MySQL(String host, int port, String username, String password, String database) throws SQLException {
42+
this(host, port, username, password, database, "useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
43+
}
44+
45+
private void connect(String host, int port, String username, String password, String database, String attributes) throws SQLException {
46+
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + (attributes.isEmpty() ? "" : "?" + attributes), username, password);
4347

4448
this.connected = true;
4549
}
4650

4751
private void createDatabase(String host, int port, String username, String password, String database) throws SQLException {
48-
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", username, password);
52+
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "?", username, password);
4953

5054
Statement statement = connection.createStatement();
5155

src/main/java/advancedsql/query/Select.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Select(ITable table, String[] columns) {
2424
}
2525

2626
public Select(ITable table) {
27-
super(table);
27+
this(table, new String[]{"*"});
2828
}
2929

3030
/**

src/main/java/advancedsql/query/action/Action.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,10 @@
66
import java.util.ArrayList;
77
import java.util.List;
88

9-
public abstract class Action implements IAction<IColumn> {
9+
public abstract class Action implements IAction<IColumn>, IActionColumns {
1010

1111
protected List<IColumn> columns = new ArrayList<>();
1212

13-
/**
14-
* Create a primary column with auto incremented.
15-
* Example: int(11) PRIMARY KEY AUTO_INCREMENT
16-
*
17-
* @return advancedsql.query.column.Integer
18-
*/
1913
public advancedsql.query.column.Integer id(String name) {
2014
advancedsql.query.column.Integer column = this.integer(name);
2115

@@ -24,6 +18,11 @@ public advancedsql.query.column.Integer id(String name) {
2418
return column;
2519
}
2620

21+
/**
22+
* Create a column with type BIGINT.
23+
* @param name Name of the column.
24+
* @return
25+
*/
2726
public advancedsql.query.column.BigInteger bigInteger(String name) {
2827
return this.bigInteger(name, 0);
2928
}
@@ -192,12 +191,6 @@ public advancedsql.query.column.Double doubleColumn(String name) {
192191
return this.doubleColumn(name, 11, 8);
193192
}
194193

195-
/**
196-
* Create a primary column named "id" with auto incremented.
197-
* Example: int(11) PRIMARY KEY AUTO_INCREMENT
198-
*
199-
* @return advancedsql.query.column.Integer
200-
*/
201194
public advancedsql.query.column.Integer id() {
202195
return this.id("id");
203196
}

src/main/java/advancedsql/query/action/IAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ public interface IAction<T> {
1515
* @return Action prefix.
1616
*/
1717
java.lang.String getPrefix();
18-
19-
java.lang.String toString();
2018
}

0 commit comments

Comments
 (0)