Skip to content

Commit

Permalink
JDBC-520 Support jdbc:firebird: as protocol prefix for all driver types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Jul 21, 2018
1 parent eadbb71 commit f39d754
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 28 deletions.
30 changes: 29 additions & 1 deletion src/documentation/release_notes.md
Expand Up @@ -477,7 +477,7 @@ authentication plugin by implementing the interfaces
- `org.firebirdsql.gds.ng.wire.auth.AuthenticationPluginSpi`
- `org.firebirdsql.gds.ng.wire.auth.AuthenticationPlugin`

The SPI implementation needs to listed in `META-INF/services/org.firebirdsql.gds.ng.wire.auth.AuthenticationPluginSpi`
The SPI implementation needs to be listed in `META-INF/services/org.firebirdsql.gds.ng.wire.auth.AuthenticationPluginSpi`
in your jar.

This support is experimental and comes with a number of caveats:
Expand Down Expand Up @@ -843,6 +843,34 @@ as is, in current Firebird versions, this means the value will be equivalent to
scale) are passed as is to cast, resulting in an error from the Firebird engine
if the resulting cast is invalid

New JDBC protocol prefix jdbc:firebird:
---------------------------------------

Historically, the JDBC protocols supported by Jaybird have used the prefix
`jdbc:firebirdsql:`. We have now added support for `jdbc:firebird:` as an
alternative prefix. This prefix was previously only supported in the
OpenOffice.org/LibreOffice pure Java variant.

Jaybird now supports the following URL prefixes (or JDBC protocols):

- Pure Java
- `jdbc:firebirdsql:`
- `jdbc:firebirdsql:java`
- `jdbc:firebird:` (new)
- `jdbc:firebird:java:` (new)
- Native
- `jdbc:firebirdsql:native:`
- `jdbc:firebird:native:` (new)
- Embedded
- `jdbc:firebirdsql:embedded:`
- `jdbc:firebird:embedded:` (new)
- Local
- `jdbc:firebirdsql:local:`
- `jdbc:firebird:local:` (new)
- OpenOffice.org/LibreOffice pure Java variant
- `jdbc:firebird:oo:`
- `jdbc:firebirdsql:oo:`

Potentially breaking changes
----------------------------

Expand Down
9 changes: 5 additions & 4 deletions src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaDatabase.java
Expand Up @@ -41,9 +41,11 @@
import java.sql.SQLException;

