Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added code to register with DriverManager

  • Loading branch information...
commit 4cb770f39193d9efbea58ab75032e6ed37424776 1 parent 423363a
@s-b-u s-b-u authored
View
15 src/main/java/org/neo4j/jdbc/Driver.java
@@ -20,6 +20,7 @@
package org.neo4j.jdbc;
+
import org.neo4j.jdbc.ext.DbVisualizerConnection;
import org.neo4j.jdbc.ext.IntelliJConnection;
import org.neo4j.jdbc.ext.LibreOfficeConnection;
@@ -31,6 +32,7 @@
import org.restlet.resource.ClientResource;
import java.sql.Connection;
+import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.util.Collections;
@@ -42,7 +44,18 @@
public class Driver
implements java.sql.Driver
{
- DriverQueries queries;
+ static
+ {
+ try
+ {
+ DriverManager.registerDriver(new Driver());
+ } catch (SQLException e) {
+ System.err.println(e.getLocalizedMessage());
+ }
+
+ }
+
+ DriverQueries queries;
public Driver()
{
View
28 src/test/java/org/neo4j/jdbc/DriverTest.java
@@ -20,14 +20,17 @@
package org.neo4j.jdbc;
+
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
+import java.util.ServiceLoader;
/**
* TODO
@@ -56,4 +59,29 @@ public void testURLProperties() throws SQLException
Assert.assertThat(conn.getProperties().getProperty("debug"), CoreMatchers.equalTo("false"));
}
+
+ @Test
+ public void testDriverRegistration()
+ {
+ try {
+ java.sql.Driver driver=DriverManager.getDriver("jdbc:neo4j://localhost:7474/");
+ Assert.assertNotNull(driver);
+ Assert.assertEquals(this.driver.getClass(), driver.getClass());
+ } catch (SQLException e) {
+ Assert.fail(e.getLocalizedMessage());
+ }
+
+
+ }
+
+ @Test
+ public void testDriverService()
+ {
+ ServiceLoader<java.sql.Driver> serviceLoader=ServiceLoader.load(java.sql.Driver.class);
+ for (java.sql.Driver driver : serviceLoader) {
+ if(Driver.class.isInstance(driver))
+ return;
+ }
+ Assert.fail(Driver.class.getName()+" not registered as a Service");
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.