Best Cerberus-source code snippet using org.cerberus.crud.utils.RequestDbUtils.RequestDbUtils
Source: TestCaseDepDAO.java
...22import org.apache.logging.log4j.Logger;23import org.cerberus.crud.dao.ITestCaseDepDAO;24import org.cerberus.crud.entity.TestCase;25import org.cerberus.crud.entity.TestCaseDep;26import org.cerberus.crud.utils.RequestDbUtils;27import org.cerberus.database.DatabaseSpring;28import org.cerberus.exception.CerberusException;29import org.springframework.beans.factory.annotation.Autowired;30import org.springframework.stereotype.Repository;31import java.sql.PreparedStatement;32import java.sql.ResultSet;33import java.sql.SQLException;34import java.util.List;35import java.util.stream.Collectors;36@Repository37public class TestCaseDepDAO implements ITestCaseDepDAO {38 @Autowired39 private DatabaseSpring databaseSpring;40 private static final Logger LOG = LogManager.getLogger(TestCaseDepDAO.class);41 @Override42 public TestCaseDep readByKey(String test, String testcase, String testDep, String testcaseDep) throws CerberusException {43 String query = "SELECT * FROM `testcasedep` tcd where tcd.Test = ? and tcd.TestCase = ? and tcd.DepTest = ? and tcd.DepTestCase = ?";44 return RequestDbUtils.executeQuery(databaseSpring, query,45 ps -> {46 int idx = 1;47 ps.setString(idx++, test);48 ps.setString(idx++, testcase);49 ps.setString(idx++, testDep);50 ps.setString(idx++, testcaseDep);51 },52 rs -> this.loadResult(rs)53 );54 }55 @Override56 public List<TestCaseDep> readByTestAndTestCase(String test, String testcase) throws CerberusException {57 String query = "SELECT tcd.*, tc.description as depDescription FROM `testcasedep` tcd " +58 "inner join testcase tc on tcd.DepTest = tc.Test and tcd.DepTestCase = tc.TestCase " +59 "where tcd.Test = ? and tcd.TestCase = ?";60 return RequestDbUtils.executeQueryList(databaseSpring, query,61 ps -> {62 int idx = 1;63 ps.setString(idx++, test);64 ps.setString(idx++, testcase);65 },66 rs -> {67 TestCaseDep dep = this.loadResult(rs);68 dep.setDepDescription(rs.getString("depDescription"));69 return dep;70 }71 );72 }73 @Override74 public List<TestCaseDep> readByTestAndTestCase(List<TestCase> testCaseList) throws CerberusException {75 String query = "SELECT tcd.*, tc.description as depDescription FROM `testcasedep` tcd " +76 "inner join testcase tc on tcd.DepTest = tc.Test and tcd.DepTestCase = tc.TestCase " +77 "where 1=1" +78 testCaseList.stream().map(s -> " and tcd.Test = ? and tcd.TestCase = ?").collect(Collectors.joining());79 return RequestDbUtils.executeQueryList(databaseSpring, query,80 ps -> {81 int idx = 1;82 for(TestCase tc : testCaseList) {83 ps.setString(idx++, tc.getTest());84 ps.setString(idx++, tc.getTestCase());85 }86 },87 rs -> {88 TestCaseDep dep = this.loadResult(rs);89 dep.setDepDescription(rs.getString("depDescription"));90 return dep;91 }92 );93 }94 @Override95 public void create(TestCaseDep testCaseDep) throws CerberusException {96 String query = "INSERT INTO `testcasedep`" +97 "(`Test`, `TestCase`, `Type`, `DepTest`, `DepTestCase`, `DepEvent`, `Active`, `Description`, `UsrCreated`, `DateCreated`, `UsrModif`, `DateModif` )" +98 "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";99 RequestDbUtils.executeUpdate(databaseSpring, query,100 ps -> this.setRequestData(ps,testCaseDep,false)101 );102 }103 @Override104 public void update(TestCaseDep testCaseDep) throws CerberusException {105 String query = "UPDATE `testcasedep` " +106 " SET `Test` = ?, `TestCase` = ?, `Type` = ?, `DepTest` = ?, `DepTestCase` = ?, `DepEvent` = ?, `Active` = ?, `Description` = ?, " +107 "`UsrCreated` = ?, `DateCreated` = ?, `UsrModif` = ?, `DateModif` = ? where id=?";108 RequestDbUtils.executeUpdate(databaseSpring, query,109 ps -> this.setRequestData(ps,testCaseDep,true)110 );111 }112 @Override113 public void delete(TestCaseDep testCaseDep) throws CerberusException {114 String query = "DELETE FROM `testcasedep` where id=?";115 RequestDbUtils.executeUpdate(databaseSpring, query,116 ps -> {117 int idx = 1;118 ps.setLong(idx++, testCaseDep.getId());119 }120 );121 }122 private void setRequestData(PreparedStatement ps, TestCaseDep testCaseDep, boolean setId) throws SQLException {123 int idx = 1;124 ps.setString(idx++, testCaseDep.getTest());125 ps.setString(idx++, testCaseDep.getTestCase());126 ps.setString(idx++, testCaseDep.getType());127 ps.setString(idx++, testCaseDep.getDepTest());128 ps.setString(idx++, testCaseDep.getDepTestCase());129 ps.setString(idx++, testCaseDep.getDepEvent());...
Check out the latest blogs from LambdaTest on this topic:
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!