diff --git a/.gitignore b/.gitignore index 98c46d185264aa7f35fb38b2ab1005504113c63f..882b67e2ec0e1a624c962e90d86272828b6f0cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ target # ignore output files from testing output* -derby.log # ignore standard eclipse .project diff --git a/jdbc/pom.xml b/jdbc/pom.xml index bebf2a3b2bc70e392f5ca3cd28f98253f3d8f15e..c03a9b68d5613e9844b4cc2e087da650d6ef0f0c 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -51,6 +51,7 @@ LICENSE file. <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>2.3.3</version> + <scope>test</scope> </dependency> </dependencies> </project> diff --git a/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java b/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java index d59b89f6e47532b6889ba641445eb7064ffd6641..968d7322591a03bced55c5619f1a5f9e59f2ca93 100644 --- a/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java +++ b/jdbc/src/main/java/com/yahoo/ycsb/db/JdbcDBClient.java @@ -245,7 +245,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants { for (int i = 0; i < insertType.numFields; i++) { insert.append(",?"); } - insert.append(")"); + insert.append(");"); PreparedStatement insertStatement = getShardConnectionByKey(key).prepareStatement(insert.toString()); PreparedStatement stmt = cachedStatements.putIfAbsent(insertType, insertStatement); if (stmt == null) return insertStatement; @@ -259,7 +259,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants { read.append(" WHERE "); read.append(PRIMARY_KEY); read.append(" = "); - read.append("?"); + read.append("?;"); PreparedStatement readStatement = getShardConnectionByKey(key).prepareStatement(read.toString()); PreparedStatement stmt = cachedStatements.putIfAbsent(readType, readStatement); if (stmt == null) return readStatement; @@ -272,7 +272,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants { delete.append(deleteType.tableName); delete.append(" WHERE "); delete.append(PRIMARY_KEY); - delete.append(" = ?"); + delete.append(" = ?;"); PreparedStatement deleteStatement = getShardConnectionByKey(key).prepareStatement(delete.toString()); PreparedStatement stmt = cachedStatements.putIfAbsent(deleteType, deleteStatement); if (stmt == null) return deleteStatement; @@ -292,7 +292,7 @@ public class JdbcDBClient extends DB implements JdbcDBClientConstants { } update.append(" WHERE "); update.append(PRIMARY_KEY); - update.append(" = ?"); + update.append(" = ?;"); PreparedStatement insertStatement = getShardConnectionByKey(key).prepareStatement(update.toString()); PreparedStatement stmt = cachedStatements.putIfAbsent(updateType, insertStatement); if (stmt == null) return insertStatement; diff --git a/jdbc/src/test/java/com/yahoo/ycsb/db/JdbcDBClientTest.java b/jdbc/src/test/java/com/yahoo/ycsb/db/JdbcDBClientTest.java index e2983d08124a2430f1e12a8cf325d5de4f25c495..901c8a668a035a8130a9070d044664736fc994ca 100644 --- a/jdbc/src/test/java/com/yahoo/ycsb/db/JdbcDBClientTest.java +++ b/jdbc/src/test/java/com/yahoo/ycsb/db/JdbcDBClientTest.java @@ -1,3 +1,20 @@ +/** + * Copyright (c) 2015 Yahoo! Inc. All rights reserved. + * + * Licensed 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. See accompanying + * LICENSE file. + */ + package com.yahoo.ycsb.db; import static org.junit.Assert.*; @@ -33,9 +50,7 @@ public class JdbcDBClientTest { @BeforeClass public static void setup() { try { - Class driverClass = Class.forName(TEST_DB_DRIVER); jdbcConnection = DriverManager.getConnection(TEST_DB_URL); - jdbcDBClient = new JdbcDBClient(); Properties p = new Properties(); @@ -45,10 +60,6 @@ public class JdbcDBClientTest { jdbcDBClient.setProperties(p); jdbcDBClient.init(); - - } catch (ClassNotFoundException e) { - e.printStackTrace(); - fail("Could not find Driver Class: " + TEST_DB_DRIVER); } catch (SQLException e) { e.printStackTrace(); fail("Could not create local Database"); @@ -61,13 +72,19 @@ public class JdbcDBClientTest { @AfterClass public static void teardown() { try { - jdbcConnection.close(); - jdbcConnection = DriverManager.getConnection(TEST_DB_URL + ";shutdown=true"); - } catch (SQLNonTransientConnectionException e) { - // Expected exception when database is destroyed + if (jdbcConnection != null) { + jdbcConnection.close(); + } } catch (SQLException e) { e.printStackTrace(); - fail("Could not drop local Database"); + } + + try { + if (jdbcDBClient != null) { + jdbcDBClient.cleanup(); + } + } catch (DBException e) { + e.printStackTrace(); } } @@ -98,7 +115,6 @@ public class JdbcDBClientTest { e.printStackTrace(); fail("Failed to prepare test"); } - } /* @@ -224,9 +240,6 @@ public class JdbcDBClientTest { e.printStackTrace(); fail("Failed updateTest"); } - - - assertTrue(true); } @Test @@ -263,12 +276,10 @@ public class JdbcDBClientTest { @Test public void deleteTest() { try { - String insertBeforeKey = "user0"; - HashMap<String, ByteIterator> insertBeforeMap = insertRow(insertBeforeKey); + insertRow("user0"); String deleteKey = "user1"; insertRow(deleteKey); - String insertAfterKey = "user2"; - HashMap<String, ByteIterator> insertAfterMap = insertRow(insertAfterKey); + insertRow("user2"); jdbcDBClient.delete(TABLE_NAME, deleteKey);