Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Registering JDBC driver not needed in test and runtime since it is ad…
Browse files Browse the repository at this point in the history
…ded in META-INF/services
  • Loading branch information
mujtabachohan committed Jul 29, 2013
1 parent 019f33d commit fc45c7c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 52 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ The Phoenix query engine transforms your [SQL query](http://forcedotcom.github.c

Tables are created and altered through [DDL statements](http://forcedotcom.github.com/phoenix/#create), and their schema is stored and versioned on the server in an HBase table. Columns are defined as either being part of a multi-part row key, or as key/value cells. You can also map Phoenix on to existing tables (see the [wiki](https://github.com/forcedotcom/phoenix/wiki) for more details).

Applications interact with Phoenix through a standard JDBC interface; all the usual interfaces are supported, including `Connection`, `Statement`, `PreparedStatement`, and `ResultSet`. The driver class is `com.salesforce.phoenix.jdbc.PhoenixDriver`, and the [connection url](https://github.com/forcedotcom/phoenix/wiki#wiki-connStr) is `jdbc:phoenix:` followed by the zookeeper quorum hostname specification plus optionally the port number and/or root node. For example:
Applications interact with Phoenix through a standard JDBC interface; all the usual interfaces are supported, including `Connection`, `Statement`, `PreparedStatement`, and `ResultSet`. The driver class is `com.salesforce.phoenix.jdbc.PhoenixDriver`, JDK 1.5+ automatically registers JDBC driver on classpath, and the [connection url](https://github.com/forcedotcom/phoenix/wiki#wiki-connStr) is `jdbc:phoenix:` followed by the zookeeper quorum hostname specification plus optionally the port number and/or root node. For example:

Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");
Connection conn = DriverManager.getConnection("jdbc:phoenix:localhost");

For detailed documentation on the current level of SQL support, see our [language reference guide](http://forcedotcom.github.com/phoenix/). For details about how Phoenix handles schema, transactions, and more, see the [wiki](https://github.com/forcedotcom/phoenix/wiki).
Expand Down
40 changes: 5 additions & 35 deletions src/main/java/com/salesforce/phoenix/pig/PhoenixHBaseStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void setStoreLocation(String location, Job job) throws IOException {
@Override
public void prepareToWrite(RecordWriter writer) throws IOException {
try {
registerDriver();
Properties props = new Properties();
conn = DriverManager.getConnection(QueryUtil.getUrl(server), props).unwrap(PhoenixConnection.class);
// Default to config defined upsert batch size if user did not specify it.
Expand All @@ -175,9 +174,6 @@ public void prepareToWrite(RecordWriter writer) throws IOException {
} catch (SQLException e) {
LOG.error("Error in constructing PreparedStatement: " + e);
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
LOG.error(e);
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -228,47 +224,21 @@ public void setStoreFuncUDFContextSignature(String signature) {

@Override
public void cleanupOnFailure(String location, Job job) throws IOException {
try {
deregisterDriver();
} catch (SQLException e) {
LOG.error("Error in while deregistering driver ", e);
}
}

@Override
public void cleanupOnSuccess(String location, Job job) throws IOException {
try {
// Commit the remaining executes after the last commit in putNext()
if (rowCount % batchSize != 0) {
try {
conn.commit();
LOG.info("Rows upserted: " + rowCount);
} catch (SQLException e) {
LOG.error("Error during upserting to HBase table " + tableName, e);
}
}
} finally {
// Commit the remaining executes after the last commit in putNext()
if (rowCount % batchSize != 0) {
try {
deregisterDriver();
conn.commit();
LOG.info("Rows upserted: " + rowCount);
} catch (SQLException e) {
LOG.error("Error while deregistering driver ", e);
LOG.error("Error during upserting to HBase table " + tableName, e);
}
}
}

public void registerDriver() throws ClassNotFoundException, SQLException {
Class.forName(PhoenixDriver.class.getName());
DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}

public void deregisterDriver() throws SQLException {
try {
PhoenixDriver.INSTANCE.close();
} finally {
DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
}
}

@Override
public String relToAbsPathForStoreLocation(String location, Path curDir)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public static void main(String [] args) {
if (isUpgrade) {
props.setProperty(SchemaUtil.UPGRADE_TO_2_0, Integer.toString(SchemaUtil.SYSTEM_TABLE_NULLABLE_VAR_LENGTH_COLUMNS));
}
Class.forName(PhoenixDriver.class.getName());
String connectionUrl = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + args[i++];
PhoenixConnection conn = DriverManager.getConnection(connectionUrl, props).unwrap(PhoenixConnection.class);

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

<pre>
Properties props = new Properties();
// Ensure the driver is registered
Class.forName("phoenix.jdbc.PhoenixProdEmbeddedDriver");
// Ensure the driver is on classpath
// Connect through Phoenix to the zookeeper quorum with a host name of myServer
Connection conn = DriverManager.getConnection("jdbc:phoenix:myServer", props);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,10 @@ private static String getUrl() {
}

@BeforeClass
public static void registerDriver() throws ClassNotFoundException, SQLException {
Class.forName(PhoenixDriver.class.getName());
DriverManager.registerDriver(PhoenixDriver.INSTANCE);
public static void verifyDriverRegistered() throws SQLException {
assertTrue(DriverManager.getDriver(getUrl()) == PhoenixDriver.INSTANCE);
}

@AfterClass
public static void deregisterDriver() throws SQLException {
try {
PhoenixDriver.INSTANCE.close();
} finally {
DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
}
}

@Test
public void testConnectionlessUpsert() throws Exception {
String dmlStmt = "create table core.entity_history(\n" +
Expand Down

0 comments on commit fc45c7c

Please sign in to comment.