ctakes-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Masanz <masanz.ja...@gmail.com>
Subject Re: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]
Date Tue, 05 Dec 2017 18:08:56 GMT
Hi Alex,

you might want to replace
LOGGER.warn("couldn't drop table test_concepts. Maybe it doesn't even
exists", e);

with something that includes the table name variable, such as:
LOGGER.warn(String.format("Couldn't drop table %s.  Maybe it doesn't even
exist.", sqlTableName), e);

On Tue, Dec 5, 2017 at 8:32 AM, Finan, Sean <
Sean.Finan@childrens.harvard.edu> wrote:

> Hi Alex,
>
> I like the approach.
>
> Sean
>
> -----Original Message-----
> From: alexz@apache.org [mailto:alexz@apache.org]
> Sent: Monday, December 04, 2017 10:58 PM
> To: commits@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=
> 4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_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);
> +                       }
> +               }
> +       }
> +}
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message