Thank you Sean.

I still try to fix the latest integration test DateAnnotatorTest. It is
interesting that I cannot reproduce the issue.

Let me know if any advice.

Alex


On Dec 5, 2017 08:32, "Finan, Sean" <sean.fi...@childrens.harvard.edu>
wrote:

Hi Alex,

I like the approach.

Sean

-----Original Message-----
From: al...@apache.org [mailto:al...@apache.org]
Sent: Monday, December 04, 2017 10:58 PM
To: comm...@ctakes.apache.org
Subject: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/
main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]

Author: alexz
Date: Tue Dec  5 03:58:07 2017
New Revision: 1817150

URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__svn.
apache.org_viewvc-3Frev-3D1817150-26view-3Drev&d=
DwICaQ&c=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU&r=
fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao&m=4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUn
Pe_xnfHUycT-U&s=PmAB90gzu1GG6yrwY6BMbc01q0hLKYE88gq79vRlpj4&e=
Log:
CTAKES-415

Added:
    ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/
util/JdbcOperationsHelper.java

Added: ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/
util/JdbcOperationsHelper.java
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__svn.
apache.org_viewvc_ctakes_trunk_ctakes-2Dytex_src_main_
java_org_apache_ctakes_util_JdbcOperationsHelper.java-
3Frev-3D1817150-26view-3Dauto&d=DwICaQ&c=qS4goWBT7poplM69zy_
3xhKwEW14JZMSdioCoppxeFU&r=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao&m=
4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U&s=DjWdjDem-SHqJcprSWE0yRIzg_
BHiR8JXqw55nGrIz0&e=
============================================================
==================
--- 
ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java
(added)
+++ ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOp
+++ erationsHelper.java Tue Dec  5 03:58:07 2017
@@ -0,0 +1,49 @@
+package org.apache.ctakes.util;
+
+import org.apache.log4j.Logger;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.JdbcOperations;
+
+/**
+ * Refactors helper functions like dropTableIfExists or other DB
+operations
+ *
+ * // TODO: consider renaming it with something more suitable  */
+public abstract class JdbcOperationsHelper {
+
+       static private final Logger LOGGER =
+Logger.getLogger(JdbcOperationsHelper.class);
+
+       /**
+        * Helper function to drop a 'table' from a DB, using SQL syntax
+        *
+        * @param jdbc
+        * @param dbEngineType
+        * @param sqlTableName
+        */
+       protected final void dropTableIfExist(JdbcOperations jdbc, final
String dbEngineType, final String sqlTableName) {
+               // TODO: consider refactor using JOOQ
+               String sqlStatement = "";
+               switch (dbEngineType.toLowerCase()) {
+                       case "hsql":
+                       case "mysql":
+                               sqlStatement = String.format("DROP TABLE IF
EXISTS %s", sqlTableName);
+                               break;
+                       case "mssql":
+                               sqlStatement = String.format("IF
EXISTS(SELECT * FROM sys.objects WHERE object_id = object_id('%s')) DROP
TABLE %s", sqlTableName);
+                               break;
+                       case "orcl":
+                               sqlStatement = String.format("DROP TABLE
%s", sqlTableName);
+                               break;
+                       default:
+                               LOGGER.warn(String.format("unsupported DB
engine type: %s", dbEngineType));
+                               break;
+               }
+               if (!sqlStatement.isEmpty()) {
+                       try {
+                               jdbc.execute(sqlStatement);
+                       } catch (DataAccessException e) {
+                               LOGGER.warn("couldn't drop table
test_concepts. Maybe it doesn't even exists", e);
+                       }
+               }
+       }
+}

Reply via email to