diff --git a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/TsurugiConnector.java b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/TsurugiConnector.java index 58703a11..03b13fe6 100755 --- a/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/TsurugiConnector.java +++ b/modules/iceaxe-core/src/main/java/com/tsurugidb/iceaxe/TsurugiConnector.java @@ -43,6 +43,19 @@ public static TsurugiConnector of(String endpoint) { return of(uri, NullCredential.INSTANCE, TgSessionOption.of()); } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, String endpoint) { + var uri = URI.create(endpoint); + return of(uri, NullCredential.INSTANCE, TgSessionOption.of()).setApplicationName(applicationName); + } + /** * create connector. * @@ -53,6 +66,18 @@ public static TsurugiConnector of(URI endpoint) { return of(endpoint, NullCredential.INSTANCE, TgSessionOption.of()); } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, URI endpoint) { + return of(endpoint, NullCredential.INSTANCE, TgSessionOption.of()).setApplicationName(applicationName); + } + /** * create connector. * @@ -65,6 +90,20 @@ public static TsurugiConnector of(String endpoint, Credential credential) { return of(uri, credential, TgSessionOption.of()); } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @param credential credential. if null, use NullCredential + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, String endpoint, Credential credential) { + var uri = URI.create(endpoint); + return of(uri, credential, TgSessionOption.of()).setApplicationName(applicationName); + } + /** * create connector. * @@ -76,6 +115,19 @@ public static TsurugiConnector of(URI endpoint, Credential credential) { return of(endpoint, credential, TgSessionOption.of()); } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @param credential credential. if null, use NullCredential + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, URI endpoint, Credential credential) { + return of(endpoint, credential, TgSessionOption.of()).setApplicationName(applicationName); + } + /** * create connector. * @@ -89,6 +141,21 @@ public static TsurugiConnector of(@Nonnull String endpoint, @Nullable Credential return of(uri, credential, sessionOption); } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @param credential credential. if null, use NullCredential + * @param sessionOption session option. if null, use new SessionOption instance + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, @Nonnull String endpoint, @Nullable Credential credential, @Nullable TgSessionOption sessionOption) { + var uri = URI.create(endpoint); + return of(uri, credential, sessionOption).setApplicationName(applicationName); + } + /** * create connector. * @@ -109,6 +176,20 @@ public static TsurugiConnector of(@Nonnull URI endpoint, @Nullable Credential cr return connector; } + /** + * create connector. + * + * @param applicationName application name + * @param endpoint the end-point URI + * @param credential credential. if null, use NullCredential + * @param sessionOption session option. if null, use new SessionOption instance + * @return connector + * @since X.X.X + */ + public static TsurugiConnector of(String applicationName, @Nonnull URI endpoint, @Nullable Credential credential, @Nullable TgSessionOption sessionOption) { + return of(endpoint, credential, sessionOption).setApplicationName(applicationName); + } + /** low connector */ protected final Connector lowConnector; private final URI endpoint; @@ -143,6 +224,10 @@ public URI getEndpoint() { return this.endpoint; } + Credential getCredential() { + return this.defaultCredential; + } + /** * get session option. * diff --git a/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/TsurugiConnectorTest.java b/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/TsurugiConnectorTest.java index 8a7eb6dd..8283539d 100755 --- a/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/TsurugiConnectorTest.java +++ b/modules/iceaxe-core/src/test/java/com/tsurugidb/iceaxe/TsurugiConnectorTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -19,6 +20,7 @@ import com.tsurugidb.iceaxe.test.low.TestLowSession; import com.tsurugidb.tsubakuro.channel.common.connection.Connector; import com.tsurugidb.tsubakuro.channel.common.connection.Credential; +import com.tsurugidb.tsubakuro.channel.common.connection.NullCredential; import com.tsurugidb.tsubakuro.channel.common.connection.UsernamePasswordCredential; import com.tsurugidb.tsubakuro.common.Session; import com.tsurugidb.tsubakuro.common.SessionBuilder; @@ -27,6 +29,144 @@ class TsurugiConnectorTest { + @Test + void of_endpointStr() { + String endpoint = "tcp://test:12345"; + var connector = TsurugiConnector.of(endpoint); + assertNull(connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(NullCredential.INSTANCE, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_name_endpointStr() { + String applicationName = "test-app"; + String endpoint = "tcp://test:12345"; + var connector = TsurugiConnector.of(applicationName, endpoint); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(NullCredential.INSTANCE, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_endpointUri() { + URI endpoint = URI.create("tcp://test:12345"); + var connector = TsurugiConnector.of(endpoint); + assertNull(connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(NullCredential.INSTANCE, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_name_endpointUri() { + String applicationName = "test-app"; + URI endpoint = URI.create("tcp://test:12345"); + var connector = TsurugiConnector.of(applicationName, endpoint); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(NullCredential.INSTANCE, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_endpointStr_credential() { + String endpoint = "tcp://test:12345"; + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var connector = TsurugiConnector.of(endpoint, credential); + assertNull(connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_name_endpointStr_credential() { + String applicationName = "test-app"; + String endpoint = "tcp://test:12345"; + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var connector = TsurugiConnector.of(applicationName, endpoint, credential); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_endpointUri_credential() { + URI endpoint = URI.create("tcp://test:12345"); + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var connector = TsurugiConnector.of(endpoint, credential); + assertNull(connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_name_endpointUri_credential() { + String applicationName = "test-app"; + URI endpoint = URI.create("tcp://test:12345"); + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var connector = TsurugiConnector.of(applicationName, endpoint, credential); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertNotNull(connector.getSessionOption()); + } + + @Test + void of_endpointStr_credential_option() { + String endpoint = "tcp://test:12345"; + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var sessionOption = TgSessionOption.of(); + var connector = TsurugiConnector.of(endpoint, credential, sessionOption); + assertNull(connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertSame(sessionOption, connector.getSessionOption()); + } + + @Test + void of_name_endpointStr_credential_option() { + String applicationName = "test-app"; + String endpoint = "tcp://test:12345"; + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var sessionOption = TgSessionOption.of(); + var connector = TsurugiConnector.of(applicationName, endpoint, credential, sessionOption); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(URI.create(endpoint), connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertSame(sessionOption, connector.getSessionOption()); + } + + @Test + void of_endpointUri_credential_option() { + URI endpoint = URI.create("tcp://test:12345"); + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var sessionOption = TgSessionOption.of(); + var connector = TsurugiConnector.of(endpoint, credential, sessionOption); + assertNull(connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertSame(sessionOption, connector.getSessionOption()); + } + + @Test + void of_name_endpointUri_credential_option() { + String applicationName = "test-app"; + URI endpoint = URI.create("tcp://test:12345"); + var credential = new UsernamePasswordCredential("test-user", "test-password"); + var sessionOption = TgSessionOption.of(); + var connector = TsurugiConnector.of(applicationName, endpoint, credential, sessionOption); + assertEquals(applicationName, connector.getApplicationName()); + assertEquals(endpoint, connector.getEndpoint()); + assertSame(credential, connector.getCredential()); + assertSame(sessionOption, connector.getSessionOption()); + } + @Test void getEndpoint() { var endpoint = URI.create("ipc:test"); diff --git a/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example01Connector.java b/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example01Connector.java index 6a2f3472..87fefd46 100755 --- a/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example01Connector.java +++ b/modules/iceaxe-examples/src/main/java/com/tsurugidb/iceaxe/example/Example01Connector.java @@ -19,13 +19,15 @@ static TsurugiConnector createConnector() { var endpoint = URI.create("tcp://localhost:12345"); var credential = Example01Credential.getCredential(); var connector = TsurugiConnector.of(endpoint, credential); +// var connector = TsurugiConnector.of("application-name", endpoint, credential); return connector; } - static TsurugiConnector createConnectorString() { + static TsurugiConnector createConnector_endpointString() { var endpoint = "tcp://localhost:12345"; var credential = Example01Credential.getCredential(); var connector = TsurugiConnector.of(endpoint, credential); +// var connector = TsurugiConnector.of("application-name", endpoint, credential); return connector; } @@ -42,6 +44,7 @@ static TsurugiConnector createConnectorWithSessionOption() { var credential = Example01Credential.getCredential(); var sessionOption = TgSessionOption.of().setTimeout(TgTimeoutKey.DEFAULT, 1, TimeUnit.MINUTES).setCommitType(TgCommitType.DEFAULT); var connector = TsurugiConnector.of(endpoint, credential, sessionOption); +// var connector = TsurugiConnector.of("application-name", endpoint, credential, sessionOption); return connector; } }