88import me .zort .sqllib .internal .factory .SQLConnectionFactory ;
99import me .zort .sqllib .internal .impl .DefaultSQLEndpoint ;
1010import me .zort .sqllib .internal .impl .SQLEndpointImpl ;
11+ import org .jetbrains .annotations .NotNull ;
1112import org .jetbrains .annotations .Nullable ;
1213
1314import java .sql .Connection ;
1617import java .util .Objects ;
1718import java .util .Optional ;
1819
19- public class SQLConnectionBuilder {
20+ public final class SQLConnectionBuilder implements Cloneable {
2021
21- public static SQLConnectionBuilder of (String address , int port , String database , String username , String password ) {
22+ public static @ NotNull SQLConnectionBuilder of (String address , int port , String database , String username , String password ) {
2223 return of (new DefaultSQLEndpoint (address + ":" + port , database , username , password ));
2324 }
2425
25- public static SQLConnectionBuilder of (String jdbc , String username , String password ) {
26+ public static @ NotNull SQLConnectionBuilder of (String jdbc , String username , String password ) {
2627 return of (new SQLEndpointImpl (jdbc , username , password ));
2728 }
2829
29- public static SQLConnectionBuilder ofSQLite (String path ) {
30+ public static @ NotNull SQLConnectionBuilder ofSQLite (String path ) {
3031 SQLConnectionBuilder builder = of (new SQLEndpointImpl ("jdbc:sqlite:" + path , null , null ));
3132 builder .withDriver ("org.sqlite.JDBC" );
3233 return builder ;
@@ -43,28 +44,28 @@ public static SQLConnectionBuilder of(SQLEndpoint endpoint) {
4344 private String jdbc ;
4445 private String driver = null ;
4546
46- public SQLConnectionBuilder (String address , int port , String database , String username , String password ) {
47- this (new DefaultSQLEndpoint (address + ":" + port , database , username , password ));
48- }
49-
5047 public SQLConnectionBuilder () {
5148 this (null );
5249 }
5350
51+ public SQLConnectionBuilder (@ NotNull String address , int port , @ NotNull String database , @ Nullable String username , @ Nullable String password ) {
52+ this (new DefaultSQLEndpoint (address + ":" + port , database , username , password ));
53+ }
54+
5455 public SQLConnectionBuilder (@ Nullable SQLEndpoint endpoint ) {
5556 this .endpoint = endpoint ;
5657 this .jdbc = endpoint != null
5758 ? endpoint .buildJdbc ()
5859 : null ;
5960 }
6061
61- public SQLConnectionBuilder withEndpoint (SQLEndpoint endpoint ) {
62+ public @ NotNull SQLConnectionBuilder withEndpoint (SQLEndpoint endpoint ) {
6263 this .endpoint = endpoint ;
6364 this .jdbc = endpoint .buildJdbc ();
6465 return this ;
6566 }
6667
67- public SQLConnectionBuilder withParam (String key , String value ) {
68+ public @ NotNull SQLConnectionBuilder withParam (String key , String value ) {
6869 Optional .ofNullable (endpoint )
6970 .ifPresent (endpoint -> {
7071 jdbc += (jdbc .contains ("?" ) ? "&" : "?" );
@@ -73,20 +74,20 @@ public SQLConnectionBuilder withParam(String key, String value) {
7374 return this ;
7475 }
7576
76- public SQLConnectionBuilder withDriver (String driver ) {
77+ public @ NotNull SQLConnectionBuilder withDriver (String driver ) {
7778 this .driver = driver ;
7879 return this ;
7980 }
8081
81- public SQLDatabaseConnection build () {
82+ public @ NotNull SQLDatabaseConnection build () {
8283 return build (null );
8384 }
8485
85- public SQLDatabaseConnection build (@ Nullable SQLDatabaseOptions options ) {
86+ public @ NotNull SQLDatabaseConnection build (@ Nullable SQLDatabaseOptions options ) {
8687 return build (driver , options );
8788 }
8889
89- public SQLDatabaseConnection build (@ Nullable String driver , @ Nullable SQLDatabaseOptions options ) {
90+ public @ NotNull SQLDatabaseConnection build (@ Nullable String driver , @ Nullable SQLDatabaseOptions options ) {
9091 Objects .requireNonNull (endpoint , "Endpoint must be set!" );
9192 Objects .requireNonNull (jdbc );
9293 if (driver == null ) {
@@ -100,6 +101,11 @@ public SQLDatabaseConnection build(@Nullable String driver, @Nullable SQLDatabas
100101 }
101102 }
102103
104+ @ Override
105+ protected SQLConnectionBuilder clone () throws CloneNotSupportedException {
106+ return (SQLConnectionBuilder ) super .clone ();
107+ }
108+
103109 @ RequiredArgsConstructor
104110 public static class BuilderSQLConnectionFactory implements SQLConnectionFactory {
105111
0 commit comments