import static org.firebirdsql.common.FBTestProperties.*;
import static org.firebirdsql.common.matchers.GdsTypeMatchers.isEmbeddedType;
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.*;
import static org.firebirdsql.util.FirebirdSupportInfo.supportInfoFor;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.isOneOf;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -115,7 +117,7 @@ public void doubleAttach() throws Exception {
@Test
public void basicStatusVectorProcessing_wrongLogin() throws Exception {
assumeThat("Embedded on windows does not use authentication",
FBTestProperties.GDS_TYPE, is(not(EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME)));
FBTestProperties.GDS_TYPE, not(isEmbeddedType()));
// set invalid password
connectionInfo.setPassword("abcd");
try (JnaDatabase db = factory.connect(connectionInfo)) {
Expand Down Expand Up @@ -266,9 +268,8 @@ public void testDetach_openTransactions() throws Exception {
public void testCancelOperation_abortSupported() throws Exception {
// TODO Investigate why this doesn't work.
assumeThat("Test doesn't work with local or embedded protocol",
FBTestProperties.GDS_TYPE, allOf(
not(equalTo(LocalGDSFactoryPlugin.LOCAL_TYPE_NAME)),
not(equalTo(EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME))));
FBTestProperties.GDS_TYPE, not(
isOneOf(LocalGDSFactoryPlugin.LOCAL_TYPE_NAME, EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME)));

FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
Expand Down
4 changes: 2 additions & 2 deletions src/jna-test/org/firebirdsql/gds/ng/jna/TestJnaService.java
Expand Up @@ -23,7 +23,6 @@
import org.firebirdsql.gds.ISCConstants;
import org.firebirdsql.gds.ServiceRequestBuffer;
import org.firebirdsql.gds.impl.GDSServerVersion;
import org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin;
import org.firebirdsql.gds.ng.FbServiceProperties;
import org.firebirdsql.management.FBManager;
import org.firebirdsql.management.FBStatisticsManager;
Expand All @@ -36,6 +35,7 @@
import java.sql.SQLException;

import static org.firebirdsql.common.FBTestProperties.*;
import static org.firebirdsql.common.matchers.GdsTypeMatchers.isEmbeddedType;
import static org.firebirdsql.common.matchers.SQLExceptionMatchers.*;
import static org.firebirdsql.gds.ISCConstants.*;
import static org.firebirdsql.gds.VaxEncoding.iscVaxInteger2;
Expand Down Expand Up @@ -98,7 +98,7 @@ public void doubleAttach() throws Exception {
@Test
public void basicStatusVectorProcessing_wrongLogin() throws Exception {
assumeThat("Embedded on windows does not use authentication",
FBTestProperties.GDS_TYPE, is(not(EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME)));
FBTestProperties.GDS_TYPE, not(isEmbeddedType()));
// set invalid password
connectionInfo.setPassword("abcd");
try (JnaService service = factory.serviceConnect(connectionInfo)) {
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class EmbeddedGDSFactoryPlugin extends BaseGDSFactoryPlugin {
private static final String[] TYPE_ALIASES = new String[0];

private static final String[] JDBC_PROTOCOLS = new String[] {
"jdbc:firebirdsql:embedded:"
"jdbc:firebirdsql:embedded:", "jdbc:firebird:embedded:"
};

public String getPluginName() {
Expand All @@ -48,8 +48,11 @@ public String[] getSupportedProtocols() {
return JDBC_PROTOCOLS;
}

public String getDatabasePath(String server, Integer port, String path)
throws GDSException {
public String getDatabasePath(String server, Integer port, String path) throws GDSException {
if (path == null) {
throw new GDSException("Database name/path is required.");
}

return path;
}

Expand Down
11 changes: 8 additions & 3 deletions src/main/org/firebirdsql/gds/impl/jni/LocalGDSFactoryPlugin.java
Expand Up @@ -28,10 +28,11 @@ public class LocalGDSFactoryPlugin extends BaseGDSFactoryPlugin {

private static final String[] TYPE_ALIASES = new String[0];
private static final String[] JDBC_PROTOCOLS = new String[] {
"jdbc:firebirdsql:local:"};
"jdbc:firebirdsql:local:", "jdbc:firebird:local:"
};

public String getPluginName() {
return "JNI-based GDS implementation using IPC communication.";
return "JNA-based GDS implementation using IPC communication.";
}

public String getTypeName() {
Expand All @@ -46,7 +47,11 @@ public String[] getSupportedProtocols() {
return JDBC_PROTOCOLS;
}

public String getDatabasePath(String server, Integer port, String path) throws GDSException{
public String getDatabasePath(String server, Integer port, String path) throws GDSException {
if (path == null) {
throw new GDSException("Database name/path is required.");
}

return path;
}

Expand Down
21 changes: 12 additions & 9 deletions src/main/org/firebirdsql/gds/impl/jni/NativeGDSFactoryPlugin.java
Expand Up @@ -26,11 +26,13 @@ public class NativeGDSFactoryPlugin extends BaseGDSFactoryPlugin {

public static final String NATIVE_TYPE_NAME = "NATIVE";

private static final String[] TYPE_ALIASES = new String[]{"TYPE2"};
private static final String[] JDBC_PROTOCOLS = new String[]{"jdbc:firebirdsql:native:"};
private static final String[] TYPE_ALIASES = new String[] { "TYPE2" };
private static final String[] JDBC_PROTOCOLS = new String[] {
"jdbc:firebirdsql:native:", "jdbc:firebird:native:"
};

public String getPluginName() {
return "JNI-based GDS implementation.";
return "JNA-based GDS implementation.";
}

public String getTypeName() {
Expand All @@ -46,18 +48,19 @@ public String[] getSupportedProtocols() {
}

public String getDatabasePath(String server, Integer port, String path) throws GDSException{
if (server == null)
throw new GDSException("Server name/address is required " +
"for native implementation.");

if (path == null)
if (server == null) {
throw new GDSException("Server name/address is required for native implementation.");
}
if (path == null) {
throw new GDSException("Database name/path is required.");
}

StringBuilder sb = new StringBuilder();

sb.append(server);
if (port != null)
if (port != null) {
sb.append('/').append(port.intValue());
}

sb.append(':').append(path);

Expand Down
Expand Up @@ -27,7 +27,9 @@ public class WireGDSFactoryPlugin extends BaseGDSFactoryPlugin {
public static final String PURE_JAVA_TYPE_NAME = "PURE_JAVA";
private static final String[] TYPE_ALIASES = new String[] { "TYPE4" };
private static final String DEFAULT_PROTOCOL = "jdbc:firebirdsql:";
private static final String[] JDBC_PROTOCOLS = new String[] { "jdbc:firebirdsql:java:", DEFAULT_PROTOCOL };
private static final String[] JDBC_PROTOCOLS = new String[] {
"jdbc:firebirdsql:java:", "jdbc:firebird:java:", "jdbc:firebird:", DEFAULT_PROTOCOL
};

@Override
public String getPluginName() {
Expand All @@ -51,7 +53,7 @@ public String[] getSupportedProtocols() {

@Override
public String getDefaultProtocol() {
return "jdbc:firebirdsql:";
return DEFAULT_PROTOCOL;
}

@Override
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class OOGDSFactoryPlugin extends BaseGDSFactoryPlugin {
private static final String[] JDBC_PROTOCOLS = new String[] { "jdbc:firebird:oo:", "jdbc:firebirdsql:oo:"};

public String getPluginName() {
return "GDS implementation for OpenOffice.";
return "GDS implementation for OpenOffice.org/LibreOffice.";
}

public String getTypeName() {
Expand All @@ -53,11 +53,12 @@ public String[] getSupportedProtocols() {
}

public String getDatabasePath(String server, Integer port, String path) throws GDSException {
if (server == null)
if (server == null) {
throw new GDSException("Server name/address is required for pure Java implementation.");

if (path == null)
}
if (path == null) {
throw new GDSException("Database name/path is required.");
}

StringBuilder sb = new StringBuilder();

Expand Down
68 changes: 68 additions & 0 deletions src/test/org/firebirdsql/common/matchers/GdsTypeMatchers.java
@@ -0,0 +1,68 @@
/*
* Firebird Open Source JavaEE Connector - JDBC Driver
*
* Distributable under LGPL license.
* You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* LGPL License for more details.
*
* This file was created by members of the firebird development team.
* All individual contributions remain the Copyright (C) of those
* individuals. Contributors to this file are either listed here or
* can be obtained from a source control history command.
*
* All rights reserved.
*/
package org.firebirdsql.common.matchers;

import org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin;
import org.firebirdsql.gds.impl.jni.LocalGDSFactoryPlugin;
import org.firebirdsql.gds.impl.jni.NativeGDSFactoryPlugin;
import org.firebirdsql.gds.impl.oo.OOGDSFactoryPlugin;
import org.firebirdsql.gds.impl.wire.WireGDSFactoryPlugin;
import org.hamcrest.Matcher;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isIn;

/**
* Matchers for checking GDS types (eg for type specific assumptions).
*
* @author <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
*/
public class GdsTypeMatchers {

private static final List<String> PURE_JAVA_TYPES = Collections.unmodifiableList(
Arrays.asList(WireGDSFactoryPlugin.PURE_JAVA_TYPE_NAME, OOGDSFactoryPlugin.TYPE_NAME));
private static final List<String> OTHER_NATIVE_TYPES = Collections.unmodifiableList(
Arrays.asList(NativeGDSFactoryPlugin.NATIVE_TYPE_NAME, LocalGDSFactoryPlugin.LOCAL_TYPE_NAME));

/**
* @return Matcher for pure java types
*/
public static Matcher<String> isPureJavaType() {
return isIn(PURE_JAVA_TYPES);
}

/**
* @return Matcher for embedded types
*/
public static Matcher<String> isEmbeddedType() {
return equalTo(EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME);
}

/**
* @return Matcher for native types (excluding embedded)
*/
public static Matcher<String> isOtherNativeType() {
return isIn(OTHER_NATIVE_TYPES);
}

}

0 comments on commit f39d754

Please sign in to comment.