-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(java/driver-manager): support loading AdbcDrivers from the Serv…
…iceLoader (#1475) Support loading AdbcDriver classes using the ServiceLoader instead of require explicit registration. An AdbcDriver module can add a file in META-INF/services named org.apache.arrow.adbc.core.AdbcDriverFactory that contains the fully-qualified class names of any AdbcDriver Factory implementations. The AdbcDriverFactory can be implemented to construct AdbcDriver instances. It must have a public no-arg constructor. Update the FlightSQL and JDBC drivers to match above changes. BREAKING CHANGE: - AdbcDriverManager#lookup() is now package-private. - AdbcDriverManager has a private instead of public constructor. Closes #48.
- Loading branch information
Showing
13 changed files
with
296 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
java/driver-manager/src/main/java/org/apache/arrow/adbc/drivermanager/AdbcDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.drivermanager; | ||
|
||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
|
||
/** A factory for instantiating new AdbcDrivers. */ | ||
public interface AdbcDriverFactory { | ||
/** | ||
* Gets a new AdbcDriver. | ||
* | ||
* @param allocator The allocator to associate with the AdbcDriver. | ||
* @return a new AdbcDriver. | ||
*/ | ||
AdbcDriver getDriver(BufferAllocator allocator); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...iver-manager/src/test/java/org/apache/arrow/adbc/drivermanager/AdbcDriverManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.drivermanager; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.function.Function; | ||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
import org.apache.arrow.adbc.test.TestDriver; | ||
import org.apache.arrow.adbc.test.TestDriverFactory; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
import org.apache.arrow.memory.RootAllocator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** Test cases for {@link AdbcDriverManager}. */ | ||
public class AdbcDriverManagerTest { | ||
@Test | ||
public void testDriverFromServiceLoader() { | ||
final Function<BufferAllocator, AdbcDriver> driverFactoryFunction = | ||
AdbcDriverManager.getInstance().lookupDriver(TestDriverFactory.class.getCanonicalName()); | ||
|
||
try (BufferAllocator allocator = new RootAllocator()) { | ||
final AdbcDriver driverInstance = driverFactoryFunction.apply(allocator); | ||
assertThat(driverInstance.getClass()).isEqualTo(TestDriver.class); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
java/driver-manager/src/test/java/org/apache/arrow/adbc/test/TestDriver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.test; | ||
|
||
import java.util.Map; | ||
import org.apache.arrow.adbc.core.AdbcDatabase; | ||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
|
||
/** A dummy {@link AdbcDriver} implementation for testing purposes. */ | ||
public class TestDriver implements AdbcDriver { | ||
public TestDriver() {} | ||
|
||
@Override | ||
public AdbcDatabase open(Map<String, Object> parameters) { | ||
return null; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
java/driver-manager/src/test/java/org/apache/arrow/adbc/test/TestDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.test; | ||
|
||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
import org.apache.arrow.adbc.drivermanager.AdbcDriverFactory; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
|
||
/** Dummy AdbcDriverFactory used for testing. */ | ||
public class TestDriverFactory implements AdbcDriverFactory { | ||
@Override | ||
public AdbcDriver getDriver(BufferAllocator allocator) { | ||
// This dummy driver doesn't need to use its allocator. | ||
return new TestDriver(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rc/test/resources/META-INF/services/org.apache.arrow.adbc.drivermanager.AdbcDriverFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
org.apache.arrow.adbc.test.TestDriverFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/FlightSqlDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.driver.flightsql; | ||
|
||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
import org.apache.arrow.adbc.drivermanager.AdbcDriverFactory; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
|
||
/** Constructs new FlightSqlDriver instances. */ | ||
public class FlightSqlDriverFactory implements AdbcDriverFactory { | ||
@Override | ||
public AdbcDriver getDriver(BufferAllocator allocator) { | ||
return new FlightSqlDriver(allocator); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rc/main/resources/META-INF/services/org.apache.arrow.adbc.drivermanager.AdbcDriverFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
org.apache.arrow.adbc.driver.flightsql.FlightSqlDriverFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.arrow.adbc.driver.jdbc; | ||
|
||
import org.apache.arrow.adbc.core.AdbcDriver; | ||
import org.apache.arrow.adbc.drivermanager.AdbcDriverFactory; | ||
import org.apache.arrow.memory.BufferAllocator; | ||
|
||
/** Constructs new JdbcDriver instances. */ | ||
public class JdbcDriverFactory implements AdbcDriverFactory { | ||
@Override | ||
public AdbcDriver getDriver(BufferAllocator allocator) { | ||
return new JdbcDriver(allocator); | ||
} | ||
} |
Oops, something went wrong.