Re: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]

2017-12-09 Thread Alexandru Zbarcea
Hi,

It is quite some time since I started to look into the DateAnnotatorTest. I
cannot reproduce the Jenkins [1] failure related to the CTAKES-415 bug [2].
However I do not understand why on Jenkins I get the following stack:

2017-12-06 21:41:29,490 INFO
org.apache.ctakes.ytex.uima.annotators.DateAnnotatorTest  - date to be
annotated: Wed Dec 06 21:41:29 UTC 2017
2017-12-06 21:41:29,559 INFO
org.apache.ctakes.ytex.uima.annotators.DateAnnotatorTest  - Using
org.apache.ctakes.ytex.uima.types.Date.type: 94
2017-12-06 21:41:29,560 INFO
org.apache.ctakes.ytex.uima.annotators.DateAnnotatorTest  -
*ytexDates.size: 0*
2017-12-06 21:41:29,570 INFO
org.apache.ctakes.ytex.uima.annotators.DateAnnotatorTest  - creating
JCas from: 
/home/jenkins/jenkins-slave/workspace/cTAKES-trunk-Java-1.8/ctakes-ytex-uima/target/classes/org/apache/ctakes/ytex/types/TypeSystem.xml
Tests run: 4, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.377
sec <<< FAILURE!


while running it myself, I get:
09 Dec 2017 10:19:59  INFO DateAnnotatorTest - date to be annotated: Sat
Dec 09 10:19:58 EST 2017
09 Dec 2017 11:29:03  INFO DateAnnotatorTest - Using
org.apache.ctakes.ytex.uima.types.Date.type: 94
09 Dec 2017 11:29:03  INFO DateAnnotatorTest - [Date
   sofa: _InitialView
   begin: 0
   end: 28
   date: "2017-12-09T10:19:58-0500"
]
09 Dec 2017 11:29:03  INFO DateAnnotatorTest - [Date
   sofa: _InitialView
   begin: 0
   end: 28
   date: "2017-12-09T10:19:58-0500"
]
09 Dec 2017 11:29:03  INFO DateAnnotatorTest - *ytexDates.size: 2*
09 Dec 2017 11:29:03  INFO DateAnnotatorTest - date from annotation:
2017-12-09T10:19:58-0500

I have added few UTests in the same DateAnnotatorTest, and I was presuming
that the following construction is idempotent (doesn't depend on
environment or external resources) :
DateAnnotator dateAnnotator = new DateAnnotator();
dateAnnotator.dateType = Date.class.getName();
dateAnnotator.process(jCas);

Looking forward to your advice,
Alex

[1] - https://builds.apache.org/view/C/view/Apache%20cTAKES/
job/cTAKES-trunk-Java-1.8/66/consoleFull
[2] - https://issues.apache.org/jira/browse/CTAKES-415

On Tue, Dec 5, 2017 at 2:26 PM, Alexandru Zbarcea 
wrote:

> Thank you James. Good catch. Will do that. I missed that when refactoring.
>
> Alex
>
> On Dec 5, 2017 1:09 PM, "James Masanz"  wrote:
>
>> 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.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=
>> > DwICaQ=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU=
>> > fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=
>> > 4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=
>> > PmAB90gzu1GG6yrwY6BMbc01q0hLKYE88gq79vRlpj4=
>> > 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=DwICaQ=qS4goWBT7poplM69zy_
>> > 3xhKwEW14JZMSdioCoppxeFU=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKG
>> d4f7d4gTao=
>> > 4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=DjWdjDem-SHqJc
>> prSWE0yRIzg_
>> > BHiR8JXqw55nGrIz0=
>> > 
>> > ==
>> > --- ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/uti
>> l/JdbcOperationsHelper.java
>> > (added)
>> > +++ ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/uti
>> l/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 

Re: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]

2017-12-05 Thread James Masanz
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.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=
> DwICaQ=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU=
> fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=
> 4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=
> PmAB90gzu1GG6yrwY6BMbc01q0hLKYE88gq79vRlpj4=
> 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=DwICaQ=qS4goWBT7poplM69zy_
> 3xhKwEW14JZMSdioCoppxeFU=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=
> 4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=DjWdjDem-SHqJcprSWE0yRIzg_
> BHiR8JXqw55nGrIz0=
> 
> ==
> --- 
> 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);
> +   }
> +   }
> +   }
> +}
>
>
>


RE: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]

2017-12-05 Thread Alexandru Zbarcea
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" 
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=
DwICaQ=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU=
fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUn
Pe_xnfHUycT-U=PmAB90gzu1GG6yrwY6BMbc01q0hLKYE88gq79vRlpj4=
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=DwICaQ=qS4goWBT7poplM69zy_
3xhKwEW14JZMSdioCoppxeFU=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=
4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=DjWdjDem-SHqJcprSWE0yRIzg_
BHiR8JXqw55nGrIz0=

==
--- 
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);
+   }
+   }
+   }
+}


RE: svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java [EXTERNAL]

2017-12-05 Thread Finan, Sean
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=DwICaQ=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=PmAB90gzu1GG6yrwY6BMbc01q0hLKYE88gq79vRlpj4=
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=DwICaQ=qS4goWBT7poplM69zy_3xhKwEW14JZMSdioCoppxeFU=fs67GvlGZstTpyIisCYNYmQCP6r0bcpKGd4f7d4gTao=4Lb1jjC4XsbSAZ2rf0gsNtrV8JdfUnPe_xnfHUycT-U=DjWdjDem-SHqJcprSWE0yRIzg_BHiR8JXqw55nGrIz0=
==
--- 
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);
+   }
+   }
+   }
+}