How to use isOnTransaction method of org.cerberus.database.DatabaseSpring class

Best Cerberus-source code snippet using org.cerberus.database.DatabaseSpring.isOnTransaction

Source:TestDataLibDataDAO.java Github

copy

Full Screen

...102 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);103 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));104 } finally {105 try {106 if (!this.databaseSpring.isOnTransaction()) {107 if (connection != null) {108 connection.close();109 }110 }111 } catch (SQLException ex) {112 LOG.warn("Unable to close connection : " + ex.toString());113 }114 }115 answer.setResultMessage(msg);116 answer.setItem(result);117 return answer;118 }119 @Override120 public AnswerItem readByKeyTech(Integer testDataLibDataID) {121 AnswerItem answer = new AnswerItem();122 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);123 TestDataLibData result = null;124 final String query = "SELECT * FROM testdatalibdata where `testdatalibdataid`=? ";125 // Debug message on SQL.126 if (LOG.isDebugEnabled()) {127 LOG.debug("SQL : " + query);128 LOG.debug("SQL.param.testDataLibDataID : " + testDataLibDataID);129 }130 Connection connection = this.databaseSpring.connect();131 try {132 PreparedStatement preStat = connection.prepareStatement(query);133 preStat.setInt(1, testDataLibDataID);134 try {135 ResultSet resultSet = preStat.executeQuery();136 try {137 if (resultSet.first()) {138 result = this.loadFromResultSet(resultSet);139 } else {140 //specific message for gefromdatalib141 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);142 }143 } catch (SQLException exception) {144 LOG.error("Unable to execute query : " + exception.toString());145 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);146 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));147 } finally {148 if (resultSet != null) {149 resultSet.close();150 }151 }152 } catch (SQLException exception) {153 LOG.error("Unable to execute query : " + exception.toString());154 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);155 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));156 } finally {157 if (preStat != null) {158 preStat.close();159 }160 }161 } catch (SQLException exception) {162 LOG.error("Unable to execute query : " + exception.toString());163 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);164 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));165 } finally {166 try {167 if (!this.databaseSpring.isOnTransaction()) {168 if (connection != null) {169 connection.close();170 }171 }172 } catch (SQLException ex) {173 LOG.warn("Unable to close connection : " + ex.toString());174 }175 }176 answer.setResultMessage(msg);177 answer.setItem(result);178 return answer;179 }180 @Override181 public AnswerList<TestDataLibData> readByVarious(Integer testDataLibID, String columnEmpty, String parsingAnswerEmpty, String columnPositionEmpty) {182 List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();183 AnswerList answer = new AnswerList();184 MessageEvent msg;185 StringBuilder query = new StringBuilder();186 query.append("SELECT * FROM testdatalibdata where `testDataLibID` = ? ");187 if ("Y".equalsIgnoreCase(columnEmpty)) {188 query.append(" and `Column`='' ");189 } else if ("N".equalsIgnoreCase(columnEmpty)) {190 query.append(" and `Column`!='' ");191 }192 if ("Y".equalsIgnoreCase(parsingAnswerEmpty)) {193 query.append(" and `ParsingAnswer`='' ");194 } else if ("N".equalsIgnoreCase(parsingAnswerEmpty)) {195 query.append(" and `ParsingAnswer`!='' ");196 }197 if ("Y".equalsIgnoreCase(columnPositionEmpty)) {198 query.append(" and `columnPosition`='' ");199 } else if ("N".equalsIgnoreCase(columnPositionEmpty)) {200 query.append(" and `columnPosition`!='' ");201 }202 // Debug message on SQL.203 if (LOG.isDebugEnabled()) {204 LOG.debug("SQL : " + query);205 LOG.debug("SQL.param.testDataLibID : " + testDataLibID);206 }207 Connection connection = this.databaseSpring.connect();208 try {209 PreparedStatement preStat = connection.prepareStatement(query.toString());210 preStat.setInt(1, testDataLibID);211 try {212 ResultSet resultSet = preStat.executeQuery();213 try {214 while (resultSet.next()) {215 testDataLibListData.add(this.loadFromResultSet(resultSet));216 }217 if (testDataLibListData.isEmpty()) {218 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);219 } else {220 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);221 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));222 }223 } catch (SQLException exception) {224 LOG.error("Unable to execute query : " + exception.toString());225 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);226 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));227 testDataLibListData.clear();228 } finally {229 if (resultSet != null) {230 resultSet.close();231 }232 }233 } catch (SQLException exception) {234 LOG.error("Unable to execute query : " + exception.toString());235 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);236 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));237 testDataLibListData.clear();238 } finally {239 if (preStat != null) {240 preStat.close();241 }242 }243 } catch (SQLException exception) {244 LOG.error("Unable to execute query : " + exception.toString());245 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);246 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));247 testDataLibListData.clear();248 } finally {249 try {250 if (!this.databaseSpring.isOnTransaction()) {251 if (connection != null) {252 connection.close();253 }254 }255 } catch (SQLException ex) {256 LOG.warn("Unable to close connection : " + ex.toString());257 }258 }259 answer.setDataList(testDataLibListData);260 answer.setTotalRows(testDataLibListData.size());261 answer.setResultMessage(msg);262 return answer;263 }264 @Override265 public AnswerList<TestDataLibData> readAll() {266 AnswerList answerList = new AnswerList();267 List<TestDataLibData> list = new ArrayList<TestDataLibData>();268 MessageEvent msg;269 final String query = "SELECT * FROM testdatalibdata";270 // Debug message on SQL.271 if (LOG.isDebugEnabled()) {272 LOG.debug("SQL : " + query);273 }274 Connection connection = this.databaseSpring.connect();275 try {276 PreparedStatement preStat = connection.prepareStatement(query);277 try {278 ResultSet resultSet = preStat.executeQuery();279 try {280 while (resultSet.next()) {281 list.add(this.loadFromResultSet(resultSet));282 }283 if (list.isEmpty()) {284 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);285 } else {286 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);287 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));288 }289 } catch (SQLException exception) {290 LOG.error("Unable to execute query : " + exception.toString());291 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);292 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));293 list.clear();294 } finally {295 if (resultSet != null) {296 resultSet.close();297 }298 }299 } catch (SQLException exception) {300 LOG.error("Unable to execute query : " + exception.toString());301 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);302 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));303 list.clear();304 } finally {305 if (preStat != null) {306 preStat.close();307 }308 }309 } catch (SQLException exception) {310 LOG.error("Unable to execute query : " + exception.toString());311 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);312 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));313 list.clear();314 } finally {315 try {316 if (!this.databaseSpring.isOnTransaction()) {317 if (connection != null) {318 connection.close();319 }320 }321 } catch (SQLException ex) {322 LOG.warn("Unable to close connection : " + ex.toString());323 }324 }325 answerList.setDataList(list);326 answerList.setTotalRows(list.size());327 answerList.setResultMessage(msg);328 return answerList;329 }330 @Override331 public AnswerList readByCriteria(int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {332 AnswerList answer = new AnswerList();333 MessageEvent msg;334 int nrTotalRows = 0;335 List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();336 StringBuilder gSearch = new StringBuilder();337 StringBuilder searchSQL = new StringBuilder();338 StringBuilder query = new StringBuilder();339 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 340 //were applied -- used for pagination p341 query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testdatalibdata ");342 gSearch.append(" where (`subdata` like '%");343 gSearch.append(searchTerm);344 gSearch.append("%'");345 gSearch.append(" or `value` like '%");346 gSearch.append(searchTerm);347 gSearch.append("%'");348 gSearch.append(" or `column` like '%");349 gSearch.append(searchTerm);350 gSearch.append("%'");351 gSearch.append(" or `parsinganswer` like '%");352 gSearch.append(searchTerm);353 gSearch.append("%'");354 gSearch.append(" or `columnPosition` like '%");355 gSearch.append(searchTerm);356 gSearch.append("%'");357 gSearch.append(" or `description` like '%");358 gSearch.append("%') ");359 if (!searchTerm.equals("") && !individualSearch.equals("")) {360 searchSQL.append(gSearch.toString());361 searchSQL.append(" and ");362 searchSQL.append(individualSearch);363 } else if (!individualSearch.equals("")) {364 searchSQL.append(" where `");365 searchSQL.append(individualSearch);366 searchSQL.append("`");367 } else if (!searchTerm.equals("")) {368 searchSQL.append(gSearch.toString());369 }370 query.append(searchSQL);371 query.append("order by `");372 query.append(colName);373 query.append("` ");374 query.append(dir);375 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {376 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);377 } else {378 query.append(" limit ").append(start).append(" , ").append(amount).append(" ");379 }380 // Debug message on SQL.381 if (LOG.isDebugEnabled()) {382 LOG.debug("SQL : " + query);383 }384 Connection connection = this.databaseSpring.connect();385 try {386 PreparedStatement preStat = connection.prepareStatement(query.toString());387 try {388 ResultSet resultSet = preStat.executeQuery();389 try {390 //gets the data391 while (resultSet.next()) {392 testDataLibListData.add(this.loadFromResultSet(resultSet));393 }394 //get the total number of rows395 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");396 if (resultSet != null && resultSet.next()) {397 nrTotalRows = resultSet.getInt(1);398 }399 if (testDataLibListData.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.400 LOG.warn("Partial Result in the query.");401 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);402 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));403 } else if (testDataLibListData.isEmpty()) {404 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);405 } else {406 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);407 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));408 }409 } catch (SQLException exception) {410 LOG.error("Unable to execute query : " + exception.toString());411 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);412 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));413 testDataLibListData.clear();414 } finally {415 if (resultSet != null) {416 resultSet.close();417 }418 }419 } catch (SQLException exception) {420 LOG.error("Unable to execute query : " + exception.toString());421 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);422 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));423 } finally {424 if (preStat != null) {425 preStat.close();426 }427 }428 } catch (SQLException exception) {429 LOG.error("Unable to execute query : " + exception.toString());430 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);431 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));432 } finally {433 try {434 if (!this.databaseSpring.isOnTransaction()) {435 if (connection != null) {436 connection.close();437 }438 }439 } catch (SQLException ex) {440 LOG.warn("Unable to close connection : " + ex.toString());441 }442 }443 answer.setTotalRows(nrTotalRows);444 answer.setResultMessage(msg);445 answer.setDataList(testDataLibListData);446 return answer;447 }448 @Override449 public AnswerList readByName(String testDataLibName) {450 AnswerList answer = new AnswerList();451 MessageEvent msg;452 List<TestDataLibData> testDataLibListData = new ArrayList<TestDataLibData>();453 StringBuilder query = new StringBuilder();454 query.append("SELECT tdld.*, tdl.`name`, tdl.type, tdl.system, tdl.country, tdl.environment FROM testdatalibdata tdld ");455 query.append("inner join testdatalib tdl ");456 query.append("on tdld.testDataLibID = tdl.testDataLibID ");457 query.append("and tdl.`name` LIKE ? ");458 // Debug message on SQL.459 if (LOG.isDebugEnabled()) {460 LOG.debug("SQL : " + query);461 LOG.debug("SQL.param.testDataLibName : " + testDataLibName);462 }463 Connection connection = this.databaseSpring.connect();464 try {465 PreparedStatement preStat = connection.prepareStatement(query.toString());466 preStat.setString(1, testDataLibName);467 try {468 ResultSet resultSet = preStat.executeQuery();469 try {470 while (resultSet.next()) {471 testDataLibListData.add(this.loadFromResultSet(resultSet));472 }473 if (testDataLibListData.isEmpty()) {474 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);475 } else {476 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);477 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));478 }479 } catch (SQLException exception) {480 LOG.error("Unable to execute query : " + exception.toString());481 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);482 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));483 } finally {484 if (resultSet != null) {485 resultSet.close();486 }487 }488 } catch (SQLException exception) {489 LOG.error("Unable to execute query : " + exception.toString());490 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);491 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));492 } finally {493 if (preStat != null) {494 preStat.close();495 }496 }497 } catch (SQLException exception) {498 LOG.error("Unable to execute query : " + exception.toString());499 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);500 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));501 } finally {502 try {503 if (!this.databaseSpring.isOnTransaction()) {504 if (connection != null) {505 connection.close();506 }507 }508 } catch (SQLException ex) {509 LOG.warn("Unable to close connection : " + ex.toString());510 }511 }512 answer.setResultMessage(msg);513 answer.setDataList(testDataLibListData);514 answer.setTotalRows(testDataLibListData.size()); //all lines are retrieved 515 return answer;516 }517 @Override...

