|
42 | 42 | */ |
43 | 43 | public final class MySqlConnectionFactory implements ConnectionFactory { |
44 | 44 |
|
45 | | - private final Mono<? extends MySqlConnection> client; |
| 45 | + private final MySqlConnectionConfiguration configuration; |
| 46 | + private final LazyQueryCache queryCache; |
46 | 47 |
|
47 | | - private MySqlConnectionFactory(Mono<? extends MySqlConnection> client) { |
48 | | - this.client = client; |
| 48 | + private MySqlConnectionFactory(MySqlConnectionConfiguration configuration) { |
| 49 | + this.configuration = configuration; |
| 50 | + this.queryCache = new LazyQueryCache(configuration.getQueryCacheSize()); |
49 | 51 | } |
50 | 52 |
|
51 | 53 | @Override |
52 | 54 | public Mono<? extends MySqlConnection> create() { |
53 | | - return client; |
54 | | - } |
55 | | - |
56 | | - @Override |
57 | | - public ConnectionFactoryMetadata getMetadata() { |
58 | | - return MySqlConnectionFactoryMetadata.INSTANCE; |
59 | | - } |
| 55 | + MySqlSslConfiguration ssl; |
| 56 | + SocketAddress address; |
60 | 57 |
|
61 | | - /** |
62 | | - * Creates a {@link MySqlConnectionFactory} with a {@link MySqlConnectionConfiguration}. |
63 | | - * |
64 | | - * @param configuration the {@link MySqlConnectionConfiguration}. |
65 | | - * @return configured {@link MySqlConnectionFactory}. |
66 | | - */ |
67 | | - public static MySqlConnectionFactory from(MySqlConnectionConfiguration configuration) { |
68 | | - requireNonNull(configuration, "configuration must not be null"); |
69 | | - |
70 | | - LazyQueryCache queryCache = new LazyQueryCache(configuration.getQueryCacheSize()); |
71 | | - |
72 | | - return new MySqlConnectionFactory(Mono.defer(() -> { |
73 | | - MySqlSslConfiguration ssl; |
74 | | - SocketAddress address; |
75 | | - |
76 | | - if (configuration.isHost()) { |
77 | | - ssl = configuration.getSsl(); |
78 | | - address = InetSocketAddress.createUnresolved(configuration.getDomain(), |
| 58 | + if (configuration.isHost()) { |
| 59 | + ssl = configuration.getSsl(); |
| 60 | + address = InetSocketAddress.createUnresolved(configuration.getDomain(), |
79 | 61 | configuration.getPort()); |
80 | | - } else { |
81 | | - ssl = MySqlSslConfiguration.disabled(); |
82 | | - address = new DomainSocketAddress(configuration.getDomain()); |
83 | | - } |
| 62 | + } else { |
| 63 | + ssl = MySqlSslConfiguration.disabled(); |
| 64 | + address = new DomainSocketAddress(configuration.getDomain()); |
| 65 | + } |
84 | 66 |
|
85 | | - String user = configuration.getUser(); |
86 | | - CharSequence password = configuration.getPassword(); |
87 | | - Publisher<String> passwordPublisher = configuration.getPasswordPublisher(); |
| 67 | + String user = configuration.getUser(); |
| 68 | + CharSequence password = configuration.getPassword(); |
| 69 | + Publisher<String> passwordPublisher = configuration.getPasswordPublisher(); |
88 | 70 |
|
89 | | - if (Objects.nonNull(passwordPublisher)) { |
90 | | - return Mono.from(passwordPublisher).flatMap(token -> getMySqlConnection( |
| 71 | + if (Objects.nonNull(passwordPublisher)) { |
| 72 | + return Mono.from(passwordPublisher).flatMap(token -> getMySqlConnection( |
91 | 73 | configuration, ssl, |
92 | 74 | queryCache, |
93 | 75 | address, |
94 | 76 | user, |
95 | 77 | token |
96 | | - )); |
97 | | - } |
| 78 | + )); |
| 79 | + } |
98 | 80 |
|
99 | | - return getMySqlConnection( |
| 81 | + return getMySqlConnection( |
100 | 82 | configuration, ssl, |
101 | 83 | queryCache, |
102 | 84 | address, |
103 | 85 | user, |
104 | 86 | password |
105 | | - ); |
106 | | - })); |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public ConnectionFactoryMetadata getMetadata() { |
| 92 | + return MySqlConnectionFactoryMetadata.INSTANCE; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Creates a {@link MySqlConnectionFactory} with a {@link MySqlConnectionConfiguration}. |
| 97 | + * |
| 98 | + * @param configuration the {@link MySqlConnectionConfiguration}. |
| 99 | + * @return configured {@link MySqlConnectionFactory}. |
| 100 | + */ |
| 101 | + public static MySqlConnectionFactory from(MySqlConnectionConfiguration configuration) { |
| 102 | + requireNonNull(configuration, "configuration must not be null"); |
| 103 | + return new MySqlConnectionFactory(configuration); |
107 | 104 | } |
108 | 105 |
|
109 | 106 | /** |
|
0 commit comments