From 37fdc0bb83d9e8a14a54c960cb915d513dfd4766 Mon Sep 17 00:00:00 2001 From: Arbel Deutsch Peled Date: Fri, 18 Dec 2015 14:39:40 +0200 Subject: [PATCH] Fixed minor H2 bug. Fixed dbTest gradle task (now tests all 3 supported DB engines). --- .../BulletinBoardClientIntegrationTest.java | 20 ++++++++--------- bulletin-board-server/build.gradle | 6 +++-- .../sqlserver/H2QueryProvider.java | 2 +- .../sqlserver/SQLiteQueryProvider.java | 22 ++++++++++++++++--- .../src/main/webapp/WEB-INF/web.xml | 2 +- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java b/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java index c090c92..55f0343 100644 --- a/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java +++ b/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java @@ -27,6 +27,12 @@ public class BulletinBoardClientIntegrationTest { Semaphore jobSemaphore; Vector thrown; + protected void genericHandleFailure(Throwable t){ + System.err.println(t.getCause() + " " + t.getMessage()); + thrown.add(t); + jobSemaphore.release(); + } + private class PostCallback implements ClientCallback{ @Override @@ -37,8 +43,7 @@ public class BulletinBoardClientIntegrationTest { @Override public void handleFailure(Throwable t) { - thrown.add(t); - jobSemaphore.release(); + genericHandleFailure(t); } } @@ -59,8 +64,7 @@ public class BulletinBoardClientIntegrationTest { @Override public void handleFailure(Throwable t) { - thrown.add(t); - jobSemaphore.release(); + genericHandleFailure(t); } } @@ -93,8 +97,7 @@ public class BulletinBoardClientIntegrationTest { @Override public void handleFailure(Throwable t) { - thrown.add(t); - jobSemaphore.release(); + genericHandleFailure(t); } } @@ -202,10 +205,7 @@ public class BulletinBoardClientIntegrationTest { } bulletinBoardClient.close(); - - for (Throwable t : thrown) { - System.err.println(t.getMessage()); - } + if (thrown.size() > 0) { assert false; } diff --git a/bulletin-board-server/build.gradle b/bulletin-board-server/build.gradle index eb197c9..62e4b0c 100644 --- a/bulletin-board-server/build.gradle +++ b/bulletin-board-server/build.gradle @@ -75,13 +75,15 @@ dependencies { test { exclude '**/*SQLite*Test*' exclude '**/*H2*Test*' - exclude '**/*MySql*Test' + exclude '**/*MySQL*Test*' exclude '**/*IntegrationTest*' } task dbTest(type: Test) { include '**/*H2*Test*' - include '**/*MySql*Test' + include '**/*MySQL*Test*' + include '**/*SQLite*Test*' + outputs.upToDateWhen { false } } task integrationTest(type: Test) { diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java index fa2b146..d76601f 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java @@ -74,7 +74,7 @@ public class H2QueryProvider implements BulletinBoardSQLServer.SQLQueryProvider case MAX_MESSAGES: return "LIMIT :Limit" + serialString; case MSG_ID: - return "MsgTable.MsgId = MsgId" + serialString; + return "MsgTable.MsgId = :MsgId" + serialString; case SIGNER_ID: return "EXISTS (SELECT 1 FROM SignatureTable" + " WHERE SignatureTable.SignerId = :SignerId" + serialString + " AND SignatureTable.EntryNum = MsgTable.EntryNum)"; diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteQueryProvider.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteQueryProvider.java index 8131d2b..d796789 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteQueryProvider.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteQueryProvider.java @@ -73,15 +73,31 @@ public class SQLiteQueryProvider implements BulletinBoardSQLServer.SQLQueryProvi @Override public String getConditionParamTypeName(FilterType filterType) throws IllegalArgumentException { - return null; //TODO: write this. + + switch(filterType) { + case EXACT_ENTRY: // Go through + case MAX_ENTRY: // Go through + case MAX_MESSAGES: + return "INTEGER"; + + case MSG_ID: // Go through + case SIGNER_ID: + return "BLOB"; + + case TAG: + return "VARCHAR"; + + default: + throw new IllegalArgumentException("Cannot serve a filter of type " + filterType); + } + } @Override public DataSource getDataSource() { - // TODO: Fix this + SQLiteDataSource dataSource = new SQLiteDataSource(); dataSource.setUrl("jdbc:sqlite:" + dbName); - dataSource.setDatabaseName("meerkat"); //TODO: Make generic return dataSource; } diff --git a/bulletin-board-server/src/main/webapp/WEB-INF/web.xml b/bulletin-board-server/src/main/webapp/WEB-INF/web.xml index 2198c07..226aa3b 100644 --- a/bulletin-board-server/src/main/webapp/WEB-INF/web.xml +++ b/bulletin-board-server/src/main/webapp/WEB-INF/web.xml @@ -31,7 +31,7 @@ mypass dbType - SQLite + H2 meerkat.bulletinboard.webapp.BulletinBoardWebApp