Full Screen

Full Screen

isOnTransaction

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecution;2import org.cerberus.engine.execution.IExecutionThreadService;3import org.cerberus.engine.execution.impl.ExecutionThreadService;4import org.cerberus.engine.queuemanagement.IExecutionThreadPoolService;5import org.cerberus.engine.queuemanagement.impl.ExecutionThreadPoolService;6import org.cerberus.engine.threadpool.IExecutionThreadPool;7import org.cerberus.engine.threadpool.impl.ExecutionThreadPool;8import org.cerberus.crud.entity.TestCaseExecutionQueue;9import org.cerberus.crud.service.ITestCaseExecutionQueueService;10import org.cerberus.crud.service.impl.TestCaseExecutionQueueService;11import org.cerberus.crud.service.impl.TestCaseExecutionService;12import org.cerberus.log.MyLogger;13import org.cerberus.util.answer.AnswerItem;14import org.springframework.beans.factory.annotation.Autowired;15import org.springframework.stereotype.Service;16import java.util.List;

Full Screen

Full Screen

isOnTransaction

Using AI Code Generation

copy

Full Screen

1import org.cerberus.database.DatabaseSpring;2import org.cerberus.engine.entity.MessageEvent;3import org.cerberus.engine.entity.MessageGeneral;4import org.cerberus.engine.entity.MessageEventEnum;5import org.cerberus.util.answer.AnswerItem;6import org.cerberus.util.answer.Answer;7import org.cerberus.util.answer.AnswerList;8import org.cerberus.util.answer.AnswerUtil;9import org.cerberus.crud.entity.Application;10import org.cerberus.crud.entity.CountryEnvironmentDatabase;11import org.cerberus.crud.entity.CountryEnvironmentParameters;12import org.cerberus.crud.entity.CountryEnvironmentParameters;13import org.cerberus.crud.factory.IFactoryCountryEnvironmentParameters;14import org.cerberus.crud.service.ICountryEnvironmentParametersService;15import org.cerberus.cru

