List of usage examples for java.sql SQLException toString
public String toString()
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public void updateTCExecution(TestCaseExecution tCExecution) throws CerberusException { boolean throwEx = false; final String query = "UPDATE testcaseexecution SET test = ?, testcase = ?, build = ?, revision = ?, environment = ?, environmentData = ?, country = ?" + ", browser = ?, application = ?, ip = ?, url = ?, port = ?, tag = ?, verbose = ?, status = ?" + ", start = ?, end = ? , controlstatus = ?, controlMessage = ?, crbversion = ?, finished = ? " + ", browserFullVersion = ?, version = ?, platform = ?, executor = ?, screensize = ? " + ", ConditionOper = ?, ConditionVal1Init = ?, ConditionVal2Init = ?, ConditionVal1 = ?, ConditionVal2 = ?, ManualExecution = ? WHERE id = ?"; Connection connection = this.databaseSpring.connect(); try {/* w w w.j ava 2 s. co m*/ PreparedStatement preStat = connection.prepareStatement(query); try { int i = 1; preStat.setString(i++, tCExecution.getTest()); preStat.setString(i++, tCExecution.getTestCase()); preStat.setString(i++, tCExecution.getBuild()); preStat.setString(i++, tCExecution.getRevision()); preStat.setString(i++, tCExecution.getEnvironment()); preStat.setString(i++, tCExecution.getEnvironmentData()); preStat.setString(i++, tCExecution.getCountry()); preStat.setString(i++, tCExecution.getBrowser()); preStat.setString(i++, tCExecution.getApplicationObj().getApplication()); preStat.setString(i++, tCExecution.getIp()); preStat.setString(i++, tCExecution.getUrl()); preStat.setString(i++, tCExecution.getPort()); preStat.setString(i++, tCExecution.getTag()); preStat.setInt(i++, tCExecution.getVerbose()); preStat.setString(i++, tCExecution.getStatus()); preStat.setTimestamp(i++, new Timestamp(tCExecution.getStart())); if (tCExecution.getEnd() != 0) { preStat.setTimestamp(i++, new Timestamp(tCExecution.getEnd())); } else { preStat.setString(i++, "1970-01-01 01:01:01"); } preStat.setString(i++, tCExecution.getControlStatus()); preStat.setString(i++, StringUtil.getLeftString(tCExecution.getControlMessage(), 500)); preStat.setString(i++, tCExecution.getCrbVersion()); preStat.setString(i++, tCExecution.getFinished()); preStat.setString(i++, tCExecution.getBrowserFullVersion()); preStat.setString(i++, tCExecution.getVersion()); preStat.setString(i++, tCExecution.getPlatform()); preStat.setString(i++, tCExecution.getExecutor()); preStat.setString(i++, tCExecution.getScreenSize()); preStat.setString(i++, tCExecution.getConditionOper()); preStat.setString(i++, tCExecution.getConditionVal1Init()); preStat.setString(i++, tCExecution.getConditionVal2Init()); preStat.setString(i++, tCExecution.getConditionVal1()); preStat.setString(i++, tCExecution.getConditionVal2()); preStat.setString(i++, tCExecution.isManualExecution() ? "Y" : "N"); preStat.setLong(i++, tCExecution.getId()); preStat.executeUpdate(); } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); throwEx = true; } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (throwEx) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA)); } }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionInQueueDAO.java
@Override public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) { AnswerList response = new AnswerList(); MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "")); List<TestCaseExecutionInQueue> objectList = new ArrayList<TestCaseExecutionInQueue>(); StringBuilder searchSQL = new StringBuilder(); List<String> individalColumnSearchValues = new ArrayList<String>(); StringBuilder query = new StringBuilder(); //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that //were applied -- used for pagination p query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaseexecutionqueue exq "); query.append(" WHERE 1=1"); if (!StringUtil.isNullOrEmpty(searchTerm)) { searchSQL.append(" and (exq.ID like ?"); searchSQL.append(" or exq.Test like ?"); searchSQL.append(" or exq.TestCase like ?"); searchSQL.append(" or exq.Country like ?"); searchSQL.append(" or exq.Environment like ?"); searchSQL.append(" or exq.Browser like ?"); searchSQL.append(" or exq.Tag like ?"); searchSQL.append(" or exq.State like ?)"); }/*w ww.ja v a 2 s . com*/ if (individualSearch != null && !individualSearch.isEmpty()) { searchSQL.append(" and ( 1=1 "); for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) { searchSQL.append(" and "); String key = "IFNULL(exq." + entry.getKey() + ",'')"; String q = SqlUtil.getInSQLClauseForPreparedStatement(key, entry.getValue()); if (q == null || q == "") { q = "(exq." + entry.getKey() + " IS NULL OR " + entry.getKey() + " = '')"; } searchSQL.append(q); individalColumnSearchValues.addAll(entry.getValue()); } searchSQL.append(" )"); } query.append(searchSQL); if (!StringUtil.isNullOrEmpty(column)) { query.append(" order by exq.").append(column).append(" ").append(dir); } if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) { query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED); } else { query.append(" limit ").append(start).append(" , ").append(amount); } // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { int i = 1; if (!StringUtil.isNullOrEmpty(searchTerm)) { preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); } for (String individualColumnSearchValue : individalColumnSearchValues) { preStat.setString(i++, individualColumnSearchValue); } ResultSet resultSet = preStat.executeQuery(); try { //gets the data while (resultSet.next()) { objectList.add(this.loadFromResultSet(resultSet)); } //get the total number of rows resultSet = preStat.executeQuery("SELECT FOUND_ROWS()"); int nrTotalRows = 0; if (resultSet != null && resultSet.next()) { nrTotalRows = resultSet.getInt(1); } if (objectList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList. LOG.error("Partial Result in the query."); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED)); response = new AnswerList(objectList, nrTotalRows); } else if (objectList.size() <= 0) { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND); response = new AnswerList(objectList, nrTotalRows); } else { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME) .replace("%OPERATION%", "SELECT")); response = new AnswerList(objectList, nrTotalRows); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } catch (FactoryCreationException exception) { LOG.error( "Unable to create Test Case Execution In Queue from Factory : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { if (resultSet != null) { resultSet.close(); } } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { if (preStat != null) { preStat.close(); } } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { try { if (!this.databaseSpring.isOnTransaction()) { if (connection != null) { connection.close(); } } } catch (SQLException exception) { LOG.warn("Unable to close connection : " + exception.toString()); } } response.setResultMessage(msg); response.setDataList(objectList); return response; }
From source file:org.etudes.component.app.jforum.dao.generic.CategoryDaoGeneric.java
/** * Checks and default categories and forums to the site * /*from www. j ava 2 s . co m*/ * @param courseId Course or site id */ protected void checkAndAddDefaultCategoriesForumsTx(final String courseId) { this.sqlService.transact(new Runnable() { public void run() { try { String sql = "SELECT course_id, init_status FROM jforum_sakai_course_initvalues WHERE course_id = ?"; Object[] fields = new Object[1]; int i = 0; fields[i++] = courseId; final Map<String, Integer> courseInitStatus = new HashMap<String, Integer>(); sqlService.dbRead(sql, fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { courseInitStatus.put(result.getString("course_id"), result.getInt("init_status")); } catch (SQLException e) { if (logger.isWarnEnabled()) { logger.warn( "checkAndAddDefaultCategoriesForums().fetch course init status: " + e, e); } } return null; } }); if (courseInitStatus.size() == 0) { // check for any existing categories and if categories are existing initialize site if (selectCategoryCount(courseId) > 0) { initializeSite(courseId); } else { addDefaultCategoriesForums(courseId); initializeSite(courseId); } } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error(e.toString(), e); } throw new RuntimeException("Error while creating new default categories and forums.", e); } } }, "checkAndAddDefaultCategoriesForumsTx: " + courseId); }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionInQueueDAO.java
@Override public AnswerList readDistinctEnvCoutnryBrowserByTag(String tag) { AnswerList answer = new AnswerList(); StringBuilder query = new StringBuilder(); MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); query.append(/* w w w . ja v a 2 s.c o m*/ "SELECT exq.* FROM testcaseexecutionqueue exq WHERE tag = ? GROUP BY Environment, Country, Browser"); Connection connection = this.databaseSpring.connect(); List<TestCaseExecutionInQueue> EnvCountryBrowserList = new ArrayList<TestCaseExecutionInQueue>(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, tag); try { ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { EnvCountryBrowserList.add(this.loadFromResultSet(resultSet)); } msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue") .replace("%OPERATION%", "SELECT")); answer = new AnswerList(EnvCountryBrowserList, EnvCountryBrowserList.size()); } catch (SQLException exception) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); EnvCountryBrowserList = null; } catch (FactoryCreationException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); EnvCountryBrowserList = null; } finally { if (resultSet != null) { resultSet.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); EnvCountryBrowserList = null; } finally { if (preStat != null) { preStat.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.WARN, ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); } } answer.setResultMessage(msg); return answer; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public long insertTCExecution(TestCaseExecution tCExecution) throws CerberusException { boolean throwEx = false; final String query = "INSERT INTO testcaseexecution(test, testcase, build, revision, environment, environmentData, country, browser, application, ip, " + "url, port, tag, verbose, status, start, controlstatus, controlMessage, crbversion, finished, browserFullVersion, executor, screensize," + "conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, manualExecution) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; Connection connection = this.databaseSpring.connect(); try {//from w w w.ja va2 s . c om PreparedStatement preStat = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); try { int i = 1; preStat.setString(i++, tCExecution.getTest()); preStat.setString(i++, tCExecution.getTestCase()); preStat.setString(i++, tCExecution.getBuild()); preStat.setString(i++, tCExecution.getRevision()); preStat.setString(i++, tCExecution.getEnvironment()); preStat.setString(i++, tCExecution.getEnvironmentData()); preStat.setString(i++, tCExecution.getCountry()); preStat.setString(i++, tCExecution.getBrowser()); preStat.setString(i++, tCExecution.getApplicationObj().getApplication()); preStat.setString(i++, tCExecution.getIp()); preStat.setString(i++, tCExecution.getUrl()); preStat.setString(i++, tCExecution.getPort()); preStat.setString(i++, tCExecution.getTag()); preStat.setInt(i++, tCExecution.getVerbose()); preStat.setString(i++, tCExecution.getStatus()); preStat.setTimestamp(i++, new Timestamp(tCExecution.getStart())); preStat.setString(i++, tCExecution.getControlStatus()); preStat.setString(i++, StringUtil.getLeftString(tCExecution.getControlMessage(), 500)); preStat.setString(i++, tCExecution.getCrbVersion()); preStat.setString(i++, tCExecution.getFinished()); preStat.setString(i++, tCExecution.getBrowserFullVersion()); preStat.setString(i++, tCExecution.getExecutor()); preStat.setString(i++, tCExecution.getScreenSize()); preStat.setString(i++, tCExecution.getConditionOper()); preStat.setString(i++, tCExecution.getConditionVal1Init()); preStat.setString(i++, tCExecution.getConditionVal2Init()); preStat.setString(i++, tCExecution.getConditionVal1()); preStat.setString(i++, tCExecution.getConditionVal2()); preStat.setString(i++, tCExecution.isManualExecution() ? "Y" : "N"); preStat.executeUpdate(); ResultSet resultSet = preStat.getGeneratedKeys(); try { if (resultSet.first()) { return resultSet.getInt(1); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); throwEx = true; } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); throwEx = true; } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); throwEx = true; } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } if (throwEx) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA)); } return 0; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public AnswerItem readLastByCriteria(String application) { AnswerItem ans = new AnswerItem(); TestCaseExecution result = null;//from w w w .j ava 2 s . co m MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "")); StringBuilder searchSQL = new StringBuilder(); StringBuilder query = new StringBuilder(); //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that //were applied -- used for pagination p query.append("select * from testcaseexecution exe "); searchSQL.append(" where 1=1 "); if (!StringUtil.isNullOrEmpty(application)) { searchSQL.append(" and (`application` = ? )"); } query.append(searchSQL); query.append(" order by id DESC limit 1 "); // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { int i = 1; if (!StringUtil.isNullOrEmpty(application)) { preStat.setString(i++, application); } ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { result = loadFromResultSet(resultSet); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME) .replace("%OPERATION%", "SELECT")); ans.setItem(result); } else { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException exception) { LOG.warn("Unable to close connection : " + exception.toString()); } } //sets the message ans.setResultMessage(msg); return ans; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase, String environment, String country, String build, String revision, String browser, String browserVersion, String ip, String port, String tag) { TestCaseExecution result = null;/*from w ww . j a v a2 s.c om*/ StringBuilder query = new StringBuilder(); query.append("SELECT exe.* FROM testcaseexecution exe ") .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.country = ? AND exe.browser = ? "); if (!StringUtil.isNull(environment)) { query.append("AND exe.environment IN ("); query.append(environment); query.append(") "); } if (!StringUtil.isNull(build)) { query.append("AND exe.build IN ("); query.append(build); query.append(") "); } if (!StringUtil.isNull(revision)) { query.append("AND exe.revision IN ("); query.append(revision); query.append(") "); } if (!StringUtil.isNull(browserVersion)) { query.append("AND exe.browserfullversion LIKE ? "); } if (!StringUtil.isNull(ip)) { query.append("AND exe.ip LIKE ? "); } if (!StringUtil.isNull(port)) { query.append("AND exe.port LIKE ? "); } if (!StringUtil.isNull(tag)) { query.append("AND exe.tag LIKE ? "); } query.append("ORDER BY exe.id DESC"); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, test); preStat.setString(2, testCase); preStat.setString(3, country); preStat.setString(4, browser); int i = 5; if (!StringUtil.isNull(browserVersion)) { preStat.setString(i, browserVersion); i++; } if (!StringUtil.isNull(ip)) { preStat.setString(i, ip); i++; } if (!StringUtil.isNull(port)) { preStat.setString(i, port); i++; } if (!StringUtil.isNull(tag)) { preStat.setString(i, tag); } try { ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { result = this.loadFromResultSet(resultSet); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { LOG.warn(e.toString()); } } return result; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionInQueueDAO.java
@Override public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) { AnswerList answer = new AnswerList(); StringBuilder query = new StringBuilder(); StringBuilder distinct = new StringBuilder(); int prev = 0; MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); if (!(!env && !country && !app && !browser)) { if (env) { distinct.append("exq.Environment"); prev++;//from ww w . j a va2s. co m } if (country) { if (prev != 0) { prev = 0; distinct.append(","); } distinct.append("exq.Country"); prev++; } if (browser) { if (prev != 0) { prev = 0; distinct.append(","); } distinct.append("exq.Browser"); prev++; } if (app) { if (prev != 0) { prev = 0; distinct.append(","); } distinct.append("tec.Application"); } query.append("SELECT tec.test, tec.testcase, exq.tag, "); query.append(distinct.toString()); query.append( " FROM testcase tec LEFT JOIN testcaseexecutionqueue exq ON exq.Test = tec.Test AND exq.TestCase = tec.TestCase WHERE tag = ? GROUP BY "); query.append(distinct.toString()); } else { //If there is no distinct, select nothing query.append("SELECT * FROM testcaseexecutionqueue exq WHERE 1=0 AND tag = ?"); } Connection connection = this.databaseSpring.connect(); List<TestCaseExecutionInQueue> column = new ArrayList<TestCaseExecutionInQueue>(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, tag); try { ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { TestCaseExecutionInQueue tmp = new TestCaseExecutionInQueue(); tmp.setTest(resultSet.getString("tec.test")); tmp.setTestCase(resultSet.getString("tec.testcase")); tmp.setTag(resultSet.getString("exq.tag")); if (env) { tmp.setEnvironment(resultSet.getString("Environment")); } else { tmp.setEnvironment(""); } if (country) { tmp.setCountry(resultSet.getString("Country")); } else { tmp.setCountry(""); } if (browser) { tmp.setBrowser(resultSet.getString("Browser")); } else { tmp.setBrowser(""); } if (app) { Application application = factoryApplication.create(resultSet.getString("Application")); tmp.setApplicationObj(application); } column.add(tmp); } msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution") .replace("%OPERATION%", "SELECT")); answer = new AnswerList(column, column.size()); } catch (SQLException exception) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); column = null; } finally { if (resultSet != null) { resultSet.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); column = null; } finally { if (preStat != null) { preStat.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.WARN, ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionInQueueDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); } } answer.setResultMessage(msg); return answer; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public AnswerList readDistinctEnvCoutnryBrowserByTag(String tag) { AnswerList answer = new AnswerList(); StringBuilder query = new StringBuilder(); MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); query.append(//from w w w . j av a2s .c o m "SELECT exe.* FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY exe.Environment, exe.Country, exe.Browser, exe.ControlStatus"); Connection connection = this.databaseSpring.connect(); List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, tag); try { ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { testCaseExecutionList.add(this.loadFromResultSet(resultSet)); } msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution") .replace("%OPERATION%", "SELECT")); answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size()); } catch (SQLException exception) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); testCaseExecutionList = null; } finally { if (resultSet != null) { resultSet.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); testCaseExecutionList = null; } finally { if (preStat != null) { preStat.close(); } } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.WARN, ex.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException ex) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + ex.toString()); } } answer.setResultMessage(msg); return answer; }
From source file:org.cerberus.crud.dao.impl.TestCaseExecutionDAO.java
@Override public AnswerList readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException { MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); AnswerList answer = new AnswerList(); List<String> individalColumnSearchValues = new ArrayList<String>(); final StringBuffer query = new StringBuffer(); query.append("SELECT * FROM testcaseexecution exe "); query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase "); query.append("left join application app on tec.application = app.application "); query.append("where exe.ID IN "); query.append("(select MAX(exe.ID) from testcaseexecution exe "); query.append("where 1=1 "); if (!StringUtil.isNullOrEmpty(tag)) { query.append("and exe.tag = ? "); }//from w ww.j a v a 2s. co m query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) "); if (!StringUtil.isNullOrEmpty(searchTerm)) { query.append("and (exe.`test` like ? "); query.append(" or exe.`testCase` like ? "); query.append(" or exe.`application` like ? "); query.append(" or tec.`bugid` like ? "); query.append(" or tec.`priority` like ? "); query.append(" or tec.`description` like ? )"); } if (individualSearch != null && !individualSearch.isEmpty()) { query.append(" and ( 1=1 "); for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) { query.append(" and "); query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue())); individalColumnSearchValues.addAll(entry.getValue()); } query.append(" ) "); } if (!StringUtil.isNullOrEmpty(sort)) { query.append(" order by ").append(sort); } if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) { query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED); } else { query.append(" limit ").append(start).append(" , ").append(amount); } // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); LOG.debug("SQL.param.tag : " + tag); } List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>(); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); int i = 1; if (!StringUtil.isNullOrEmpty(tag)) { preStat.setString(i++, tag); } if (!Strings.isNullOrEmpty(searchTerm)) { preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); } for (String individualColumnSearchValue : individalColumnSearchValues) { preStat.setString(i++, individualColumnSearchValue); } try { ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet)); } msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution") .replace("%OPERATION%", "SELECT")); // answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size()); answer.setTotalRows(testCaseExecutionList.size()); } catch (SQLException exception) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); testCaseExecutionList = null; } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); testCaseExecutionList = null; } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); testCaseExecutionList = null; } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(TestCaseExecutionDAO.class.getName(), Level.WARN, e.toString()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription( msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!")); } } answer.setResultMessage(msg); answer.setDataList(testCaseExecutionList); return answer; }