ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject svn commit: r1817150 - /ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java
Date Tue, 05 Dec 2017 03:58:07 GMT
Author: alexz
Date: Tue Dec  5 03:58:07 2017
New Revision: 1817150

URL: http://svn.apache.org/viewvc?rev=1817150&view=rev
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: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-ytex/src/main/java/org/apache/ctakes/util/JdbcOperationsHelper.java?rev=1817150&view=auto
==============================================================================
--- 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
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
View raw message