Full Screen

Full Screen

isOnTransaction

Using AI Code Generation

copy

Full Screen

1public boolean isOnTransaction(String connectionName) throws CerberusException {2 boolean result = false;3 try {4 Connection connection = this.connect(connectionName);5 result = connection.getAutoCommit();6 } catch (SQLException exception) {7 LOG.error("Unable to check if connection " + connectionName + " is on a transaction", exception);8 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));9 }10 return result;11}12public void commitTransaction(String connectionName) throws CerberusException {13 try {14 Connection connection = this.connect(connectionName);15 connection.commit();16 connection.setAutoCommit(true);17 } catch (SQLException exception) {18 LOG.error("Unable to commit transaction", exception);19 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));20 }21}22public void rollbackTransaction(String connectionName) throws CerberusException {23 try {24 Connection connection = this.connect(connectionName);25 connection.rollback();26 connection.setAutoCommit(true);27 } catch (SQLException exception) {28 LOG.error("Unable to rollback transaction", exception);29 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));30 }31}32public void startTransaction(String connectionName) throws CerberusException {33 try {34 Connection connection = this.connect(connectionName);35 connection.setAutoCommit(false);36 } catch (SQLException exception) {37 LOG.error("Unable to start transaction", exception);38 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));39 }40}41public void closeConnection(String connectionName) throws CerberusException {42 try {43 Connection connection = this.connect(connectionName);44 connection.close();45 } catch (SQLException exception) {46 LOG.error("Unable to close connection", exception);47 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));48 }49}50public void closeAllConnection() throws CerberusException {51 for (Map.Entry<String, Connection> entry : this.connections.entrySet()) {52 try {53 entry.getValue().close();54 } catch (SQLException exception) {55 LOG.error("Unable to close connection", exception);56 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CONNECTION_ERROR));57 }58 }59}60private Connection connect(String connectionName) throws CerberusException {61 Connection connection = this.connections.get(connectionName);

Full Screen

Full Screen

isOnTransaction

Using AI Code Generation

copy

Full Screen

1if (isOnTransaction()) {2 echo "On transaction";3} else {4 echo "Not on transaction";5}6if (isOnTransaction()) {7 $sql = "insert into mytable values (1,'test')";8 $statement = $this->databaseSpring->prepare($sql);9 $statement->execute();10} else {11 $this->databaseSpring->beginTransaction();12 try {13 $sql = "insert into mytable values (1,'test')";14 $statement = $this->databaseSpring->prepare($sql);15 $statement->execute();16 $this->databaseSpring->commit();17 } catch (Exception $ex) {18 $this->databaseSpring->rollBack();19 }20}21if (isOnTransaction()) {22 $sql = "insert into mytable values (1,'test')";23 $statement = $this->databaseSpring->prepare($sql);24 $statement->execute();25} else {26 $this->databaseSpring->beginTransaction();27 try {28 $sql = "insert into mytable values (1,'test')";29 $statement = $this->databaseSpring->prepare($sql);30 $statement->execute();31 $this->databaseSpring->commit();32 } catch (Exception $ex) {33 $this->databaseSpring->rollBack();34 }35}36if (isOnTransaction()) {37 $sql = "insert into mytable values (1,'test')";38 $statement = $this->databaseSpring->prepare($sql);39 $statement->execute();40} else {41 $this->databaseSpring->beginTransaction();42 try {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful